Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
Y.Node.prototype.on = function (type, fn) {
if (type === "attributes") {
// YUI changes where the extra data comes from
var el = can.$(this);
can.data(el, "canHasAttributesBindings", (can.data(el, "canHasAttributesBindings") || 0) + 1);
var handle = oldOn.apply(this, arguments),
oldDetach = handle.detach;
handle.detach = function () {
var cur = can.data(el, "canHasAttributesBindings") || 0;
if (cur <= 0) {
can.cleanData(el, "canHasAttributesBindings");
} else {
can.data(el, "canHasAttributesBindings", cur - 1);
}
return oldDetach.apply(this, arguments);
};
return handle;
} else {
return oldOn.apply(this, arguments);
can.unbind = function (ev, cb) {
// If we can bind to it...
if (this.unbind && this.unbind !== can.unbind) {
this.unbind(ev, cb);
} else if (this.nodeName && (this.nodeType && this.nodeType !== 11)) {
can.$(this)
.removeEvent(ev, cb);
} else if (this.removeEvent) {
this.removeEvent(ev, cb);
} else {
// Make it bind-able...
can.removeEvent.call(this, ev, cb);
}
return this;
};
// Alias on/off to bind/unbind respectively
can.delegate = function (selector, ev, cb) {
if (this.on || this.nodeType) {
addBinding(can.$(this), selector, ev, cb);
} else if (this.delegate) {
this.delegate(selector, ev, cb);
} else {
// make it bind-able ...
can.bind.call(this, ev, cb);
}
return this;
};
can.undelegate = function (selector, ev, cb) {
can.inserted = function (elems, document) {
if(!elems.length) {
return;
}
// Turn the `elems` property into an array to prevent mutations from changing the looping.
elems = can.makeArray(elems);
var doc = document || elems[0].ownerDocument || elems[0],
inDocument = false,
// Gets the `doc` to use as a reference for finding out whether the element is in the document.
root = can.$(doc.contains ? doc : doc.body),
children;
// Go through `elems` and trigger the `inserted` event.
// If the first element is not in the document (a Document Fragment) it will exit the function. If it is in the document it sets the `inDocument` flag to true. This means that we only check for the first element and either exit the function or start triggering "inserted" for child elements.
for (var i = 0, elem;
(elem = elems[i]) !== undefined; i++) {
if (!inDocument) {
if (elem.getElementsByTagName) {
if (can.has(root, elem)
.length) {
inDocument = true;
} else {
return;
}
} else {
continue;
var propagating = true;
if (item.fireEvent) {
item = item[0] || item;
// walk up parents to simulate bubbling .
while (item && propagating) {
// Handle walking yourself.
if (!event.type) {
event = {
type: event,
target: item,
stopPropagation: function () {
propagating = false;
}
};
}
var events = item !== window ? can.$(item)
.retrieve('events')[0] : item.retrieve('events');
if (events && events[event.type]) {
events[event.type].keys.each(function (fn) {
fn.apply(item, [event].concat(args));
}, this);
}
// If we are bubbling, get parent node.
if (bubble && item.parentNode && item.parentNode.nodeType !== 11) {
item = item.parentNode;
} else {
item = null;
}
}
} else {
if (typeof event === 'string') {
event = {
this.each(function () {
var el = can.$(this),
cur = can.data(el, "canHasAttributesBindings") || 0;
if (cur <= 0) {
can.data(el, "canHasAttributesBindings", 0);
} else {
can.data(el, "canHasAttributesBindings", cur - 1);
}
});
}
onRemove: function () {
var el = can.$(this),
cur = can.data(el, "canHasAttributesBindings") || 0;
if (cur <= 0) {
can.cleanData(el, "canHasAttributesBindings");
} else {
can.data(el, "canHasAttributesBindings", cur - 1);
}
}
};
can.undelegate = function (selector, ev, cb) {
if (this.on || this.nodeType) {
removeBinding(can.$(this), selector, ev, cb);
} else if (this.undelegate) {
this.undelegate(selector, ev, cb);
} else {
can.unbind.call(this, ev, cb);
}
return this;
};
nodelist.each(function (node) {
node = can.$(node);
var events = can.data(node, 'events'),
eventName = ev + ':' + selector;
if (!events) {
can.data(node, 'events', events = {});
}
if (!events[eventName]) {
events[eventName] = {};
}
if (cb.__bindingsIds === undefined) {
cb.__bindingsIds = yuiEventId++;
}
events[eventName][cb.__bindingsIds] = selector ? node.item(0)
.delegate(ev, cb, selector) : node.item(0)
.on(ev, cb);
});
} else {
onAdd: function () {
var el = can.$(this);
can.data(el, "canHasAttributesBindings", (can.data(el, "canHasAttributesBindings") || 0) + 1);
},
onRemove: function () {