2 lines
22 KiB
JavaScript
2 lines
22 KiB
JavaScript
|
(function(t){var e=typeof self=="object"&&self.self==self&&self||typeof global=="object"&&global.global==global&&global;if(typeof define==="function"&&define.amd){define(["underscore","jquery","exports"],function(i,r,s){e.Backbone=t(e,s,i,r)})}else if(typeof exports!=="undefined"){var i=require("underscore"),r;try{r=require("jquery")}catch(s){}t(e,exports,i,r)}else{e.Backbone=t(e,{},e._,e.jQuery||e.Zepto||e.ender||e.$)}})(function(t,e,i,r){var s=t.Backbone;var n=[];var a=n.slice;e.VERSION="1.2.0";e.$=r;e.noConflict=function(){t.Backbone=s;return this};e.emulateHTTP=false;e.emulateJSON=false;var o=e.Events={};var h=/\s+/;var u=function(t,e,r,s,n){var a=0,o;if(r&&typeof r==="object"){for(o=i.keys(r);a<o.length;a++){e=t(e,o[a],r[o[a]],n)}}else if(r&&h.test(r)){for(o=r.split(h);a<o.length;a++){e=t(e,o[a],s,n)}}else{e=t(e,r,s,n)}return e};o.on=function(t,e,i){return l(this,t,e,i)};var l=function(t,e,i,r,s){t._events=u(c,t._events||{},e,i,{context:r,ctx:t,listening:s});if(s){var n=t._listeners||(t._listeners={});n[s.id]=s}return t};o.listenTo=function(t,e,r){if(!t)return this;var s=t._listenId||(t._listenId=i.uniqueId("l"));var n=this._listeningTo||(this._listeningTo={});var a=n[s];if(!a){var o=this._listenId||(this._listenId=i.uniqueId("l"));a=n[s]={obj:t,objId:s,id:o,listeningTo:n,count:0}}l(t,e,r,this,a);return this};var c=function(t,e,i,r){if(i){var s=t[e]||(t[e]=[]);var n=r.context,a=r.ctx,o=r.listening;if(o)o.count++;s.push({callback:i,context:n,ctx:n||a,listening:o})}return t};o.off=function(t,e,i){if(!this._events)return this;this._events=u(f,this._events,t,e,{context:i,listeners:this._listeners});return this};o.stopListening=function(t,e,r){var s=this._listeningTo;if(!s)return this;var n=t?[t._listenId]:i.keys(s);for(var a=0;a<n.length;a++){var o=s[n[a]];if(!o)break;o.obj.off(e,r,this)}if(i.isEmpty(s))this._listeningTo=void 0;return this};var f=function(t,e,r,s){if(!t)return;var n=0,a,o;var h=s.context,u=s.listeners;if(!e&&!r&&!h){var l=i.keys(u);for(;n<l.length;n++){o=u[l[n]];delete u[o.id];delete o.listeningTo[o.objId]}return}var c=e?[e]:i.keys(t);for(;n<c.length;n++){e=c[n];var f=t[e];if(!f)break;var d=[];for(var v=0;v<f.length;v++){var g=f[v];if(r&&r!==g.callback&&r!==g.callback._callback||h&&h!==g.context){d.push(g)}else{o=g.listening;if(o&&--o.count===0){delete u[o.id];delete o.listeningTo[o.objId]}}}if(d.length){t[e]=d}else{delete t[e]}}if(i.size(t))return t};o.once=function(t,e,r){var s=u(d,{},t,e,i.bind(this.off,this));return this.on(s,void 0,r)};o.listenToOnce=function(t,e,r){var s=u(d,{},e,r,i.bind(this.stopListening,this,t));return this.listenTo(t,s)};var d=function(t,e,r,s){if(r){var n=t[e]=i.once(function(){s(e,n);r.apply(this,arguments)});n._callback=r}return t};o.trigger=function(t){if(!this._events)return this;var e=Math.max(0,arguments.length-1);var i=Array(e);for(var r=0;r<e;r++)i[r]=arguments[r+1];u(v,this._events,t,void 0,i);return this};var v=function(t,e,i,r){if(t){var s=t[e];var n=t.all;if(s&&n)n=n.slice();if(s)g(s,r);if(n)g(n,[e].concat(r))}return t};var g=function(t,e){var i,r=-1,s=t.length,n=e[0],a=e[1],o=e[2];switch(e.length){case 0:while(++r<s)(i=t[r]).callback.call(i.ctx);return;case 1:while(++r<s)(i=t[r]).callback.call(i.ctx,n);return;case 2:while(++r<s)(i=t[r]).callback.call(i.ctx,n,a);return;case 3:while(++r<s)(i=t[r]).callback.call(i.ctx,n,a,o);return;default:while(++r<s)(i=t[r]).callback.apply(i.ctx,e);return}};var p=function(t,e,r){switch(t){case 1:return function(){return i[e](this[r])};case 2:return function(t){return i[e](this[r],t)};case 3:return function(t,s){return i[e](this[r],t,s)};case 4:return function(t,s,n){return i[e](this[r],t,s,n)};default:return function(){var t=a.call(arguments);t.unshift(this[r]);return i[e].apply(i,t)}}};var m=function(t,e,r){i.each(e,function(e,s){if(i[s])t.prototype[s]=p(e,s,r)})};o.bind=o.on;o.unbind=o.off;i.extend(e,o);var _=e.Model=function(t,e){var r=t||{};e||(e={});this.cid=i.uniqueId(this.cidPrefix);this.attributes={};if(e.collection)this.collection=e.collection;if(e.parse)r=this.parse(r,e)||{};r=i.defaults({},r,i.result(this,"defaults"))
|
||
|
//# sourceMappingURL=backbone-min.map
|