source: trunk/themes/default/js/ui/jquery.ui.tabs.js @ 28780

Last change on this file since 28780 was 28780, checked in by rvelices, 10 years ago

upgrade jquery ui from 1.10.1 to 1.10.4

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