UNPKG

can

Version:

MIT-licensed, client-side, JavaScript framework that makes building rich web applications easy.

1,299 lines (1,295 loc) 359 kB
/*! * 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/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/jquery/jquery*/ define('can/util/jquery/jquery', [ 'dist/jquery', 'can/util/can', 'can/util/attr/attr', 'can/event/event', 'can/util/fragment', 'can/util/array/each', 'can/util/inserted/inserted' ], function ($, can, attr, event) { var isBindableElement = function (node) { return node.nodeName && (node.nodeType === 1 || node.nodeType === 9) || node == window || node.addEventListener; }; $ = $ || window.jQuery; $.extend(can, $, { trigger: function (obj, event, args, bubbles) { if (isBindableElement(obj)) { $.event.trigger(event, args, obj, !bubbles); } else if (obj.trigger) { obj.trigger(event, args); } else { if (typeof event === 'string') { event = { type: event }; } event.target = event.target || obj; if (args) { if (args.length && typeof args === 'string') { args = [args]; } else if (!args.length) { args = [args]; } } if (!args) { args = []; } can.dispatch.call(obj, event, args); } }, event: can.event, addEvent: can.addEvent, removeEvent: can.removeEvent, buildFragment: can.buildFragment, $: $, each: can.each, bind: function (ev, cb) { if (this.nodeType === 11) { return; } if (this.bind && this.bind !== can.bind) { this.bind(ev, cb); } else if (isBindableElement(this)) { $.event.add(this, ev, cb); } else { can.addEvent.call(this, ev, cb); } return this; }, unbind: function (ev, cb) { if (this.nodeType === 11) { return; } if (this.unbind && this.unbind !== can.unbind) { this.unbind(ev, cb); } else if (isBindableElement(this)) { $.event.remove(this, ev, cb); } else { can.removeEvent.call(this, ev, cb); } return this; }, delegate: function (selector, ev, cb) { if (this.delegate) { this.delegate(selector, ev, cb); } else if (isBindableElement(this)) { $(this).delegate(selector, ev, cb); } else { can.bind.call(this, ev, cb); } return this; }, undelegate: function (selector, ev, cb) { if (this.undelegate) { this.undelegate(selector, ev, cb); } else if (isBindableElement(this)) { $(this).undelegate(selector, ev, cb); } else { can.unbind.call(this, ev, cb); } return this; }, proxy: can.proxy, attr: attr }); can.on = can.bind; can.off = can.unbind; $.each([ 'append', 'filter', 'addClass', 'remove', 'data', 'get', 'has' ], function (i, name) { can[name] = function (wrapped) { return wrapped[name].apply(wrapped, can.makeArray(arguments).slice(1)); }; }); var oldClean = $.cleanData; $.cleanData = function (elems) { $.each(elems, function (i, elem) { if (elem) { can.trigger(elem, 'removed', [], false); } }); oldClean(elems); }; var oldDomManip = $.fn.domManip, cbIndex; $.fn.domManip = function (args, cb1, cb2) { for (var i = 1; i < arguments.length; i++) { if (typeof arguments[i] === 'function') { cbIndex = i; break; } } return oldDomManip.apply(this, arguments); }; $(document.createElement('div')).append(document.createElement('div')); var getChildNodes = function (node) { var childNodes = node.childNodes; if ('length' in childNodes) { return can.makeArray(childNodes); } else { var cur = node.firstChild; var nodes = []; while (cur) { nodes.push(cur); cur = cur.nextSibling; } return nodes; } }; if (cbIndex === undefined) { $.fn.domManip = oldDomManip; can.each([ 'after', 'prepend', 'before', 'append', 'replaceWith' ], function (name) { var original = $.fn[name]; $.fn[name] = function () { var elems = [], args = can.makeArray(arguments); if (args[0] != null) { if (typeof args[0] === 'string') { args[0] = can.buildFragment(args[0]); } if (args[0].nodeType === 11) { elems = getChildNodes(args[0]); } else if (can.isArrayLike(args[0])) { elems = can.makeArray(args[0]); } else { elems = [args[0]]; } } var ret = original.apply(this, args); can.inserted(elems); return ret; }; }); } else { $.fn.domManip = cbIndex === 2 ? function (args, table, callback) { return oldDomManip.call(this, args, table, function (elem) { var elems; if (elem.nodeType === 11) { elems = can.makeArray(can.childNodes(elem)); } var ret = callback.apply(this, arguments); can.inserted(elems ? elems : [elem]); return ret; }); } : function (args, callback) { return oldDomManip.call(this, args, function (elem) { var elems; if (elem.nodeType === 11) { elems = can.makeArray(can.childNodes(elem)); } var ret = callback.apply(this, arguments); can.inserted(elems ? elems : [elem]); return ret; }); }; } var oldAttr = $.attr; $.attr = function (el, attrName) { if (can.isDOM(el) && can.attr.MutationObserver) { return oldAttr.apply(this, arguments); } else { var oldValue, newValue; if (arguments.length >= 3) { oldValue = oldAttr.call(this, el, attrName); } var res = oldAttr.apply(this, arguments); if (arguments.length >= 3) { newValue = oldAttr.call(this, el, attrName); } if (newValue !== oldValue) { can.attr.trigger(el, attrName, oldValue); } return res; } }; var oldRemove = $.removeAttr; $.removeAttr = function (el, attrName) { if (can.isDOM(el) && can.attr.MutationObserver) { return oldRemove.apply(this, arguments); } else { var oldValue = oldAttr.call(this, el, attrName), res = oldRemove.apply(this, arguments); if (oldValue != null) { can.attr.trigger(el, attrName, oldValue); } return res; } }; $.event.special.attributes = { setup: function () { if (can.isDOM(this) && can.attr.MutationObserver) { var self = this; var observer = new can.attr.MutationObserver(function (mutations) { mutations.forEach(function (mutation) { var copy = can.simpleExtend({}, mutation); can.trigger(self, copy, []); }); }); observer.observe(this, { attributes: true, attributeOldValue: true }); can.data(can.$(this), 'canAttributesObserver', observer); } else { can.data(can.$(this), 'canHasAttributesBindings', true); } }, teardown: function () { if (can.isDOM(this) && can.attr.MutationObserver) { can.data(can.$(this), 'canAttributesObserver').disconnect(); $.removeData(this, 'canAttributesObserver'); } else { $.removeData(this, 'canHasAttributesBindings'); } } }; $.event.special.inserted = {}; $.event.special.removed = {}; return can; }); /*can@2.3.34#util/util*/ define('can/util/util', ['can/util/jquery/jquery'], function (can) { return can; }); /*can@2.3.34#view/view*/ define('can/view/view', ['can/util/util'], function (can) { var isFunction = can.isFunction, makeArray = can.makeArray, hookupId = 1; var makeRenderer = function (textRenderer) { var renderer = function () { return $view.frag(textRenderer.apply(this, arguments)); }; renderer.render = function () { return textRenderer.apply(textRenderer, arguments); }; return renderer; }; var checkText = function (text, url) { if (!text.length) { can.dev.log('can/view/view.js: There is no template or an empty template at ' + url); throw new Error('can.view: No template or empty template:' + url); } }; var getRenderer = function (obj, async) { if (isFunction(obj)) { var def = can.Deferred(); return def.resolve(obj); } var url = typeof obj === 'string' ? obj : obj.url, suffix = obj.engine && '.' + obj.engine || url.match(/\.[\w\d]+$/), type, el, id; if (url.match(/^#/)) { url = url.substr(1); } if (el = document.getElementById(url)) { suffix = '.' + el.type.match(/\/(x\-)?(.+)/)[2]; } if (!suffix && !$view.cached[url]) { url += suffix = $view.ext; } if (can.isArray(suffix)) { suffix = suffix[0]; } id = $view.toId(url); if (url.match(/^\/\//)) { url = url.substr(2); url = !window.steal ? url : steal.config().root.mapJoin('' + steal.id(url)); } if (window.require) { if (require.toUrl) { url = require.toUrl(url); } } type = $view.types[suffix]; if ($view.cached[id]) { return $view.cached[id]; } else if (el) { return $view.registerView(id, el.innerHTML, type); } else { var d = new can.Deferred(); can.ajax({ async: async, url: url, dataType: 'text', error: function (jqXHR) { checkText('', url); d.reject(jqXHR); }, success: function (text) { checkText(text, url); $view.registerView(id, text, type, d); } }); return d; } }; var getDeferreds = function (data) { var deferreds = []; if (can.isPromise(data)) { return [data]; } else { for (var prop in data) { if (can.isPromise(data[prop])) { deferreds.push(data[prop]); } } } return deferreds; }; var usefulPart = function (resolved) { return can.isArray(resolved) && resolved[1] === 'success' ? resolved[0] : resolved; }; var $view = can.view = can.template = function (view, data, helpers, callback) { if (isFunction(helpers)) { callback = helpers; helpers = undefined; } return $view.renderAs('fragment', view, data, helpers, callback); }; can.extend($view, { frag: function (result, parentNode) { return $view.hookup($view.fragment(result), parentNode); }, fragment: function (result) { return can.frag(result, document); }, toId: function (src) { return can.map(src.toString().split(/\/|\./g), function (part) { if (part) { return part; } }).join('_'); }, toStr: function (txt) { return txt == null ? '' : '' + txt; }, hookup: function (fragment, parentNode) { var hookupEls = [], id, func; can.each(fragment.childNodes ? can.makeArray(fragment.childNodes) : fragment, function (node) { if (node.nodeType === 1) { hookupEls.push(node); hookupEls.push.apply(hookupEls, can.makeArray(node.getElementsByTagName('*'))); } }); can.each(hookupEls, function (el) { if (el.getAttribute && (id = el.getAttribute('data-view-id')) && (func = $view.hookups[id])) { func(el, parentNode, id); delete $view.hookups[id]; el.removeAttribute('data-view-id'); } }); return fragment; }, hookups: {}, hook: function (cb) { $view.hookups[++hookupId] = cb; return ' data-view-id=\'' + hookupId + '\''; }, cached: {}, cachedRenderers: {}, cache: true, register: function (info) { this.types['.' + info.suffix] = info; if (typeof window !== 'undefined' && window.steal && steal.type) { steal.type(info.suffix + ' view js', function (options, success, error) { var type = $view.types['.' + options.type], id = $view.toId(options.id + ''); options.text = type.script(id, options.text); success(); }); } can[info.suffix] = $view[info.suffix] = function (id, text) { var renderer, renderFunc; if (!text) { renderFunc = function () { if (!renderer) { if (info.fragRenderer) { renderer = info.fragRenderer(null, id); } else { renderer = makeRenderer(info.renderer(null, id)); } } return renderer.apply(this, arguments); }; renderFunc.render = function () { var textRenderer = info.renderer(null, id); return textRenderer.apply(textRenderer, arguments); }; return renderFunc; } var registeredRenderer = function () { if (!renderer) { if (info.fragRenderer) { renderer = info.fragRenderer(id, text); } else { renderer = info.renderer(id, text); } } return renderer.apply(this, arguments); }; if (info.fragRenderer) { return $view.preload(id, registeredRenderer); } else { return $view.preloadStringRenderer(id, registeredRenderer); } }; }, types: {}, ext: '.ejs', registerScript: function (type, id, src) { return 'can.view.preloadStringRenderer(\'' + id + '\',' + $view.types['.' + type].script(id, src) + ');'; }, preload: function (id, renderer) { var def = $view.cached[id] = new can.Deferred().resolve(function (data, helpers) { return renderer.call(data, data, helpers); }); def.__view_id = id; $view.cachedRenderers[id] = renderer; return renderer; }, preloadStringRenderer: function (id, stringRenderer) { return this.preload(id, makeRenderer(stringRenderer)); }, render: function (view, data, helpers, callback, nodelist) { return can.view.renderAs('string', view, data, helpers, callback, nodelist); }, renderTo: function (format, renderer, data, helpers, nodelist) { return (format === 'string' && renderer.render ? renderer.render : renderer)(data, helpers, nodelist); }, renderAs: function (format, view, data, helpers, callback, nodelist) { if (callback !== undefined && typeof callback.expression === 'string') { nodelist = callback; callback = undefined; } if (isFunction(helpers)) { callback = helpers; helpers = undefined; } var deferreds = getDeferreds(data); var deferred, dataCopy, async, response; if (deferreds.length) { deferred = new can.Deferred(); dataCopy = can.extend({}, data); deferreds.push(getRenderer(view, true)); can.when.apply(can, deferreds).then(function (resolv