Skip to content

Commit e5f081b

Browse files
committed
Tabs: Deprecate enable and disable events. Fixes #7142 Tabs: Deprecate enable and disable events
1 parent e7971c9 commit e5f081b

File tree

4 files changed

+76
-39
lines changed

4 files changed

+76
-39
lines changed

tests/unit/tabs/tabs_defaults.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ var tabs_defaults = {
77
beforeload: null,
88
collapsible: false,
99
cookie: null,
10-
disable: null,
1110
disabled: false,
12-
enable: null,
1311
event: "click",
1412
fx: null,
1513
idPrefix: "ui-tabs-",

tests/unit/tabs/tabs_deprecated.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,39 @@ test('spinner', function() {
4141
});
4242
});
4343

44+
module("tabs (deprecated): enable/disable events");
45+
46+
test('enable', function() {
47+
expect(4);
48+
49+
var uiObj;
50+
el = $('#tabs1').tabs({
51+
disabled: [ 0, 1 ],
52+
enable: function (event, ui) {
53+
uiObj = ui;
54+
}
55+
});
56+
el.tabs('enable', 1);
57+
ok(uiObj !== undefined, 'trigger callback');
58+
equals(uiObj.tab, $('a', el)[1], 'contain tab as DOM anchor element');
59+
equals(uiObj.panel, $('div', el)[1], 'contain panel as DOM div element');
60+
equals(uiObj.index, 1, 'contain index');
61+
});
62+
63+
test('disable', function() {
64+
expect(4);
65+
66+
var uiObj;
67+
el = $('#tabs1').tabs({
68+
disable: function (event, ui) {
69+
uiObj = ui;
70+
}
71+
});
72+
el.tabs('disable', 1);
73+
ok(uiObj !== undefined, 'trigger callback');
74+
equals(uiObj.tab, $('a', el)[1], 'contain tab as DOM anchor element');
75+
equals(uiObj.panel, $('div', el)[1], 'contain panel as DOM div element');
76+
equals(uiObj.index, 1, 'contain index');
77+
});
78+
4479
}( jQuery ) );

tests/unit/tabs/tabs_events.js

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -88,37 +88,4 @@ test('remove', function() {
8888
ok(false, "missing test - untested code is broken code.");
8989
});
9090

91-
test('enable', function() {
92-
expect(4);
93-
94-
var uiObj;
95-
el = $('#tabs1').tabs({
96-
disabled: [ 0, 1 ],
97-
enable: function (event, ui) {
98-
uiObj = ui;
99-
}
100-
});
101-
el.tabs('enable', 1);
102-
ok(uiObj !== undefined, 'trigger callback');
103-
equals(uiObj.tab, $('a', el)[1], 'contain tab as DOM anchor element');
104-
equals(uiObj.panel, $('div', el)[1], 'contain panel as DOM div element');
105-
equals(uiObj.index, 1, 'contain index');
106-
});
107-
108-
test('disable', function() {
109-
expect(4);
110-
111-
var uiObj;
112-
el = $('#tabs1').tabs({
113-
disable: function (event, ui) {
114-
uiObj = ui;
115-
}
116-
});
117-
el.tabs('disable', 1);
118-
ok(uiObj !== undefined, 'trigger callback');
119-
equals(uiObj.tab, $('a', el)[1], 'contain tab as DOM anchor element');
120-
equals(uiObj.panel, $('div', el)[1], 'contain panel as DOM div element');
121-
equals(uiObj.index, 1, 'contain index');
122-
});
123-
12491
})(jQuery);

ui/jquery.ui.tabs.js

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ $.widget( "ui.tabs", {
3030
beforeload: null,
3131
cookie: null, // e.g. { expires: 7, path: '/', domain: 'jquery.com', secure: true }
3232
collapsible: false,
33-
disable: null,
3433
disabled: false,
35-
enable: null,
3634
event: "click",
3735
fx: null, // e.g. { height: 'toggle', opacity: 'toggle', duration: 200 }
3836
idPrefix: "ui-tabs-",
@@ -545,7 +543,6 @@ $.widget( "ui.tabs", {
545543
o.disabled = false;
546544
}
547545

548-
this._trigger( "enable", null, this._ui( this.anchors[ index ], this.panels[ index ] ) );
549546
return this;
550547
},
551548

@@ -569,7 +566,6 @@ $.widget( "ui.tabs", {
569566
o.disabled = true;
570567
}
571568

572-
this._trigger( "disable", null, this._ui( this.anchors[ index ], this.panels[ index ] ) );
573569
}
574570

575571
return this;
@@ -768,6 +764,47 @@ if ( $.uiBackCompat !== false ) {
768764
});
769765
};
770766
}( jQuery, jQuery.ui.tabs.prototype ) );
767+
768+
// enable/disable events
769+
(function( $, prototype ) {
770+
$.extend( prototype.options, {
771+
enable: null,
772+
disable: null
773+
});
774+
775+
var enable = prototype.enable,
776+
disable = prototype.disable;
777+
778+
prototype.enable = function( index ) {
779+
var o = this.options,
780+
trigger;
781+
782+
if ( index && o.disabled || ($.isArray( o.disabled ) && $.inArray( index, o.disabled ) !== -1 ) ) {
783+
trigger = true;
784+
}
785+
786+
enable.apply( this, arguments );
787+
788+
if ( trigger ) {
789+
this._trigger( "enable", null, this._ui( this.anchors[ index ], this.panels[ index ] ) );
790+
}
791+
};
792+
793+
prototype.disable = function( index ) {
794+
var o = this.options,
795+
trigger;
796+
797+
if ( index && !o.disabled || ($.isArray( o.disabled ) && $.inArray( index, o.disabled ) == -1 ) ) {
798+
trigger = true;
799+
}
800+
801+
disable.apply( this, arguments );
802+
803+
if ( trigger ) {
804+
this._trigger( "disable", null, this._ui( this.anchors[ index ], this.panels[ index ] ) );
805+
}
806+
};
807+
}( jQuery, jQuery.ui.tabs.prototype ) );
771808
}
772809

773810
})( jQuery );

0 commit comments

Comments
 (0)