-
Notifications
You must be signed in to change notification settings - Fork 19
/
gillie.min.js
1 lines (1 loc) · 3.79 KB
/
gillie.min.js
1
!function(t,e){function n(){}function i(t){return[].slice.call(arguments,1).forEach(function(e){if(e)for(var n in e)t[n]=e[n]}),t}function r(t,e,n,i){if(n){if("object"==typeof n){for(var r in n)t[e].apply(t,[r,n[r]].concat(i));return!1}if(h.test(n)){for(var s=n.split(h),a=0,u=s.length;u>a;a++)t[e].apply(t,[s[a]].concat(i));return!1}return!0}}function s(t,e){for(var n,i=-1,r=t.length,s=e.length>3?e:e.slice(e.length);++i<r;)(n=t[i]).callback.apply(n.ctx,s)}function a(t){function e(){c||i.apply(this,arguments)}var n=this.prototype,i=this;c=!0;var r=new this;c=!1;for(var s in t)r[s]="function"==typeof t[s]&&"function"==typeof n[s]&&o.test(t[s])?function(t,e){return function(){var i=this._super;this._super=n[t];var r=e.apply(this,arguments);return this._super=i,r}}(s,t[s]):t[s];return e.prototype=r,e.prototype.constructor=e,e.extend=arguments.callee,e}function u(t){var e=++j+"";return t?t+e:e}var c=!1,o=/xyz/.test(function(){})?/\b_super\b/:/.*/,l=n.Events={on:function(t,e,n){return r(this,"on",t,[e,n])&&e?(this._events||(this._events={}),(this._events[t]||(this._events[t]=[])).push({callback:e,context:n,ctx:n||this}),this):this},trigger:function(t){if(!this._events)return this;var e=[].slice.call(arguments,1);if(!r(this,"trigger",t,e))return this;var n=this._events[t];return n&&s(n,e),this}},h=/\s+/,f={on:"listenTo"};t.each(f,function(t,e){l[e]=function(e,n,i){var r=this._listeners||(this._listeners={}),s=e._listenerId||(e._listenerId=u("l"));return r[s]=e,"object"==typeof n&&(i=this),e[t](n,i,this),this}});var p=n.Handler=function(){this.initialize&&this.initialize.apply(this,arguments),this.delegateEvents()},v=/^(\S+)\s*(.*)$/;i(p.prototype,l,{bind:function(t,e){return function(){return t.apply(e,arguments)}},delegateEvents:function(e){if(e=e||this.events,!e)return this;for(var n in e){var i=e[n];if(i=this[e[n]]){var r=n.match(v),s=r[1],a=r[2],u=this.el||document;i=this.bind(i,this),""===a?t(u).on(s,i):t(u).on(s,a,i)}}return this}});var d=n.Model=function(e){var n;e=e||{},this.attributes={},this.cid=u("c"),(n=this.defaults)&&(e=t.extend({},n,e)),this.attributes=e,this.initialize&&this.initialize()},y=/(\(\?)?:\w+/g;i(d.prototype,l,{set:function(t,e,n){var i,r,s,a;if(null==t)return this;"object"==typeof t?(r=t,n=e):(r={})[t]=e,n||(n={}),a=n.unset,s=this.attributes;for(i in r)e=r[i],a?delete s[i]:s[i]=e;return this},get:function(t){return this.attributes[t]},unset:function(t,e){return this.set(t,void 0,i({},e,{unset:!0}))},toJSON:function(){return t.extend({},this.attributes)},buildRequestUrl:function(t){var n=this;t=t.replace(y,function(t,e){var i=n.get(t.replace(":",""));return e?t:i||t});var i=this.url||e.location.href+"/";return/^(\/\/|http:|https:).*/.test(t)?t:i+t},sync:function(){return n.sync.apply(this,arguments)}});var g=[["Get","read"],["Post","create"],["Put","update"],["Delete","delete"],["Patch","patch"]],b={};t.each(g,function(t,e){b[e[0]]=function(t,n,i){i=i||{};var r,s=this,a=i.success;return i.success=function(t){a&&a(s,t,i),s.trigger(n,s,t,i)},i.url=this.buildRequestUrl(t),r=this.sync(e[1],this,i)}}),i(d.prototype,b);var x=n.View=function(){this.initialize&&this.initialize()};i(x.prototype,l),n.sync=function(e,i,r){var s=T[e],a={type:s,dataType:"json"};r.url||(a.url=i.url),null!=r.data||!i||"create"!==e&&"update"!==e&&"patch"!==e||(a.contentType="application/json",a.data=JSON.stringify(r.attrs||i.toJSON())),"GET"!==a.type&&(a.processData=!1),"PATCH"===a.type&&_&&(a.xhr=function(){return new ActiveXObject("Microsoft.XMLHTTP")});var u=r.xhr=n.ajax(t.extend(a,r));return i.trigger("request",i,u,r),u};var _=!(void 0===e||!e.ActiveXObject||e.XMLHttpRequest&&(new XMLHttpRequest).dispatchEvent),T={create:"POST",update:"PUT",patch:"PATCH","delete":"DELETE",read:"GET"};n.ajax=function(){return t.ajax.apply(t,arguments)};var j=0;n.Handler.extend=n.Model.extend=n.View.extend=a,e.Gillie=n}(jQuery,this);