/*! * # Semantic UI 2.0.0 - Tab * http://github.com/semantic-org/semantic-ui/ * * * Copyright 2015 Contributors * Released under the MIT license * http://opensource.org/licenses/MIT * */ !function(e,t,a,n){"use strict";e.fn.tab=function(a){var i,o,r=e(e.isFunction(this)?t:this),s=e.isPlainObject(a)?e.extend(!0,{},e.fn.tab.settings,a):e.extend({},e.fn.tab.settings),c=r.selector||"",l=(new Date).getTime(),d=[],u=arguments[0],b="string"==typeof u,g=[].slice.call(arguments,1);return r.each(function(){var f,h,p,m,v,y=s.className,T=s.metadata,L=s.selector,x=s.error,A="."+s.namespace,P="module-"+s.namespace,C=e(this),F={},S=!0,E=0,j=this,w=C.data(P);i={initialize:function(){i.debug("Initializing tab menu item",C),i.fix.callbacks(),i.determineTabs(),i.debug("Determining tabs",s.context,h),s.auto&&i.set.auto(),e.isWindow(j)||(i.debug("Attaching tab activation events to element",C),C.on("click"+A,i.event.click)),i.instantiate()},determineTabs:function(){var t;"parent"===s.context?(C.closest(L.ui).length>0?(t=C.closest(L.ui),i.verbose("Using closest UI element for determining parent",t)):t=C,f=t.parent(),i.verbose("Determined parent element for creating context",f)):s.context?(f=e(s.context),i.verbose("Using selector for tab context",s.context,f)):f=e("body"),s.childrenOnly?(h=f.children(L.tabs),i.debug("Searching tab context children for tabs",f,h)):(h=f.find(L.tabs),i.debug("Searching tab context for tabs",f,h))},fix:{callbacks:function(){e.isPlainObject(a)&&(a.onTabLoad||a.onTabInit)&&(a.onTabLoad&&(a.onLoad=a.onTabLoad,delete a.onTabLoad,i.error(x.legacyLoad,a.onLoad)),a.onTabInit&&(a.onFirstLoad=a.onTabInit,delete a.onTabInit,i.error(x.legacyInit,a.onFirstLoad)),s=e.extend(!0,{},e.fn.tab.settings,a))}},initializeHistory:function(){if(s.history){if(i.debug("Initializing page state"),e.address===n)return i.error(x.state),!1;if("state"==s.historyType){if(i.debug("Using HTML5 to manage state"),s.path===!1)return i.error(x.path),!1;e.address.history(!0).state(s.path)}e.address.bind("change",i.event.history.change)}},instantiate:function(){i.verbose("Storing instance of module",i),w=i,C.data(P,i)},destroy:function(){i.debug("Destroying tabs",C),C.removeData(P).off(A)},event:{click:function(t){var a=e(this).data(T.tab);a!==n?(s.history?(i.verbose("Updating page state",t),e.address.value(a)):(i.verbose("Changing tab",t),i.changeTab(a)),t.preventDefault()):i.debug("No tab specified")},history:{change:function(t){var a=t.pathNames.join("/")||i.get.initialPath(),o=s.templates.determineTitle(a)||!1;i.performance.display(),i.debug("History change event",a,t),v=t,a!==n&&i.changeTab(a),o&&e.address.title(o)}}},refresh:function(){p&&(i.debug("Refreshing tab",p),i.changeTab(p))},cache:{read:function(e){return e!==n?F[e]:!1},add:function(e,t){e=e||p,i.debug("Adding cached content for",e),F[e]=t},remove:function(e){e=e||p,i.debug("Removing cached content for",e),delete F[e]}},set:{auto:function(){var t="string"==typeof s.path?s.path.replace(/\/$/,"")+"/{$tab}":"/{$tab}";i.verbose("Setting up automatic tab retrieval from server",t),e.isPlainObject(s.apiSettings)?s.apiSettings.url=t:s.apiSettings={url:t}},loading:function(e){var t=i.get.tabElement(e),a=t.hasClass(y.loading);a||(i.verbose("Setting loading state for",t),t.addClass(y.loading).siblings(h).removeClass(y.active+" "+y.loading),t.length>0&&s.onRequest.call(t[0],e))},state:function(t){e.address.value(t)}},changeTab:function(a){var a="string"==typeof a?a.toLowerCase():a,n=t.history&&t.history.pushState,o=n&&s.ignoreFirstLoad&&S,r=s.auto||e.isPlainObject(s.apiSettings),c=r&&!o?i.utilities.pathToArray(a):i.get.defaultPathArray(a);a=i.utilities.arrayToPath(c),e.each(c,function(t,n){var l,d,u,b,g=c.slice(0,t+1),h=i.utilities.arrayToPath(g),y=i.is.tab(h),T=t+1==c.length,L=i.get.tabElement(h);if(i.verbose("Looking for tab",n),y){if(i.verbose("Tab was found",n),p=h,m=i.utilities.filterArray(c,g),T?b=!0:(d=c.slice(0,t+2),u=i.utilities.arrayToPath(d),b=!i.is.tab(u),b&&i.verbose("Tab parameters found",d)),b&&r)return o?(i.debug("Ignoring remote content on first tab load",h),S=!1,i.cache.add(a,L.html()),i.activate.all(h),s.onFirstLoad.call(L[0],h,m,v),s.onLoad.call(L[0],h,m,v)):(i.activate.navigation(h),i.fetch.content(h,a)),!1;i.debug("Opened local tab",h),i.activate.all(h),i.cache.read(h)||(i.cache.add(h,!0),i.debug("First time tab loaded calling tab init"),s.onFirstLoad.call(L[0],h,m,v)),s.onLoad.call(L[0],h,m,v)}else{if(-1!=a.search("/")||""===a)return i.error(x.missingTab,C,f,h),!1;if(l=e("#"+a+', a[name="'+a+'"]'),h=l.closest("[data-tab]").data("tab"),L=i.get.tabElement(h),l&&l.length>0&&h)return i.debug("No tab found, but deep anchor link present, opening parent tab"),i.activate.all(h),i.cache.read(h)||(i.cache.add(h,!0),i.debug("First time tab loaded calling tab init"),s.onFirstLoad.call(L[0],h,m,v)),!1}})},update:{content:function(e,t,a){var o=i.get.tabElement(e),r=o[0];a=a!==n?a:s.evaluateScripts,a?(i.debug("Updating HTML and evaluating inline scripts",e,t),o.html(t)):(i.debug("Updating HTML",e,t),r.innerHTML=t)}},fetch:{content:function(t,a){var o,r,c=i.get.tabElement(t),l={dataType:"html",on:"now",cache:"local",onSuccess:function(e){i.cache.add(a,e),i.update.content(t,e),t==p?(i.debug("Content loaded",t),i.activate.tab(t)):i.debug("Content loaded in background",t),s.onFirstLoad.call(c[0],t,m,v),s.onLoad.call(c[0],t,m,v)},urlData:{tab:a}},d=c.api("get request")||!1,u=d&&"pending"===d.state();a=a||t,r=i.cache.read(a),s.cache&&r?(i.activate.tab(t),i.debug("Adding cached content",a),"once"==s.evaluateScripts?i.update.content(t,r,!1):i.update.content(t,r),s.onLoad.call(c[0],t,m,v)):u?(i.set.loading(t),i.debug("Content is already loading",a)):e.api!==n?(o=e.extend(!0,{headers:{"X-Remote":!0}},s.apiSettings,l),i.debug("Retrieving remote content",a,o),c.api(o)):i.error(x.api)}},activate:{all:function(e){i.activate.tab(e),i.activate.navigation(e)},tab:function(e){var t=i.get.tabElement(e),a=t.hasClass(y.active);i.verbose("Showing tab content for",t),a||(t.addClass(y.active).siblings(h).removeClass(y.active+" "+y.loading),t.length>0&&s.onVisible.call(t[0],e))},navigation:function(e){var t=i.get.navElement(e),a=t.hasClass(y.active);i.verbose("Activating tab navigation for",t,e),a||t.addClass(y.active).siblings(r).removeClass(y.active+" "+y.loading)}},deactivate:{all:function(){i.deactivate.navigation(),i.deactivate.tabs()},navigation:function(){r.removeClass(y.active)},tabs:function(){h.removeClass(y.active+" "+y.loading)}},is:{tab:function(e){return e!==n?i.get.tabElement(e).length>0:!1}},get:{initialPath:function(){return r.eq(0).data(T.tab)||h.eq(0).data(T.tab)},path:function(){return e.address.value()},defaultPathArray:function(e){return i.utilities.pathToArray(i.get.defaultPath(e))},defaultPath:function(e){var t=r.filter("[data-"+T.tab+'^="'+e+'/"]').eq(0),a=t.data(T.tab)||!1;if(a){if(i.debug("Found default tab",a),E0?t:a},tab:function(){return p}},utilities:{filterArray:function(t,a){return e.grep(t,function(t){return-1==e.inArray(t,a)})},last:function(t){return e.isArray(t)?t[t.length-1]:!1},pathToArray:function(e){return e===n&&(e=p),"string"==typeof e?e.split("/"):[e]},arrayToPath:function(t){return e.isArray(t)?t.join("/"):!1}},setting:function(t,a){if(i.debug("Changing setting",t,a),e.isPlainObject(t))e.extend(!0,s,t);else{if(a===n)return s[t];s[t]=a}},internal:function(t,a){if(e.isPlainObject(t))e.extend(!0,i,t);else{if(a===n)return i[t];i[t]=a}},debug:function(){s.debug&&(s.performance?i.performance.log(arguments):(i.debug=Function.prototype.bind.call(console.info,console,s.name+":"),i.debug.apply(console,arguments)))},verbose:function(){s.verbose&&s.debug&&(s.performance?i.performance.log(arguments):(i.verbose=Function.prototype.bind.call(console.info,console,s.name+":"),i.verbose.apply(console,arguments)))},error:function(){i.error=Function.prototype.bind.call(console.error,console,s.name+":"),i.error.apply(console,arguments)},performance:{log:function(e){var t,a,n;s.performance&&(t=(new Date).getTime(),n=l||t,a=t-n,l=t,d.push({Name:e[0],Arguments:[].slice.call(e,1)||"",Element:j,"Execution Time":a})),clearTimeout(i.performance.timer),i.performance.timer=setTimeout(i.performance.display,500)},display:function(){var t=s.name+":",a=0;l=!1,clearTimeout(i.performance.timer),e.each(d,function(e,t){a+=t["Execution Time"]}),t+=" "+a+"ms",c&&(t+=" '"+c+"'"),(console.group!==n||console.table!==n)&&d.length>0&&(console.groupCollapsed(t),console.table?console.table(d):e.each(d,function(e,t){console.log(t.Name+": "+t["Execution Time"]+"ms")}),console.groupEnd()),d=[]}},invoke:function(t,a,r){var s,c,l,d=w;return a=a||g,r=j||r,"string"==typeof t&&d!==n&&(t=t.split(/[\. ]/),s=t.length-1,e.each(t,function(a,o){var r=a!=s?o+t[a+1].charAt(0).toUpperCase()+t[a+1].slice(1):t;if(e.isPlainObject(d[r])&&a!=s)d=d[r];else{if(d[r]!==n)return c=d[r],!1;if(!e.isPlainObject(d[o])||a==s)return d[o]!==n?(c=d[o],!1):(i.error(x.method,t),!1);d=d[o]}})),e.isFunction(c)?l=c.apply(r,a):c!==n&&(l=c),e.isArray(o)?o.push(l):o!==n?o=[o,l]:l!==n&&(o=l),c}},b?(w===n&&i.initialize(),i.invoke(u)):(w!==n&&w.invoke("destroy"),i.initialize())}),i&&!b&&i.initializeHistory(),o!==n?o:this},e.tab=function(){e(t).tab.apply(this,arguments)},e.fn.tab.settings={name:"Tab",namespace:"tab",debug:!1,verbose:!1,performance:!0,auto:!1,history:!1,historyType:"hash",path:!1,context:!1,childrenOnly:!1,maxDepth:25,alwaysRefresh:!1,cache:!0,ignoreFirstLoad:!1,apiSettings:!1,evaluateScripts:"once",onFirstLoad:function(e,t,a){},onLoad:function(e,t,a){},onVisible:function(e,t,a){},onRequest:function(e,t,a){},templates:{determineTitle:function(e){}},error:{api:"You attempted to load content without API module",method:"The method you called is not defined",missingTab:"Activated tab cannot be found for this context.",noContent:"The tab you specified is missing a content url.",path:"History enabled, but no path was specified",recursion:"Max recursive depth reached",legacyInit:"onTabInit has been renamed to onFirstLoad in 2.0, please adjust your code.",legacyLoad:"onTabLoad has been renamed to onLoad in 2.0. Please adjust your code",state:"History requires Asual's Address library "},metadata:{tab:"tab",loaded:"loaded",promise:"promise"},className:{loading:"loading",active:"active"},selector:{tabs:".ui.tab",ui:".ui"}}}(jQuery,window,document);