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.

895 lines
30 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
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
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('Anchor link used, opening parent tab', $tab, $anchor);
  339. if( !$tab.hasClass(className.active) ) {
  340. setTimeout(function() {
  341. module.scrollTo($anchor);
  342. }, 0);
  343. }
  344. module.activate.all(currentPath);
  345. if( !module.cache.read(currentPath) ) {
  346. module.cache.add(currentPath, true);
  347. module.debug('First time tab loaded calling tab init');
  348. settings.onFirstLoad.call($tab[0], currentPath, parameterArray, historyEvent);
  349. }
  350. settings.onLoad.call($tab[0], currentPath, parameterArray, historyEvent);
  351. return false;
  352. }
  353. }
  354. else {
  355. module.error(error.missingTab, $module, $context, currentPath);
  356. return false;
  357. }
  358. });
  359. },
  360. scrollTo: function($element) {
  361. var
  362. scrollOffset = ($element && $element.length > 0)
  363. ? $element.offset().top
  364. : false
  365. ;
  366. if(scrollOffset !== false) {
  367. module.debug('Forcing scroll to an in-page link in a hidden tab', scrollOffset, $element);
  368. $(document).scrollTop(scrollOffset);
  369. }
  370. },
  371. update: {
  372. content: function(tabPath, html, evaluateScripts) {
  373. var
  374. $tab = module.get.tabElement(tabPath),
  375. tab = $tab[0]
  376. ;
  377. evaluateScripts = (evaluateScripts !== undefined)
  378. ? evaluateScripts
  379. : settings.evaluateScripts
  380. ;
  381. if(evaluateScripts) {
  382. module.debug('Updating HTML and evaluating inline scripts', tabPath, html);
  383. $tab.html(html);
  384. }
  385. else {
  386. module.debug('Updating HTML', tabPath, html);
  387. tab.innerHTML = html;
  388. }
  389. }
  390. },
  391. fetch: {
  392. content: function(tabPath, fullTabPath) {
  393. var
  394. $tab = module.get.tabElement(tabPath),
  395. apiSettings = {
  396. dataType : 'html',
  397. on : 'now',
  398. cache : 'local',
  399. onSuccess : function(response) {
  400. module.cache.add(fullTabPath, response);
  401. module.update.content(tabPath, response);
  402. if(tabPath == activeTabPath) {
  403. module.debug('Content loaded', tabPath);
  404. module.activate.tab(tabPath);
  405. }
  406. else {
  407. module.debug('Content loaded in background', tabPath);
  408. }
  409. settings.onFirstLoad.call($tab[0], tabPath, parameterArray, historyEvent);
  410. settings.onLoad.call($tab[0], tabPath, parameterArray, historyEvent);
  411. },
  412. urlData: {
  413. tab: fullTabPath
  414. }
  415. },
  416. request = $tab.api('get request') || false,
  417. existingRequest = ( request && request.state() === 'pending' ),
  418. requestSettings,
  419. cachedContent
  420. ;
  421. fullTabPath = fullTabPath || tabPath;
  422. cachedContent = module.cache.read(fullTabPath);
  423. if(settings.cache && cachedContent) {
  424. module.activate.tab(tabPath);
  425. module.debug('Adding cached content', fullTabPath);
  426. if(settings.evaluateScripts == 'once') {
  427. module.update.content(tabPath, cachedContent, false);
  428. }
  429. else {
  430. module.update.content(tabPath, cachedContent);
  431. }
  432. settings.onLoad.call($tab[0], tabPath, parameterArray, historyEvent);
  433. }
  434. else if(existingRequest) {
  435. module.set.loading(tabPath);
  436. module.debug('Content is already loading', fullTabPath);
  437. }
  438. else if($.api !== undefined) {
  439. requestSettings = $.extend(true, {
  440. headers: {
  441. 'X-Remote': true
  442. }
  443. }, settings.apiSettings, apiSettings);
  444. module.debug('Retrieving remote content', fullTabPath, requestSettings);
  445. $tab.api(requestSettings);
  446. }
  447. else {
  448. module.error(error.api);
  449. }
  450. }
  451. },
  452. activate: {
  453. all: function(tabPath) {
  454. module.activate.tab(tabPath);
  455. module.activate.navigation(tabPath);
  456. },
  457. tab: function(tabPath) {
  458. var
  459. $tab = module.get.tabElement(tabPath),
  460. isActive = $tab.hasClass(className.active)
  461. ;
  462. module.verbose('Showing tab content for', $tab);
  463. if(!isActive) {
  464. $tab
  465. .addClass(className.active)
  466. .siblings($tabs)
  467. .removeClass(className.active + ' ' + className.loading)
  468. ;
  469. if($tab.length > 0) {
  470. settings.onVisible.call($tab[0], tabPath);
  471. }
  472. }
  473. },
  474. navigation: function(tabPath) {
  475. var
  476. $navigation = module.get.navElement(tabPath),
  477. isActive = $navigation.hasClass(className.active)
  478. ;
  479. module.verbose('Activating tab navigation for', $navigation, tabPath);
  480. if(!isActive) {
  481. $navigation
  482. .addClass(className.active)
  483. .siblings($allModules)
  484. .removeClass(className.active + ' ' + className.loading)
  485. ;
  486. }
  487. }
  488. },
  489. deactivate: {
  490. all: function() {
  491. module.deactivate.navigation();
  492. module.deactivate.tabs();
  493. },
  494. navigation: function() {
  495. $allModules
  496. .removeClass(className.active)
  497. ;
  498. },
  499. tabs: function() {
  500. $tabs
  501. .removeClass(className.active + ' ' + className.loading)
  502. ;
  503. }
  504. },
  505. is: {
  506. tab: function(tabName) {
  507. return (tabName !== undefined)
  508. ? ( module.get.tabElement(tabName).length > 0 )
  509. : false
  510. ;
  511. }
  512. },
  513. get: {
  514. initialPath: function() {
  515. return $allModules.eq(0).data(metadata.tab) || $tabs.eq(0).data(metadata.tab);
  516. },
  517. path: function() {
  518. return $.address.value();
  519. },
  520. // adds default tabs to tab path
  521. defaultPathArray: function(tabPath) {
  522. return module.utilities.pathToArray( module.get.defaultPath(tabPath) );
  523. },
  524. defaultPath: function(tabPath) {
  525. var
  526. $defaultNav = $allModules.filter('[data-' + metadata.tab + '^="' + tabPath + '/"]').eq(0),
  527. defaultTab = $defaultNav.data(metadata.tab) || false
  528. ;
  529. if( defaultTab ) {
  530. module.debug('Found default tab', defaultTab);
  531. if(recursionDepth < settings.maxDepth) {
  532. recursionDepth++;
  533. return module.get.defaultPath(defaultTab);
  534. }
  535. module.error(error.recursion);
  536. }
  537. else {
  538. module.debug('No default tabs found for', tabPath, $tabs);
  539. }
  540. recursionDepth = 0;
  541. return tabPath;
  542. },
  543. navElement: function(tabPath) {
  544. tabPath = tabPath || activeTabPath;
  545. return $allModules.filter('[data-' + metadata.tab + '="' + tabPath + '"]');
  546. },
  547. tabElement: function(tabPath) {
  548. var
  549. $fullPathTab,
  550. $simplePathTab,
  551. tabPathArray,
  552. lastTab
  553. ;
  554. tabPath = tabPath || activeTabPath;
  555. tabPathArray = module.utilities.pathToArray(tabPath);
  556. lastTab = module.utilities.last(tabPathArray);
  557. $fullPathTab = $tabs.filter('[data-' + metadata.tab + '="' + lastTab + '"]');
  558. $simplePathTab = $tabs.filter('[data-' + metadata.tab + '="' + tabPath + '"]');
  559. return ($fullPathTab.length > 0)
  560. ? $fullPathTab
  561. : $simplePathTab
  562. ;
  563. },
  564. tab: function() {
  565. return activeTabPath;
  566. }
  567. },
  568. utilities: {
  569. filterArray: function(keepArray, removeArray) {
  570. return $.grep(keepArray, function(keepValue) {
  571. return ( $.inArray(keepValue, removeArray) == -1);
  572. });
  573. },
  574. last: function(array) {
  575. return $.isArray(array)
  576. ? array[ array.length - 1]
  577. : false
  578. ;
  579. },
  580. pathToArray: function(pathName) {
  581. if(pathName === undefined) {
  582. pathName = activeTabPath;
  583. }
  584. return typeof pathName == 'string'
  585. ? pathName.split('/')
  586. : [pathName]
  587. ;
  588. },
  589. arrayToPath: function(pathArray) {
  590. return $.isArray(pathArray)
  591. ? pathArray.join('/')
  592. : false
  593. ;
  594. }
  595. },
  596. setting: function(name, value) {
  597. module.debug('Changing setting', name, value);
  598. if( $.isPlainObject(name) ) {
  599. $.extend(true, settings, name);
  600. }
  601. else if(value !== undefined) {
  602. settings[name] = value;
  603. }
  604. else {
  605. return settings[name];
  606. }
  607. },
  608. internal: function(name, value) {
  609. if( $.isPlainObject(name) ) {
  610. $.extend(true, module, name);
  611. }
  612. else if(value !== undefined) {
  613. module[name] = value;
  614. }
  615. else {
  616. return module[name];
  617. }
  618. },
  619. debug: function() {
  620. if(settings.debug) {
  621. if(settings.performance) {
  622. module.performance.log(arguments);
  623. }
  624. else {
  625. module.debug = Function.prototype.bind.call(console.info, console, settings.name + ':');
  626. module.debug.apply(console, arguments);
  627. }
  628. }
  629. },
  630. verbose: function() {
  631. if(settings.verbose && settings.debug) {
  632. if(settings.performance) {
  633. module.performance.log(arguments);
  634. }
  635. else {
  636. module.verbose = Function.prototype.bind.call(console.info, console, settings.name + ':');
  637. module.verbose.apply(console, arguments);
  638. }
  639. }
  640. },
  641. error: function() {
  642. module.error = Function.prototype.bind.call(console.error, console, settings.name + ':');
  643. module.error.apply(console, arguments);
  644. },
  645. performance: {
  646. log: function(message) {
  647. var
  648. currentTime,
  649. executionTime,
  650. previousTime
  651. ;
  652. if(settings.performance) {
  653. currentTime = new Date().getTime();
  654. previousTime = time || currentTime;
  655. executionTime = currentTime - previousTime;
  656. time = currentTime;
  657. performance.push({
  658. 'Name' : message[0],
  659. 'Arguments' : [].slice.call(message, 1) || '',
  660. 'Element' : element,
  661. 'Execution Time' : executionTime
  662. });
  663. }
  664. clearTimeout(module.performance.timer);
  665. module.performance.timer = setTimeout(module.performance.display, 500);
  666. },
  667. display: function() {
  668. var
  669. title = settings.name + ':',
  670. totalTime = 0
  671. ;
  672. time = false;
  673. clearTimeout(module.performance.timer);
  674. $.each(performance, function(index, data) {
  675. totalTime += data['Execution Time'];
  676. });
  677. title += ' ' + totalTime + 'ms';
  678. if(moduleSelector) {
  679. title += ' \'' + moduleSelector + '\'';
  680. }
  681. if( (console.group !== undefined || console.table !== undefined) && performance.length > 0) {
  682. console.groupCollapsed(title);
  683. if(console.table) {
  684. console.table(performance);
  685. }
  686. else {
  687. $.each(performance, function(index, data) {
  688. console.log(data['Name'] + ': ' + data['Execution Time']+'ms');
  689. });
  690. }
  691. console.groupEnd();
  692. }
  693. performance = [];
  694. }
  695. },
  696. invoke: function(query, passedArguments, context) {
  697. var
  698. object = instance,
  699. maxDepth,
  700. found,
  701. response
  702. ;
  703. passedArguments = passedArguments || queryArguments;
  704. context = element || context;
  705. if(typeof query == 'string' && object !== undefined) {
  706. query = query.split(/[\. ]/);
  707. maxDepth = query.length - 1;
  708. $.each(query, function(depth, value) {
  709. var camelCaseValue = (depth != maxDepth)
  710. ? value + query[depth + 1].charAt(0).toUpperCase() + query[depth + 1].slice(1)
  711. : query
  712. ;
  713. if( $.isPlainObject( object[camelCaseValue] ) && (depth != maxDepth) ) {
  714. object = object[camelCaseValue];
  715. }
  716. else if( object[camelCaseValue] !== undefined ) {
  717. found = object[camelCaseValue];
  718. return false;
  719. }
  720. else if( $.isPlainObject( object[value] ) && (depth != maxDepth) ) {
  721. object = object[value];
  722. }
  723. else if( object[value] !== undefined ) {
  724. found = object[value];
  725. return false;
  726. }
  727. else {
  728. module.error(error.method, query);
  729. return false;
  730. }
  731. });
  732. }
  733. if ( $.isFunction( found ) ) {
  734. response = found.apply(context, passedArguments);
  735. }
  736. else if(found !== undefined) {
  737. response = found;
  738. }
  739. if($.isArray(returnedValue)) {
  740. returnedValue.push(response);
  741. }
  742. else if(returnedValue !== undefined) {
  743. returnedValue = [returnedValue, response];
  744. }
  745. else if(response !== undefined) {
  746. returnedValue = response;
  747. }
  748. return found;
  749. }
  750. };
  751. if(methodInvoked) {
  752. if(instance === undefined) {
  753. module.initialize();
  754. }
  755. module.invoke(query);
  756. }
  757. else {
  758. if(instance !== undefined) {
  759. instance.invoke('destroy');
  760. }
  761. module.initialize();
  762. }
  763. })
  764. ;
  765. if(module && !methodInvoked) {
  766. module.initializeHistory();
  767. }
  768. return (returnedValue !== undefined)
  769. ? returnedValue
  770. : this
  771. ;
  772. };
  773. // shortcut for tabbed content with no defined navigation
  774. $.tab = function() {
  775. $(window).tab.apply(this, arguments);
  776. };
  777. $.fn.tab.settings = {
  778. name : 'Tab',
  779. namespace : 'tab',
  780. debug : false,
  781. verbose : false,
  782. performance : true,
  783. auto : false, // uses pjax style endpoints fetching content from same url with remote-content headers
  784. history : false, // use browser history
  785. historyType : 'hash', // #/ or html5 state
  786. path : false, // base path of url
  787. context : false, // specify a context that tabs must appear inside
  788. childrenOnly : false, // use only tabs that are children of context
  789. maxDepth : 25, // max depth a tab can be nested
  790. alwaysRefresh : false, // load tab content new every tab click
  791. cache : true, // cache the content requests to pull locally
  792. ignoreFirstLoad : false, // don't load remote content on first load
  793. apiSettings : false, // settings for api call
  794. evaluateScripts : 'once', // whether inline scripts should be parsed (true/false/once). Once will not re-evaluate on cached content
  795. onFirstLoad : function(tabPath, parameterArray, historyEvent) {}, // called first time loaded
  796. onLoad : function(tabPath, parameterArray, historyEvent) {}, // called on every load
  797. onVisible : function(tabPath, parameterArray, historyEvent) {}, // called every time tab visible
  798. onRequest : function(tabPath, parameterArray, historyEvent) {}, // called ever time a tab beings loading remote content
  799. templates : {
  800. determineTitle: function(tabArray) {} // returns page title for path
  801. },
  802. error: {
  803. api : 'You attempted to load content without API module',
  804. method : 'The method you called is not defined',
  805. missingTab : 'Activated tab cannot be found for this context.',
  806. noContent : 'The tab you specified is missing a content url.',
  807. path : 'History enabled, but no path was specified',
  808. recursion : 'Max recursive depth reached',
  809. legacyInit : 'onTabInit has been renamed to onFirstLoad in 2.0, please adjust your code.',
  810. legacyLoad : 'onTabLoad has been renamed to onLoad in 2.0. Please adjust your code',
  811. state : 'History requires Asual\'s Address library <https://github.com/asual/jquery-address>'
  812. },
  813. metadata : {
  814. tab : 'tab',
  815. loaded : 'loaded',
  816. promise: 'promise'
  817. },
  818. className : {
  819. loading : 'loading',
  820. active : 'active'
  821. },
  822. selector : {
  823. tabs : '.ui.tab',
  824. ui : '.ui'
  825. }
  826. };
  827. })( jQuery, window , document );