can
Version:
MIT-licensed, client-side, JavaScript framework that makes building rich web applications easy.
1,320 lines (1,315 loc) • 373 kB
JavaScript
/*!
* CanJS - 2.3.34
* http://canjs.com/
* Copyright (c) 2018 Bitovi
* Mon, 30 Apr 2018 20:56:51 GMT
* Licensed MIT
*/
/*[global-shim-start]*/
(function (exports, global){
var origDefine = global.define;
var get = function(name){
var parts = name.split("."),
cur = global,
i;
for(i = 0 ; i < parts.length; i++){
if(!cur) {
break;
}
cur = cur[parts[i]];
}
return cur;
};
var modules = (global.define && global.define.modules) ||
(global._define && global._define.modules) || {};
var ourDefine = global.define = function(moduleName, deps, callback){
var module;
if(typeof deps === "function") {
callback = deps;
deps = [];
}
var args = [],
i;
for(i =0; i < deps.length; i++) {
args.push( exports[deps[i]] ? get(exports[deps[i]]) : ( modules[deps[i]] || get(deps[i]) ) );
}
// CJS has no dependencies but 3 callback arguments
if(!deps.length && callback.length) {
module = { exports: {} };
var require = function(name) {
return exports[name] ? get(exports[name]) : modules[name];
};
args.push(require, module.exports, module);
}
// Babel uses the exports and module object.
else if(!args[0] && deps[0] === "exports") {
module = { exports: {} };
args[0] = module.exports;
if(deps[1] === "module") {
args[1] = module;
}
} else if(!args[0] && deps[0] === "module") {
args[0] = { id: moduleName };
}
global.define = origDefine;
var result = callback ? callback.apply(null, args) : undefined;
global.define = ourDefine;
// Favor CJS module.exports over the return value
modules[moduleName] = module && module.exports ? module.exports : result;
};
global.define.orig = origDefine;
global.define.modules = modules;
global.define.amd = true;
ourDefine("@loader", [], function(){
// shim for @@global-helpers
var noop = function(){};
return {
get: function(){
return { prepareGlobal: noop, retrieveGlobal: noop };
},
global: global,
__exec: function(__load){
eval("(function() { " + __load.source + " \n }).call(global);");
}
};
});
})({},window)
/*can@2.3.34#util/can*/
define('can/util/can', [], function () {
var glbl = typeof window !== 'undefined' ? window : typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope ? self : global;
var can = {};
if (typeof GLOBALCAN === 'undefined' || GLOBALCAN !== false) {
glbl.can = can;
}
can.global = glbl;
can.k = function () {
};
can.isDeferred = function (obj) {
if (!!can.dev) {
can.dev.warn('can.isDeferred: this function is deprecated and will be removed in a future release. can.isPromise replaces the functionality of can.isDeferred.');
}
return obj && typeof obj.then === 'function' && typeof obj.pipe === 'function';
};
can.isPromise = function (obj) {
return !!obj && (window.Promise && obj instanceof Promise || can.isFunction(obj.then) && (can.List === undefined || !(obj instanceof can.List)));
};
can.isMapLike = function (obj) {
return can.Map && (obj instanceof can.Map || obj && obj.___get);
};
var cid = 0;
can.cid = function (object, name) {
if (!object._cid) {
cid++;
object._cid = (name || '') + cid;
}
return object._cid;
};
can.VERSION = '2.3.34';
can.simpleExtend = function (d, s) {
for (var prop in s) {
d[prop] = s[prop];
}
return d;
};
can.last = function (arr) {
return arr && arr[arr.length - 1];
};
can.isDOM = function (el) {
return (el.ownerDocument || el) === can.global.document;
};
can.childNodes = function (node) {
var childNodes = node.childNodes;
if ('length' in childNodes) {
return childNodes;
} else {
var cur = node.firstChild;
var nodes = [];
while (cur) {
nodes.push(cur);
cur = cur.nextSibling;
}
return nodes;
}
};
var protoBind = Function.prototype.bind;
if (protoBind) {
can.proxy = function (fn, context) {
return protoBind.call(fn, context);
};
} else {
can.proxy = function (fn, context) {
return function () {
return fn.apply(context, arguments);
};
};
}
can.frag = function (item, doc) {
var document = doc || can.document || can.global.document;
var frag;
if (!item || typeof item === 'string') {
frag = can.buildFragment(item == null ? '' : '' + item, document);
if (!frag.childNodes.length) {
frag.appendChild(document.createTextNode(''));
}
return frag;
} else if (item.nodeType === 11) {
return item;
} else if (typeof item.nodeType === 'number') {
frag = document.createDocumentFragment();
frag.appendChild(item);
return frag;
} else if (typeof item.length === 'number') {
frag = document.createDocumentFragment();
can.each(item, function (item) {
frag.appendChild(can.frag(item));
});
if (!can.childNodes(frag).length) {
frag.appendChild(document.createTextNode(''));
}
return frag;
} else {
frag = can.buildFragment('' + item, document);
if (!can.childNodes(frag).length) {
frag.appendChild(document.createTextNode(''));
}
return frag;
}
};
can.scope = can.viewModel = function (el, attr, val) {
el = can.$(el);
var scope = can.data(el, 'scope') || can.data(el, 'viewModel');
if (!scope) {
scope = new can.Map();
can.data(el, 'scope', scope);
can.data(el, 'viewModel', scope);
}
switch (arguments.length) {
case 0:
case 1:
return scope;
case 2:
return scope.attr(attr);
default:
scope.attr(attr, val);
return el;
}
};
var parseURI = function (url) {
var m = String(url).replace(/^\s+|\s+$/g, '').match(/^([^:\/?#]+:)?(\/\/(?:[^:@]*(?::[^:@]*)?@)?(([^:\/?#]*)(?::(\d*))?))?([^?#]*)(\?[^#]*)?(#[\s\S]*)?/);
return m ? {
href: m[0] || '',
protocol: m[1] || '',
authority: m[2] || '',
host: m[3] || '',
hostname: m[4] || '',
port: m[5] || '',
pathname: m[6] || '',
search: m[7] || '',
hash: m[8] || ''
} : null;
};
can.joinURIs = function (base, href) {
function removeDotSegments(input) {
var output = [];
input.replace(/^(\.\.?(\/|$))+/, '').replace(/\/(\.(\/|$))+/g, '/').replace(/\/\.\.$/, '/../').replace(/\/?[^\/]*/g, function (p) {
if (p === '/..') {
output.pop();
} else {
output.push(p);
}
});
return output.join('').replace(/^\//, input.charAt(0) === '/' ? '/' : '');
}
href = parseURI(href || '');
base = parseURI(base || '');
return !href || !base ? null : (href.protocol || base.protocol) + (href.protocol || href.authority ? href.authority : base.authority) + removeDotSegments(href.protocol || href.authority || href.pathname.charAt(0) === '/' ? href.pathname : href.pathname ? (base.authority && !base.pathname ? '/' : '') + base.pathname.slice(0, base.pathname.lastIndexOf('/') + 1) + href.pathname : base.pathname) + (href.protocol || href.authority || href.pathname ? href.search : href.search || base.search) + href.hash;
};
can['import'] = function (moduleName, parentName) {
var deferred = new can.Deferred();
if (typeof window.System === 'object' && can.isFunction(window.System['import'])) {
window.System['import'](moduleName, { name: parentName }).then(can.proxy(deferred.resolve, deferred), can.proxy(deferred.reject, deferred));
} else if (window.define && window.define.amd) {
window.require([moduleName], function (value) {
deferred.resolve(value);
});
} else if (window.steal) {
steal.steal(moduleName, function (value) {
deferred.resolve(value);
});
} else if (window.require) {
deferred.resolve(window.require(moduleName));
} else {
deferred.resolve();
}
return deferred.promise();
};
can.__observe = function () {
};
can.isNode = typeof process === 'object' && {}.toString.call(process) === '[object process]';
can.isBrowserWindow = typeof window !== 'undefined' && typeof document !== 'undefined' && typeof SimpleDOM === 'undefined';
can.isWebWorker = typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope;
can.dev = {
warnTimeout: 5000,
logLevel: 0,
warn: function (out) {
var ll = this.logLevel;
if (ll < 2) {
Array.prototype.unshift.call(arguments, 'WARN:');
if (typeof window !== undefined && window.console && console.warn) {
this._logger('warn', Array.prototype.slice.call(arguments));
} else if (window.console && console.log) {
this._logger('log', Array.prototype.slice.call(arguments));
} else if (window.opera && window.opera.postError) {
window.opera.postError('steal.js WARNING: ' + out);
}
}
},
log: function (out) {
var ll = this.logLevel;
if (ll < 1) {
if (window.console && console.log) {
Array.prototype.unshift.call(arguments, 'Info:');
this._logger('log', Array.prototype.slice.call(arguments));
} else if (window.opera && window.opera.postError) {
window.opera.postError('steal.js INFO: ' + out);
}
}
},
_logger: function (type, arr) {
try {
console[type].apply(console, arr);
} catch (e) {
console[type](arr);
}
}
};
return can;
});
/*can@2.3.34#util/attr/attr*/
define('can/util/attr/attr', ['can/util/can'], function (can) {
var namespaces = { 'xlink': 'http://www.w3.org/1999/xlink' };
var setImmediate = can.global.setImmediate || function (cb) {
return setTimeout(cb, 0);
}, formElements = {
'input': true,
'textarea': true,
'select': true
}, hasProperty = function (el, attrName) {
return attrName in el || can.document && formElements[el.nodeName.toLowerCase()];
}, attr = {
MutationObserver: can.global.MutationObserver || can.global.WebKitMutationObserver || can.global.MozMutationObserver,
map: {
'class': function (el, val) {
val = val || '';
if (el.namespaceURI === 'http://www.w3.org/2000/svg') {
el.setAttribute('class', val);
} else {
el.className = val;
}
return val;
},
'value': 'value',
'innertext': 'innerText',
'innerhtml': 'innerHTML',
'textcontent': 'textContent',
'for': 'htmlFor',
'checked': true,
'disabled': true,
'readonly': function (el, val) {
el.readOnly = val || typeof val === 'string' ? true : false;
return val;
},
'required': true,
src: function (el, val) {
if (val == null || val === '') {
el.removeAttribute('src');
return null;
} else {
el.setAttribute('src', val);
return val;
}
},
style: function () {
var el = can.global.document && document.createElement('div');
if (el && el.style && 'cssText' in el.style) {
return function (el, val) {
return el.style.cssText = val || '';
};
} else {
return function (el, val) {
return el.setAttribute('style', val);
};
}
}()
},
defaultValue: [
'input',
'textarea'
],
setAttrOrProp: function (el, attrName, val) {
attrName = attrName.toLowerCase();
var prop = attr.map[attrName];
if (prop === true && !val) {
this.remove(el, attrName);
} else {
this.set(el, attrName, val);
}
},
setSelectValue: function (el, val) {
if (val != null) {
var options = el.getElementsByTagName('option');
for (var i = 0; i < options.length; i++) {
if (val == options[i].value) {
options[i].selected = true;
return;
}
}
}
el.selectedIndex = -1;
},
set: function (el, attrName, val) {
var usingMutationObserver = can.isDOM(el) && attr.MutationObserver;
attrName = attrName.toLowerCase();
var oldValue;
if (!usingMutationObserver) {
oldValue = attr.get(el, attrName);
}
var prop = attr.map[attrName], newValue;
if (typeof prop === 'function') {
newValue = prop(el, val);
} else if (prop === true && hasProperty(el, attrName)) {
newValue = el[attrName] = true;
if (attrName === 'checked' && el.type === 'radio') {
if (can.inArray((el.nodeName + '').toLowerCase(), attr.defaultValue) >= 0) {
el.defaultChecked = true;
}
}
} else if (typeof prop === 'string' && hasProperty(el, prop)) {
newValue = val;
if (el[prop] !== val || el.nodeName.toUpperCase() === 'OPTION') {
el[prop] = val;
}
if (prop === 'value' && can.inArray((el.nodeName + '').toLowerCase(), attr.defaultValue) >= 0) {
el.defaultValue = val;
}
} else {
attr.setAttribute(el, attrName, val);
}
if (!usingMutationObserver && newValue !== oldValue) {
attr.trigger(el, attrName, oldValue);
}
},
setAttribute: function () {
var doc = can.global.document;
if (doc && document.createAttribute) {
try {
doc.createAttribute('{}');
} catch (e) {
var invalidNodes = {}, attributeDummy = document.createElement('div');
return function (el, attrName, val) {
var first = attrName.charAt(0), cachedNode, node, attr;
if ((first === '{' || first === '(' || first === '*') && el.setAttributeNode) {
cachedNode = invalidNodes[attrName];
if (!cachedNode) {
attributeDummy.innerHTML = '<div ' + attrName + '=""></div>';
cachedNode = invalidNodes[attrName] = attributeDummy.childNodes[0].attributes[0];
}
node = cachedNode.cloneNode();
node.value = val;
el.setAttributeNode(node);
} else {
attr = attrName.split(':');
if (attr.length !== 1) {
el.setAttributeNS(namespaces[attr[0]], attrName, val);
} else {
el.setAttribute(attrName, val);
}
}
};
}
}
return function (el, attrName, val) {
el.setAttribute(attrName, val);
};
}(),
trigger: function (el, attrName, oldValue) {
if (can.data(can.$(el), 'canHasAttributesBindings')) {
attrName = attrName.toLowerCase();
return setImmediate(function () {
can.trigger(el, {
type: 'attributes',
attributeName: attrName,
target: el,
oldValue: oldValue,
bubbles: false
}, []);
});
}
},
get: function (el, attrName) {
attrName = attrName.toLowerCase();
var prop = attr.map[attrName];
if (typeof prop === 'string' && hasProperty(el, prop)) {
return el[prop];
} else if (prop === true && hasProperty(el, attrName)) {
return el[attrName];
}
return el.getAttribute(attrName);
},
remove: function (el, attrName) {
attrName = attrName.toLowerCase();
var oldValue;
if (!attr.MutationObserver) {
oldValue = attr.get(el, attrName);
}
var setter = attr.map[attrName];
if (typeof setter === 'function') {
setter(el, undefined);
}
if (setter === true && hasProperty(el, attrName)) {
el[attrName] = false;
} else if (typeof setter === 'string' && hasProperty(el, setter)) {
el[setter] = '';
} else {
el.removeAttribute(attrName);
}
if (!attr.MutationObserver && oldValue != null) {
attr.trigger(el, attrName, oldValue);
}
},
has: function () {
var el = can.global.document && document.createElement('div');
if (el && el.hasAttribute) {
return function (el, name) {
return el.hasAttribute(name);
};
} else {
return function (el, name) {
return el.getAttribute(name) !== null;
};
}
}()
};
return attr;
});
/*can@2.3.34#event/event*/
define('can/event/event', ['can/util/can'], function (can) {
can.addEvent = function (event, handler) {
var allEvents = this.__bindEvents || (this.__bindEvents = {}), eventList = allEvents[event] || (allEvents[event] = []);
eventList.push({
handler: handler,
name: event
});
return this;
};
can.listenTo = function (other, event, handler) {
var idedEvents = this.__listenToEvents;
if (!idedEvents) {
idedEvents = this.__listenToEvents = {};
}
var otherId = can.cid(other);
var othersEvents = idedEvents[otherId];
if (!othersEvents) {
othersEvents = idedEvents[otherId] = {
obj: other,
events: {}
};
}
var eventsEvents = othersEvents.events[event];
if (!eventsEvents) {
eventsEvents = othersEvents.events[event] = [];
}
eventsEvents.push(handler);
can.bind.call(other, event, handler);
};
can.stopListening = function (other, event, handler) {
var idedEvents = this.__listenToEvents, iterIdedEvents = idedEvents, i = 0;
if (!idedEvents) {
return this;
}
if (other) {
var othercid = can.cid(other);
(iterIdedEvents = {})[othercid] = idedEvents[othercid];
if (!idedEvents[othercid]) {
return this;
}
}
for (var cid in iterIdedEvents) {
var othersEvents = iterIdedEvents[cid], eventsEvents;
other = idedEvents[cid].obj;
if (!event) {
eventsEvents = othersEvents.events;
} else {
(eventsEvents = {})[event] = othersEvents.events[event];
}
for (var eventName in eventsEvents) {
var handlers = eventsEvents[eventName] || [];
i = 0;
while (i < handlers.length) {
if (handler && handler === handlers[i] || !handler) {
can.unbind.call(other, eventName, handlers[i]);
handlers.splice(i, 1);
} else {
i++;
}
}
if (!handlers.length) {
delete othersEvents.events[eventName];
}
}
if (can.isEmptyObject(othersEvents.events)) {
delete idedEvents[cid];
}
}
return this;
};
can.removeEvent = function (event, fn, __validate) {
if (!this.__bindEvents) {
return this;
}
var events = this.__bindEvents[event] || [], i = 0, ev, isFunction = typeof fn === 'function';
while (i < events.length) {
ev = events[i];
if (__validate ? __validate(ev, event, fn) : isFunction && ev.handler === fn || !isFunction && (ev.cid === fn || !fn)) {
events.splice(i, 1);
} else {
i++;
}
}
return this;
};
can.dispatch = function (event, args) {
var events = this.__bindEvents;
if (!events) {
return;
}
var eventName;
if (typeof event === 'string') {
eventName = event;
event = { type: event };
} else {
eventName = event.type;
}
var handlers = events[eventName];
if (!handlers) {
return;
} else {
handlers = handlers.slice(0);
}
var passed = [event];
if (args) {
passed.push.apply(passed, args);
}
for (var i = 0, len = handlers.length; i < len; i++) {
handlers[i].handler.apply(this, passed);
}
return event;
};
can.one = function (event, handler) {
var one = function () {
can.unbind.call(this, event, one);
return handler.apply(this, arguments);
};
can.bind.call(this, event, one);
return this;
};
can.event = {
on: function () {
if (arguments.length === 0 && can.Control && this instanceof can.Control) {
return can.Control.prototype.on.call(this);
} else {
return can.addEvent.apply(this, arguments);
}
},
off: function () {
if (arguments.length === 0 && can.Control && this instanceof can.Control) {
return can.Control.prototype.off.call(this);
} else {
return can.removeEvent.apply(this, arguments);
}
},
bind: can.addEvent,
unbind: can.removeEvent,
delegate: function (selector, event, handler) {
return can.addEvent.call(this, event, handler);
},
undelegate: function (selector, event, handler) {
return can.removeEvent.call(this, event, handler);
},
trigger: can.dispatch,
one: can.one,
addEvent: can.addEvent,
removeEvent: can.removeEvent,
listenTo: can.listenTo,
stopListening: can.stopListening,
dispatch: can.dispatch
};
return can.event;
});
/*can@2.3.34#util/fragment*/
define('can/util/fragment', ['can/util/can'], function (can) {
var fragmentRE = /^\s*<(\w+)[^>]*>/, toString = {}.toString, fragment = function (html, name, doc) {
if (name === undefined) {
name = fragmentRE.test(html) && RegExp.$1;
}
if (html && toString.call(html.replace) === '[object Function]') {
html = html.replace(/<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/gi, '<$1></$2>');
}
var container = doc.createElement('div'), temp = doc.createElement('div');
if (name === 'tbody' || name === 'tfoot' || name === 'thead' || name === 'colgroup') {
temp.innerHTML = '<table>' + html + '</table>';
container = temp.firstChild.nodeType === 3 ? temp.lastChild : temp.firstChild;
} else if (name === 'col') {
temp.innerHTML = '<table><colgroup>' + html + '</colgroup></table>';
container = temp.firstChild.nodeType === 3 ? temp.lastChild : temp.firstChild.firstChild;
} else if (name === 'tr') {
temp.innerHTML = '<table><tbody>' + html + '</tbody></table>';
container = temp.firstChild.nodeType === 3 ? temp.lastChild : temp.firstChild.firstChild;
} else if (name === 'td' || name === 'th') {
temp.innerHTML = '<table><tbody><tr>' + html + '</tr></tbody></table>';
container = temp.firstChild.nodeType === 3 ? temp.lastChild : temp.firstChild.firstChild.firstChild;
} else if (name === 'option') {
temp.innerHTML = '<select>' + html + '</select>';
container = temp.firstChild.nodeType === 3 ? temp.lastChild : temp.firstChild;
} else {
container.innerHTML = '' + html;
}
var tmp = {}, children = can.childNodes(container);
tmp.length = children.length;
for (var i = 0; i < children.length; i++) {
tmp[i] = children[i];
}
return [].slice.call(tmp);
};
can.buildFragment = function (html, doc) {
if (html && html.nodeType === 11) {
return html;
}
if (!doc) {
doc = document;
} else if (doc.length) {
doc = doc[0];
}
var parts = fragment(html, undefined, doc), frag = (doc || document).createDocumentFragment();
for (var i = 0, length = parts.length; i < length; i++) {
frag.appendChild(parts[i]);
}
return frag;
};
(function () {
var text = '<-\n>', frag = can.buildFragment(text, document);
if (text !== frag.firstChild.nodeValue) {
var oldBuildFragment = can.buildFragment;
can.buildFragment = function (html, nodes) {
var res = oldBuildFragment(html, nodes);
if (res.childNodes.length === 1 && res.childNodes[0].nodeType === 3) {
res.childNodes[0].nodeValue = html;
}
return res;
};
}
}());
return can;
});
/*can@2.3.34#util/array/isArrayLike*/
define('can/util/array/isArrayLike', ['can/util/can'], function (can) {
can.isArrayLike = function (obj) {
var length = obj && typeof obj !== 'boolean' && typeof obj !== 'number' && 'length' in obj && obj.length;
return typeof arr !== 'function' && (length === 0 || typeof length === 'number' && length > 0 && length - 1 in obj);
};
});
/*can@2.3.34#util/array/each*/
define('can/util/array/each', [
'can/util/can',
'can/util/array/isArrayLike'
], function (can) {
can.each = function (elements, callback, context) {
var i = 0, key, len, item;
if (elements) {
if (can.isArrayLike(elements)) {
if (can.List && elements instanceof can.List) {
for (len = elements.attr('length'); i < len; i++) {
item = elements.attr(i);
if (callback.call(context || item, item, i, elements) === false) {
break;
}
}
} else {
for (len = elements.length; i < len; i++) {
item = elements[i];
if (callback.call(context || item, item, i, elements) === false) {
break;
}
}
}
} else if (typeof elements === 'object') {
if (can.Map && elements instanceof can.Map || elements === can.route) {
var keys = can.Map.keys(elements);
for (i = 0, len = keys.length; i < len; i++) {
key = keys[i];
item = elements.attr(key);
if (callback.call(context || item, item, key, elements) === false) {
break;
}
}
} else {
for (key in elements) {
if (Object.prototype.hasOwnProperty.call(elements, key) && callback.call(context || elements[key], elements[key], key, elements) === false) {
break;
}
}
}
}
}
return elements;
};
return can;
});
/*can@2.3.34#util/object/isplain/isplain*/
define('can/util/object/isplain/isplain', ['can/util/can'], function (can) {
var core_hasOwn = Object.prototype.hasOwnProperty, isWindow = function (obj) {
return obj !== null && obj == obj.window;
}, isPlainObject = function (obj) {
if (!obj || typeof obj !== 'object' || obj.nodeType || isWindow(obj)) {
return false;
}
try {
if (obj.constructor && !core_hasOwn.call(obj, 'constructor') && !core_hasOwn.call(obj.constructor.prototype, 'isPrototypeOf')) {
return false;
}
} catch (e) {
return false;
}
var key;
for (key in obj) {
}
return key === undefined || core_hasOwn.call(obj, key);
};
can.isPlainObject = isPlainObject;
return can;
});
/*can@2.3.34#util/deferred*/
define('can/util/deferred', ['can/util/can'], function (can) {
var extend = function (target, src) {
for (var key in src) {
if (src.hasOwnProperty(key)) {
target[key] = src[key];
}
}
}, Deferred = function (func) {
if (!(this instanceof Deferred)) {
return new Deferred();
}
this._doneFuncs = [];
this._failFuncs = [];
this._resultArgs = null;
this._status = '';
if (func) {
func.call(this, this);
}
};
can.Deferred = Deferred;
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, rp = [];
can.each(args, function (arg, j) {
arg.done(function () {
rp[j] = arguments.length < 2 ? arguments[0] : arguments;
if (++done === args.length) {
df.resolve.apply(df, rp);
}
}).fail(function () {
df.reject(arguments.length === 1 ? arguments[0] : arguments);
});
});
return df;
}
};
var resolveFunc = function (type, _status) {
return function (context) {
var args = this._resultArgs = arguments.length > 1 ? arguments[1] : [];
return this.exec(context, this[type], args, _status);
};
}, doneFunc = function doneFunc(type, _status) {
return function () {
var self = this;
can.each(Array.prototype.slice.call(arguments), function (v, i, args) {
if (!v) {
return;
}
if (v.constructor === Array) {
doneFunc.apply(self, v);
} else {
if (self._status === _status) {
v.apply(self, self._resultArgs || []);
}
self[type].push(v);
}
});
return this;
};
};
var isDeferred = function (obj) {
return obj && obj.then && obj.fail && obj.done;
};
var wire = function (parentDeferred, result, setter, value) {
if (isDeferred(result)) {
result.done(can.proxy(parentDeferred.resolve, parentDeferred)).fail(can.proxy(parentDeferred.reject, parentDeferred));
} else {
setter.call(parentDeferred, result !== undefined ? result : value);
}
};
extend(Deferred.prototype, {
then: function (done, fail) {
var d = can.Deferred(), resolve = d.resolve, reject = d.reject;
this.done(function (value) {
if (typeof done === 'function') {
wire(d, done.apply(this, arguments), resolve, value);
} else {
resolve.apply(d, arguments);
}
});
this.fail(function (value) {
if (typeof fail === 'function') {
wire(d, fail.apply(this, arguments), reject, value);
} else {
reject.apply(d, arguments);
}
});
return d;
},
resolveWith: resolveFunc('_doneFuncs', 'rs'),
rejectWith: resolveFunc('_failFuncs', 'rj'),
done: doneFunc('_doneFuncs', 'rs'),
fail: doneFunc('_failFuncs', 'rj'),
always: function () {
var args = can.makeArray(arguments);
if (args.length && args[0]) {
this.done(args[0]).fail(args[0]);
}
return this;
},
state: function () {
switch (this._status) {
case 'rs':
return 'resolved';
case 'rj':
return 'rejected';
default:
return 'pending';
}
},
isResolved: function () {
return this._status === 'rs';
},
isRejected: function () {
return this._status === 'rj';
},
reject: function () {
return this.rejectWith(this, arguments);
},
resolve: function () {
return this.resolveWith(this, arguments);
},
exec: function (context, dst, args, st) {
if (this._status !== '') {
return this;
}
this._status = st;
can.each(dst, function (d) {
if (typeof d.apply === 'function') {
d.apply(context, args);
}
});
return this;
},
promise: function () {
var promise = this.then();
promise.reject = promise.resolve = undefined;
return promise;
}
});
Deferred.prototype.pipe = Deferred.prototype.then;
return can;
});
/*can@2.3.34#util/hashchange*/
define('can/util/hashchange', ['can/util/can'], function (can) {
(function () {
var addEvent = function (el, ev, fn) {
if (el.addEventListener) {
el.addEventListener(ev, fn, false);
} else if (el.attachEvent) {
el.attachEvent('on' + ev, fn);
} else {
el['on' + ev] = fn;
}
}, onHashchange = function () {
can.trigger(window, 'hashchange');
};
addEvent(window, 'hashchange', onHashchange);
}());
});
/*can@2.3.34#util/inserted/inserted*/
define('can/util/inserted/inserted', ['can/util/can'], function (can) {
can.inserted = function (elems, document) {
if (!elems.length) {
return;
}
elems = can.makeArray(elems);
var doc = document || elems[0].ownerDocument || elems[0], inDocument = false, root = can.$(doc.contains ? doc : doc.body), children;
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;
}
}
if (inDocument && elem.getElementsByTagName) {
children = can.makeArray(elem.getElementsByTagName('*'));
can.trigger(elem, 'inserted', [], false);
for (var j = 0, child; (child = children[j]) !== undefined; j++) {
can.trigger(child, 'inserted', [], false);
}
}
}
};
can.appendChild = function (el, child, document) {
var children;
if (child.nodeType === 11) {
children = can.makeArray(can.childNodes(child));
} else {
children = [child];
}
el.appendChild(child);
can.inserted(children, document);
};
can.insertBefore = function (el, child, ref, document) {
var children;
if (child.nodeType === 11) {
children = can.makeArray(can.childNodes(child));
} else {
children = [child];
}
el.insertBefore(child, ref);
can.inserted(children, document);
};
});
/*can@2.3.34#util/util*/
'format steal';
define('can/util/util', [
'can/util/can',
'can/util/attr/attr',
'can/dojo/dojo',
'can/event/event',
'can/util/fragment',
'can/util/array/each',
'can/util/object/isplain/isplain',
'can/util/deferred',
'can/util/hashchange',
'can/util/inserted/inserted'
], function (can, attr, djo) {
var dojo = djo || window.dojo;
define('plugd/trigger', ['dojo/main'], function () {
var d = dojo;
var isfn = d.isFunction;
var leaveRe = /mouse(enter|leave)/;
var _fix = function (_, p) {
return 'mouse' + (p === 'enter' ? 'over' : 'out');
};
var mix = d._mixin;
var realTrigger;
if (d.doc.createEvent) {
realTrigger = function (n, e, a) {
var ev = d.doc.createEvent('HTMLEvents');
e = e.replace(leaveRe, _fix);
ev.initEvent(e, e === 'removed' || e === 'inserted' ? false : true, true);
if (a) {
mix(ev, a);
}
n.dispatchEvent(ev);
};
} else {
realTrigger = function (n, e, a) {
var ev = 'on' + e, stop = false;
try {
var evObj = document.createEventObject();
if (e === 'inserted' || e === 'removed') {
evObj.cancelBubble = true;
}
mix(evObj, a);
n.fireEvent(ev, evObj);
} catch (er) {
var evdata = mix({
type: e,
target: n,
faux: true,
_stopper: function () {
stop = this.cancelBubble;
}
}, a);
if (isfn(n[ev])) {
n[ev](evdata);
}
if (e === 'inserted' || e === 'removed') {
return;
}
while (!stop && n !== d.doc && n.parentNode) {
n = n.parentNode;
if (isfn(n[ev])) {
n[ev](evdata);
}
}
}
};
}
d._trigger = function (node, event, extraArgs) {
if (typeof event !== 'string') {
extraArgs = event;
event = extraArgs.type;
delete extraArgs.type;
}
var n = d.byId(node), ev = event && event.slice(0, 2) === 'on' ? event.slice(2) : event;
realTrigger(n, ev, extraArgs);
};
d.trigger = function (obj, event, extraArgs) {
return isfn(obj) || isfn(event) || isfn(obj[event]) ? d.hitch.apply(d, arguments)() : d._trigger.apply(d, arguments);
};
d.NodeList.prototype.trigger = d.NodeList._adaptAsForEach(d._trigger);
if (d._Node && !d._Node.prototype.trigger) {
d.extend(d._Node, {
trigger: function (ev, data) {
d._trigger(this, ev, data);
return this;
}
});
}
return d.trigger;
});
require([
'dojo/main',
'dojo/query',
'plugd/trigger',
'dojo/NodeList-dom'
]);
can.trim = function (s) {
return s && dojo.trim(s);
};
can.makeArray = function (arr) {
var array = [];
dojo.forEach(arr, function (item) {
array.push(item);
});
return array;
};
can.isArray = dojo.isArray;
can.inArray = function (item, arr, from) {
return dojo.indexOf(arr, item, from);
};
can.map = function (arr, fn) {
return dojo.map(can.makeArray(arr || []), fn);
};
can.extend = function (first) {
if (first === true) {
var args = can.makeArray(arguments);
args.shift();
return dojo.mixin.apply(dojo, args);
}
return dojo.mixin.apply(dojo, arguments);
};
can.isEmptyObject = function (object) {
var prop;
for (prop in object) {
break;
}
return prop === undefined;
};
can.param = function (object) {
var pairs = [], add = function (key, value) {
pairs.push(encodeURIComponent(key) + '=' + encodeURIComponent(value));
};
for (var name in object) {
can.buildParam(name, object[name], add);
}
return pairs.join('&').replace(/%20/g, '+');
};
can.buildParam = function (prefix, obj, add) {
if (can.isArray(obj)) {
for (var i = 0, l = obj.length; i < l; ++i) {
add(prefix + '[]', obj[i]);
}
} else if (dojo.isObject(obj)) {
for (var name in obj) {
can.buildParam(prefix + '[' + name + ']', obj[name], add);
}
} else {
add(prefix, obj);
}
};
can.proxy = function (func, context) {
return dojo.hitch(context, func);
};
can.isFunction = function (f) {
return dojo.isFunction(f);
};
var dojoId = 0, isFormNode = function (node) {
return node.nodeName === 'SELECT' || node.nodeName === 'FORM';
}, dojoAddBinding = function (nodelist, ev, cb) {
nodelist.forEach(function (node) {
node = new dojo.NodeList(isFormNode(node) ? [node] : node);
var events = can.data(node, 'events');
if (!events) {
can.data(node, 'events', events = {});
}
if (!events[ev]) {
events[ev] = {};
}
if (cb.__bindingsIds === undefined) {
cb.__bindingsIds = dojoId++;
}
events[ev][cb.__bindingsIds] = node.on(ev, cb)[0];
});
}, dojoRemoveBinding = function (nodelist, ev, cb) {
nodelist.forEach(function (node) {
var currentNode = new dojo.NodeList(node), events = can.data(currentNode, 'events');
if (!events) {
return;
}
var handlers = events[ev];
if (!handlers) {
return;
}
var handler = handlers[cb.__bindingsIds];
dojo.disconnect(handler);
delete handlers[cb.__bindingsIds];
if (can.isEmptyObject(handlers)) {
delete events[ev];
}
});
};
can.bind = function (ev, cb) {
if (this.bind && this.bind !== can.bind) {
this.bind(ev, cb);
} else if (this.on || this.nodeType) {
dojoAddBinding(new dojo.NodeList(isFormNode(this) ? [this] : this), ev, cb);
} else if (this.addEvent) {
this.addEvent(ev, cb);
} else {
can.addEvent.call(this, ev, cb);
}
return this;
};
can.unbind = function (ev, cb) {
if (this.unbind && this.unbind !== can.unbind) {
this.unbind(ev, cb);
} else if (this.on || this.nodeType) {
dojoRemoveBinding(new dojo.NodeList(this), ev, cb);
} else {
can.removeEvent.call(this, ev, cb);
}
return this;
};
can.on = can.bind;
can.off = can.unbind;
can.trigger = function (item, event, args, bubble) {
if (!(item instanceof dojo.NodeList) && (item.nodeName || item === window)) {
item = can.$(item);
}
if (item.trigger) {
if (bubble === false) {
if (!item[0] || item[0].nodeType === 3) {
return;
}
var connect = item.on(event, function (ev) {
if (ev.stopPropagation) {
ev.stopPropagation();
}
ev.cancelBubble = true;
if (ev._stopper) {
ev._stopper();
}
dojo.disconnect(connect);
});
item.trigger(event, args);
} else {
item.trigger(event, args);
}
} 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) {
if (!selector) {
can.bind.call(this, ev, cb);
} else if (this.on || this.nodeType) {
dojoAddBinding(new dojo.NodeList(this), selector + ':' + ev, cb);
} else if (this.delegate) {
this.delegate(selector, ev, cb);
} else {
can.bind.call(this, ev, cb);
}
return this;
};
can.undelegate = function (selector, ev, cb) {
if (!selector) {
can.unbind.call(this, ev, cb);
} else if (this.on || this.nodeType) {
dojoRemoveBinding(new dojo.NodeList(this), selector + ':' + ev, cb);
} else if (this.undelegate) {
this.undelegate(selector, ev, cb);
} else {
can.unbind.call(this, ev, cb);
}
return this;
};
var updateDeferred = function (xhr, d) {
for (var prop in xhr) {
if (typeof d[prop] === 'function') {
d[prop] = function () {
xhr[prop].apply(xhr, arguments);
};
} else {
d[prop] = prop[xhr];
}
}
};
can.ajax = function (options) {
var type = can.capitalize((options.type || 'get').toLowerCase()), method = dojo['xhr' + type];
var success = options.success, error = options.error, d = new can.Deferred();
var def = method({
url: options.url,
handleAs: options.dataType,
sync: !options.async,
headers: options.headers,
content: options.data
});
def.then(function (data, ioargs) {
updateDeferred(xhr, d);
d.resolve(data, 'success', xhr);
if (success) {
success(data, 'success', xhr);
}
}, function (data, ioargs) {
updateDeferred(xhr, d);
d.reject(xhr, 'error');
error(xhr, 'error');
});
var xhr = def.ioArgs.xhr;
updateDeferred(xhr, d);
return d;