ui.tabs.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780
  1. /*
  2. * jQuery UI Tabs 1.8.5
  3. * Depends:
  4. * jquery.ui.core.js
  5. * jquery.ui.widget.js
  6. */
  7. (function( $, undefined ) {
  8. var tabId = 0,
  9. listId = 0;
  10. function getNextTabId() {
  11. return ++tabId;
  12. }
  13. function getNextListId() {
  14. return ++listId;
  15. }
  16. //初始化按钮
  17. function setLinkButton(target){
  18. $(".buttonlink",target).each(function(){
  19. var plain = $(this).attr("plain");
  20. if(plain=="false"||plain==null||plain==""){
  21. $(this).attr({"plain":"true"});
  22. $(this).linkbutton({plain:false});
  23. }
  24. });
  25. }
  26. $.widget( "ui.tabs", {
  27. options: {
  28. add: null,
  29. ajaxOptions: null,
  30. cache: false,
  31. cookie: null, // e.g. { expires: 7, path: '/', domain: 'jquery.com', secure: true }
  32. collapsible: false,
  33. disable: null,
  34. disabled: [],
  35. enable: null,
  36. event: "click",
  37. fx: null, // e.g. { height: 'toggle', opacity: 'toggle', duration: 200 }
  38. idPrefix: "ui-tabs-",
  39. load: null,
  40. panelTemplate: "<div></div>",
  41. remove: null,
  42. select: null,
  43. show: null,
  44. spinner: "<em>Loading&#8230;</em>",
  45. tabTemplate: "<li><a href='#{href}'><span>#{label}</span></a></li>"
  46. },
  47. _create: function() {
  48. this._tabify( true );
  49. },
  50. _setOption: function( key, value ) {
  51. if ( key == "selected" ) {
  52. if (this.options.collapsible && value == this.options.selected ) {
  53. return;
  54. }
  55. this.select( value );
  56. } else {
  57. this.options[ key ] = value;
  58. this._tabify();
  59. }
  60. },
  61. _tabId: function( a ) {
  62. //alert("000==="+$( a ).parent().html()+"-----------------"+ $( a ).attr( "rel" ));
  63. return a.title && a.title.replace( /\s/g, "_" ).replace( /[^\w\u00c0-\uFFFF-]/g, "" ) ||a.rel||
  64. this.options.idPrefix + getNextTabId();
  65. },
  66. _sanitizeSelector: function( hash ) {
  67. // we need this because an id may contain a ":"
  68. return hash.replace( /:/g, "\\:" );
  69. },
  70. _cookie: function() {
  71. var cookie = this.cookie ||
  72. ( this.cookie = this.options.cookie.name || "ui-tabs-" + getNextListId() );
  73. return $.cookie.apply( null, [ cookie ].concat( $.makeArray( arguments ) ) );
  74. },
  75. _ui: function( tab, panel ) {
  76. return {
  77. tab: tab,
  78. panel: panel,
  79. index: this.anchors.index( tab )
  80. };
  81. },
  82. _cleanup: function() {
  83. // restore all former loading tabs labels
  84. this.lis.filter( ".ui-state-processing" )
  85. .removeClass( "ui-state-processing" )
  86. .find( "span:data(label.tabs)" )
  87. .each(function() {
  88. var el = $( this );
  89. el.html( el.data( "label.tabs" ) ).removeData( "label.tabs" );
  90. });
  91. },
  92. _tabify: function( init ) {
  93. var self = this,
  94. o = this.options,
  95. fragmentId = /^#.+/; // Safari 2 reports '#' for an empty hash
  96. this.list = this.element.find( "ol,ul" ).eq( 0 );
  97. this.lis = $( " > li:has(a[href])", this.list );
  98. this.anchors = this.lis.map(function() {
  99. return $( "a", this )[ 0 ];
  100. });
  101. this.panels = $( [] );
  102. this.anchors.each(function( i, a ) {
  103. var href = $( a ).attr( "href" );
  104. // For dynamically created HTML that contains a hash as href IE < 8 expands
  105. // such href to the full page url with hash and then misinterprets tab as ajax.
  106. // Same consideration applies for an added tab with a fragment identifier
  107. // since a[href=#fragment-identifier] does unexpectedly not match.
  108. // Thus normalize href attribute...
  109. var hrefBase = href.split( "#" )[ 0 ],
  110. baseEl;
  111. if ( hrefBase && ( hrefBase === location.toString().split( "#" )[ 0 ] ||
  112. ( baseEl = $( "base" )[ 0 ]) && hrefBase === baseEl.href ) ) {
  113. href = a.hash;
  114. a.href = href;
  115. }
  116. // inline tab
  117. if ( fragmentId.test( href ) ) {
  118. self.panels = self.panels.add( self._sanitizeSelector( href ) );
  119. // remote tab
  120. // prevent loading the page itself if href is just "#"
  121. } else if ( href && href !== "#" ) {
  122. // required for restore on destroy
  123. $.data( a, "href.tabs", href );
  124. // TODO until #3808 is fixed strip fragment identifier from url
  125. // (IE fails to load from such url)
  126. $.data( a, "load.tabs", href.replace( /#.*$/, "" ) );
  127. var id = self._tabId( a );
  128. a.href = "#" + id;
  129. var $panel = $( "#" + id );
  130. if ( !$panel.length ) {
  131. $panel = $( o.panelTemplate )
  132. .attr( "id", id )
  133. .addClass( "ui-tabs-panel ui-widget-content ui-corner-bottom" )
  134. .insertAfter( self.panels[ i - 1 ] || self.list );
  135. $panel.data( "destroy.tabs", true );
  136. }
  137. self.panels = self.panels.add( $panel );
  138. // invalid tab href
  139. } else {
  140. o.disabled.push( i );
  141. }
  142. });
  143. // initialization from scratch
  144. if ( init ) {
  145. // attach necessary classes for styling
  146. this.element.addClass( "ui-tabs ui-widget ui-widget-content ui-corner-all" );
  147. this.list.addClass( "ui-tabs-nav ui-helper-reset ui-helper-clearfix ui-widget-header ui-corner-all" );
  148. this.lis.addClass( "ui-state-default ui-corner-top" );
  149. this.panels.addClass( "ui-tabs-panel ui-widget-content ui-corner-bottom" );
  150. // Selected tab
  151. // use "selected" option or try to retrieve:
  152. // 1. from fragment identifier in url
  153. // 2. from cookie
  154. // 3. from selected class attribute on <li>
  155. if ( o.selected === undefined ) {
  156. if ( location.hash ) {
  157. this.anchors.each(function( i, a ) {
  158. if ( a.hash == location.hash ) {
  159. o.selected = i;
  160. return false;
  161. }
  162. });
  163. }
  164. if ( typeof o.selected !== "number" && o.cookie ) {
  165. o.selected = parseInt( self._cookie(), 10 );
  166. }
  167. if ( typeof o.selected !== "number" && this.lis.filter( ".ui-tabs-selected" ).length ) {
  168. o.selected = this.lis.index( this.lis.filter( ".ui-tabs-selected" ) );
  169. }
  170. o.selected = o.selected || ( this.lis.length ? 0 : -1 );
  171. } else if ( o.selected === null ) { // usage of null is deprecated, TODO remove in next release
  172. o.selected = -1;
  173. }
  174. // sanity check - default to first tab...
  175. o.selected = ( ( o.selected >= 0 && this.anchors[ o.selected ] ) || o.selected < 0 )
  176. ? o.selected
  177. : 0;
  178. // Take disabling tabs via class attribute from HTML
  179. // into account and update option properly.
  180. // A selected tab cannot become disabled.
  181. o.disabled = $.unique( o.disabled.concat(
  182. $.map( this.lis.filter( ".ui-state-disabled" ), function( n, i ) {
  183. return self.lis.index( n );
  184. })
  185. ) ).sort();
  186. if ( $.inArray( o.selected, o.disabled ) != -1 ) {
  187. o.disabled.splice( $.inArray( o.selected, o.disabled ), 1 );
  188. }
  189. // highlight selected tab
  190. this.panels.addClass( "ui-tabs-hide" );
  191. this.lis.removeClass( "ui-tabs-selected ui-state-active" );
  192. // check for length avoids error when initializing empty list
  193. if ( o.selected >= 0 && this.anchors.length ) {
  194. this.panels.eq( o.selected ).removeClass( "ui-tabs-hide" );
  195. this.lis.eq( o.selected ).addClass( "ui-tabs-selected ui-state-active" );
  196. // seems to be expected behavior that the show callback is fired
  197. self.element.queue( "tabs", function() {
  198. self._trigger( "show", null,
  199. self._ui( self.anchors[ o.selected ], self.panels[ o.selected ] ) );
  200. //显示多记录
  201. var obj = self.panels[o.selected];
  202. });
  203. this.load( o.selected );
  204. }
  205. // clean up to avoid memory leaks in certain versions of IE 6
  206. // TODO: namespace this event
  207. $( window ).bind( "unload", function() {
  208. self.lis.add( self.anchors ).unbind( ".tabs" );
  209. self.lis = self.anchors = self.panels = null;
  210. });
  211. // update selected after add/remove
  212. } else {
  213. o.selected = this.lis.index( this.lis.filter( ".ui-tabs-selected" ) );
  214. }
  215. // update collapsible
  216. // TODO: use .toggleClass()
  217. this.element[ o.collapsible ? "addClass" : "removeClass" ]( "ui-tabs-collapsible" );
  218. // set or update cookie after init and add/remove respectively
  219. if ( o.cookie ) {
  220. this._cookie( o.selected, o.cookie );
  221. }
  222. // disable tabs
  223. for ( var i = 0, li; ( li = this.lis[ i ] ); i++ ) {
  224. $( li )[ $.inArray( i, o.disabled ) != -1 &&
  225. // TODO: use .toggleClass()
  226. !$( li ).hasClass( "ui-tabs-selected" ) ? "addClass" : "removeClass" ]( "ui-state-disabled" );
  227. }
  228. // reset cache if switching from cached to not cached
  229. if ( o.cache === false ) {
  230. this.anchors.removeData( "cache.tabs" );
  231. }
  232. // remove all handlers before, tabify may run on existing tabs after add or option change
  233. this.lis.add( this.anchors ).unbind( ".tabs" );
  234. if ( o.event !== "mouseover" ) {
  235. var addState = function( state, el ) {
  236. if ( el.is( ":not(.ui-state-disabled)" ) ) {
  237. el.addClass( "ui-state-" + state );
  238. }
  239. };
  240. var removeState = function( state, el ) {
  241. el.removeClass( "ui-state-" + state );
  242. };
  243. this.lis.bind( "mouseover.tabs" , function() {
  244. addState( "hover", $( this ) );
  245. });
  246. this.lis.bind( "mouseout.tabs", function() {
  247. removeState( "hover", $( this ) );
  248. });
  249. this.anchors.bind( "focus.tabs", function() {
  250. addState( "focus", $( this ).closest( "li" ) );
  251. });
  252. this.anchors.bind( "blur.tabs", function() {
  253. removeState( "focus", $( this ).closest( "li" ) );
  254. });
  255. }
  256. // set up animations
  257. var hideFx, showFx;
  258. if ( o.fx ) {
  259. if ( $.isArray( o.fx ) ) {
  260. hideFx = o.fx[ 0 ];
  261. showFx = o.fx[ 1 ];
  262. } else {
  263. hideFx = showFx = o.fx;
  264. }
  265. }
  266. // Reset certain styles left over from animation
  267. // and prevent IE's ClearType bug...
  268. function resetStyle( $el, fx ) {
  269. $el.css( "display", "" );
  270. if ( !$.support.opacity && fx.opacity ) {
  271. $el[ 0 ].style.removeAttribute( "filter" );
  272. }
  273. }
  274. // Show a tab...
  275. var showTab = showFx
  276. ? function( clicked, $show ) {
  277. $( clicked ).closest( "li" ).addClass( "ui-tabs-selected ui-state-active" );
  278. var obj = $show.get(0);
  279. $show.hide().removeClass( "ui-tabs-hide" ) // avoid flicker that way
  280. .animate( showFx, showFx.duration || "normal", function() {
  281. resetStyle( $show, showFx );
  282. self._trigger( "show", null, self._ui( clicked, $show[ 0 ] ) );
  283. });
  284. CFW.oWin.fnResizeObject(obj);
  285. }
  286. : function( clicked, $show ) {
  287. $( clicked ).closest( "li" ).addClass( "ui-tabs-selected ui-state-active" );
  288. //显示多记录
  289. var obj = $show.get(0);
  290. setLinkButton(obj);
  291. $show.removeClass( "ui-tabs-hide" );
  292. self._trigger( "show", null, self._ui( clicked, $show[ 0 ] ) );
  293. CFW.oWin.fnResizeObject(obj);
  294. };
  295. // Hide a tab, $show is optional...
  296. var hideTab = hideFx
  297. ? function( clicked, $hide ) {
  298. $hide.animate( hideFx, hideFx.duration || "normal", function() {
  299. self.lis.removeClass( "ui-tabs-selected ui-state-active" );
  300. $hide.addClass( "ui-tabs-hide" );
  301. resetStyle( $hide, hideFx );
  302. self.element.dequeue( "tabs" );
  303. });
  304. }
  305. : function( clicked, $hide, $show ) {
  306. self.lis.removeClass( "ui-tabs-selected ui-state-active" );
  307. $hide.addClass( "ui-tabs-hide" );
  308. self.element.dequeue( "tabs" );
  309. };
  310. // attach tab event handler, unbind to avoid duplicates from former tabifying...
  311. this.anchors.bind( o.event + ".tabs", function() {
  312. var el = this,
  313. $li = $(el).closest( "li" ),
  314. $hide = self.panels.filter( ":not(.ui-tabs-hide)" ),
  315. $show = $( self._sanitizeSelector( el.hash ) );
  316. // If tab is already selected and not collapsible or tab disabled or
  317. // or is already loading or click callback returns false stop here.
  318. // Check if click handler returns false last so that it is not executed
  319. // for a disabled or loading tab!
  320. if ( ( $li.hasClass( "ui-tabs-selected" ) && !o.collapsible) ||
  321. $li.hasClass( "ui-state-disabled" ) ||
  322. $li.hasClass( "ui-state-processing" ) ||
  323. self.panels.filter( ":animated" ).length ||
  324. self._trigger( "select", null, self._ui( this, $show[ 0 ] ) ) === false ) {
  325. this.blur();
  326. return false;
  327. }
  328. o.selected = self.anchors.index( this );
  329. self.abort();
  330. // if tab may be closed
  331. if ( o.collapsible ) {
  332. if ( $li.hasClass( "ui-tabs-selected" ) ) {
  333. o.selected = -1;
  334. if ( o.cookie ) {
  335. self._cookie( o.selected, o.cookie );
  336. }
  337. self.element.queue( "tabs", function() {
  338. hideTab( el, $hide );
  339. }).dequeue( "tabs" );
  340. this.blur();
  341. return false;
  342. } else if ( !$hide.length ) {
  343. if ( o.cookie ) {
  344. self._cookie( o.selected, o.cookie );
  345. }
  346. self.element.queue( "tabs", function() {
  347. showTab( el, $show );
  348. });
  349. // TODO make passing in node possible, see also http://dev.jqueryui.com/ticket/3171
  350. self.load( self.anchors.index( this ) );
  351. this.blur();
  352. return false;
  353. }
  354. }
  355. if ( o.cookie ) {
  356. self._cookie( o.selected, o.cookie );
  357. }
  358. // show new tab
  359. if ( $show.length ) {
  360. if ( $hide.length ) {
  361. self.element.queue( "tabs", function() {
  362. hideTab( el, $hide );
  363. });
  364. }
  365. self.element.queue( "tabs", function() {
  366. showTab( el, $show );
  367. });
  368. self.load( self.anchors.index( this ) );
  369. } else {
  370. throw "jQuery UI Tabs: Mismatching fragment identifier.";
  371. }
  372. // Prevent IE from keeping other link focussed when using the back button
  373. // and remove dotted border from clicked link. This is controlled via CSS
  374. // in modern browsers; blur() removes focus from address bar in Firefox
  375. // which can become a usability and annoying problem with tabs('rotate').
  376. if ( $.browser.msie ) {
  377. this.blur();
  378. }
  379. });
  380. // disable click in any case
  381. this.anchors.bind( "click.tabs", function(){
  382. return false;
  383. });
  384. },
  385. _getIndex: function( index ) {
  386. // meta-function to give users option to provide a href string instead of a numerical index.
  387. // also sanitizes numerical indexes to valid values.
  388. if ( typeof index == "string" ) {
  389. index = this.anchors.index( this.anchors.filter( "[href$=" + index + "]" ) );
  390. }
  391. return index;
  392. },
  393. destroy: function() {
  394. var o = this.options;
  395. this.abort();
  396. this.element
  397. .unbind( ".tabs" )
  398. .removeClass( "ui-tabs ui-widget ui-widget-content ui-corner-all ui-tabs-collapsible" )
  399. .removeData( "tabs" );
  400. this.list.removeClass( "ui-tabs-nav ui-helper-reset ui-helper-clearfix ui-widget-header ui-corner-all" );
  401. this.anchors.each(function() {
  402. var href = $.data( this, "href.tabs" );
  403. if ( href ) {
  404. this.href = href;
  405. }
  406. var $this = $( this ).unbind( ".tabs" );
  407. $.each( [ "href", "load", "cache" ], function( i, prefix ) {
  408. $this.removeData( prefix + ".tabs" );
  409. });
  410. });
  411. this.lis.unbind( ".tabs" ).add( this.panels ).each(function() {
  412. if ( $.data( this, "destroy.tabs" ) ) {
  413. $( this ).remove();
  414. } else {
  415. $( this ).removeClass([
  416. "ui-state-default",
  417. "ui-corner-top",
  418. "ui-tabs-selected",
  419. "ui-state-active",
  420. "ui-state-hover",
  421. "ui-state-focus",
  422. "ui-state-disabled",
  423. "ui-tabs-panel",
  424. "ui-widget-content",
  425. "ui-corner-bottom",
  426. "ui-tabs-hide"
  427. ].join( " " ) );
  428. }
  429. });
  430. if ( o.cookie ) {
  431. this._cookie( null, o.cookie );
  432. }
  433. return this;
  434. },
  435. add: function( url, label, index ) {
  436. if ( index === undefined ) {
  437. index = this.anchors.length;
  438. }
  439. var self = this,
  440. o = this.options,
  441. $li = $( o.tabTemplate.replace( /#\{href\}/g, url ).replace( /#\{label\}/g, label ) ),
  442. id = !url.indexOf( "#" ) ? url.replace( "#", "" ) : this._tabId( $( "a", $li )[ 0 ] );
  443. $li.addClass( "ui-state-default ui-corner-top" ).data( "destroy.tabs", true );
  444. // try to find an existing element before creating a new one
  445. var $panel = $( "#" + id );
  446. if ( !$panel.length ) {
  447. $panel = $( o.panelTemplate )
  448. .attr( "id", id )
  449. .data( "destroy.tabs", true );
  450. }
  451. $panel.addClass( "ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide" );
  452. if ( index >= this.lis.length ) {
  453. $li.appendTo( this.list );
  454. $panel.appendTo( this.list[ 0 ].parentNode );
  455. } else {
  456. $li.insertBefore( this.lis[ index ] );
  457. $panel.insertBefore( this.panels[ index ] );
  458. }
  459. o.disabled = $.map( o.disabled, function( n, i ) {
  460. return n >= index ? ++n : n;
  461. });
  462. this._tabify();
  463. if ( this.anchors.length == 1 ) {
  464. o.selected = 0;
  465. $li.addClass( "ui-tabs-selected ui-state-active" );
  466. $panel.removeClass( "ui-tabs-hide" );
  467. this.element.queue( "tabs", function() {
  468. self._trigger( "show", null, self._ui( self.anchors[ 0 ], self.panels[ 0 ] ) );
  469. });
  470. this.load( 0 );
  471. }
  472. this._trigger( "add", null, this._ui( this.anchors[ index ], this.panels[ index ] ) );
  473. return this;
  474. },
  475. remove: function( index ) {
  476. index = this._getIndex( index );
  477. var o = this.options,
  478. $li = this.lis.eq( index ).remove(),
  479. $panel = this.panels.eq( index ).remove();
  480. // If selected tab was removed focus tab to the right or
  481. // in case the last tab was removed the tab to the left.
  482. if ( $li.hasClass( "ui-tabs-selected" ) && this.anchors.length > 1) {
  483. this.select( index + ( index + 1 < this.anchors.length ? 1 : -1 ) );
  484. }
  485. o.disabled = $.map(
  486. $.grep( o.disabled, function(n, i) {
  487. return n != index;
  488. }),
  489. function( n, i ) {
  490. return n >= index ? --n : n;
  491. });
  492. this._tabify();
  493. this._trigger( "remove", null, this._ui( $li.find( "a" )[ 0 ], $panel[ 0 ] ) );
  494. return this;
  495. },
  496. enable: function( index ) {
  497. index = this._getIndex( index );
  498. var o = this.options;
  499. if ( $.inArray( index, o.disabled ) == -1 ) {
  500. return;
  501. }
  502. this.lis.eq( index ).removeClass( "ui-state-disabled" );
  503. o.disabled = $.grep( o.disabled, function( n, i ) {
  504. return n != index;
  505. });
  506. this._trigger( "enable", null, this._ui( this.anchors[ index ], this.panels[ index ] ) );
  507. return this;
  508. },
  509. disable: function( index ) {
  510. index = this._getIndex( index );
  511. var self = this, o = this.options;
  512. // cannot disable already selected tab
  513. if ( index != o.selected ) {
  514. this.lis.eq( index ).addClass( "ui-state-disabled" );
  515. o.disabled.push( index );
  516. o.disabled.sort();
  517. this._trigger( "disable", null, this._ui( this.anchors[ index ], this.panels[ index ] ) );
  518. }
  519. return this;
  520. },
  521. select: function( index ) {
  522. index = this._getIndex( index );
  523. if ( index == -1 ) {
  524. if ( this.options.collapsible && this.options.selected != -1 ) {
  525. index = this.options.selected;
  526. } else {
  527. return this;
  528. }
  529. }
  530. this.anchors.eq( index ).trigger( this.options.event + ".tabs" );
  531. return this;
  532. },
  533. load: function( index ) {
  534. index = this._getIndex( index );
  535. var self = this,
  536. o = this.options,
  537. a = this.anchors.eq( index )[ 0 ],
  538. url = $.data( a, "load.tabs" );
  539. this.abort();
  540. // not remote or from cache
  541. if ( !url || this.element.queue( "tabs" ).length !== 0 && $.data( a, "cache.tabs" ) ) {
  542. this.element.dequeue( "tabs" );
  543. return;
  544. }
  545. // load remote from here on
  546. this.lis.eq( index ).addClass( "ui-state-processing" );
  547. if ( o.spinner ) {
  548. var span = $( "span", a );
  549. span.data( "label.tabs", span.html() ).html( o.spinner );
  550. }
  551. this.xhr = $.ajax( $.extend( {}, o.ajaxOptions, {
  552. url: url,
  553. success: function( r, s ) {
  554. $( self._sanitizeSelector( a.hash ) ).html( r );
  555. // take care of tab labels
  556. self._cleanup();
  557. if ( o.cache ) {
  558. $.data( a, "cache.tabs", true );
  559. }
  560. self._trigger( "load", null, self._ui( self.anchors[ index ], self.panels[ index ] ) );
  561. try {
  562. o.ajaxOptions.success( r, s );
  563. }
  564. catch ( e ) {}
  565. //初始化按钮
  566. var obj = self.panels[index];
  567. setLinkButton(obj);
  568. },
  569. error: function( xhr, s, e ) {
  570. // take care of tab labels
  571. self._cleanup();
  572. self._trigger( "load", null, self._ui( self.anchors[ index ], self.panels[ index ] ) );
  573. try {
  574. // Passing index avoid a race condition when this method is
  575. // called after the user has selected another tab.
  576. // Pass the anchor that initiated this request allows
  577. // loadError to manipulate the tab content panel via $(a.hash)
  578. o.ajaxOptions.error( xhr, s, index, a );
  579. }
  580. catch ( e ) {}
  581. },
  582. beforeSend:function(XMLHttpRequest ){
  583. var cToken = $.cookie(headtoken) || token;XMLHttpRequest.setRequestHeader(headtoken,cToken);
  584. }
  585. } ) );
  586. // last, so that load event is fired before show...
  587. self.element.dequeue( "tabs" );
  588. return this;
  589. },
  590. abort: function() {
  591. // stop possibly running animations
  592. this.element.queue( [] );
  593. this.panels.stop( false, true );
  594. // "tabs" queue must not contain more than two elements,
  595. // which are the callbacks for the latest clicked tab...
  596. this.element.queue( "tabs", this.element.queue( "tabs" ).splice( -2, 2 ) );
  597. // terminate pending requests from other tabs
  598. if ( this.xhr ) {
  599. this.xhr.abort();
  600. delete this.xhr;
  601. }
  602. // take care of tab labels
  603. this._cleanup();
  604. return this;
  605. },
  606. url: function( index, url ) {
  607. this.anchors.eq( index ).removeData( "cache.tabs" ).data( "load.tabs", url );
  608. return this;
  609. },
  610. length: function() {
  611. return this.anchors.length;
  612. }
  613. });
  614. $.extend( $.ui.tabs, {
  615. version: "1.8.5"
  616. });
  617. /*
  618. * Tabs Extensions
  619. */
  620. /*
  621. * Rotate
  622. */
  623. $.extend( $.ui.tabs.prototype, {
  624. rotation: null,
  625. rotate: function( ms, continuing ) {
  626. var self = this,
  627. o = this.options;
  628. var rotate = self._rotate || ( self._rotate = function( e ) {
  629. clearTimeout( self.rotation );
  630. self.rotation = setTimeout(function() {
  631. var t = o.selected;
  632. self.select( ++t < self.anchors.length ? t : 0 );
  633. }, ms );
  634. if ( e ) {
  635. e.stopPropagation();
  636. }
  637. });
  638. var stop = self._unrotate || ( self._unrotate = !continuing
  639. ? function(e) {
  640. if (e.clientX) { // in case of a true click
  641. self.rotate(null);
  642. }
  643. }
  644. : function( e ) {
  645. t = o.selected;
  646. rotate();
  647. });
  648. // start rotation
  649. if ( ms ) {
  650. this.element.bind( "tabsshow", rotate );
  651. this.anchors.bind( o.event + ".tabs", stop );
  652. rotate();
  653. // stop rotation
  654. } else {
  655. clearTimeout( self.rotation );
  656. this.element.unbind( "tabsshow", rotate );
  657. this.anchors.unbind( o.event + ".tabs", stop );
  658. delete this._rotate;
  659. delete this._unrotate;
  660. }
  661. return this;
  662. }
  663. });
  664. })( jQuery );