WordPress/wp-includes/js/backbone.min.js

1 line
22 KiB
JavaScript
Raw Normal View History

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