-
Notifications
You must be signed in to change notification settings - Fork 130
/
Copy pathjquery.observable.min.js
3 lines (3 loc) · 12.1 KB
/
jquery.observable.min.js
1
2
3
/*! JsObservable v1.0.15: 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"jquery.observable.js requires jQuery";var r,i,o="v1.0.15",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,p=e.expando,u=e.isArray,d="string",h="object";if(s.jsviews!==o)throw"jquery.observable.js requires jsrender.js "+o;if(!e.observe){var v=e.event.special,g=[].slice,_=[].splice,b=[].concat,y=parseInt,m=/\S+/g,I=/^[^.[]*$/,w=a.propChng=a.propChng||"propertyChange",j=a.arrChng=a.arrChng||"arrayChange",x={},A=w+".observe",k=1,C=1,F=1,P=e.data,S={},T=[],V=function(t){return t?t._cId=t._cId||".obs"+C++:""},q=function(t,e){return this._data=e,this._ns=t,this},D=function(t,e){return this._data=e,this._ns=t,this},O=function(t){return u(t)?[t]:t},H=function(t,e,n){t=t?u(t)?t:[t]:[];var r,i,o,s,a=o=e,c=t&&t.length,l=[];for(r=0;c>r;r++)i=t[r],f(i)?(s=e.tagName?e.linkCtx.data:e,l=l.concat(H(i.call(e,s,n),s,n))):typeof i===d?(a!==o&&l.push(o=a),l.push(i)):(e=a=i=void 0===i?null:i,a!==o&&l.push(o=a));return l.length&&(l.unshift({_ar:1}),l.push({_ar:-1})),l},Q=function(t,e){function n(t){return typeof t===h&&(d[0]||!p&&u(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,p=c._arOk?0:1,d=c.paths,v=c.ns;t.type===j?(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)&&M(void 0,v,[s],d,f,!0,i,[o],r),n(a)&&M(void 0,v,[a],d,f,void 0,i,[o],r)):(n(s)&&M(p,v,[s],d,f,!0),n(a)&&M(p,v,[a],d,f)),c.cb(t,e))}},M=function(){var t=b.apply([],arguments);return r.apply(t.shift(),t)},B=function(t,e,n){$(this._ns,this._data,t,e,[],"root",n)},N=function(t,e){B.call(this,t,e,!0)},$=function(t,n,o,s,a,c,l,f){function d(t,e){for(_=t.length,y=c+"[]";_--;)v(t,_,e,1)}function v(e,n,r,a){var c,l;+n!==n&&n===p||!(c=i._fltr(y,e[n],m,s))||(l=m.slice(),a&&I&&l[0]!==I&&l.unshift(I),$(t,c,o,s||(a?void 0:0),l,y,r,f))}function g(t,e){switch(c=t.data.observeAll._path,I=t.target,e.change){case"insert":d(e.items);break;case"remove":d(e.items,!0);break;case"set":y=c+"."+e.path,v(e,"oldValue",!0),v(e,"value")}I=void 0,o.apply(this,arguments)}g._wrp=1;var _,b,y,m,I,w,j=!f||f.un||!l;if(n&&typeof n===h){if(m=[n].concat(a),b=u(n)?"":"*",f&&j&&e.hasData(n)&&f[w=P(n).obId])return void f[w]++;if(f||(f={un:l}),o){if(b||0!==s)if(g._cId=V(o),j)r(t,n,b,g,l,s,m,c),w=P(n).obId,f[w]=(f[w]||0)+1;else{if(--f[P(n).obId])return;r(t,n,b,g,l,s,m,c)}}else f&&(f[P(n).obId]=1),r(t,n,b,void 0,l,s,m,c);if(b)for(_ in n)y=c+"."+_,v(n,_,l);else d(n,l)}},z=function(t){return I.test(t)},E=function(){return[].push.call(arguments,!0),r.apply(void 0,arguments)},G=function(t){var e,n=this.slice();for(this.length=0,this._go=0;e=n.shift();)e.skip||e[0]._trigger(e[1],e[2],!0);this.paths={}};r=function(){function t(){function s(t,e){var n;for(q in e)n=e[q],u(n)?l(t,n,I,I):c(t,n,void 0,W,"")}function c(t,r,i,s,a,c,l){var f,p,u,d=O(r),h=$,v=z;if(s=n?s+"."+n:s,!I&&(l||c))for(R=e._data(r).events,R=R&&R[c?j:w],U=R&&R.length;U--;)if(q=R[U]&&R[U].data,q&&(l&&q.ns!==n||!l&&q.ns===n&&q.cb&&q.cb._cId===t._cId&&q.cb._inId===t._inId&&(!t._wrp||q.cb._wrp)))return;I||l?e(d).off(s,Q):(p=c?{}:{fullPath:i,paths:a?[a]:[],prop:L,_arOk:o},p.ns=n,p.cb=t,z&&(p.observeAll={_path:v,path:function(){return f=h.length,v.replace(/[[.]/g,function(t){return f--,"["===t?"["+e.inArray(h[f-1],h[f]):"."})},parents:function(){return h},filter:E}),e(d).on(s,null,p,Q),B&&(u=P(r),u=u.obId||(u.obId=k++),B[u]=B[u]||(B.len++,r)))}function l(t,e,n,r,s){if(o){var a,l=z;a=e,s&&(a=e[s],z=z?z+"."+s:z),E&&a&&(a=i._fltr(z,a,s?[e].concat($):$,E)),a&&(r||u(a))&&c(t,a,void 0,j+".observe"+V(t),void 0,!0,n),z=l}}function v(i){function s(i,g,_,m){function x(e){return e.ob=m(e),e.cb=function(n,r){var i=e.ob,s=e.sb,a=m(e);a!==i&&(typeof i===h&&(l(_,i,!0),(s||o&&u(i))&&t([i],s,_,m,!0)),e.ob=a,typeof a===h&&(l(_,a),(s||o&&u(a))&&t([a],s,_,m))),_(n,r)}}function A(t,i){function a(t,e){var n;if("insert"===e.change||(I="remove"===e.change)){for(n=e.items.length;n--;)A(e.items[n],i.slice());I=!1}}_&&(a._cId=V(_),a._inId=".arIn"+F++);var g,y,x,k,S,T,D,O=t;if(t&&t._cxp)return s(t[0],[t[1]],_,m);for(;void 0!==(L=i.shift());){if(O&&typeof O===h&&typeof L===d){if(""===L)continue;if("()"===L.slice(-2)&&(L=L.slice(0,-2),D=!0),i.length<P+1&&!O.nodeType){if(!I&&(R=e._data(O).events)){for(R=R&&R[w],U=R&&R.length,y=0;U--;)q=R[U].data,!q||q.ns!==n||q.cb._cId!==_._cId||q.cb._inId!==_._inId||!q._arOk!=!o||q.prop!==L&&"*"!==q.prop&&"**"!==q.prop||((S=i.join("."))&&q.paths.push(S),y++);if(y){T=O[L],O=f(T)?T.call(O):O[L];continue}}if("*"===L||"**"===L){if(!I&&R&&R.length&&c(_,O,C,W,"",!1,!0),"*"===L){c(_,O,C,W,"");for(S in O)S!==p&&l(_,O,I,void 0,S)}else e.observable(n,O)[(I?"un":"")+"observeAll"](_);break}"[]"==L?u(O)&&(I?c(_,O,C,j+V(_),void 0,I,I):r(n,O,a,I)):L&&c(_,O,C,W+".p_"+L,i.join("^"))}if(z&&(z+="."+L),"[]"===L){for(u(O)&&(k=O,g=O.length);g--;)O=k[g],A(O,i.slice());return}L=O[L],i[0]||l(_,L,I)}if(f(L)&&(T=L,(x=T.depends)&&(O._vw&&O._ocp&&(O=O._vw,O._tgId&&(O=O.tagCtx.view),O=O.data),v(b.apply([],[[O],H(x,O,_)]))),D)){if(!i[0]){l(_,T.call(O),I);break}if(L=T.call(O),!L)break}O=L}}var k,C,P=0,S=g.length;for(!i||m||!(K="view"===i._is)&&"tag"!==i._is||(m=a._gccb(K?i:i.tagCtx.contentView),_&&!I&&!function(){var t=i,e=_;_=function(n,r){e.call(t,n,r)},_._cId=e._cId,_._inId=e._inId}(),i=K?i.data:i),g[0]||(u(i)?l(_,i,I,!0):I&&c(_,i,void 0,W,"")),k=0;S>k;k++)if(C=g[k],""!==C)if(C&&C._ar)o+=C._ar;else if(typeof C===d)if(y=C.split("^"),y[1]&&(P=y[0].split(".").length,C=y.join("."),P=C.split(".").length-P),m&&(M=m(C,P))){if(M.length){var T=M[0],D=M[1];if(T&&T._cxp&&(D=T[1],T=T[0],"view"===T._is)){s(T,[D],_);continue}typeof D===d?A(T,D.split(".")):s(M.shift(),M,_,m)}}else A(i,C.split("."));else!f(C)&&C&&C._cpfn&&(N=I?C.cb:x(C),N._cId=_._cId,N._inId=N._inId||".obIn"+F++,(C.bnd||C.prm&&C.prm.length||!C.sb)&&t([i],C.path,C.prm.length?[C.root||i]:[],C.prm,N,m,I),C.sb&&(C.sb.prm&&(C.sb.root=i),s(C.ob,[C.sb],_,m)))}for(var g,_=[],m=i.length;m--;)g=i[m],typeof g===d||g&&(g._ar||g._cpfn)?_.unshift(g):(s(g,_,C,D),_=[])}var _,y,I,C,S,T,q,D,M,B,N,$,z,E,G,J,K,L,R,U,W=A,X=1!=this?b.apply([],arguments):g.call(arguments),Y=X.pop()||!1,Z=X.length;if(typeof Y===d&&(z=Y,$=X.pop(),E=X.pop(),Y=!!X.pop(),Z-=3),Y===!!Y&&(I=Y,Y=X[Z-1],Y=!Z||typeof Y===d||Y&&!f(Y)?void 0:(Z--,X.pop()),I&&!Z&&f(X[0])&&(Y=X.shift())),C=Y,Z&&f(X[Z-1])&&(D=C,Y=C=X.pop(),Z--),!I||!C||C._cId){for(W+=C?(T=C._inId||"",I?C._cId+T:(S=V(C))+T):"",S&&!I&&(B=x[S]=x[S]||{len:0}),G=n&&n.match(m)||[""],J=G.length;J--;){if(n=G[J],I&&arguments.length<3)if(C)s(C,x[C._cId]);else if(!X[0])for(_ in x)s(C,x[_]);v(X)}return S&&!B.len&&delete x[S],{cbId:S,bnd:B,s:x}}}var n,o=1==this?0:1,s=g.call(arguments),c=s[0];return typeof c===d&&(n=c,s.shift()),t.apply(1,s)},T.wait=function(){var t=this;t._go=1,setTimeout(function(){t.trigger(!0),t._go=0,t.paths={}})},i=function(t,e,n){typeof t!==d&&(n=e,e=t,t=""),n=void 0===n?l.asyncObserve:n;var r=u(e)?new D(t,e):new q(t,e);return n&&(n===!0&&(r.async=!0,n=T),n.trigger||(u(n)?(n.trigger=G,n.paths={}):n=void 0),r._batch=n),r},e.observable=i,i._fltr=function(t,e,n,r){return(r&&f(r)?r(t,e,n):!0)?(e=f(e)?e.set&&e.call(n[0]):e,typeof e===h&&e):void 0},i.Object=q,i.Array=D,e.observe=i.observe=r,e.unobserve=i.unobserve=E,i._apply=M,q.prototype={_data:null,observeAll:B,unobserveAll:N,data:function(){return this._data},setProperty:function(t,e,n,r){t=t||"";var i,o,s,a,c=typeof t!==d,l=this,f=l._data,h=l._batch;if(f)if(c)if(n=e,u(t))for(i=t.length;i--;)o=t[i],l.setProperty(o.name,o.value,void 0===n||n);else{h||(l._batch=a=[],a.trigger=G,a.paths={});for(i in t)l.setProperty(i,t[i],n);a&&(l._batch.trigger(),l._batch=void 0)}else if(t!==p){for(s=t.split(/[.^]/);f&&s.length>1;)f=f[s.shift()];f&&l._setProperty(f,s[0],e,n,r)}return l},removeProperty:function(t){return this.setProperty(t,S),this},_setProperty:function(t,e,n,r,i){var o,s,a,c,l,p=e?t[e]:t;if(f(p)&&!f(n)){if(i&&!p.set)return;p.set&&(l=t._vw||t,s=p,o=s.set===!0?s:s.set,p=s.call(l))}(p!==n||r&&p!=n)&&(!(p instanceof Date&&n instanceof Date)||p>n||n>p)&&(o?(o.call(l,n),n=s.call(l)):(a=n===S)?void 0!==p?(delete t[e],n=void 0):e=void 0:e&&(t[e]=n),e&&(c={change:"set",path:e,value:n,oldValue:p,remove:a},t._ocp&&(c.ctxPrm=t._key),this._trigger(t,c)))},_trigger:function(t,n,r){c._cchCt++;var i,o,s,a=this;e.hasData(t)&&(!r&&(o=a._batch)?(a.async&&!o._go&&o.wait(),o.push([a,t,n]),i=P(t).obId+n.path,(s=o.paths[i])&&(o[s-1].skip=1),o.paths[i]=o.length):(e(t).triggerHandler(w+(this._ns?"."+/^\S+/.exec(this._ns)[0]:""),n),n.oldValue=null))}},D.prototype={_data:null,observeAll:B,unobserveAll:N,data:function(){return this._data},insert:function(t,e){var n=this._data;return 1===arguments.length&&(e=t,t=n.length),t=y(t),t>-1&&(e=u(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),_.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=y(t),e=e?y(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?y(n):0===n?0:1,t=y(t),e=y(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),_.apply(i,[e,0].concat(r)),e!==t&&this._trigger({change:"move",oldIndex:t,index:e,items:r},o))},refresh:function(t){function e(){i&&(a.insert(r-i,c),u+=i,n+=i,i=0,c=[])}var n,r,i,o,s,a=this,c=[],l=a._data,f=l.slice(),p=l.length,u=p,d=t.length;for(a._srt=!0,r=i=0;d>r;r++)if((o=t[r])===l[r-i])e();else{for(n=r-i;u>n&&o!==l[n];n++);if(u>n){for(e(),s=0;s++<d-n&&t[r+s]===l[n+s];);a.move(n,r,s),r+=s-1}else i++,c.push(o)}return e(),u>r&&a.remove(r,u-r),a._srt=void 0,(p||d)&&a._trigger({change:"refresh",oldItems:f},p),a},_trigger:function(t,n,r){c._cchCt++;var i,o,s,a=this;e.hasData(o=a._data)&&(!r&&(s=a._batch)?(t._dly=!0,s.push([a,t,n]),a.async&&!s._go&&s.wait()):(i=o.length,o=e([o]),a._srt?t.refresh=!0:i!==n&&o.triggerHandler(w,{change:"set",path:"length",value:i,oldValue:n}),o.triggerHandler(j+(a._ns?"."+/^\S+/.exec(a._ns)[0]:""),t)))}},v[w]=v[j]={remove:function(t){var n,r,i,o,s,a=t.data;if(a&&(a.off=!0,a=a.cb)&&(n=x[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||(--n.len?delete n[P(this).obId]:delete x[a._cId])}}},s.map=function(t){function n(e,n,r,o){var s,a,c=this;c.src&&c.unmap(),n&&(n.map=c),(typeof e===h||f(e))&&(c.src=e,o?c.tgt=t.getTgt(e,n):(r&&(c.tgt=r.tgt||u(r)&&r),c.tgt=c.tgt||[],c.options=n||c.options,(a=c.update())?c=a:(t.obsSrc&&i(c.src).observeAll(c.obs=function(e,n){s||n.refresh||(s=!0,t.obsSrc(c,e,n),s=void 0)},c.srcFlt),t.obsTgt&&i(c.tgt).observeAll(c.obt=function(e,n){s||c.tgt._updt||(s=!0,t.obsTgt(c,e,n),s=void 0)},c.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,r,o=this,s=o.tgt;return!s._updt&&(s._updt=!0,n=o.options&&o.options.map,i(s).refresh(t.getTgt(o.src,o.options=e||o.options)),s._updt=!1,r=o.options&&o.options.map,r&&n!==r)?r:void 0},observe:function(t,n){var r=this,o=r.options;r.obmp&&E(r.obmp),r.obmp=function(){var t=n.fn(n.data,n.view,a)[o.index];e.extend(o.props,t.props),o.args=t.args,r.update()},i._apply(1,n.data,H(t,n.tag,r.obmp),r.obmp,n._ctxCb)},unmap:function(){var t=this;t.src&&t.obs&&i(t.src).unobserveAll(t.obs,t.srcFlt),t.tgt&&t.obt&&i(t.tgt).unobserveAll(t.obt,t.tgtFlt),t.obmp&&E(t.obmp),t.src=void 0},map:n,_def:t}).constructor=n,t},a.advSet=function(){a=this,l=c.advanced,t._jsv=l._jsv?{cbBindings:x}:void 0},a._dp=H,a._gck=V,a._obs=r,c._cchCt=0,l=c.advanced=l||{useViews:!1,_jsv:!1}}return e},window);
//# sourceMappingURL=jquery.observable.min.js.map