Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Tabs: Deprecate enable and disable events. Fixes #7142 Tabs: Deprecat…

…e enable and disable events
  • Loading branch information...
commit e5f081bc1c16c051665eafc22c9a7af3fba456c8 1 parent e7971c9
David Petersen authored March 26, 2011
2  tests/unit/tabs/tabs_defaults.js
@@ -7,9 +7,7 @@ var tabs_defaults = {
7 7
 	beforeload: null,
8 8
 	collapsible: false,
9 9
 	cookie: null,
10  
-	disable: null,
11 10
 	disabled: false,
12  
-	enable: null,
13 11
 	event: "click",
14 12
 	fx: null,
15 13
 	idPrefix: "ui-tabs-",
35  tests/unit/tabs/tabs_deprecated.js
@@ -41,4 +41,39 @@ test('spinner', function() {
41 41
 	});
42 42
 });
43 43
 
  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
+
44 79
 }( jQuery ) );
33  tests/unit/tabs/tabs_events.js
@@ -88,37 +88,4 @@ test('remove', function() {
88 88
 	ok(false, "missing test - untested code is broken code.");
89 89
 });
90 90
 
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  
-
124 91
 })(jQuery);
45  ui/jquery.ui.tabs.js
@@ -30,9 +30,7 @@ $.widget( "ui.tabs", {
30 30
 		beforeload: null,
31 31
 		cookie: null, // e.g. { expires: 7, path: '/', domain: 'jquery.com', secure: true }
32 32
 		collapsible: false,
33  
-		disable: null,
34 33
 		disabled: false,
35  
-		enable: null,
36 34
 		event: "click",
37 35
 		fx: null, // e.g. { height: 'toggle', opacity: 'toggle', duration: 200 }
38 36
 		idPrefix: "ui-tabs-",
@@ -545,7 +543,6 @@ $.widget( "ui.tabs", {
545 543
 			o.disabled = false;
546 544
 		}
547 545
 
548  
-		this._trigger( "enable", null, this._ui( this.anchors[ index ], this.panels[ index ] ) );
549 546
 		return this;
550 547
 	},
551 548
 
@@ -569,7 +566,6 @@ $.widget( "ui.tabs", {
569 566
 				o.disabled = true;
570 567
 			}
571 568
 
572  
-			this._trigger( "disable", null, this._ui( this.anchors[ index ], this.panels[ index ] ) );
573 569
 		}
574 570
 
575 571
 		return this;
@@ -768,6 +764,47 @@ if ( $.uiBackCompat !== false ) {
768 764
 			});
769 765
 		};
770 766
 	}( 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 ) );
771 808
 }
772 809
 
773 810
 })( jQuery );

0 notes on commit e5f081b

Please sign in to comment.
Something went wrong with that request. Please try again.