forked from ds300/tabangular
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tabangular.min.js
2 lines (2 loc) · 9.03 KB
/
tabangular.min.js
1
2
(function(){var a,b,c,d,e,f,g,h,i,j,k,l={}.hasOwnProperty,m=function(a,b){function c(){this.constructor=a}for(var d in b)l.call(b,d)&&(a[d]=b[d]);return c.prototype=b.prototype,a.prototype=new c,a.__super__=b.prototype,a};k=angular.module("tabangular",[]),k.run(function(){var a;return a=angular.element(document.head),a.ready(function(){return a.append("<style type='text/css'>.tabangular-hide {display: none;}</style>")})}),i=function(a,b){var c;return-1!==(c=a.indexOf(b))?(a.splice(c,1),!0):!1},h=function(a){return a[a.length-1]},g=function(a,b,c,d){var e;return null==(e=b[c])&&(e=[],b[c]=e),e.push(d),a.trigger("_attach",{event:c,callback:d}),function(){var b;return b=e.indexOf(d),-1!==b?(e.splice(b,1),a.trigger("_detach",{event:c,callback:d}),!0):!1}},b=function(){function a(){this._handlers={},this._onceHandlers={}}return a.prototype.on=function(a,b){return g(this,this._handlers,a,b)},a.prototype.one=function(a,b){return g(this,this._onceHandlers,a,b)},a.prototype.trigger=function(a,b){var c,d,e,f,g,h,i;if(null!=(e=this._handlers[a]))for(f=0,h=e.length;h>f;f++)c=e[f],c.call(this,b);if(null!=(d=this._onceHandlers[a]))for(g=0,i=d.length;i>g;g++)c=d[g],c.call(this,b);null!=d&&(d.length=0)},a}(),j={scope:!0},e=function(){function a(){this._tabTypes={},this._templateLoadCallbacks={},this._tabTypeFetcher=null,this.$get=["$http","$compile","$controller","$templateCache","$q","$injector",function(a){return function(b,c,d,e,g,h){return new f(a,b,c,d,e,g,h)}}(this)]}return a.prototype.registerTabType=function(a,b){if(null!=this._tabTypes[a])throw new Error("duplicate tab type '"+a+"'");return this._tabTypes[a]=b},a.prototype.typeFetcherFactory=function(a){this._typeFetcherFactory=a},a.prototype._reifyFetcher=function(a){if(null!=this._typeFetcherFactory&&(this._tabTypeFetcher=a.invoke(this._typeFetcherFactory),delete this._typeFetcherFactory,"function"!=typeof this._tabTypeFetcher))throw new Error("Tab type fetcher must be a function")},a}(),f=function(){function a(a,b,c,d,e,f,g){this.provider=a,this.$http=b,this.$compile=c,this.$controller=d,this.$templateCache=e,this.$q=f,this.$injector=g}return a.prototype._getTabType=function(a){var b,c;return this.provider._reifyFetcher(this.$injector),null!=this.provider._tabTypes[a]?c=this.$q.when(this.provider._tabTypes[a]):null!=this.provider._tabTypeFetcher?(b=this.$q.defer(),this.provider._tabTypeFetcher(b,a),this.provider._tabTypes[a]=b.promise,c=b.promise):c=this.$q.when(null),c},a.prototype._compileElem=function(a,b,c){return null!=c&&this.$controller(c,{$scope:a._scope,Tab:a}),a._elem=this.$compile(b.trim())(a._scope),a.focused?a._elem.removeClass("tabangular-hide"):a._elem.addClass("tabangular-hide")},a.prototype._compileContent=function(a,b,c){return"string"==typeof a.type?this._getTabType(a.type).then(function(d){return function(e){if(null==e)throw new Error("Unrecognised tab type: "+a.type);return d.__compileContent(a,b,c,e)}}(this),function(d){var e;return console.warn("Tab type not found: "+a.type),console.warn("Reason: "+d),e={templateString:"Tab type '"+a.type+"' not found because "+d,scope:!1},this.__compileContent(a,b,c,e)}):this.__compileContent(a,b,c,a.type)},a.prototype.__compileContent=function(a,b,c,d){var e,f,g,h;if(d=angular.extend({},j,d),a._scope=d.scope?b.$new():b,f=function(b){return function(e){return b._compileElem(a,e,d.controller),c()}}(this),null!=d.template)return f(d.template);if(null!=(g=d.templateUrl))return null!=(e=this.$templateCache.get(g))?f(e):null!=(h=this.provider._templateLoadCallbacks[g])?h.push(f):(this.provider._templateLoadCallbacks[g]=[f],this.$http.get(g).then(function(a){return function(b){var c,d,e,f,h;for(d=b.data,a.$templateCache.put(g,d),h=a.provider._templateLoadCallbacks[g],e=0,f=h.length;f>e;e++)(c=h[e])(d);return delete a.provider._templateLoadCallbacks[g]}}(this),function(b){return function(c){throw delete b.provider._templateLoadCallbacks[g],a.trigger("load_fail",c),new Error("Unable to load template from "+g)}}(this)));throw new Error("no template supplied")},a.prototype.newArea=function(a){var b;return b=new d(this,a),window.addEventListener("beforeunload",function(){return b._persist()}),b},a}(),c=function(a){function b(a,c,d){this.area=a,this.type=c,this.options=d,b.__super__.constructor.call(this),this.loading=!0,this.loadingDeferred=!1,this.closed=!1,this.focused=!1,this._elem=null,this._scope=null,this.enableAutoClose(),this.on("_attach",function(a){return function(b){return"loaded"!==b.event||a.loading?void 0:b.callback()}}(this))}return m(b,a),b.prototype.deferLoading=function(){return this.loadingDeferred=!0,this},b.prototype.doneLoading=function(){return this.loading&&(this.loading=!1,this.area._scope.$root.$$phase||this.area._scope.$apply(),this.closed||this.trigger("loaded")),this},b.prototype.close=function(a){var b;if(this.closed)throw new Error("Tab already closed");return a||this.autoClose?(i(this.area._tabs,this),i(this.area._focusStack,this),this.closed=!0,this.area._persist(),this.loading||(this._elem.remove(),this._scope!==this.area._scope&&this._scope.$destroy(),this._elem=this._scope=null,this.trigger("closed"),this.focused&&(null!=(b=h(this.area._focusStack)||h(this.area._tabs))&&b.focus(),this.focused=!1))):this.trigger("close"),this},b.prototype.enableAutoClose=function(){return this.autoClose=!0,this},b.prototype.disableAutoClose=function(){return this.autoClose=!1,this},b.prototype.focus=function(){var a,b,c;if(this.loading)this.on("loaded",function(a){return function(){return a.focus()}}(this));else{if(this.closed)throw new Error("Cannot focus closed tab");this.focused||(0!==(b=this.area._focusStack.length)&&(a=this.area._focusStack[b-1],a._elem.addClass("tabangular-hide"),a.focused=!1),this.focused=!0,null!=(c=this._elem)&&c.removeClass("tabangular-hide"),i(this.area._focusStack,this),this.area._focusStack.push(this),this.area._persist(),this.trigger("focused"))}return this},b.prototype.move=function(a,b){var c;return i(this.area._tabs,this),a!==this.area&&(i(this.area._focusStack,this),this.area._persist(),a._contentPane.append(this._elem),this.focused&&null!=(c=h(this.area._focusStack)||h(this.area._tabs))&&c.focus(),this.area=a),b=Math.min(Math.max(0,b),this.area._tabs.length),this.area._tabs.splice(b,0,this),(this.focused||1===this.area._tabs.length)&&(this.focused=!1,this.focus()),this.area._persist(),this},b}(b),a={id:null,persist:function(a){return null!=this.id?window.localStorage["tabangular:"+this.id]=a:void 0},getExisting:function(a){var b;return null!=this.id&&null!=(b=window.localStorage["tabangular:"+this.id])?a(b):void 0},transformOptions:function(a){return a},parseOptions:function(a){return a}},d=function(b){function d(b,c){var e;this._service=b,this.options=null!=c?c:{},d.__super__.constructor.call(this),this.options=angular.extend({},a,this.options),this._existingReady=!1,this._existingTabs=[],this._existingReadyQueue=[],"function"==typeof(e=this.options).getExisting&&e.getExisting(function(a){return function(b){var c,d,e,f;for(b=(null!=b?b.trim():void 0)||"[]",a._existingReady=!0,a._existingTabs=JSON.parse(b).map(function(b){return b.options=a.options.parseOptions(b.options),b}),f=a._existingReadyQueue,d=0,e=f.length;e>d;d++)(c=f[d])();return a._existingReadyQueue=[]}}(this)),this._tabs=[],this._focusStack=[],this._readyQueue=[],this._contentPane=null,this._scope=null,this.on("_attach",function(a){return function(b){return"loaded"===b.event&&null!=a._contentPane?b.callback():void 0}}(this))}return m(d,b),d.prototype._persist=function(){var a;return"function"==typeof(a=this.options).persist?a.persist(JSON.stringify(this._tabs.map(function(a){return function(b){return{type:b.type,options:a.options.transformOptions(b.options),focused:!!b.focused}}}(this)))):void 0},d.prototype.handleExisting=function(a){var b,c,d,e,f;if(a=a||function(){return!0},this._existingReady){for(f=this._existingTabs,d=0,e=f.length;e>d;d++)c=f[d],a(c)&&(b=this.load(c.type,c.options),c.focused&&b.focus());this._persist()}else this._existingReadyQueue.push(function(b){return function(){return b.handleExisting(a)}}(this));return this},d.prototype._registerContentPane=function(a,b){var c,d,e,f;for(this._contentPane=b,this._scope=a,f=this._readyQueue,d=0,e=f.length;e>d;d++)(c=f[d])();return this._readyQueue=[],this.trigger("loaded")},d.prototype._createTab=function(a,b){var d;return d=new c(this,a,b),this._tabs.push(d),d},d.prototype.load=function(a,b){var c;return null==b&&(b={}),c=this._createTab(a,b),null!=this._contentPane?this._load(c):this._readyQueue.push(function(a){return function(){return a._load(c)}}(this)),this._persist(),c},d.prototype._load=function(a){return this._service._compileContent(a,this._scope,function(b){return function(){return b._contentPane.append(a._elem),a.trigger("dom_ready"),a.loadingDeferred?void 0:a.doneLoading()}}(this))},d.prototype.open=function(a,b){return this.load(a,b).focus()},d.prototype.list=function(){return this._tabs},d}(b),k.provider("Tabs",e),k.directive("tabContent",function(){return{scope:!1,restrict:"A",link:function(a,b,c){var e;if(e=a.$eval(c.tabContent),!(e instanceof d))throw new Error("'"+c.tabContent+"' is not a tab area");e._registerContentPane(a,b)}}})}).call(this);
//# sourceMappingURL=tabangular.min.map