-
Notifications
You must be signed in to change notification settings - Fork 3
/
bigbird.min.js
1 lines (1 loc) · 2.65 KB
/
bigbird.min.js
1
(function(t,e){"function"==typeof define&&define.amd?define(["underscore","eventablejs","jquery"],e):"object"==typeof exports?module.exports=e(require("underscore"),require("eventablejs"),require("jquery")):t.BigBird=e(t._,t.Eventable,t.$)})(this,function(t,e,i){"use strict";function n(e,i){var n,s=this;n=e&&e.hasOwnProperty("constructor")?e.constructor:function(){s.apply(this,arguments)},t.extend(n,s,i);var o=function(){this.constructor=n};return o.prototype=s.prototype,n.prototype=new o,e&&t.extend(n.prototype,e),n.__super__=s.prototype,n}function s(t){var e=t.match(/^(\S+)\s*(.*)$/);return{kind:e[1],selector:e[2]}}function o(t){return t.charAt(0).toUpperCase()+t.slice(1)}var r={};r.VERSION="0.3.5",r.Events=t.extend({},e);var u=r.Initializer=function(e){var n=e.base||i(document.body);t.extend(this,{modules:{},module:n.data("module"),action:n.data("action")},e),this.initialize()};t.extend(u.prototype,{initialize:function(){this.execute("common","initialize"),this.execute(this.module,"initialize"),this.execute(this.module,this.action)},execute:function(e,i){var n,s;e&&i&&(n=this.modules[e]||this.modules[o(e)],t.isUndefined(n)||(s=n[i]||n[o(i)],t.isFunction(s)&&s()))},rerunAction:function(){this.execute(this.module,this.action)}});var h=r.Module=function(e){return t.extend(this,e),this.el&&this.setElement(),this.proxied&&this.proxyMethods(),this.events&&this.attachEvents(),this.subscriptions&&this.subscribeToEvents(),this.initialize.apply(this,arguments)};return h.extend=n,t.extend(h.prototype,r.Events,{publish:t.bind(r.Events.trigger,r.Events),subscribe:t.bind(r.Events.on,r.Events),$el:null,_$els:{},initialize:function(){},proxyMethods:function(){t.bindAll.apply(null,t.union(this,this.proxied))},attachEvents:function(){var e,i;t.each(this.events,function(n,o){e=t.bind(this[n],this),i=s(o),i.selector?this.$el.on(i.kind,i.selector,e):this.$el.on(i.kind,e)},this)},subscribeToEvents:function(){t.each(this.subscriptions,function(t,e){this.subscribe(e,this[t],this)},this)},setElement:function(t){var e=t||this.el;this.$el=e instanceof i?e:i(e),this.el=this.$el[0],this.data=this.$el.data()},setElements:function(){t.each(this.$("[data-bb-el]"),this._setBBElement,this)},els:function(t,e){return this._getBBElement(t,!!e)[0]},$els:function(t,e){return this._getBBElement(t,!!e)},$:function(t){return this.$el.find(t)},destroy:function(){var e;t.each(this.events,function(t,i){e=s(i),e.selector?this.$el.off(e.kind,e.selector):this.$el.off(e.kind)},this),this.$el.remove()},_getBBElement:function(e,i){var n=this._$els[e];return(i||t.isUndefined(n))&&(n=this.$("[data-bb-el="+e+"]"),this._setBBElement(n)),n},_setBBElement:function(t){var e=i(t);this._$els[e.data("bbEl")]=e}}),r});