forked from jb55/bquery
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bquery.min.js
5 lines (5 loc) · 2.42 KB
/
bquery.min.js
1
2
3
4
5
(function(){var bQuery,bQueryView,root,_,__slice=[].slice,__hasProp={}.hasOwnProperty;root=typeof exports!=="undefined"&&exports!==null?exports:this;if(typeof require!=="undefined")if(!_)_=require("underscore");if(typeof exports!=="undefined")bQuery=exports;else bQuery=root.bQuery={};bQueryView=function(){function bQueryView(opts){if(opts==null)opts={};bQueryView=function(){};this._events=[];this._properties=[];this._init=[];this._view=opts.view||Backbone.View.extend(bQueryView)}bQueryView.prototype.init=
function(f){this._init.push(f);return this};bQueryView.prototype.on=function(e,f){this._events.push({name:e,fn:f});return this};bQueryView.prototype.sets=function(p,v){this.view()[p]=v;return this};bQueryView.prototype.set=function(p,v){this._properties.push({name:p,value:v});return this};bQueryView.prototype.use=function(p){p(this,this.view);return this};bQueryView.prototype.view=function(x){if(x&&_.isFunction(x)){x(this._view);return this}return this._view};bQueryView.prototype.make=function(v){var name,
t,value,_i,_len,_ref,_ref1,_this=this;v=v||this.view();v.prototype.events=function(){var evts,groupedEvents,k,_fn;evts={};groupedEvents=_.groupBy(_this._events,function(e){return e.name});_fn=function(k,v){var fn,fns,name;name=k;fns=v;if(v.length>1)return evts[k]=function(){var fn,_i,_len;for(_i=0,_len=fns.length;_i<_len;_i++){fn=fns[_i].fn;fn.apply(this,[].slice(arguments))}};else{fn=fns[0].fn;return evts[k]=fn}};for(k in groupedEvents){v=groupedEvents[k];_fn(k,v)}return evts};_ref=this._properties;
for(_i=0,_len=_ref.length;_i<_len;_i++){_ref1=_ref[_i],name=_ref1.name,value=_ref1.value;v.prototype[name]=value}t=this;v.prototype.initialize=function(opts){var i,_j,_len1,_ref2;if(opts==null)opts={};_ref2=t._init;for(_j=0,_len1=_ref2.length;_j<_len1;_j++){i=_ref2[_j];i.call(this,opts)}};return v};return bQueryView}();bQuery.view=function(){return new bQueryView};bQuery.view.mixin=function(name,mixin){var go,key,val,_results;go=function(n,m){if(!bQuery.allowOverwrite)if(bQueryView.prototype[n])throw"bQuery plugin with the name '"+
n+"' already exists. Set bQuery.allowOverwrite = true to allow overwriting plugins";return bQueryView.prototype[n]=function(){var xs;xs=1<=arguments.length?__slice.call(arguments,0):[];return this.use(m.apply(null,xs))}};if(typeof name==="object"){_results=[];for(key in name){if(!__hasProp.call(name,key))continue;val=name[key];_results.push(go(key,val))}return _results}else return go(name,mixin)}}).call(this);