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.

928 lines
31 KiB

9 years ago
8 years ago
10 years ago
10 years ago
9 years ago
10 years ago
9 years ago
10 years ago
9 years ago
10 years ago
9 years ago
10 years ago
9 years ago
10 years ago
10 years ago
9 years ago
10 years ago
9 years ago
10 years ago
10 years ago
9 years ago
10 years ago
9 years ago
10 years ago
9 years ago
10 years ago
9 years ago
10 years ago
9 years ago
10 years ago
9 years ago
9 years ago
9 years ago
10 years ago
10 years ago
10 years ago
10 years ago
9 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
9 years ago
10 years ago
9 years ago
10 years ago
9 years ago
10 years ago
9 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
9 years ago
10 years ago
10 years ago
9 years ago
10 years ago
10 years ago
10 years ago
10 years ago
9 years ago
10 years ago
10 years ago
9 years ago
9 years ago
8 years ago
10 years ago
8 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
9 years ago
10 years ago
9 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
9 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
8 years ago
10 years ago
9 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
9 years ago
  1. /*!
  2. * # Semantic UI 2.2.2 - Tab
  3. * http://github.com/semantic-org/semantic-ui/
  4. *
  5. *
  6. * Released under the MIT license
  7. * http://opensource.org/licenses/MIT
  8. *
  9. */
  10. ;(function ($, window, document, undefined) {
  11. "use strict";
  12. window = (typeof window != 'undefined' && window.Math == Math)
  13. ? window
  14. : (typeof self != 'undefined' && self.Math == Math)
  15. ? self
  16. : Function('return this')()
  17. ;
  18. $.fn.tab = function(parameters) {
  19. var
  20. // use window context if none specified
  21. $allModules = $.isFunction(this)
  22. ? $(window)
  23. : $(this),
  24. moduleSelector = $allModules.selector || '',
  25. time = new Date().getTime(),
  26. performance = [],
  27. query = arguments[0],
  28. methodInvoked = (typeof query == 'string'),
  29. queryArguments = [].slice.call(arguments, 1),
  30. initializedHistory = false,
  31. returnedValue
  32. ;
  33. $allModules
  34. .each(function() {
  35. var
  36. settings = ( $.isPlainObject(parameters) )
  37. ? $.extend(true, {}, $.fn.tab.settings, parameters)
  38. : $.extend({}, $.fn.tab.settings),
  39. className = settings.className,
  40. metadata = settings.metadata,
  41. selector = settings.selector,
  42. error = settings.error,
  43. eventNamespace = '.' + settings.namespace,
  44. moduleNamespace = 'module-' + settings.namespace,
  45. $module = $(this),
  46. $context,
  47. $tabs,
  48. cache = {},
  49. firstLoad = true,
  50. recursionDepth = 0,
  51. element = this,
  52. instance = $module.data(moduleNamespace),
  53. activeTabPath,
  54. parameterArray,
  55. module,
  56. historyEvent
  57. ;
  58. module = {
  59. initialize: function() {
  60. module.debug('Initializing tab menu item', $module);
  61. module.fix.callbacks();
  62. module.determineTabs();
  63. module.debug('Determining tabs', settings.context, $tabs);
  64. // set up automatic routing
  65. if(settings.auto) {
  66. module.set.auto();
  67. }
  68. module.bind.events();
  69. if(settings.history && !initializedHistory) {
  70. module.initializeHistory();
  71. initializedHistory = true;
  72. }
  73. module.instantiate();
  74. },
  75. instantiate: function () {
  76. module.verbose('Storing instance of module', module);
  77. instance = module;
  78. $module
  79. .data(moduleNamespace, module)
  80. ;
  81. },
  82. destroy: function() {
  83. module.debug('Destroying tabs', $module);
  84. $module
  85. .removeData(moduleNamespace)
  86. .off(eventNamespace)
  87. ;
  88. },
  89. bind: {
  90. events: function() {
  91. // if using $.tab don't add events
  92. if( !$.isWindow( element ) ) {
  93. module.debug('Attaching tab activation events to element', $module);
  94. $module
  95. .on('click' + eventNamespace, module.event.click)
  96. ;
  97. }
  98. }
  99. },
  100. determineTabs: function() {
  101. var
  102. $reference
  103. ;
  104. // determine tab context
  105. if(settings.context === 'parent') {
  106. if($module.closest(selector.ui).length > 0) {
  107. $reference = $module.closest(selector.ui);
  108. module.verbose('Using closest UI element as parent', $reference);
  109. }
  110. else {
  111. $reference = $module;
  112. }
  113. $context = $reference.parent();
  114. module.verbose('Determined parent element for creating context', $context);
  115. }
  116. else if(settings.context) {
  117. $context = $(settings.context);
  118. module.verbose('Using selector for tab context', settings.context, $context);
  119. }
  120. else {
  121. $context = $('body');
  122. }
  123. // find tabs
  124. if(settings.childrenOnly) {
  125. $tabs = $context.children(selector.tabs);
  126. module.debug('Searching tab context children for tabs', $context, $tabs);
  127. }
  128. else {
  129. $tabs = $context.find(selector.tabs);
  130. module.debug('Searching tab context for tabs', $context, $tabs);
  131. }
  132. },
  133. fix: {
  134. callbacks: function() {
  135. if( $.isPlainObject(parameters) && (parameters.onTabLoad || parameters.onTabInit) ) {
  136. if(parameters.onTabLoad) {
  137. parameters.onLoad = parameters.onTabLoad;
  138. delete parameters.onTabLoad;
  139. module.error(error.legacyLoad, parameters.onLoad);
  140. }
  141. if(parameters.onTabInit) {
  142. parameters.onFirstLoad = parameters.onTabInit;
  143. delete parameters.onTabInit;
  144. module.error(error.legacyInit, parameters.onFirstLoad);
  145. }
  146. settings = $.extend(true, {}, $.fn.tab.settings, parameters);
  147. }
  148. }
  149. },
  150. initializeHistory: function() {
  151. module.debug('Initializing page state');
  152. if( $.address === undefined ) {
  153. module.error(error.state);
  154. return false;
  155. }
  156. else {
  157. if(settings.historyType == 'state') {
  158. module.debug('Using HTML5 to manage state');
  159. if(settings.path !== false) {
  160. $.address
  161. .history(true)
  162. .state(settings.path)
  163. ;
  164. }
  165. else {
  166. module.error(error.path);
  167. return false;
  168. }
  169. }
  170. $.address
  171. .bind('change', module.event.history.change)
  172. ;
  173. }
  174. },
  175. event: {
  176. click: function(event) {
  177. var
  178. tabPath = $(this).data(metadata.tab)
  179. ;
  180. if(tabPath !== undefined) {
  181. if(settings.history) {
  182. module.verbose('Updating page state', event);
  183. $.address.value(tabPath);
  184. }
  185. else {
  186. module.verbose('Changing tab', event);
  187. module.changeTab(tabPath);
  188. }
  189. event.preventDefault();
  190. }
  191. else {
  192. module.debug('No tab specified');
  193. }
  194. },
  195. history: {
  196. change: function(event) {
  197. var
  198. tabPath = event.pathNames.join('/') || module.get.initialPath(),
  199. pageTitle = settings.templates.determineTitle(tabPath) || false
  200. ;
  201. module.performance.display();
  202. module.debug('History change event', tabPath, event);
  203. historyEvent = event;
  204. if(tabPath !== undefined) {
  205. module.changeTab(tabPath);
  206. }
  207. if(pageTitle) {
  208. $.address.title(pageTitle);
  209. }
  210. }
  211. }
  212. },
  213. refresh: function() {
  214. if(activeTabPath) {
  215. module.debug('Refreshing tab', activeTabPath);
  216. module.changeTab(activeTabPath);
  217. }
  218. },
  219. cache: {
  220. read: function(cacheKey) {
  221. return (cacheKey !== undefined)
  222. ? cache[cacheKey]
  223. : false
  224. ;
  225. },
  226. add: function(cacheKey, content) {
  227. cacheKey = cacheKey || activeTabPath;
  228. module.debug('Adding cached content for', cacheKey);
  229. cache[cacheKey] = content;
  230. },
  231. remove: function(cacheKey) {
  232. cacheKey = cacheKey || activeTabPath;
  233. module.debug('Removing cached content for', cacheKey);
  234. delete cache[cacheKey];
  235. }
  236. },
  237. set: {
  238. auto: function() {
  239. var
  240. url = (typeof settings.path == 'string')
  241. ? settings.path.replace(/\/$/, '') + '/{$tab}'
  242. : '/{$tab}'
  243. ;
  244. module.verbose('Setting up automatic tab retrieval from server', url);
  245. if($.isPlainObject(settings.apiSettings)) {
  246. settings.apiSettings.url = url;
  247. }
  248. else {
  249. settings.apiSettings = {
  250. url: url
  251. };
  252. }
  253. },
  254. loading: function(tabPath) {
  255. var
  256. $tab = module.get.tabElement(tabPath),
  257. isLoading = $tab.hasClass(className.loading)
  258. ;
  259. if(!isLoading) {
  260. module.verbose('Setting loading state for', $tab);
  261. $tab
  262. .addClass(className.loading)
  263. .siblings($tabs)
  264. .removeClass(className.active + ' ' + className.loading)
  265. ;
  266. if($tab.length > 0) {
  267. settings.onRequest.call($tab[0], tabPath);
  268. }
  269. }
  270. },
  271. state: function(state) {
  272. $.address.value(state);
  273. }
  274. },
  275. changeTab: function(tabPath) {
  276. var
  277. pushStateAvailable = (window.history && window.history.pushState),
  278. shouldIgnoreLoad = (pushStateAvailable && settings.ignoreFirstLoad && firstLoad),
  279. remoteContent = (settings.auto || $.isPlainObject(settings.apiSettings) ),
  280. // only add default path if not remote content
  281. pathArray = (remoteContent && !shouldIgnoreLoad)
  282. ? module.utilities.pathToArray(tabPath)
  283. : module.get.defaultPathArray(tabPath)
  284. ;
  285. tabPath = module.utilities.arrayToPath(pathArray);
  286. $.each(pathArray, function(index, tab) {
  287. var
  288. currentPathArray = pathArray.slice(0, index + 1),
  289. currentPath = module.utilities.arrayToPath(currentPathArray),
  290. isTab = module.is.tab(currentPath),
  291. isLastIndex = (index + 1 == pathArray.length),
  292. $tab = module.get.tabElement(currentPath),
  293. $anchor,
  294. nextPathArray,
  295. nextPath,
  296. isLastTab
  297. ;
  298. module.verbose('Looking for tab', tab);
  299. if(isTab) {
  300. module.verbose('Tab was found', tab);
  301. // scope up
  302. activeTabPath = currentPath;
  303. parameterArray = module.utilities.filterArray(pathArray, currentPathArray);
  304. if(isLastIndex) {
  305. isLastTab = true;
  306. }
  307. else {
  308. nextPathArray = pathArray.slice(0, index + 2);
  309. nextPath = module.utilities.arrayToPath(nextPathArray);
  310. isLastTab = ( !module.is.tab(nextPath) );
  311. if(isLastTab) {
  312. module.verbose('Tab parameters found', nextPathArray);
  313. }
  314. }
  315. if(isLastTab && remoteContent) {
  316. if(!shouldIgnoreLoad) {
  317. module.activate.navigation(currentPath);
  318. module.fetch.content(currentPath, tabPath);
  319. }
  320. else {
  321. module.debug('Ignoring remote content on first tab load', currentPath);
  322. firstLoad = false;
  323. module.cache.add(tabPath, $tab.html());
  324. module.activate.all(currentPath);
  325. settings.onFirstLoad.call($tab[0], currentPath, parameterArray, historyEvent);
  326. settings.onLoad.call($tab[0], currentPath, parameterArray, historyEvent);
  327. }
  328. return false;
  329. }
  330. else {
  331. module.debug('Opened local tab', currentPath);
  332. module.activate.all(currentPath);
  333. if( !module.cache.read(currentPath) ) {
  334. module.cache.add(currentPath, true);
  335. module.debug('First time tab loaded calling tab init');
  336. settings.onFirstLoad.call($tab[0], currentPath, parameterArray, historyEvent);
  337. }
  338. settings.onLoad.call($tab[0], currentPath, parameterArray, historyEvent);
  339. }
  340. }
  341. else if(tabPath.search('/') == -1 && tabPath !== '') {
  342. // look for in page anchor
  343. $anchor = $('#' + tabPath + ', a[name="' + tabPath + '"]');
  344. currentPath = $anchor.closest('[data-tab]').data(metadata.tab);
  345. $tab = module.get.tabElement(currentPath);
  346. // if anchor exists use parent tab
  347. if($anchor && $anchor.length > 0 && currentPath) {
  348. module.debug('Anchor link used, opening parent tab', $tab, $anchor);
  349. if( !$tab.hasClass(className.active) ) {
  350. setTimeout(function() {
  351. module.scrollTo($anchor);
  352. }, 0);
  353. }
  354. module.activate.all(currentPath);
  355. if( !module.cache.read(currentPath) ) {
  356. module.cache.add(currentPath, true);
  357. module.debug('First time tab loaded calling tab init');
  358. settings.onFirstLoad.call($tab[0], currentPath, parameterArray, historyEvent);
  359. }
  360. settings.onLoad.call($tab[0], currentPath, parameterArray, historyEvent);
  361. return false;
  362. }
  363. }
  364. else {
  365. module.error(error.missingTab, $module, $context, currentPath);
  366. return false;
  367. }
  368. });
  369. },
  370. scrollTo: function($element) {
  371. var
  372. scrollOffset = ($element && $element.length > 0)
  373. ? $element.offset().top
  374. : false
  375. ;
  376. if(scrollOffset !== false) {
  377. module.debug('Forcing scroll to an in-page link in a hidden tab', scrollOffset, $element);
  378. $(document).scrollTop(scrollOffset);
  379. }
  380. },
  381. update: {
  382. content: function(tabPath, html, evaluateScripts) {
  383. var
  384. $tab = module.get.tabElement(tabPath),
  385. tab = $tab[0]
  386. ;
  387. evaluateScripts = (evaluateScripts !== undefined)
  388. ? evaluateScripts
  389. : settings.evaluateScripts
  390. ;
  391. if(evaluateScripts) {
  392. module.debug('Updating HTML and evaluating inline scripts', tabPath, html);
  393. $tab.html(html);
  394. }
  395. else {
  396. module.debug('Updating HTML', tabPath, html);
  397. tab.innerHTML = html;
  398. }
  399. }
  400. },
  401. fetch: {
  402. content: function(tabPath, fullTabPath) {
  403. var
  404. $tab = module.get.tabElement(tabPath),
  405. apiSettings = {
  406. dataType : 'html',
  407. encodeParameters : false,
  408. on : 'now',
  409. cache : settings.alwaysRefresh,
  410. headers : {
  411. 'X-Remote': true
  412. },
  413. onSuccess : function(response) {
  414. if(settings.cacheType == 'response') {
  415. module.cache.add(fullTabPath, response);
  416. }
  417. module.update.content(tabPath, response);
  418. if(tabPath == activeTabPath) {
  419. module.debug('Content loaded', tabPath);
  420. module.activate.tab(tabPath);
  421. }
  422. else {
  423. module.debug('Content loaded in background', tabPath);
  424. }
  425. settings.onFirstLoad.call($tab[0], tabPath, parameterArray, historyEvent);
  426. settings.onLoad.call($tab[0], tabPath, parameterArray, historyEvent);
  427. if(settings.cacheType != 'response') {
  428. module.cache.add(fullTabPath, $tab.html());
  429. }
  430. },
  431. urlData: {
  432. tab: fullTabPath
  433. }
  434. },
  435. request = $tab.api('get request') || false,
  436. existingRequest = ( request && request.state() === 'pending' ),
  437. requestSettings,
  438. cachedContent
  439. ;
  440. fullTabPath = fullTabPath || tabPath;
  441. cachedContent = module.cache.read(fullTabPath);
  442. if(settings.cache && cachedContent) {
  443. module.activate.tab(tabPath);
  444. module.debug('Adding cached content', fullTabPath);
  445. if(settings.evaluateScripts == 'once') {
  446. module.update.content(tabPath, cachedContent, false);
  447. }
  448. else {
  449. module.update.content(tabPath, cachedContent);
  450. }
  451. settings.onLoad.call($tab[0], tabPath, parameterArray, historyEvent);
  452. }
  453. else if(existingRequest) {
  454. module.set.loading(tabPath);
  455. module.debug('Content is already loading', fullTabPath);
  456. }
  457. else if($.api !== undefined) {
  458. requestSettings = $.extend(true, {}, settings.apiSettings, apiSettings);
  459. module.debug('Retrieving remote content', fullTabPath, requestSettings);
  460. module.set.loading(tabPath);
  461. $tab.api(requestSettings);
  462. }
  463. else {
  464. module.error(error.api);
  465. }
  466. }
  467. },
  468. activate: {
  469. all: function(tabPath) {
  470. module.activate.tab(tabPath);
  471. module.activate.navigation(tabPath);
  472. },
  473. tab: function(tabPath) {
  474. var
  475. $tab = module.get.tabElement(tabPath),
  476. $deactiveTabs = (settings.deactivate == 'siblings')
  477. ? $tab.siblings($tabs)
  478. : $tabs.not($tab),
  479. isActive = $tab.hasClass(className.active)
  480. ;
  481. module.verbose('Showing tab content for', $tab);
  482. if(!isActive) {
  483. $tab
  484. .addClass(className.active)
  485. ;
  486. $deactiveTabs
  487. .removeClass(className.active + ' ' + className.loading)
  488. ;
  489. if($tab.length > 0) {
  490. settings.onVisible.call($tab[0], tabPath);
  491. }
  492. }
  493. },
  494. navigation: function(tabPath) {
  495. var
  496. $navigation = module.get.navElement(tabPath),
  497. $deactiveNavigation = (settings.deactivate == 'siblings')
  498. ? $navigation.siblings($allModules)
  499. : $allModules.not($navigation),
  500. isActive = $navigation.hasClass(className.active)
  501. ;
  502. module.verbose('Activating tab navigation for', $navigation, tabPath);
  503. if(!isActive) {
  504. $navigation
  505. .addClass(className.active)
  506. ;
  507. $deactiveNavigation
  508. .removeClass(className.active + ' ' + className.loading)
  509. ;
  510. }
  511. }
  512. },
  513. deactivate: {
  514. all: function() {
  515. module.deactivate.navigation();
  516. module.deactivate.tabs();
  517. },
  518. navigation: function() {
  519. $allModules
  520. .removeClass(className.active)
  521. ;
  522. },
  523. tabs: function() {
  524. $tabs
  525. .removeClass(className.active + ' ' + className.loading)
  526. ;
  527. }
  528. },
  529. is: {
  530. tab: function(tabName) {
  531. return (tabName !== undefined)
  532. ? ( module.get.tabElement(tabName).length > 0 )
  533. : false
  534. ;
  535. }
  536. },
  537. get: {
  538. initialPath: function() {
  539. return $allModules.eq(0).data(metadata.tab) || $tabs.eq(0).data(metadata.tab);
  540. },
  541. path: function() {
  542. return $.address.value();
  543. },
  544. // adds default tabs to tab path
  545. defaultPathArray: function(tabPath) {
  546. return module.utilities.pathToArray( module.get.defaultPath(tabPath) );
  547. },
  548. defaultPath: function(tabPath) {
  549. var
  550. $defaultNav = $allModules.filter('[data-' + metadata.tab + '^="' + tabPath + '/"]').eq(0),
  551. defaultTab = $defaultNav.data(metadata.tab) || false
  552. ;
  553. if( defaultTab ) {
  554. module.debug('Found default tab', defaultTab);
  555. if(recursionDepth < settings.maxDepth) {
  556. recursionDepth++;
  557. return module.get.defaultPath(defaultTab);
  558. }
  559. module.error(error.recursion);
  560. }
  561. else {
  562. module.debug('No default tabs found for', tabPath, $tabs);
  563. }
  564. recursionDepth = 0;
  565. return tabPath;
  566. },
  567. navElement: function(tabPath) {
  568. tabPath = tabPath || activeTabPath;
  569. return $allModules.filter('[data-' + metadata.tab + '="' + tabPath + '"]');
  570. },
  571. tabElement: function(tabPath) {
  572. var
  573. $fullPathTab,
  574. $simplePathTab,
  575. tabPathArray,
  576. lastTab
  577. ;
  578. tabPath = tabPath || activeTabPath;
  579. tabPathArray = module.utilities.pathToArray(tabPath);
  580. lastTab = module.utilities.last(tabPathArray);
  581. $fullPathTab = $tabs.filter('[data-' + metadata.tab + '="' + tabPath + '"]');
  582. $simplePathTab = $tabs.filter('[data-' + metadata.tab + '="' + lastTab + '"]');
  583. return ($fullPathTab.length > 0)
  584. ? $fullPathTab
  585. : $simplePathTab
  586. ;
  587. },
  588. tab: function() {
  589. return activeTabPath;
  590. }
  591. },
  592. utilities: {
  593. filterArray: function(keepArray, removeArray) {
  594. return $.grep(keepArray, function(keepValue) {
  595. return ( $.inArray(keepValue, removeArray) == -1);
  596. });
  597. },
  598. last: function(array) {
  599. return $.isArray(array)
  600. ? array[ array.length - 1]
  601. : false
  602. ;
  603. },
  604. pathToArray: function(pathName) {
  605. if(pathName === undefined) {
  606. pathName = activeTabPath;
  607. }
  608. return typeof pathName == 'string'
  609. ? pathName.split('/')
  610. : [pathName]
  611. ;
  612. },
  613. arrayToPath: function(pathArray) {
  614. return $.isArray(pathArray)
  615. ? pathArray.join('/')
  616. : false
  617. ;
  618. }
  619. },
  620. setting: function(name, value) {
  621. module.debug('Changing setting', name, value);
  622. if( $.isPlainObject(name) ) {
  623. $.extend(true, settings, name);
  624. }
  625. else if(value !== undefined) {
  626. if($.isPlainObject(settings[name])) {
  627. $.extend(true, settings[name], value);
  628. }
  629. else {
  630. settings[name] = value;
  631. }
  632. }
  633. else {
  634. return settings[name];
  635. }
  636. },
  637. internal: function(name, value) {
  638. if( $.isPlainObject(name) ) {
  639. $.extend(true, module, name);
  640. }
  641. else if(value !== undefined) {
  642. module[name] = value;
  643. }
  644. else {
  645. return module[name];
  646. }
  647. },
  648. debug: function() {
  649. if(!settings.silent && settings.debug) {
  650. if(settings.performance) {
  651. module.performance.log(arguments);
  652. }
  653. else {
  654. module.debug = Function.prototype.bind.call(console.info, console, settings.name + ':');
  655. module.debug.apply(console, arguments);
  656. }
  657. }
  658. },
  659. verbose: function() {
  660. if(!settings.silent && settings.verbose && settings.debug) {
  661. if(settings.performance) {
  662. module.performance.log(arguments);
  663. }
  664. else {
  665. module.verbose = Function.prototype.bind.call(console.info, console, settings.name + ':');
  666. module.verbose.apply(console, arguments);
  667. }
  668. }
  669. },
  670. error: function() {
  671. if(!settings.silent) {
  672. module.error = Function.prototype.bind.call(console.error, console, settings.name + ':');
  673. module.error.apply(console, arguments);
  674. }
  675. },
  676. performance: {
  677. log: function(message) {
  678. var
  679. currentTime,
  680. executionTime,
  681. previousTime
  682. ;
  683. if(settings.performance) {
  684. currentTime = new Date().getTime();
  685. previousTime = time || currentTime;
  686. executionTime = currentTime - previousTime;
  687. time = currentTime;
  688. performance.push({
  689. 'Name' : message[0],
  690. 'Arguments' : [].slice.call(message, 1) || '',
  691. 'Element' : element,
  692. 'Execution Time' : executionTime
  693. });
  694. }
  695. clearTimeout(module.performance.timer);
  696. module.performance.timer = setTimeout(module.performance.display, 500);
  697. },
  698. display: function() {
  699. var
  700. title = settings.name + ':',
  701. totalTime = 0
  702. ;
  703. time = false;
  704. clearTimeout(module.performance.timer);
  705. $.each(performance, function(index, data) {
  706. totalTime += data['Execution Time'];
  707. });
  708. title += ' ' + totalTime + 'ms';
  709. if(moduleSelector) {
  710. title += ' \'' + moduleSelector + '\'';
  711. }
  712. if( (console.group !== undefined || console.table !== undefined) && performance.length > 0) {
  713. console.groupCollapsed(title);
  714. if(console.table) {
  715. console.table(performance);
  716. }
  717. else {
  718. $.each(performance, function(index, data) {
  719. console.log(data['Name'] + ': ' + data['Execution Time']+'ms');
  720. });
  721. }
  722. console.groupEnd();
  723. }
  724. performance = [];
  725. }
  726. },
  727. invoke: function(query, passedArguments, context) {
  728. var
  729. object = instance,
  730. maxDepth,
  731. found,
  732. response
  733. ;
  734. passedArguments = passedArguments || queryArguments;
  735. context = element || context;
  736. if(typeof query == 'string' && object !== undefined) {
  737. query = query.split(/[\. ]/);
  738. maxDepth = query.length - 1;
  739. $.each(query, function(depth, value) {
  740. var camelCaseValue = (depth != maxDepth)
  741. ? value + query[depth + 1].charAt(0).toUpperCase() + query[depth + 1].slice(1)
  742. : query
  743. ;
  744. if( $.isPlainObject( object[camelCaseValue] ) && (depth != maxDepth) ) {
  745. object = object[camelCaseValue];
  746. }
  747. else if( object[camelCaseValue] !== undefined ) {
  748. found = object[camelCaseValue];
  749. return false;
  750. }
  751. else if( $.isPlainObject( object[value] ) && (depth != maxDepth) ) {
  752. object = object[value];
  753. }
  754. else if( object[value] !== undefined ) {
  755. found = object[value];
  756. return false;
  757. }
  758. else {
  759. module.error(error.method, query);
  760. return false;
  761. }
  762. });
  763. }
  764. if ( $.isFunction( found ) ) {
  765. response = found.apply(context, passedArguments);
  766. }
  767. else if(found !== undefined) {
  768. response = found;
  769. }
  770. if($.isArray(returnedValue)) {
  771. returnedValue.push(response);
  772. }
  773. else if(returnedValue !== undefined) {
  774. returnedValue = [returnedValue, response];
  775. }
  776. else if(response !== undefined) {
  777. returnedValue = response;
  778. }
  779. return found;
  780. }
  781. };
  782. if(methodInvoked) {
  783. if(instance === undefined) {
  784. module.initialize();
  785. }
  786. module.invoke(query);
  787. }
  788. else {
  789. if(instance !== undefined) {
  790. instance.invoke('destroy');
  791. }
  792. module.initialize();
  793. }
  794. })
  795. ;
  796. return (returnedValue !== undefined)
  797. ? returnedValue
  798. : this
  799. ;
  800. };
  801. // shortcut for tabbed content with no defined navigation
  802. $.tab = function() {
  803. $(window).tab.apply(this, arguments);
  804. };
  805. $.fn.tab.settings = {
  806. name : 'Tab',
  807. namespace : 'tab',
  808. silent : false,
  809. debug : false,
  810. verbose : false,
  811. performance : true,
  812. auto : false, // uses pjax style endpoints fetching content from same url with remote-content headers
  813. history : false, // use browser history
  814. historyType : 'hash', // #/ or html5 state
  815. path : false, // base path of url
  816. context : false, // specify a context that tabs must appear inside
  817. childrenOnly : false, // use only tabs that are children of context
  818. maxDepth : 25, // max depth a tab can be nested
  819. deactivate : 'siblings', // whether tabs should deactivate sibling menu elements or all elements initialized together
  820. alwaysRefresh : false, // load tab content new every tab click
  821. cache : true, // cache the content requests to pull locally
  822. cacheType : 'response', // Whether to cache exact response, or to html cache contents after scripts execute
  823. ignoreFirstLoad : false, // don't load remote content on first load
  824. apiSettings : false, // settings for api call
  825. evaluateScripts : 'once', // whether inline scripts should be parsed (true/false/once). Once will not re-evaluate on cached content
  826. onFirstLoad : function(tabPath, parameterArray, historyEvent) {}, // called first time loaded
  827. onLoad : function(tabPath, parameterArray, historyEvent) {}, // called on every load
  828. onVisible : function(tabPath, parameterArray, historyEvent) {}, // called every time tab visible
  829. onRequest : function(tabPath, parameterArray, historyEvent) {}, // called ever time a tab beings loading remote content
  830. templates : {
  831. determineTitle: function(tabArray) {} // returns page title for path
  832. },
  833. error: {
  834. api : 'You attempted to load content without API module',
  835. method : 'The method you called is not defined',
  836. missingTab : 'Activated tab cannot be found. Tabs are case-sensitive.',
  837. noContent : 'The tab you specified is missing a content url.',
  838. path : 'History enabled, but no path was specified',
  839. recursion : 'Max recursive depth reached',
  840. legacyInit : 'onTabInit has been renamed to onFirstLoad in 2.0, please adjust your code.',
  841. legacyLoad : 'onTabLoad has been renamed to onLoad in 2.0. Please adjust your code',
  842. state : 'History requires Asual\'s Address library <https://github.com/asual/jquery-address>'
  843. },
  844. metadata : {
  845. tab : 'tab',
  846. loaded : 'loaded',
  847. promise: 'promise'
  848. },
  849. className : {
  850. loading : 'loading',
  851. active : 'active'
  852. },
  853. selector : {
  854. tabs : '.ui.tab',
  855. ui : '.ui'
  856. }
  857. };
  858. })( jQuery, window, document );