-
Notifications
You must be signed in to change notification settings - Fork 130
/
Copy pathjquery.observable.min.js
3 lines (3 loc) · 9.69 KB
/
jquery.observable.min.js
1
2
3
/*! JsObservable v0.9.81 (Beta): http://jsviews.com/#jsobservable */
!function(t,e){var n=e.jQuery;"object"==typeof exports?module.exports=n?t(e,n):function(n){return t(e,n)}:"function"==typeof define&&define.amd?define(["jquery"],function(n){return t(e,n)}):t(e,!1)}(function(t,e){"use strict";var n=e===!1;if(e=e||t.jQuery,!e||!e.fn)throw"JsObservable requires jQuery";var r,i,o="v0.9.81",s=e.views=e.views||n&&t.jsrender&&jsrender.views||{jsviews:o,sub:{settings:{}},settings:{advanced:function(t){return l=c.advanced=c.advanced||{_jsv:!0},t?("_jsv"in t&&(l._jsv=t._jsv),a.advSet(),s.settings):l}}},a=s.sub,c=a.settings,l=c.advanced,f=e.isFunction,u=e.expando,p=e.isArray,d="object";if(!e.observe){var h=e.event.special,v=[].slice,g=[].splice,_=[].concat,b=parseInt,y=/\S+/g,m=a.propChng=a.propChng||"propertyChange",I=a.arrChng=a.arrChng||"arrayChange",j={},A=m+".observe",w=1,x=1,F=1,P=e.hasData,S=e.data,C={},T=function(t){return t._cId=t._cId||".obs"+x++},k=function(t,e){return this._data=e,this._ns=t,this},O=function(t,e){return this._data=e,this._ns=t,this},V=function(t){return p(t)?[t]:t},D=function(t,e,n){t=t?p(t)?t:[t]:[];var r,i,o=e,s=o,a=t&&t.length,c=[];for(r=0;r<a;r++)i=t[r],f(i)?c=c.concat(D(i.call(e,e,n),e)):""+i===i?(s!==o&&c.push(o=s),c.push(i)):(e=s=i,s!==o&&c.push(o=s));return c},H=function(t,e){for(var n in t)return;delete j[e]},Q=function(t,e){function n(t){return typeof t===d&&(h[0]||u&&p(t))}if(!t.data||!t.data.off){var r,i,o,s=e.oldValue,a=e.value,c=t.data,l=c.observeAll,f=c.cb,u=!f.noArray,h=c.paths,v=c.ns;t.type===I?(f.array||f).call(c,t,e):c.prop!==e.path&&"*"!==c.prop||(l?(r=l._path+"."+e.path,i=l.filter,o=[t.target].concat(l.parents()),n(s)&&q(u,v,[s],h,f,!0,i,[o],r),n(a)&&q(u,v,[a],h,f,void 0,i,[o],r)):(n(s)&&q(u,v,[s],h,f,!0),n(a)&&q(u,v,[a],h,f)),c.cb(t,e))}},q=function(){var t=_.apply([],arguments);return r.apply(t.shift(),t)},M=function(t,e,n){J(this._ns,this._data,t,e,[],"root",n)},B=function(t,e){M.call(this,t,e,!0)},J=function(t,e,n,o,s,a,c,l){function f(t,e){for(g=t.length,b=a+"[]";g--;)h(t,g,e,1)}function h(e,r,s,a){var c,f;r!==u&&(c=i._fltr(b,e[r],y,o))&&(f=y.slice(),a&&m&&f[0]!==m&&f.unshift(m),J(t,c,n,o||(a?void 0:0),f,b,s,l))}function v(t,e){switch(a=t.data.observeAll._path,m=t.target,e.change){case"insert":f(e.items);break;case"remove":f(e.items,!0);break;case"set":b=a+"."+e.path,h(e,"oldValue",!0),h(e,"value")}m=void 0,n.apply(this,arguments)}var g,_,b,y,m,I,j=!l||l.un||!c;if(e&&typeof e===d){if(y=[e].concat(s),_=p(e)?"":"*",l&&j&&P(e)&&l[I=S(e).obId])return void l[I]++;if(l||(l={un:c}),n){if(_||0!==o)if(v._cId=T(n),j)r(t,e,_,v,c,o,y,a),I=S(e).obId,l[I]=(l[I]||0)+1;else{if(--l[S(e).obId])return;r(t,e,_,v,c,o,y,a)}}else l&&(l[S(e).obId]=1),r(t,e,_,void 0,c,o,y,a);if(_)for(g in e)b=a+"."+g,h(e,g,c);else f(e,c)}},z=function(t){return t.indexOf(".")<0&&t.indexOf("[")<0},E=function(){return[].push.call(arguments,!0),r.apply(this,arguments)};r=function(){function t(){function o(t,r,i,o){var s,a,c=P(it),l=V(it),f=W,u=X;if(t=n?t+"."+n:t,!q&&(o||i))for(G=c&&e._data(it),G=G&&G.events,G=G&&G[i?I:m],z=G&&G.length;z--;)if(E=G[z]&&G[z].data,E&&(o&&E.ns!==n||!o&&E.ns===n&&E.cb&&E.cb._cId===M._cId))return;q||o?e(l).off(t,Q):(a=i?{}:{fullPath:k,paths:r?[r]:[],prop:C},a.ns=n,a.cb=M,X&&(a.observeAll={_path:u,path:function(){return s=f.length,u.replace(/[[.]/g,function(t){return s--,"["===t?"["+e.inArray(f[s-1],f[s]):"."})},parents:function(){return f},filter:Y}),e(l).on(t,null,a,Q),N&&(N[S(it).obId||S(it,"obId",w++)]=it))}function a(e){var n=rt;return e.ob=K(e,n),e.cb=function(i,o){var s=e.ob,a=e.sb,l=K(e,n);l!==s&&(typeof s===d&&(c(s,!0),(a||r&&p(s))&&t([s],a,M,K,!0)),e.ob=l,typeof l===d&&(c(l),(a||r&&p(l))&&t([l],a,M,K))),M(i,o)}}function c(t,e,n,s){if(r){var a=it,c=X;it=t,s&&(it=t[s],X+="."+s),Y&&it&&(it=i._fltr(X,it,s?[t].concat(W):W,Y)),it&&(n||p(it))&&o(I+".observe"+(M?T(M):""),void 0,!0,e),it=a,X=c}}var l,h,b,x,C,k,O,q,M,B,J,z,E,G,K,L,N,R,U,W,X,Y,Z,$,tt=A,et=1!=this?_.apply([],arguments):v.call(arguments),nt=et.pop()||!1,rt=et.shift(),it=rt,ot=et.length;if(nt+""===nt&&(X=nt,W=et.pop(),Y=et.pop(),nt=!!et.pop(),ot-=3),nt===!!nt&&(q=nt,nt=et[ot-1],nt=!ot||nt+""===nt||nt&&!f(nt)?void 0:(ot--,et.pop()),q&&!ot&&f(rt)&&(nt=rt,rt=void 0)),M=nt,ot&&f(et[ot-1])&&(K=M,M=et.pop(),ot--),!q||!M||M._cId){for(tt+=M?(J=M._inId||"",q?M._cId+J:(B=T(M))+J):"",B&&!q&&(N=j[B]=j[B]||{}),Z=n&&n.match(y)||[""],$=Z.length;$--;){if(n=Z[$],rt&&(k=et[0],!k||k+""!==k)&&(p(rt)?c(rt,q,!0):q&&o(tt,"")),q&&!ot&&!rt)for(h in j){h=j[h];for(E in h)it=h[E],p(it)?c(it,q,q):o(tt,"")}for(R=0,l=0;l<ot;l++)if(k=et[l],""!==k){if(it=rt,""+k===k){if(x=k.split("^"),x[1]&&(R=x[0].split(".").length,k=x.join("."),R=k.split(".").length-R),K&&(L=K(k,rt,R))){ot+=L.length-1,g.apply(et,[l--,1].concat(L));continue}x=k.split(".")}else f(k)||(k&&k._jsv?(U=q?k.cb:a(k),U.noArray=!r,U._cId=M._cId,U._inId=U._inId||".obIn"+F++,(k.bnd||k.prm&&k.prm.length||!k.sb)&&t([it],k.path,[s],k.prm,U,K,q),k.sb&&t([k.ob],k.sb,M,K,q),k=s,it=void 0):it=k),x=[rt=k];for(;it&&void 0!==(C=x.shift());)if(typeof it===d){if(""+C===C){if(""===C)continue;if(x.length<R+1&&!it.nodeType){if(!q&&(G=P(it)&&e._data(it))){for(G=G.events,G=G&&G[m],z=G&&G.length,b=0;z--;)E=G[z].data,!E||E.ns!==n||E.cb._cId!==M._cId||E.cb._inId!==M._inId||E.prop!==C&&"*"!==E.prop&&"**"!==E.prop||((h=x.join("."))&&E.paths.push(h),b++);if(b){it=it[C];continue}}if("*"===C||"**"===C){if(!q&&G&&G.length&&o(tt,"",!1,!0),"*"===C){o(tt,"");for(h in it)h!==u&&c(it,q,void 0,h)}else e.observable(n,it)[(q?"un":"")+"observeAll"](M);break}C&&o(tt+".p_"+C,x.join("^"))}X&&(X+="."+C),C=it[C]}if(f(C)){(O=C.depends)&&t([it],D(O,it,M),M,K,q);break}it=C,q&&it===rt&&(l>ot-2||et[l+1]+""!==et[l+1])&&o(tt,"")}c(it,q)}}return B&&H(N,B),{cbId:B,bnd:N,s:j}}}var n,r=0!=this,o=v.call(arguments),s=o[0];return s+""===s&&r&&(n=s,o.shift(),s=o[0]),t.apply(1,o)},i=function(t,e){return 1===arguments.length&&(e=t,t=""),p(e)?new O(t,e):new k(t,e)},a.getDeps=function(){var t=arguments;return function(){for(var e,n,r=[],i=t.length;i--;)e=t[i--],n=t[i],n&&(r=r.concat(f(n)?n(e,e):n));return r}},e.observable=i,i._fltr=function(t,e,n,r){if(!r||!f(r)||r(t,e,n))return e=f(e)?e.set&&e.call(n[0]):e,typeof e===d&&e},i.Object=k,i.Array=O,e.observe=i.observe=r,e.unobserve=i.unobserve=E,i._apply=q,k.prototype={_data:null,observeAll:M,unobserveAll:B,data:function(){return this._data},setProperty:function(t,e,n){t=t||"";var r,i,o,s=t+""!==t,a=this,c=a._data;if(c)if(s)if(n=e,p(t))for(r=t.length;r--;)i=t[r],a.setProperty(i.name,i.value,void 0===n||n);else for(r in t)a.setProperty(r,t[r],n);else if(t!==u){for(o=t.split(/[.^]/);c&&o.length>1;)c=c[o.shift()];c&&a._setProperty(c,o[0],e,n)}return a},removeProperty:function(t){return this.setProperty(t,C),this},_setProperty:function(t,e,n,r){var i,o,s,a=e?t[e]:t;f(a)&&a.set&&(t=t._wrp||t,o=a,i=o.set===!0?o:o.set,a=o.call(t)),(a!==n||r&&a!=n)&&(!(a instanceof Date)||a>n||a<n)&&(i?(i.call(t,n),n=o.call(t)):(s=n===C)?void 0!==a?(delete t[e],n=void 0):e=void 0:e&&(t[e]=n),e&&this._trigger(t,{change:"set",path:e,value:n,oldValue:a,remove:s}))},_trigger:function(t,n){e(t).triggerHandler(m+(this._ns?"."+/^\S+/.exec(this._ns)[0]:""),n)}},O.prototype={_data:null,observeAll:M,unobserveAll:B,data:function(){return this._data},insert:function(t,e){var n=this._data;return 1===arguments.length&&(e=t,t=n.length),t=b(t),t>-1&&(e=p(e)?e:[e],e.length&&this._insert(t,e)),this},_insert:function(t,e){var n=this._data,r=n.length;t>r&&(t=r),g.apply(n,[t,0].concat(e)),this._trigger({change:"insert",index:t,items:e},r)},remove:function(t,e){var n,r=this._data;return void 0===t&&(t=r.length-1),t=b(t),e=e?b(e):0===e?0:1,e>0&&t>-1&&(n=r.slice(t,t+e),(e=n.length)&&this._remove(t,e,n)),this},_remove:function(t,e,n){var r=this._data,i=r.length;r.splice(t,e),this._trigger({change:"remove",index:t,items:n},i)},move:function(t,e,n){return n=n?b(n):0===n?0:1,t=b(t),e=b(e),n>0&&t>-1&&e>-1&&t!==e&&this._move(t,e,n),this},_move:function(t,e,n){var r,i=this._data,o=i.length,s=t+n-o;s>0&&(n-=s),n&&(r=i.splice(t,n),e>i.length&&(e=i.length),g.apply(i,[e,0].concat(r)),this._trigger({change:"move",oldIndex:t,index:e,items:r},o))},refresh:function(t,e){function n(){o&&(c.insert(i-o,l),d+=o,r+=o,o=0,l=[])}var r,i,o,s,a,c=this,l=[],f=c._data,u=f.slice(),p=f.length,d=p,h=t.length;for(c._srt=!0,i=o=0;i<h;i++)if((s=t[i])===f[i-o])n();else{for(r=i-o;r<d&&s!==f[r];r++);if(r<d){for(n(),a=0;a++<h-r&&t[i+a]===f[r+a];);c.move(r,i,a),i+=a-1}else o++,l.push(s)}return n(),d>i&&c.remove(i,d-i),c._srt=void 0,c._trigger({change:"refresh",oldItems:u},p),c},_trigger:function(t,n){var r=this,i=r._data,o=i.length,s=e([i]);r._srt?t.refresh=!0:o!==n&&s.triggerHandler(m,{change:"set",path:"length",value:o,oldValue:n}),s.triggerHandler(I+(r._ns?"."+/^\S+/.exec(r._ns)[0]:""),t)}},h[m]=h[I]={remove:function(t){var n,r,i,o,s,a=t.data;if(a&&(a.off=!0,a=a.cb)&&(n=j[a._cId])){for(i=e._data(this).events[t.type],o=i.length;o--&&!r;)r=(s=i[o].data)&&s.cb&&s.cb._cId===a._cId;r||(delete n[S(this).obId],H(n,a._cId))}}},s.map=function(t){function n(e,n,r,o){var s,a=this;this.src&&this.unmap(),typeof e===d&&(a.src=e,a.tgt=r||a.tgt||[],a.options=n||a.options,a.update(),o||(t.obsSrc&&i(a.src).observeAll(a.obs=function(e,n){s||(s=!0,t.obsSrc(a,e,n),s=void 0)},a.srcFlt),t.obsTgt&&i(a.tgt).observeAll(a.obt=function(e,n){s||(s=!0,t.obsTgt(a,e,n),s=void 0)},a.tgtFlt)))}return f(t)&&(t={getTgt:t}),t.baseMap&&(t=e.extend({},t.baseMap,t)),t.map=function(t,e,r,i){return new n(t,e,r,i)},(n.prototype={srcFlt:t.srcFlt||z,tgtFlt:t.tgtFlt||z,update:function(e){var n=this;i(n.tgt).refresh(t.getTgt(n.src,n.options=e||n.options))},unmap:function(){var t=this;t.src&&(t.obs&&i(t.src).unobserveAll(t.obs,t.srcFlt),t.obt&&i(t.tgt).unobserveAll(t.obt,t.tgtFlt),t.src=void 0)},map:n,_def:t}).constructor=n,t},a.advSet=function(){t._jsv=c.advanced._jsv?{cbBindings:j}:void 0}}return e},window);
//# sourceMappingURL=jquery.observable.min.js.map