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.

921 lines
23 KiB

1 year ago
  1. /*!
  2. * jQuery UI Tabs 1.13.2
  3. * http://jqueryui.com
  4. *
  5. * Copyright jQuery Foundation and other contributors
  6. * Released under the MIT license.
  7. * http://jquery.org/license
  8. */
  9. //>>label: Tabs
  10. //>>group: Widgets
  11. //>>description: Transforms a set of container elements into a tab structure.
  12. //>>docs: http://api.jqueryui.com/tabs/
  13. //>>demos: http://jqueryui.com/tabs/
  14. //>>css.structure: ../../themes/base/core.css
  15. //>>css.structure: ../../themes/base/tabs.css
  16. //>>css.theme: ../../themes/base/theme.css
  17. ( function( factory ) {
  18. "use strict";
  19. if ( typeof define === "function" && define.amd ) {
  20. // AMD. Register as an anonymous module.
  21. define( [
  22. "jquery",
  23. "./core"
  24. ], factory );
  25. } else {
  26. // Browser globals
  27. factory( jQuery );
  28. }
  29. } )( function( $ ) {
  30. "use strict";
  31. $.widget( "ui.tabs", {
  32. version: "1.13.2",
  33. delay: 300,
  34. options: {
  35. active: null,
  36. classes: {
  37. "ui-tabs": "ui-corner-all",
  38. "ui-tabs-nav": "ui-corner-all",
  39. "ui-tabs-panel": "ui-corner-bottom",
  40. "ui-tabs-tab": "ui-corner-top"
  41. },
  42. collapsible: false,
  43. event: "click",
  44. heightStyle: "content",
  45. hide: null,
  46. show: null,
  47. // Callbacks
  48. activate: null,
  49. beforeActivate: null,
  50. beforeLoad: null,
  51. load: null
  52. },
  53. _isLocal: ( function() {
  54. var rhash = /#.*$/;
  55. return function( anchor ) {
  56. var anchorUrl, locationUrl;
  57. anchorUrl = anchor.href.replace( rhash, "" );
  58. locationUrl = location.href.replace( rhash, "" );
  59. // Decoding may throw an error if the URL isn't UTF-8 (#9518)
  60. try {
  61. anchorUrl = decodeURIComponent( anchorUrl );
  62. } catch ( error ) {}
  63. try {
  64. locationUrl = decodeURIComponent( locationUrl );
  65. } catch ( error ) {}
  66. return anchor.hash.length > 1 && anchorUrl === locationUrl;
  67. };
  68. } )(),
  69. _create: function() {
  70. var that = this,
  71. options = this.options;
  72. this.running = false;
  73. this._addClass( "ui-tabs", "ui-widget ui-widget-content" );
  74. this._toggleClass( "ui-tabs-collapsible", null, options.collapsible );
  75. this._processTabs();
  76. options.active = this._initialActive();
  77. // Take disabling tabs via class attribute from HTML
  78. // into account and update option properly.
  79. if ( Array.isArray( options.disabled ) ) {
  80. options.disabled = $.uniqueSort( options.disabled.concat(
  81. $.map( this.tabs.filter( ".ui-state-disabled" ), function( li ) {
  82. return that.tabs.index( li );
  83. } )
  84. ) ).sort();
  85. }
  86. // Check for length avoids error when initializing empty list
  87. if ( this.options.active !== false && this.anchors.length ) {
  88. this.active = this._findActive( options.active );
  89. } else {
  90. this.active = $();
  91. }
  92. this._refresh();
  93. if ( this.active.length ) {
  94. this.load( options.active );
  95. }
  96. },
  97. _initialActive: function() {
  98. var active = this.options.active,
  99. collapsible = this.options.collapsible,
  100. locationHash = location.hash.substring( 1 );
  101. if ( active === null ) {
  102. // check the fragment identifier in the URL
  103. if ( locationHash ) {
  104. this.tabs.each( function( i, tab ) {
  105. if ( $( tab ).attr( "aria-controls" ) === locationHash ) {
  106. active = i;
  107. return false;
  108. }
  109. } );
  110. }
  111. // Check for a tab marked active via a class
  112. if ( active === null ) {
  113. active = this.tabs.index( this.tabs.filter( ".ui-tabs-active" ) );
  114. }
  115. // No active tab, set to false
  116. if ( active === null || active === -1 ) {
  117. active = this.tabs.length ? 0 : false;
  118. }
  119. }
  120. // Handle numbers: negative, out of range
  121. if ( active !== false ) {
  122. active = this.tabs.index( this.tabs.eq( active ) );
  123. if ( active === -1 ) {
  124. active = collapsible ? false : 0;
  125. }
  126. }
  127. // Don't allow collapsible: false and active: false
  128. if ( !collapsible && active === false && this.anchors.length ) {
  129. active = 0;
  130. }
  131. return active;
  132. },
  133. _getCreateEventData: function() {
  134. return {
  135. tab: this.active,
  136. panel: !this.active.length ? $() : this._getPanelForTab( this.active )
  137. };
  138. },
  139. _tabKeydown: function( event ) {
  140. var focusedTab = $( $.ui.safeActiveElement( this.document[ 0 ] ) ).closest( "li" ),
  141. selectedIndex = this.tabs.index( focusedTab ),
  142. goingForward = true;
  143. if ( this._handlePageNav( event ) ) {
  144. return;
  145. }
  146. switch ( event.keyCode ) {
  147. case $.ui.keyCode.RIGHT:
  148. case $.ui.keyCode.DOWN:
  149. selectedIndex++;
  150. break;
  151. case $.ui.keyCode.UP:
  152. case $.ui.keyCode.LEFT:
  153. goingForward = false;
  154. selectedIndex--;
  155. break;
  156. case $.ui.keyCode.END:
  157. selectedIndex = this.anchors.length - 1;
  158. break;
  159. case $.ui.keyCode.HOME:
  160. selectedIndex = 0;
  161. break;
  162. case $.ui.keyCode.SPACE:
  163. // Activate only, no collapsing
  164. event.preventDefault();
  165. clearTimeout( this.activating );
  166. this._activate( selectedIndex );
  167. return;
  168. case $.ui.keyCode.ENTER:
  169. // Toggle (cancel delayed activation, allow collapsing)
  170. event.preventDefault();
  171. clearTimeout( this.activating );
  172. // Determine if we should collapse or activate
  173. this._activate( selectedIndex === this.options.active ? false : selectedIndex );
  174. return;
  175. default:
  176. return;
  177. }
  178. // Focus the appropriate tab, based on which key was pressed
  179. event.preventDefault();
  180. clearTimeout( this.activating );
  181. selectedIndex = this._focusNextTab( selectedIndex, goingForward );
  182. // Navigating with control/command key will prevent automatic activation
  183. if ( !event.ctrlKey && !event.metaKey ) {
  184. // Update aria-selected immediately so that AT think the tab is already selected.
  185. // Otherwise AT may confuse the user by stating that they need to activate the tab,
  186. // but the tab will already be activated by the time the announcement finishes.
  187. focusedTab.attr( "aria-selected", "false" );
  188. this.tabs.eq( selectedIndex ).attr( "aria-selected", "true" );
  189. this.activating = this._delay( function() {
  190. this.option( "active", selectedIndex );
  191. }, this.delay );
  192. }
  193. },
  194. _panelKeydown: function( event ) {
  195. if ( this._handlePageNav( event ) ) {
  196. return;
  197. }
  198. // Ctrl+up moves focus to the current tab
  199. if ( event.ctrlKey && event.keyCode === $.ui.keyCode.UP ) {
  200. event.preventDefault();
  201. this.active.trigger( "focus" );
  202. }
  203. },
  204. // Alt+page up/down moves focus to the previous/next tab (and activates)
  205. _handlePageNav: function( event ) {
  206. if ( event.altKey && event.keyCode === $.ui.keyCode.PAGE_UP ) {
  207. this._activate( this._focusNextTab( this.options.active - 1, false ) );
  208. return true;
  209. }
  210. if ( event.altKey && event.keyCode === $.ui.keyCode.PAGE_DOWN ) {
  211. this._activate( this._focusNextTab( this.options.active + 1, true ) );
  212. return true;
  213. }
  214. },
  215. _findNextTab: function( index, goingForward ) {
  216. var lastTabIndex = this.tabs.length - 1;
  217. function constrain() {
  218. if ( index > lastTabIndex ) {
  219. index = 0;
  220. }
  221. if ( index < 0 ) {
  222. index = lastTabIndex;
  223. }
  224. return index;
  225. }
  226. while ( $.inArray( constrain(), this.options.disabled ) !== -1 ) {
  227. index = goingForward ? index + 1 : index - 1;
  228. }
  229. return index;
  230. },
  231. _focusNextTab: function( index, goingForward ) {
  232. index = this._findNextTab( index, goingForward );
  233. this.tabs.eq( index ).trigger( "focus" );
  234. return index;
  235. },
  236. _setOption: function( key, value ) {
  237. if ( key === "active" ) {
  238. // _activate() will handle invalid values and update this.options
  239. this._activate( value );
  240. return;
  241. }
  242. this._super( key, value );
  243. if ( key === "collapsible" ) {
  244. this._toggleClass( "ui-tabs-collapsible", null, value );
  245. // Setting collapsible: false while collapsed; open first panel
  246. if ( !value && this.options.active === false ) {
  247. this._activate( 0 );
  248. }
  249. }
  250. if ( key === "event" ) {
  251. this._setupEvents( value );
  252. }
  253. if ( key === "heightStyle" ) {
  254. this._setupHeightStyle( value );
  255. }
  256. },
  257. _sanitizeSelector: function( hash ) {
  258. return hash ? hash.replace( /[!"$%&'()*+,.\/:;<=>?@\[\]\^`{|}~]/g, "\\$&" ) : "";
  259. },
  260. refresh: function() {
  261. var options = this.options,
  262. lis = this.tablist.children( ":has(a[href])" );
  263. // Get disabled tabs from class attribute from HTML
  264. // this will get converted to a boolean if needed in _refresh()
  265. options.disabled = $.map( lis.filter( ".ui-state-disabled" ), function( tab ) {
  266. return lis.index( tab );
  267. } );
  268. this._processTabs();
  269. // Was collapsed or no tabs
  270. if ( options.active === false || !this.anchors.length ) {
  271. options.active = false;
  272. this.active = $();
  273. // was active, but active tab is gone
  274. } else if ( this.active.length && !$.contains( this.tablist[ 0 ], this.active[ 0 ] ) ) {
  275. // all remaining tabs are disabled
  276. if ( this.tabs.length === options.disabled.length ) {
  277. options.active = false;
  278. this.active = $();
  279. // activate previous tab
  280. } else {
  281. this._activate( this._findNextTab( Math.max( 0, options.active - 1 ), false ) );
  282. }
  283. // was active, active tab still exists
  284. } else {
  285. // make sure active index is correct
  286. options.active = this.tabs.index( this.active );
  287. }
  288. this._refresh();
  289. },
  290. _refresh: function() {
  291. this._setOptionDisabled( this.options.disabled );
  292. this._setupEvents( this.options.event );
  293. this._setupHeightStyle( this.options.heightStyle );
  294. this.tabs.not( this.active ).attr( {
  295. "aria-selected": "false",
  296. "aria-expanded": "false",
  297. tabIndex: -1
  298. } );
  299. this.panels.not( this._getPanelForTab( this.active ) )
  300. .hide()
  301. .attr( {
  302. "aria-hidden": "true"
  303. } );
  304. // Make sure one tab is in the tab order
  305. if ( !this.active.length ) {
  306. this.tabs.eq( 0 ).attr( "tabIndex", 0 );
  307. } else {
  308. this.active
  309. .attr( {
  310. "aria-selected": "true",
  311. "aria-expanded": "true",
  312. tabIndex: 0
  313. } );
  314. this._addClass( this.active, "ui-tabs-active", "ui-state-active" );
  315. this._getPanelForTab( this.active )
  316. .show()
  317. .attr( {
  318. "aria-hidden": "false"
  319. } );
  320. }
  321. },
  322. _processTabs: function() {
  323. var that = this,
  324. prevTabs = this.tabs,
  325. prevAnchors = this.anchors,
  326. prevPanels = this.panels;
  327. this.tablist = this._getList().attr( "role", "tablist" );
  328. this._addClass( this.tablist, "ui-tabs-nav",
  329. "ui-helper-reset ui-helper-clearfix ui-widget-header" );
  330. // Prevent users from focusing disabled tabs via click
  331. this.tablist
  332. .on( "mousedown" + this.eventNamespace, "> li", function( event ) {
  333. if ( $( this ).is( ".ui-state-disabled" ) ) {
  334. event.preventDefault();
  335. }
  336. } )
  337. // Support: IE <9
  338. // Preventing the default action in mousedown doesn't prevent IE
  339. // from focusing the element, so if the anchor gets focused, blur.
  340. // We don't have to worry about focusing the previously focused
  341. // element since clicking on a non-focusable element should focus
  342. // the body anyway.
  343. .on( "focus" + this.eventNamespace, ".ui-tabs-anchor", function() {
  344. if ( $( this ).closest( "li" ).is( ".ui-state-disabled" ) ) {
  345. this.blur();
  346. }
  347. } );
  348. this.tabs = this.tablist.find( "> li:has(a[href])" )
  349. .attr( {
  350. role: "tab",
  351. tabIndex: -1
  352. } );
  353. this._addClass( this.tabs, "ui-tabs-tab", "ui-state-default" );
  354. this.anchors = this.tabs.map( function() {
  355. return $( "a", this )[ 0 ];
  356. } )
  357. .attr( {
  358. tabIndex: -1
  359. } );
  360. this._addClass( this.anchors, "ui-tabs-anchor" );
  361. this.panels = $();
  362. this.anchors.each( function( i, anchor ) {
  363. var selector, panel, panelId,
  364. anchorId = $( anchor ).uniqueId().attr( "id" ),
  365. tab = $( anchor ).closest( "li" ),
  366. originalAriaControls = tab.attr( "aria-controls" );
  367. // Inline tab
  368. if ( that._isLocal( anchor ) ) {
  369. selector = anchor.hash;
  370. panelId = selector.substring( 1 );
  371. panel = that.element.find( that._sanitizeSelector( selector ) );
  372. // remote tab
  373. } else {
  374. // If the tab doesn't already have aria-controls,
  375. // generate an id by using a throw-away element
  376. panelId = tab.attr( "aria-controls" ) || $( {} ).uniqueId()[ 0 ].id;
  377. selector = "#" + panelId;
  378. panel = that.element.find( selector );
  379. if ( !panel.length ) {
  380. panel = that._createPanel( panelId );
  381. panel.insertAfter( that.panels[ i - 1 ] || that.tablist );
  382. }
  383. panel.attr( "aria-live", "polite" );
  384. }
  385. if ( panel.length ) {
  386. that.panels = that.panels.add( panel );
  387. }
  388. if ( originalAriaControls ) {
  389. tab.data( "ui-tabs-aria-controls", originalAriaControls );
  390. }
  391. tab.attr( {
  392. "aria-controls": panelId,
  393. "aria-labelledby": anchorId
  394. } );
  395. panel.attr( "aria-labelledby", anchorId );
  396. } );
  397. this.panels.attr( "role", "tabpanel" );
  398. this._addClass( this.panels, "ui-tabs-panel", "ui-widget-content" );
  399. // Avoid memory leaks (#10056)
  400. if ( prevTabs ) {
  401. this._off( prevTabs.not( this.tabs ) );
  402. this._off( prevAnchors.not( this.anchors ) );
  403. this._off( prevPanels.not( this.panels ) );
  404. }
  405. },
  406. // Allow overriding how to find the list for rare usage scenarios (#7715)
  407. _getList: function() {
  408. return this.tablist || this.element.find( "ol, ul" ).eq( 0 );
  409. },
  410. _createPanel: function( id ) {
  411. return $( "<div>" )
  412. .attr( "id", id )
  413. .data( "ui-tabs-destroy", true );
  414. },
  415. _setOptionDisabled: function( disabled ) {
  416. var currentItem, li, i;
  417. if ( Array.isArray( disabled ) ) {
  418. if ( !disabled.length ) {
  419. disabled = false;
  420. } else if ( disabled.length === this.anchors.length ) {
  421. disabled = true;
  422. }
  423. }
  424. // Disable tabs
  425. for ( i = 0; ( li = this.tabs[ i ] ); i++ ) {
  426. currentItem = $( li );
  427. if ( disabled === true || $.inArray( i, disabled ) !== -1 ) {
  428. currentItem.attr( "aria-disabled", "true" );
  429. this._addClass( currentItem, null, "ui-state-disabled" );
  430. } else {
  431. currentItem.removeAttr( "aria-disabled" );
  432. this._removeClass( currentItem, null, "ui-state-disabled" );
  433. }
  434. }
  435. this.options.disabled = disabled;
  436. this._toggleClass( this.widget(), this.widgetFullName + "-disabled", null,
  437. disabled === true );
  438. },
  439. _setupEvents: function( event ) {
  440. var events = {};
  441. if ( event ) {
  442. $.each( event.split( " " ), function( index, eventName ) {
  443. events[ eventName ] = "_eventHandler";
  444. } );
  445. }
  446. this._off( this.anchors.add( this.tabs ).add( this.panels ) );
  447. // Always prevent the default action, even when disabled
  448. this._on( true, this.anchors, {
  449. click: function( event ) {
  450. event.preventDefault();
  451. }
  452. } );
  453. this._on( this.anchors, events );
  454. this._on( this.tabs, { keydown: "_tabKeydown" } );
  455. this._on( this.panels, { keydown: "_panelKeydown" } );
  456. this._focusable( this.tabs );
  457. this._hoverable( this.tabs );
  458. },
  459. _setupHeightStyle: function( heightStyle ) {
  460. var maxHeight,
  461. parent = this.element.parent();
  462. if ( heightStyle === "fill" ) {
  463. maxHeight = parent.height();
  464. maxHeight -= this.element.outerHeight() - this.element.height();
  465. this.element.siblings( ":visible" ).each( function() {
  466. var elem = $( this ),
  467. position = elem.css( "position" );
  468. if ( position === "absolute" || position === "fixed" ) {
  469. return;
  470. }
  471. maxHeight -= elem.outerHeight( true );
  472. } );
  473. this.element.children().not( this.panels ).each( function() {
  474. maxHeight -= $( this ).outerHeight( true );
  475. } );
  476. this.panels.each( function() {
  477. $( this ).height( Math.max( 0, maxHeight -
  478. $( this ).innerHeight() + $( this ).height() ) );
  479. } )
  480. .css( "overflow", "auto" );
  481. } else if ( heightStyle === "auto" ) {
  482. maxHeight = 0;
  483. this.panels.each( function() {
  484. maxHeight = Math.max( maxHeight, $( this ).height( "" ).height() );
  485. } ).height( maxHeight );
  486. }
  487. },
  488. _eventHandler: function( event ) {
  489. var options = this.options,
  490. active = this.active,
  491. anchor = $( event.currentTarget ),
  492. tab = anchor.closest( "li" ),
  493. clickedIsActive = tab[ 0 ] === active[ 0 ],
  494. collapsing = clickedIsActive && options.collapsible,
  495. toShow = collapsing ? $() : this._getPanelForTab( tab ),
  496. toHide = !active.length ? $() : this._getPanelForTab( active ),
  497. eventData = {
  498. oldTab: active,
  499. oldPanel: toHide,
  500. newTab: collapsing ? $() : tab,
  501. newPanel: toShow
  502. };
  503. event.preventDefault();
  504. if ( tab.hasClass( "ui-state-disabled" ) ||
  505. // tab is already loading
  506. tab.hasClass( "ui-tabs-loading" ) ||
  507. // can't switch durning an animation
  508. this.running ||
  509. // click on active header, but not collapsible
  510. ( clickedIsActive && !options.collapsible ) ||
  511. // allow canceling activation
  512. ( this._trigger( "beforeActivate", event, eventData ) === false ) ) {
  513. return;
  514. }
  515. options.active = collapsing ? false : this.tabs.index( tab );
  516. this.active = clickedIsActive ? $() : tab;
  517. if ( this.xhr ) {
  518. this.xhr.abort();
  519. }
  520. if ( !toHide.length && !toShow.length ) {
  521. $.error( "jQuery UI Tabs: Mismatching fragment identifier." );
  522. }
  523. if ( toShow.length ) {
  524. this.load( this.tabs.index( tab ), event );
  525. }
  526. this._toggle( event, eventData );
  527. },
  528. // Handles show/hide for selecting tabs
  529. _toggle: function( event, eventData ) {
  530. var that = this,
  531. toShow = eventData.newPanel,
  532. toHide = eventData.oldPanel;
  533. this.running = true;
  534. function complete() {
  535. that.running = false;
  536. that._trigger( "activate", event, eventData );
  537. }
  538. function show() {
  539. that._addClass( eventData.newTab.closest( "li" ), "ui-tabs-active", "ui-state-active" );
  540. if ( toShow.length && that.options.show ) {
  541. that._show( toShow, that.options.show, complete );
  542. } else {
  543. toShow.show();
  544. complete();
  545. }
  546. }
  547. // Start out by hiding, then showing, then completing
  548. if ( toHide.length && this.options.hide ) {
  549. this._hide( toHide, this.options.hide, function() {
  550. that._removeClass( eventData.oldTab.closest( "li" ),
  551. "ui-tabs-active", "ui-state-active" );
  552. show();
  553. } );
  554. } else {
  555. this._removeClass( eventData.oldTab.closest( "li" ),
  556. "ui-tabs-active", "ui-state-active" );
  557. toHide.hide();
  558. show();
  559. }
  560. toHide.attr( "aria-hidden", "true" );
  561. eventData.oldTab.attr( {
  562. "aria-selected": "false",
  563. "aria-expanded": "false"
  564. } );
  565. // If we're switching tabs, remove the old tab from the tab order.
  566. // If we're opening from collapsed state, remove the previous tab from the tab order.
  567. // If we're collapsing, then keep the collapsing tab in the tab order.
  568. if ( toShow.length && toHide.length ) {
  569. eventData.oldTab.attr( "tabIndex", -1 );
  570. } else if ( toShow.length ) {
  571. this.tabs.filter( function() {
  572. return $( this ).attr( "tabIndex" ) === 0;
  573. } )
  574. .attr( "tabIndex", -1 );
  575. }
  576. toShow.attr( "aria-hidden", "false" );
  577. eventData.newTab.attr( {
  578. "aria-selected": "true",
  579. "aria-expanded": "true",
  580. tabIndex: 0
  581. } );
  582. },
  583. _activate: function( index ) {
  584. var anchor,
  585. active = this._findActive( index );
  586. // Trying to activate the already active panel
  587. if ( active[ 0 ] === this.active[ 0 ] ) {
  588. return;
  589. }
  590. // Trying to collapse, simulate a click on the current active header
  591. if ( !active.length ) {
  592. active = this.active;
  593. }
  594. anchor = active.find( ".ui-tabs-anchor" )[ 0 ];
  595. this._eventHandler( {
  596. target: anchor,
  597. currentTarget: anchor,
  598. preventDefault: $.noop
  599. } );
  600. },
  601. _findActive: function( index ) {
  602. return index === false ? $() : this.tabs.eq( index );
  603. },
  604. _getIndex: function( index ) {
  605. // meta-function to give users option to provide a href string instead of a numerical index.
  606. if ( typeof index === "string" ) {
  607. index = this.anchors.index( this.anchors.filter( "[href$='" +
  608. $.escapeSelector( index ) + "']" ) );
  609. }
  610. return index;
  611. },
  612. _destroy: function() {
  613. if ( this.xhr ) {
  614. this.xhr.abort();
  615. }
  616. this.tablist
  617. .removeAttr( "role" )
  618. .off( this.eventNamespace );
  619. this.anchors
  620. .removeAttr( "role tabIndex" )
  621. .removeUniqueId();
  622. this.tabs.add( this.panels ).each( function() {
  623. if ( $.data( this, "ui-tabs-destroy" ) ) {
  624. $( this ).remove();
  625. } else {
  626. $( this ).removeAttr( "role tabIndex " +
  627. "aria-live aria-busy aria-selected aria-labelledby aria-hidden aria-expanded" );
  628. }
  629. } );
  630. this.tabs.each( function() {
  631. var li = $( this ),
  632. prev = li.data( "ui-tabs-aria-controls" );
  633. if ( prev ) {
  634. li
  635. .attr( "aria-controls", prev )
  636. .removeData( "ui-tabs-aria-controls" );
  637. } else {
  638. li.removeAttr( "aria-controls" );
  639. }
  640. } );
  641. this.panels.show();
  642. if ( this.options.heightStyle !== "content" ) {
  643. this.panels.css( "height", "" );
  644. }
  645. },
  646. enable: function( index ) {
  647. var disabled = this.options.disabled;
  648. if ( disabled === false ) {
  649. return;
  650. }
  651. if ( index === undefined ) {
  652. disabled = false;
  653. } else {
  654. index = this._getIndex( index );
  655. if ( Array.isArray( disabled ) ) {
  656. disabled = $.map( disabled, function( num ) {
  657. return num !== index ? num : null;
  658. } );
  659. } else {
  660. disabled = $.map( this.tabs, function( li, num ) {
  661. return num !== index ? num : null;
  662. } );
  663. }
  664. }
  665. this._setOptionDisabled( disabled );
  666. },
  667. disable: function( index ) {
  668. var disabled = this.options.disabled;
  669. if ( disabled === true ) {
  670. return;
  671. }
  672. if ( index === undefined ) {
  673. disabled = true;
  674. } else {
  675. index = this._getIndex( index );
  676. if ( $.inArray( index, disabled ) !== -1 ) {
  677. return;
  678. }
  679. if ( Array.isArray( disabled ) ) {
  680. disabled = $.merge( [ index ], disabled ).sort();
  681. } else {
  682. disabled = [ index ];
  683. }
  684. }
  685. this._setOptionDisabled( disabled );
  686. },
  687. load: function( index, event ) {
  688. index = this._getIndex( index );
  689. var that = this,
  690. tab = this.tabs.eq( index ),
  691. anchor = tab.find( ".ui-tabs-anchor" ),
  692. panel = this._getPanelForTab( tab ),
  693. eventData = {
  694. tab: tab,
  695. panel: panel
  696. },
  697. complete = function( jqXHR, status ) {
  698. if ( status === "abort" ) {
  699. that.panels.stop( false, true );
  700. }
  701. that._removeClass( tab, "ui-tabs-loading" );
  702. panel.removeAttr( "aria-busy" );
  703. if ( jqXHR === that.xhr ) {
  704. delete that.xhr;
  705. }
  706. };
  707. // Not remote
  708. if ( this._isLocal( anchor[ 0 ] ) ) {
  709. return;
  710. }
  711. this.xhr = $.ajax( this._ajaxSettings( anchor, event, eventData ) );
  712. // Support: jQuery <1.8
  713. // jQuery <1.8 returns false if the request is canceled in beforeSend,
  714. // but as of 1.8, $.ajax() always returns a jqXHR object.
  715. if ( this.xhr && this.xhr.statusText !== "canceled" ) {
  716. this._addClass( tab, "ui-tabs-loading" );
  717. panel.attr( "aria-busy", "true" );
  718. this.xhr
  719. .done( function( response, status, jqXHR ) {
  720. // support: jQuery <1.8
  721. // http://bugs.jquery.com/ticket/11778
  722. setTimeout( function() {
  723. panel.html( response );
  724. that._trigger( "load", event, eventData );
  725. complete( jqXHR, status );
  726. }, 1 );
  727. } )
  728. .fail( function( jqXHR, status ) {
  729. // support: jQuery <1.8
  730. // http://bugs.jquery.com/ticket/11778
  731. setTimeout( function() {
  732. complete( jqXHR, status );
  733. }, 1 );
  734. } );
  735. }
  736. },
  737. _ajaxSettings: function( anchor, event, eventData ) {
  738. var that = this;
  739. return {
  740. // Support: IE <11 only
  741. // Strip any hash that exists to prevent errors with the Ajax request
  742. url: anchor.attr( "href" ).replace( /#.*$/, "" ),
  743. beforeSend: function( jqXHR, settings ) {
  744. return that._trigger( "beforeLoad", event,
  745. $.extend( { jqXHR: jqXHR, ajaxSettings: settings }, eventData ) );
  746. }
  747. };
  748. },
  749. _getPanelForTab: function( tab ) {
  750. var id = $( tab ).attr( "aria-controls" );
  751. return this.element.find( this._sanitizeSelector( "#" + id ) );
  752. }
  753. } );
  754. // DEPRECATED
  755. // TODO: Switch return back to widget declaration at top of file when this is removed
  756. if ( $.uiBackCompat !== false ) {
  757. // Backcompat for ui-tab class (now ui-tabs-tab)
  758. $.widget( "ui.tabs", $.ui.tabs, {
  759. _processTabs: function() {
  760. this._superApply( arguments );
  761. this._addClass( this.tabs, "ui-tab" );
  762. }
  763. } );
  764. }
  765. return $.ui.tabs;
  766. } );