Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
can.when = Deferred.when = function () {
var args = can.makeArray(arguments);
if (args.length < 2) {
var obj = args[0];
if (obj && (can.isFunction(obj.isResolved) && can.isFunction(obj.isRejected))) {
return obj;
} else {
return Deferred()
.resolve(obj);
}
} else {
var df = Deferred(),
done = 0,
// Resolve params -- params of each resolve, we need to track them down
// to be able to pass them in the correct order if the master
// needs to be resolved.
rp = [];
can.each(args, function (arg, j) {
can.map = function (arr, fn) {
return Y.Array.map(can.makeArray(arr || []), fn);
};
// Map object helpers.
Zepto.fn[name] = function () {
var elems,
args = can.makeArray(arguments);
if (args[0] != null) {
// documentFragment
if (typeof args[0] === "string") {
args[0] = $.zepto.fragment(args[0]);
}
if (args[0].nodeType === 11) {
elems = can.makeArray(args[0].childNodes);
} else if(args[0] instanceof Zepto.fn.constructor) {
elems = can.makeArray(args[0]);
} else {
elems = [args[0]];
}
}
var ret = original.apply(this, args);
can.inserted(elems);
return ret;
};
});
Zepto.fn[name] = function () {
var elems,
args = can.makeArray(arguments);
if (args[0] != null) {
// documentFragment
if (typeof args[0] === "string") {
args[0] = $.zepto.fragment(args[0]);
}
if (args[0].nodeType === 11) {
elems = can.makeArray(args[0].childNodes);
} else if(args[0] instanceof Zepto.fn.constructor) {
elems = can.makeArray(args[0]);
} else {
elems = [args[0]];
}
}
var ret = original.apply(this, args);
can.inserted(elems);
return ret;
};
});
}
// 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 = {
type: event
};
}
event.target = event.target || item;
can.dispatch.call(item, event, can.makeArray(args));
}
};
can.delegate = function (selector, ev, cb) {
this.each(function () {
if (this.getElementsByTagName) {
$.cleanData([this].concat(can.makeArray(this.getElementsByTagName('*'))));
}
});
return $_remove.call(this);
grab: function (el) {
var elems;
if (el && el.nodeType === 11) {
elems = can.makeArray(el.childNodes);
} else {
elems = [el];
}
var ret = grab.apply(this, arguments);
can.inserted(elems);
return ret;
},
set: function (attrName, value) {
if (bubble === false) {
$([obj])
.triggerHandler(event, args);
} else {
$([obj])
.trigger(event, args);
}
} else {
if (typeof event === "string") {
event = {
type: event
};
}
event.target = event.target || obj;
can.dispatch.call(obj, event, can.makeArray(args));
}
};
on: function () {
var args = can.makeArray(arguments);
return Y.Event._attach(args, {
facade: false
});
}
};
Y.DOM.addHTML = function (node, content, where) {
if (typeof content === "string" || typeof content === "number") {
content = can.buildFragment(content, node.ownerDocument || node.getDOMNode().ownerDocument);
}
var elems;
if (content.nodeType === 11) {
elems = can.makeArray(content.childNodes);
} else {
elems = [content];
}
var ret = addHTML.call(this, node, content, where);
can.inserted(elems);
return ret;
};