Skip to content

Commit c363019

Browse files
committed
Tabs: Deprecate templating (idPrefix, tabTemplate, panelTemplate options) Fixes #7139 Tabs: Deprecate templating (idPrefix, tabTemplate, panelTemplate options)
1 parent 1e2d314 commit c363019

File tree

4 files changed

+49
-32
lines changed

4 files changed

+49
-32
lines changed

tests/unit/tabs/tabs_defaults.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,9 @@ var tabs_defaults = {
99
disabled: false,
1010
event: "click",
1111
fx: null,
12-
idPrefix: "ui-tabs-",
1312
load: null,
14-
panelTemplate: "<div></div>",
1513
select: null,
16-
show: null,
17-
tabTemplate: "<li><a href='#{href}'><span>#{label}</span></a></li>"
14+
show: null
1815
};
1916

2017
// FAIL: falsy values break the cookie option

tests/unit/tabs/tabs_deprecated.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,18 @@ test('cache', function() {
2424
ok(false, "missing test - untested code is broken code.");
2525
});
2626

27+
test('idPrefix', function() {
28+
ok(false, "missing test - untested code is broken code.");
29+
});
30+
31+
test('tabTemplate', function() {
32+
ok(false, "missing test - untested code is broken code.");
33+
});
34+
35+
test('panelTemplate', function() {
36+
ok(false, "missing test - untested code is broken code.");
37+
});
38+
2739
test('spinner', function() {
2840
expect(4);
2941
stop();

tests/unit/tabs/tabs_options.js

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,6 @@ test('fx', function() {
7979
ok(false, "missing test - untested code is broken code.");
8080
});
8181

82-
test('idPrefix', function() {
83-
ok(false, "missing test - untested code is broken code.");
84-
});
85-
86-
test('panelTemplate', function() {
87-
ok(false, "missing test - untested code is broken code.");
88-
});
89-
9082
test('selected', function() {
9183
expect(8);
9284

@@ -117,8 +109,4 @@ test('selected', function() {
117109
equals(el.tabs('option', 'selected'), 0, 'should not collapse tab if value is same as selected');
118110
});
119111

120-
test('tabTemplate', function() {
121-
ok(false, "missing test - untested code is broken code.");
122-
});
123-
124112
})(jQuery);

ui/jquery.ui.tabs.js

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,9 @@ $.widget( "ui.tabs", {
3232
disabled: false,
3333
event: "click",
3434
fx: null, // e.g. { height: 'toggle', opacity: 'toggle', duration: 200 }
35-
idPrefix: "ui-tabs-",
3635
load: null,
37-
panelTemplate: "<div></div>",
3836
select: null,
39-
show: null,
40-
tabTemplate: "<li><a href='#{href}'><span>#{label}</span></a></li>"
37+
show: null
4138
},
4239

4340
_create: function() {
@@ -135,7 +132,7 @@ $.widget( "ui.tabs", {
135132

136133
_tabId: function( a ) {
137134
return ( $( a ).attr( "aria-controls" ) || "" ).replace( /^#/ , "" ) ||
138-
this.options.idPrefix + getNextTabId();
135+
"ui-tabs-" + getNextTabId();
139136
},
140137

141138
_sanitizeSelector: function( hash ) {
@@ -253,11 +250,8 @@ $.widget( "ui.tabs", {
253250
selector = "#" + id;
254251
panel = self.element.find( selector );
255252
if ( !panel.length ) {
256-
panel = $( self.options.panelTemplate )
257-
.attr( "id", id )
258-
.addClass( "ui-tabs-panel ui-widget-content ui-corner-bottom" )
259-
.data( "destroy.tabs", true )
260-
.insertAfter( self.panels[ i - 1 ] || self.list );
253+
panel = self._createPanel( id );
254+
panel.insertAfter( self.panels[ i - 1 ] || self.list );
261255
}
262256
// invalid tab href
263257
} else {
@@ -271,6 +265,13 @@ $.widget( "ui.tabs", {
271265
});
272266
},
273267

268+
_createPanel: function( id ) {
269+
return $( "<div></div>" )
270+
.attr( "id", id )
271+
.addClass( "ui-tabs-panel ui-widget-content ui-corner-bottom" )
272+
.data( "destroy.tabs", true );
273+
},
274+
274275
_setupFx: function( fx ) {
275276
// set up animations
276277
if ( fx ) {
@@ -772,7 +773,8 @@ if ( $.uiBackCompat !== false ) {
772773
(function( $, prototype ) {
773774
$.extend( prototype.options, {
774775
add: null,
775-
remove: null
776+
remove: null,
777+
tabTemplate: "<li><a href='#{href}'><span>#{label}</span></a></li>"
776778
});
777779

778780
prototype.add = function( url, label, index ) {
@@ -790,9 +792,7 @@ if ( $.uiBackCompat !== false ) {
790792
// try to find an existing element before creating a new one
791793
var $panel = self.element.find( "#" + id );
792794
if ( !$panel.length ) {
793-
$panel = $( o.panelTemplate )
794-
.attr( "id", id )
795-
.data( "destroy.tabs", true );
795+
$panel = self._createPanel( id );
796796
}
797797
$panel.addClass( "ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide" );
798798

@@ -868,10 +868,30 @@ if ( $.uiBackCompat !== false ) {
868868

869869
// _tabId method
870870
(function( $, prototype ) {
871+
$.extend( prototype.options, {
872+
idPrefix: "ui-tabs-"
873+
});
874+
871875
var _tabId = prototype._tabId;
872876
prototype._tabId = function( a ) {
873-
return a.title && a.title.replace( /\s/g, "_" ).replace( /[^\w\u00c0-\uFFFF-]/g, "" ) ||
874-
_tabId.apply( this, arguments );
877+
return ( $( a ).attr( "aria-controls" ) || "" ).replace( /^#/ , "" ) ||
878+
a.title && a.title.replace( /\s/g, "_" ).replace( /[^\w\u00c0-\uFFFF-]/g, "" ) ||
879+
this.options.idPrefix + getNextTabId();
880+
};
881+
}( jQuery, jQuery.ui.tabs.prototype ) );
882+
883+
// _tabId method
884+
(function( $, prototype ) {
885+
$.extend( prototype.options, {
886+
panelTemplate: "<div></div>"
887+
});
888+
889+
var _createPanel = prototype._createPanel;
890+
prototype._createPanel = function( id ) {
891+
return $( this.options.panelTemplate )
892+
.attr( "id", id )
893+
.addClass( "ui-tabs-panel ui-widget-content ui-corner-bottom" )
894+
.data( "destroy.tabs", true );
875895
};
876896
}( jQuery, jQuery.ui.tabs.prototype ) );
877897
}

0 commit comments

Comments
 (0)