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.

877 lines
29 KiB

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