forked from BorisMoore/jsviews
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery.observable.min.js
4 lines (4 loc) · 8.56 KB
/
jquery.observable.min.js
1
2
3
4
/*! JsObservable v1.0.0-alpha: http://github.com/BorisMoore/jsviews and http://jsviews.com/jsviews
informal pre V1.0 commit counter: 63 (Beta Candidate) */
(function(n,t,i){"use strict";function p(n){return n._cId=n._cId||".obs"+yt++}function r(n){return u(n)?new b(n):new w(n)}function w(n){return this._data=n,this}function b(n){return this._data=n,this}function wt(n){return u(n)?[n]:n}function et(n,t){n=u(n)?n:[n];for(var i,e=t,o=e,h=n.length,r=[],s=0;s<h;s++){if(i=n[s],f(i)){r=r.concat(et(i.call(t,t),t));continue}else if(""+i!==i){t=o=i;o!==e&&r.push(e=o);continue}o!==e&&r.push(e=o);r.push(i)}return r}function ot(n,t){for(var i in n)return;delete l[t]}function k(n,t){function h(n){return typeof n===o&&(s[0]||e&&u(n))}if(!(n.data&&n.data.off)){var y,p,w,l=t.oldValue,a=t.value,r=n.data,f=r.observeAll,e=!r.cb.noArray,s=r.paths;n.type===c?(r.cb.array||r.cb).call(r,n,t):(r.prop===t.path||r.prop==="*")&&(f?(y=f._path+"."+t.path,p=f.filter,w=[n.target].concat(f.parents()),h(l)&&v(e,f.ns,[l],s,r.cb,!0,p,[w],y),h(a)&&v(e,f.ns,[a],s,r.cb,i,p,[w],y)):(h(l)&&v(e,[l],s,r.cb,!0),h(a)&&v(e,[a],s,r.cb)),r.cb(n,t))}}function a(){function e(){function ti(i,r,u,f){var o,e,a=ut(v),y=wt(v),s=si,p=bt;if(i=n?i+"."+n:i,nt||f)a&&t(y).off(i,k);else{if(b=a&&t._data(v))for(b=b&&b.events,b=b&&b[u?c:h],gt=b&&b.length;gt--;)if((st=b[gt].data)&&st.cb._cId===d._cId&&st.ns===n){if(u)return;r==="*"&&st.prop!==r&&t(v).off(i,k)}e=u?{}:{fullPath:w,paths:r?[r]:[],prop:g};e.ns=n;e.cb=d;bt&&(e.observeAll={_path:p,path:function(){return o=s.length,p.replace(/[[.]/g,function(n){return o--,n==="["?"["+t.inArray(s[o-1],s[o]):"."})},parents:function(){return s},filter:hi,ns:n});t(y).on(i,null,e,k);ui&&((l[d._cId]=ui)[t.data(v,"obId")||t.data(v,"obId",vt++)]=v)}}function pi(n){var t=kt;return n.ob=ct(n,t),n.cb=function(i,r){var s=n.ob,h=n.sb,f=ct(n,t);f!==s&&(typeof s===o&&(ii(s,!0),(h||a&&u(s))&&e([s],h,d,ct,!0)),n.ob=f,typeof f===o&&(ii(f),(h||a&&u(f))&&e([f],h,d,ct)));d(i,r)}}function ii(n,t,f,e){if(a){var o=v,s=bt;v=n;e&&(v=n[e],bt+="."+e);hi&&v&&(v=r._fltr(bt,v,e?[n].concat(si):si,hi));v&&(f||u(v))&&ti(c+".observe"+(d?dt=p(d):""),i,!0,t);v=o;bt=s}}var ri,oi,ci,ht,g,w,yi,nt,d,dt,gt,st,b,ct,li,ui,fi,ni,si,bt,hi,ai,vi,ei=at,rt=this!=1?it.apply([],arguments):tt.call(arguments),ft=rt.pop()||!1,kt=rt.shift(),v=kt,yt=rt.length;for(ft+""===ft&&(bt=ft,si=rt.pop(),hi=rt.pop(),ft=!!rt.pop(),yt-=3),ft===!!ft&&(nt=ft,ft=rt[yt-1],ft=yt&&ft+""!==ft?(yt--,rt.pop()):i),d=ft,yt&&f(rt[yt-1])&&(ct=d,d=rt.pop(),yt--),ei+=nt?d?d._cId+(d._inId||""):"":(dt=p(d))+(d._inId||""),nt||(ui=l[dt]=l[dt]||{}),ai=n&&n.match(lt)||[""],vi=ai.length;vi--;)for(n=ai[vi],u(kt)?ii(kt,nt,!0):nt&&yt===0&&kt&&ti(ei,""),fi=0,ri=0;ri<yt;ri++)if(w=rt[ri],w!==""&&w!==i){if(v=kt,""+w===w){if(ht=w.split("^"),ht[1]&&(fi=ht[0].split(".").length,w=ht.join("."),fi=w.split(".").length-fi),ct&&(li=ct(w,kt))){yt+=li.length-1;y.apply(rt,[ri--,1].concat(li));continue}ht=w.split(".")}else f(w)||(w&&w._jsv?(ni=nt?w.cb:pi(w),ni.noArray=!a,ni._cId=d._cId,ni._inId=ni._inId||".obIn"+pt++,(w.bnd||w.prm&&w.prm.length||!w.sb)&&e([v],w.path,[s],w.prm,ni,ct,nt),w.sb&&e([w.ob],w.sb,d,ct,nt),w=s,v=i):v=w),ht=[kt=w];while(v&&(g=ht.shift())!==i)if(typeof v===o){if(""+g===g){if(g==="")continue;if(ht.length<fi+1&&!v.nodeType){if(!nt&&(b=ut(v)&&t._data(v))){for(b=b.events,b=b&&b[h],gt=b&&b.length,ci=0;gt--;)st=b[gt].data,st&&st.cb===d&&st.ns===n&&(st.prop===g||st.prop==="*")&&((oi=ht.join("."))&&st.paths.push(oi),ci++);if(ci){v=v[g];continue}}if(g==="*"){!nt&&b&&b.length&&ti(ei,"",!1,!0);ti(ei,"");for(oi in v)ii(v,nt,i,oi);break}else g&&ti(ei+"."+g,ht.join("^"))}bt&&(bt+="."+g);g=v[g]}if(f(g)){(yi=g.depends)&&e([v],et(yi,v),d,ct,nt);break}v=g}ii(v,nt)}return dt&&ot(ui,dt),{cbId:dt,bnd:ui}}var n,a=this!=!1,v=tt.call(arguments),s=v[0];return s+""===s&&a&&(n=s,v.shift(),s=v[0]),e.apply(1,v)}function bt(){return[].push.call(arguments,!0),a.apply(this,arguments)}function v(){var n=it.apply([],arguments);return a.apply(n.shift(),n)}function d(n,t,i,r){n+""!==n&&(i=t,t=n,n="");ht(n,this._data,t,i,[],"root",r)}function st(n,t,i){d.call(this,n,t,i,!0)}function ht(n,t,f,e,s,h,c){function v(n,t){for(l=n.length,w=h+"[]";l--;)k(n,l,t,1)}function k(t,u,o,s){var c,h;u!==rt&&(c=r._fltr(w,t[u],b,e))&&(h=b.slice(),s&&d&&h.unshift(d),ht(n,c,f,e||(s?i:0),h,w,o))}function g(n,t){h=n.data.observeAll._path;d=n.target;switch(t.change){case"insert":v(t.items);break;case"remove":v(t.items,!0);break;case"refresh":v(t.oldItems,!0);v(n.target);break;case"set":w=h+"."+t.path;k(t,"oldValue",!0);k(t,"value")}d=i;f.apply(this,arguments)}var l,y,w,b,d;if(typeof t===o)if(b=[t].concat(s),y=u(t)?"":"*",f?(y||e!==0)&&(g._cId=p(f),a(n,t,y,g,c,e,b,h)):a(n,t,y,i,c,e,b,h),y)for(l in t)w=h+"."+l,k(t,l,c);else v(t,c)}function ct(n){return n.indexOf(".")<0&&n.indexOf("[")<0}if(!t)throw"jsViews/jsObservable require jQuery";if(!t.observable){var g=t.views=t.views||{jsviews:"v1.0.0-alpha",sub:{}},e=g.sub,nt=t.event.special,tt=[].slice,y=[].splice,it=[].concat,u=t.isArray,rt=t.expando,o="object",s=parseInt,lt=/\S+/g,h=e.propChng=e.propChng||"propertyChange",c=e.arrChng=e.arrChng||"arrayChange",l=e._cbBnds=e._cbBnds||{},at=h+".observe",f=t.isFunction,vt=1,yt=1,pt=1,ut=t.hasData,ft={};e.getDeps=function(){var n=arguments;return function(){for(var i,t,r=[],u=n.length;u--;)i=n[u--],t=n[u],t&&(r=r.concat(f(t)?t(i,i):t));return r}};t.observable=r;r._fltr=function(n,t,i,r){if(r&&f(r)?r(n,t,i):!0)return t=f(t)?t.set&&t.call(i[0]):t,typeof t===o&&t};r.Object=w;r.Array=b;t.observe=r.observe=a;t.unobserve=r.unobserve=bt;r._apply=v;w.prototype={_data:null,observeAll:d,unobserveAll:st,data:function(){return this._data},setProperty:function(n,t,r){var f,h,s,o=this,e=o._data;if(n=n||"",e)if(u(n))for(f=n.length;f--;)h=n[f],o.setProperty(h.name,h.value,r===i||r);else if(""+n!==n)for(f in n)o.setProperty(f,n[f],t);else if(n!==rt){for(s=n.split(".");e&&s.length>1;)e=e[s.shift()];e&&o._setProperty(e,s[0],t,r)}return o},removeProperty:function(n){return this.setProperty(n,ft),this},_setProperty:function(n,t,r,u){var o,s,h,e=t?n[t]:n;f(e)&&e.set&&(s=e,o=e.set===!0?e:e.set,e=e.call(n));(e!==r||u&&e!=r)&&(!(e instanceof Date)||e>r||e<r)&&(o?(o.call(n,r),r=s.call(n)):(h=r===ft)?(delete n[t],r=i):t&&(n[t]=r),this._trigger(n,{change:"set",path:t,value:r,oldValue:e,remove:h}))},_trigger:function(n,i){t(n).triggerHandler(h,i)}};b.prototype={_data:null,observeAll:d,unobserveAll:st,data:function(){return this._data},insert:function(n,t){var i=this._data;return arguments.length===1&&(t=n,n=i.length),n=s(n),n>-1&&n<=i.length&&(t=u(t)?t:[t],t.length&&this._insert(n,t)),this},_insert:function(n,t){var i=this._data,r=i.length;y.apply(i,[n,0].concat(t));this._trigger({change:"insert",index:n,items:t},r)},remove:function(n,t){var r,u=this._data;return n===i&&(n=u.length-1),n=s(n),t=t?s(t):t===0?0:1,t>-1&&n>-1&&(r=u.slice(n,n+t),t=r.length,t&&this._remove(n,t,r)),this},_remove:function(n,t,i){var r=this._data,u=r.length;r.splice(n,t);this._trigger({change:"remove",index:n,items:i},u)},move:function(n,t,i){if(i=i?s(i):i===0?0:1,n=s(n),t=s(t),i>0&&n>-1&&t>-1&&n!==t){var r=this._data.slice(n,n+i);i=r.length;i&&this._move(n,t,i,r)}return this},_move:function(n,t,i,r){var u=this._data,f=u.length;u.splice(n,i);y.apply(u,[t,0].concat(r));this._trigger({change:"move",oldIndex:n,index:t,items:r},f)},refresh:function(n){var t=this._data.slice();return this._refresh(t,n),this},_refresh:function(n,t){var i=this._data,r=i.length;y.apply(i,[0,i.length].concat(t));this._trigger({change:"refresh",oldItems:n},r)},_trigger:function(n,i){var r=this._data,u=r.length,f=t([r]);u!==i&&f.triggerHandler(h,{change:"set",path:"length",value:u,oldValue:i});f.triggerHandler(c,n)}};nt[h]=nt[c]={remove:function(n){var r,u,f,e,o,i=n.data;if(i&&(i.off=!0,i=i.cb)&&(r=l[i._cId])){for(f=t._data(this).events[n.type],e=f.length;e--&&!u;)u=(o=f[e].data)&&o.cb._cId===i._cId;u||(delete r[t.data(this,"obId")],ot(r,i._cId))}}};g.map=function(n){function u(t,u,f){var s,e=this;this.src&&this.unmap();typeof t===o&&(e.src=t,e.tgt=f||e.tgt||[],e.options=u||e.options,e.update(),n.obsSrc&&r(e.src).observeAll(e.obs=function(t,r){s||(s=!0,n.obsSrc(e,t,r),s=i)},e.srcFlt),n.obsTgt&&r(e.tgt).observeAll(e.obt=function(t,r){s||(s=!0,n.obsTgt(e,t,r),s=i)},e.tgtFlt))}return f(n)&&(n={getTgt:n}),n.baseMap&&(n=t.extend({},n.baseMap,n)),n.map=function(n,t,i){return new u(n,t,i)},(u.prototype={srcFlt:n.srcFlt||ct,tgtFlt:n.tgtFlt||ct,update:function(t){var i=this;r(i.tgt).refresh(n.getTgt(i.src,i.options=t||i.options))},unmap:function(){var n=this;n.src&&(n.obs&&r(n.src).unobserveAll(n.obs,n.srcFlt),n.obt&&r(n.tgt).unobserveAll(n.obt,n.tgtFlt),n.src=i)},map:u,_def:n}).constructor=u,n}}})(this,this.jQuery);
//# sourceMappingURL=jquery.observable.min.js.map