]> source.dussan.org Git - jquery-ui.git/commitdiff
Tabs: Deprecate enable and disable events. Fixes #7142 Tabs: Deprecate enable and...
authorDavid Petersen <public@petersendidit.com>
Sat, 26 Mar 2011 20:12:05 +0000 (16:12 -0400)
committerDavid Petersen <public@petersendidit.com>
Sun, 27 Mar 2011 01:00:45 +0000 (21:00 -0400)
tests/unit/tabs/tabs_defaults.js
tests/unit/tabs/tabs_deprecated.js
tests/unit/tabs/tabs_events.js
ui/jquery.ui.tabs.js

index 397d81ce617b45d13cb6659e7ab0e4a42189d080..5a6bc065eb209bf73107c58c25456bb96e7dadac 100644 (file)
@@ -7,9 +7,7 @@ var tabs_defaults = {
        beforeload: null,
        collapsible: false,
        cookie: null,
-       disable: null,
        disabled: false,
-       enable: null,
        event: "click",
        fx: null,
        idPrefix: "ui-tabs-",
index cec68980830cda63fbf0971ef6abb50fd095f310..ee2dbdc74d06808213cc4b21b829dcf63d81a406 100644 (file)
@@ -41,4 +41,39 @@ test('spinner', function() {
        });
 });
 
+module("tabs (deprecated): enable/disable events");
+
+test('enable', function() {
+       expect(4);
+
+       var uiObj;
+       el = $('#tabs1').tabs({
+               disabled: [ 0, 1 ],
+               enable: function (event, ui) {
+                       uiObj = ui;
+               }
+       });
+       el.tabs('enable', 1);
+       ok(uiObj !== undefined, 'trigger callback');
+       equals(uiObj.tab, $('a', el)[1], 'contain tab as DOM anchor element');
+       equals(uiObj.panel, $('div', el)[1], 'contain panel as DOM div element');
+       equals(uiObj.index, 1, 'contain index');
+});
+
+test('disable', function() {
+       expect(4);
+
+       var uiObj;
+       el = $('#tabs1').tabs({
+               disable: function (event, ui) {
+                       uiObj = ui;
+               }
+       });
+       el.tabs('disable', 1);
+       ok(uiObj !== undefined, 'trigger callback');
+       equals(uiObj.tab, $('a', el)[1], 'contain tab as DOM anchor element');
+       equals(uiObj.panel, $('div', el)[1], 'contain panel as DOM div element');
+       equals(uiObj.index, 1, 'contain index');
+});
+
 }( jQuery ) );
index 26ea76fb49ccadd601c444b44dbc828f7bf4f570..56c1360eea7d390fffaa118ebcd69338f874e8de 100644 (file)
@@ -88,37 +88,4 @@ test('remove', function() {
        ok(false, "missing test - untested code is broken code.");
 });
 
-test('enable', function() {
-       expect(4);
-
-       var uiObj;
-       el = $('#tabs1').tabs({
-               disabled: [ 0, 1 ],
-               enable: function (event, ui) {
-                       uiObj = ui;
-               }
-       });
-       el.tabs('enable', 1);
-       ok(uiObj !== undefined, 'trigger callback');
-       equals(uiObj.tab, $('a', el)[1], 'contain tab as DOM anchor element');
-       equals(uiObj.panel, $('div', el)[1], 'contain panel as DOM div element');
-       equals(uiObj.index, 1, 'contain index');
-});
-
-test('disable', function() {
-       expect(4);
-
-       var uiObj;
-       el = $('#tabs1').tabs({
-               disable: function (event, ui) {
-                       uiObj = ui;
-               }
-       });
-       el.tabs('disable', 1);
-       ok(uiObj !== undefined, 'trigger callback');
-       equals(uiObj.tab, $('a', el)[1], 'contain tab as DOM anchor element');
-       equals(uiObj.panel, $('div', el)[1], 'contain panel as DOM div element');
-       equals(uiObj.index, 1, 'contain index');
-});
-
 })(jQuery);
index f54b166c91b87bebd58f8665c9dbf47e0a89785a..b7a270fb6dbc7af099064cbbe5960bc8355a5ec5 100755 (executable)
@@ -30,9 +30,7 @@ $.widget( "ui.tabs", {
                beforeload: null,
                cookie: null, // e.g. { expires: 7, path: '/', domain: 'jquery.com', secure: true }
                collapsible: false,
-               disable: null,
                disabled: false,
-               enable: null,
                event: "click",
                fx: null, // e.g. { height: 'toggle', opacity: 'toggle', duration: 200 }
                idPrefix: "ui-tabs-",
@@ -545,7 +543,6 @@ $.widget( "ui.tabs", {
                        o.disabled = false;
                }
 
-               this._trigger( "enable", null, this._ui( this.anchors[ index ], this.panels[ index ] ) );
                return this;
        },
 
@@ -569,7 +566,6 @@ $.widget( "ui.tabs", {
                                o.disabled = true;
                        }
 
-                       this._trigger( "disable", null, this._ui( this.anchors[ index ], this.panels[ index ] ) );
                }
 
                return this;
@@ -768,6 +764,47 @@ if ( $.uiBackCompat !== false ) {
                        });
                };
        }( jQuery, jQuery.ui.tabs.prototype ) );
+
+       // enable/disable events
+       (function( $, prototype ) {
+               $.extend( prototype.options, {
+                       enable: null,
+                       disable: null
+               });
+
+               var enable = prototype.enable,
+                       disable = prototype.disable;
+
+               prototype.enable = function( index ) {
+                       var o = this.options,
+                               trigger;
+
+                       if ( index && o.disabled || ($.isArray( o.disabled ) && $.inArray( index, o.disabled ) !== -1 ) ) {
+                               trigger = true;
+                       }
+
+                       enable.apply( this, arguments );
+
+                       if ( trigger ) {
+                               this._trigger( "enable", null, this._ui( this.anchors[ index ], this.panels[ index ] ) );
+                       }
+               };
+
+               prototype.disable = function( index ) {
+                       var o = this.options,
+                               trigger;
+
+                       if ( index && !o.disabled || ($.isArray( o.disabled ) && $.inArray( index, o.disabled ) == -1 ) ) {
+                               trigger = true;
+                       }
+
+                       disable.apply( this, arguments );
+
+                       if ( trigger ) {
+                               this._trigger( "disable", null, this._ui( this.anchors[ index ], this.panels[ index ] ) );
+                       }
+               };
+       }( jQuery, jQuery.ui.tabs.prototype ) );
 }
 
 })( jQuery );