You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

11 lines
11 KiB

/*!
* # 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(i){var o,r,s=e(e.isFunction(this)?t:this),c=e.isPlainObject(i)?e.extend(!0,{},e.fn.tab.settings,i):e.extend({},e.fn.tab.settings),l=s.selector||"",d=(new Date).getTime(),u=[],b=arguments[0],g="string"==typeof b,f=[].slice.call(arguments,1);return s.each(function(){var h,p,m,v,y,T=c.className,L=c.metadata,x=c.selector,A=c.error,C="."+c.namespace,P="module-"+c.namespace,F=e(this),S={},E=!0,j=0,k=this,w=F.data(P);o={initialize:function(){o.debug("Initializing tab menu item",F),o.fix.callbacks(),o.determineTabs(),o.debug("Determining tabs",c.context,p),c.auto&&o.set.auto(),e.isWindow(k)||(o.debug("Attaching tab activation events to element",F),F.on("click"+C,o.event.click)),o.instantiate()},determineTabs:function(){var t;"parent"===c.context?(F.closest(x.ui).length>0?(t=F.closest(x.ui),o.verbose("Using closest UI element for determining parent",t)):t=F,h=t.parent(),o.verbose("Determined parent element for creating context",h)):c.context?(h=e(c.context),o.verbose("Using selector for tab context",c.context,h)):h=e("body"),c.childrenOnly?(p=h.children(x.tabs),o.debug("Searching tab context children for tabs",h,p)):(p=h.find(x.tabs),o.debug("Searching tab context for tabs",h,p))},fix:{callbacks:function(){e.isPlainObject(i)&&(i.onTabLoad||i.onTabInit)&&(i.onTabLoad&&(i.onLoad=i.onTabLoad,delete i.onTabLoad,o.error(A.legacyLoad,i.onLoad)),i.onTabInit&&(i.onFirstLoad=i.onTabInit,delete i.onTabInit,o.error(A.legacyInit,i.onFirstLoad)),c=e.extend(!0,{},e.fn.tab.settings,i))}},initializeHistory:function(){if(c.history){if(o.debug("Initializing page state"),e.address===n)return o.error(A.state),!1;if("state"==c.historyType){if(o.debug("Using HTML5 to manage state"),c.path===!1)return o.error(A.path),!1;e.address.history(!0).state(c.path)}e.address.bind("change",o.event.history.change)}},instantiate:function(){o.verbose("Storing instance of module",o),w=o,F.data(P,o)},destroy:function(){o.debug("Destroying tabs",F),F.removeData(P).off(C)},event:{click:function(t){var a=e(this).data(L.tab);a!==n?(c.history?(o.verbose("Updating page state",t),e.address.value(a)):(o.verbose("Changing tab",t),o.changeTab(a)),t.preventDefault()):o.debug("No tab specified")},history:{change:function(t){var a=t.pathNames.join("/")||o.get.initialPath(),i=c.templates.determineTitle(a)||!1;o.performance.display(),o.debug("History change event",a,t),y=t,a!==n&&o.changeTab(a),i&&e.address.title(i)}}},refresh:function(){m&&(o.debug("Refreshing tab",m),o.changeTab(m))},cache:{read:function(e){return e!==n?S[e]:!1},add:function(e,t){e=e||m,o.debug("Adding cached content for",e),S[e]=t},remove:function(e){e=e||m,o.debug("Removing cached content for",e),delete S[e]}},set:{auto:function(){var t="string"==typeof c.path?c.path.replace(/\/$/,"")+"/{$tab}":"/{$tab}";o.verbose("Setting up automatic tab retrieval from server",t),e.isPlainObject(c.apiSettings)?c.apiSettings.url=t:c.apiSettings={url:t}},loading:function(e){var t=o.get.tabElement(e),a=t.hasClass(T.loading);a||(o.verbose("Setting loading state for",t),t.addClass(T.loading).siblings(p).removeClass(T.active+" "+T.loading),t.length>0&&c.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,i=n&&c.ignoreFirstLoad&&E,r=c.auto||e.isPlainObject(c.apiSettings),s=r&&!i?o.utilities.pathToArray(a):o.get.defaultPathArray(a);a=o.utilities.arrayToPath(s),e.each(s,function(t,n){var l,d,u,b,g=s.slice(0,t+1),f=o.utilities.arrayToPath(g),p=o.is.tab(f),L=t+1==s.length,x=o.get.tabElement(f);if(o.verbose("Looking for tab",n),p){if(o.verbose("Tab was found",n),m=f,v=o.utilities.filterArray(s,g),L?b=!0:(d=s.slice(0,t+2),u=o.utilities.arrayToPath(d),b=!o.is.tab(u),b&&o.verbose("Tab parameters found",d)),b&&r)return i?(o.debug("Ignoring remote content on first tab load",f),E=!1,o.cache.add(a,x.html()),o.activate.all(f),c.onFirstLoad.call(x[0],f,v,y),c.onLoad.call(x[0],f,v,y)):(o.activate.navigation(f),o.fetch.content(f,a)),!1;o.debug("Opened local tab",f),o.activate.all(f),o.cache.read(f)||(o.cache.add(f,!0),o.debug("First time tab loaded calling tab init"),c.onFirstLoad.call(x[0],f,v,y)),c.onLoad.call(x[0],f,v,y)}else{if(-1!=a.search("/")||""===a)return o.error(A.missingTab,F,h,f),!1;if(l=e("#"+a+', a[name="'+a+'"]'),f=l.closest("[data-tab]").data("tab"),x=o.get.tabElement(f),l&&l.length>0&&f)return o.debug("Anchor link used, opening parent tab",x,l),x.hasClass(T.active)||setTimeout(function(){o.scrollTo(l)},0),o.activate.all(f),o.cache.read(f)||(o.cache.add(f,!0),o.debug("First time tab loaded calling tab init"),c.onFirstLoad.call(x[0],f,v,y)),c.onLoad.call(x[0],f,v,y),!1}})},scrollTo:function(t){var n=t&&t.length>0?t.offset().top:!1;n!==!1&&(o.debug("Forcing scroll to an in-page link in a hidden tab",n,t),e(a).scrollTop(n))},update:{content:function(e,t,a){var i=o.get.tabElement(e),r=i[0];a=a!==n?a:c.evaluateScripts,a?(o.debug("Updating HTML and evaluating inline scripts",e,t),i.html(t)):(o.debug("Updating HTML",e,t),r.innerHTML=t)}},fetch:{content:function(t,a){var i,r,s=o.get.tabElement(t),l={dataType:"html",on:"now",cache:"local",onSuccess:function(e){o.cache.add(a,e),o.update.content(t,e),t==m?(o.debug("Content loaded",t),o.activate.tab(t)):o.debug("Content loaded in background",t),c.onFirstLoad.call(s[0],t,v,y),c.onLoad.call(s[0],t,v,y)},urlData:{tab:a}},d=s.api("get request")||!1,u=d&&"pending"===d.state();a=a||t,r=o.cache.read(a),c.cache&&r?(o.activate.tab(t),o.debug("Adding cached content",a),"once"==c.evaluateScripts?o.update.content(t,r,!1):o.update.content(t,r),c.onLoad.call(s[0],t,v,y)):u?(o.set.loading(t),o.debug("Content is already loading",a)):e.api!==n?(i=e.extend(!0,{headers:{"X-Remote":!0}},c.apiSettings,l),o.debug("Retrieving remote content",a,i),s.api(i)):o.error(A.api)}},activate:{all:function(e){o.activate.tab(e),o.activate.navigation(e)},tab:function(e){var t=o.get.tabElement(e),a=t.hasClass(T.active);o.verbose("Showing tab content for",t),a||(t.addClass(T.active).siblings(p).removeClass(T.active+" "+T.loading),t.length>0&&c.onVisible.call(t[0],e))},navigation:function(e){var t=o.get.navElement(e),a=t.hasClass(T.active);o.verbose("Activating tab navigation for",t,e),a||t.addClass(T.active).siblings(s).removeClass(T.active+" "+T.loading)}},deactivate:{all:function(){o.deactivate.navigation(),o.deactivate.tabs()},navigation:function(){s.removeClass(T.active)},tabs:function(){p.removeClass(T.active+" "+T.loading)}},is:{tab:function(e){return e!==n?o.get.tabElement(e).length>0:!1}},get:{initialPath:function(){return s.eq(0).data(L.tab)||p.eq(0).data(L.tab)},path:function(){return e.address.value()},defaultPathArray:function(e){return o.utilities.pathToArray(o.get.defaultPath(e))},defaultPath:function(e){var t=s.filter("[data-"+L.tab+'^="'+e+'/"]').eq(0),a=t.data(L.tab)||!1;if(a){if(o.debug("Found default tab",a),j<c.maxDepth)return j++,o.get.defaultPath(a);o.error(A.recursion)}else o.debug("No default tabs found for",e,p);return j=0,e},navElement:function(e){return e=e||m,s.filter("[data-"+L.tab+'="'+e+'"]')},tabElement:function(e){var t,a,n,i;return e=e||m,n=o.utilities.pathToArray(e),i=o.utilities.last(n),t=p.filter("[data-"+L.tab+'="'+i+'"]'),a=p.filter("[data-"+L.tab+'="'+e+'"]'),t.length>0?t:a},tab:function(){return m}},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=m),"string"==typeof e?e.split("/"):[e]},arrayToPath:function(t){return e.isArray(t)?t.join("/"):!1}},setting:function(t,a){if(o.debug("Changing setting",t,a),e.isPlainObject(t))e.extend(!0,c,t);else{if(a===n)return c[t];c[t]=a}},internal:function(t,a){if(e.isPlainObject(t))e.extend(!0,o,t);else{if(a===n)return o[t];o[t]=a}},debug:function(){c.debug&&(c.performance?o.performance.log(arguments):(o.debug=Function.prototype.bind.call(console.info,console,c.name+":"),o.debug.apply(console,arguments)))},verbose:function(){c.verbose&&c.debug&&(c.performance?o.performance.log(arguments):(o.verbose=Function.prototype.bind.call(console.info,console,c.name+":"),o.verbose.apply(console,arguments)))},error:function(){o.error=Function.prototype.bind.call(console.error,console,c.name+":"),o.error.apply(console,arguments)},performance:{log:function(e){var t,a,n;c.performance&&(t=(new Date).getTime(),n=d||t,a=t-n,d=t,u.push({Name:e[0],Arguments:[].slice.call(e,1)||"",Element:k,"Execution Time":a})),clearTimeout(o.performance.timer),o.performance.timer=setTimeout(o.performance.display,500)},display:function(){var t=c.name+":",a=0;d=!1,clearTimeout(o.performance.timer),e.each(u,function(e,t){a+=t["Execution Time"]}),t+=" "+a+"ms",l&&(t+=" '"+l+"'"),(console.group!==n||console.table!==n)&&u.length>0&&(console.groupCollapsed(t),console.table?console.table(u):e.each(u,function(e,t){console.log(t.Name+": "+t["Execution Time"]+"ms")}),console.groupEnd()),u=[]}},invoke:function(t,a,i){var s,c,l,d=w;return a=a||f,i=k||i,"string"==typeof t&&d!==n&&(t=t.split(/[\. ]/),s=t.length-1,e.each(t,function(a,i){var r=a!=s?i+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[i])||a==s)return d[i]!==n?(c=d[i],!1):(o.error(A.method,t),!1);d=d[i]}})),e.isFunction(c)?l=c.apply(i,a):c!==n&&(l=c),e.isArray(r)?r.push(l):r!==n?r=[r,l]:l!==n&&(r=l),c}},g?(w===n&&o.initialize(),o.invoke(b)):(w!==n&&w.invoke("destroy"),o.initialize())}),o&&!g&&o.initializeHistory(),r!==n?r: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(){},onLoad:function(){},onVisible:function(){},onRequest:function(){},templates:{determineTitle:function(){}},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 <https://github.com/asual/jquery-address>"},metadata:{tab:"tab",loaded:"loaded",promise:"promise"},className:{loading:"loading",active:"active"},selector:{tabs:".ui.tab",ui:".ui"}}}(jQuery,window,document);