Events - Yapapaya/jquery-cloneya GitHub Wiki
Namespace
All CloneYa events have a namespace of cloneya. So, each event can be accessed as eventname.cloneya
Clone Events
Sequence
When maximum limit is reached:
clone
(params: event, toClone)
The main clone event. This is triggered by the click event of the cloneButton
. Passes the item to be cloned. CloneYa itself binds to this event to try and clone toClone
.
$clonecontainer.on('clone.cloneya', function (event, toClone) {
// do something
});
If not using cloneButton
, you could trigger the cloning from an external control like this:
// $toclone is what we want to clone
$customcloneButton.on('click',function(){
$clonecontainer.triggerHandler('clone.cloneya',[$toclone]);
});
Was called clone_clone in versions < 1.0.
before_clone
(params: event, toClone)
Triggered just before the jQuery clone()
function is run. Passes the item to be cloned.
Was called clone_before_clone in versions < 1.0.
form_input
(params: event, input, toClone, newClone)
Triggered for each form input in the newly created clone. Passes the input itself, the item to be cloned and the newly created clone. Useful for manipulating indexes of form inputs.
$clonecontainer.on('form_input.cloneya', function (event, input, toClone, newClone) {
// manipulate input's name attribute to manipulate index
});
Was called clone_form_input in versions < 1.0.
after_clone
(params: event, toClone, newClone)
Triggered after the jQuery clone()
function is run and form_input
is done. Passes the item to be cloned and the new clone created.
Was called clone_after_clone in versions < 1.0.
before_append
(params: event, toClone, newClone)
Triggered just before the new clone is appended to the DOM. Passes the item to be cloned and the new clone created.
Was called clone_before_append in versions < 1.0.
after_append
(params: event, toClone, newClone)
Triggered just after the new clone is appended to the DOM. Passes the item to be cloned and the new clone created.
Was called clone_after_append in versions < 1.0.
maximum
(params: event, maximumCount, toClone)
Trigerred when the maximum count of clones allowed, is exceeded. Passes the maximum count and the item to be cloned. Useful to display an error message.
$clonecontainer.on('maximum.cloneya', function (event, maximumCount, toClone) {
alert("You can't have more than " + maximumCount + " clones.");
});
Was called clone_limit in versions < 1.0.
Delete Events
Sequence
When minimum limit is reached:
delete
(params: event, toDelete)
The main delete event. This is triggered by the click event of the deleteButton
. Passes the item to be deleted. CloneYa itself binds to this event to try and delete toDelete
.
$clonecontainer.on('delete.cloneya', function (event, toDelete) {
// do something
});
If not using deleteButton
, you could trigger the deletion from an external control like this:
// $todelete is what we want to clone
$customdeleteButton.on('click',function(){
$clonecontainer.triggerHandler('delete.cloneya',[$todelete]);
});
Was called clone_delete in versions < 1.0.
before_delete
(params: event, toDelete, cloneCount)
Triggered just before the item is deleted. Passes the item to be deleted and the number of sibling clones.
Was called clone_before_delete in versions < 1.0.
remove
(params: event, toDelete)
Triggered by CloneYa. CloneYa then binds to this event to remove the item from DOM. Passes the item to be deleted.
This is done so that, one may replace this way of removal with a different one:
$clonecontainer
.off('remove.cloneya')
.on('remove.cloneya', function (event, clone) {
clone.css('background-color', 'red');
$(clone).slideToggle('slow', function () {
$(clone).remove();
});
})
after_delete
(*params: *)
Triggered just after the item is deleted. Passes no variables.
Was called clone_after_delete in versions < 1.0.
minimum
(params: event, minimumCount, toDelete)
Trigerred when the minimum count of clones required is reached. Passes the minimum count and the item to be deleted. Useful to display an error message.
$clonecontainer.on('minimum.cloneya', function (event, minimumCount, toDelete) {
alert("You can't have less than " + minimumCount + " clones.");
});