Tabs: Deprecate templating (idPrefix, tabTemplate, panelTemplate options) Fixes #7139 Tabs: Deprecate templating (idPrefix, tabTemplate, panelTemplate options)

This commit is contained in:
David Petersen 2011-03-27 15:12:53 -04:00
parent 1e2d3145ff
commit c363019590
4 changed files with 49 additions and 32 deletions

View File

@ -9,12 +9,9 @@ var tabs_defaults = {
disabled: false, disabled: false,
event: "click", event: "click",
fx: null, fx: null,
idPrefix: "ui-tabs-",
load: null, load: null,
panelTemplate: "<div></div>",
select: null, select: null,
show: null, show: null
tabTemplate: "<li><a href='#{href}'><span>#{label}</span></a></li>"
}; };
// FAIL: falsy values break the cookie option // FAIL: falsy values break the cookie option

View File

@ -24,6 +24,18 @@ test('cache', function() {
ok(false, "missing test - untested code is broken code."); ok(false, "missing test - untested code is broken code.");
}); });
test('idPrefix', function() {
ok(false, "missing test - untested code is broken code.");
});
test('tabTemplate', function() {
ok(false, "missing test - untested code is broken code.");
});
test('panelTemplate', function() {
ok(false, "missing test - untested code is broken code.");
});
test('spinner', function() { test('spinner', function() {
expect(4); expect(4);
stop(); stop();

View File

@ -79,14 +79,6 @@ test('fx', function() {
ok(false, "missing test - untested code is broken code."); ok(false, "missing test - untested code is broken code.");
}); });
test('idPrefix', function() {
ok(false, "missing test - untested code is broken code.");
});
test('panelTemplate', function() {
ok(false, "missing test - untested code is broken code.");
});
test('selected', function() { test('selected', function() {
expect(8); expect(8);
@ -117,8 +109,4 @@ test('selected', function() {
equals(el.tabs('option', 'selected'), 0, 'should not collapse tab if value is same as selected'); equals(el.tabs('option', 'selected'), 0, 'should not collapse tab if value is same as selected');
}); });
test('tabTemplate', function() {
ok(false, "missing test - untested code is broken code.");
});
})(jQuery); })(jQuery);

52
ui/jquery.ui.tabs.js vendored
View File

@ -32,12 +32,9 @@ $.widget( "ui.tabs", {
disabled: false, disabled: false,
event: "click", event: "click",
fx: null, // e.g. { height: 'toggle', opacity: 'toggle', duration: 200 } fx: null, // e.g. { height: 'toggle', opacity: 'toggle', duration: 200 }
idPrefix: "ui-tabs-",
load: null, load: null,
panelTemplate: "<div></div>",
select: null, select: null,
show: null, show: null
tabTemplate: "<li><a href='#{href}'><span>#{label}</span></a></li>"
}, },
_create: function() { _create: function() {
@ -135,7 +132,7 @@ $.widget( "ui.tabs", {
_tabId: function( a ) { _tabId: function( a ) {
return ( $( a ).attr( "aria-controls" ) || "" ).replace( /^#/ , "" ) || return ( $( a ).attr( "aria-controls" ) || "" ).replace( /^#/ , "" ) ||
this.options.idPrefix + getNextTabId(); "ui-tabs-" + getNextTabId();
}, },
_sanitizeSelector: function( hash ) { _sanitizeSelector: function( hash ) {
@ -253,11 +250,8 @@ $.widget( "ui.tabs", {
selector = "#" + id; selector = "#" + id;
panel = self.element.find( selector ); panel = self.element.find( selector );
if ( !panel.length ) { if ( !panel.length ) {
panel = $( self.options.panelTemplate ) panel = self._createPanel( id );
.attr( "id", id ) panel.insertAfter( self.panels[ i - 1 ] || self.list );
.addClass( "ui-tabs-panel ui-widget-content ui-corner-bottom" )
.data( "destroy.tabs", true )
.insertAfter( self.panels[ i - 1 ] || self.list );
} }
// invalid tab href // invalid tab href
} else { } else {
@ -271,6 +265,13 @@ $.widget( "ui.tabs", {
}); });
}, },
_createPanel: function( id ) {
return $( "<div></div>" )
.attr( "id", id )
.addClass( "ui-tabs-panel ui-widget-content ui-corner-bottom" )
.data( "destroy.tabs", true );
},
_setupFx: function( fx ) { _setupFx: function( fx ) {
// set up animations // set up animations
if ( fx ) { if ( fx ) {
@ -772,7 +773,8 @@ if ( $.uiBackCompat !== false ) {
(function( $, prototype ) { (function( $, prototype ) {
$.extend( prototype.options, { $.extend( prototype.options, {
add: null, add: null,
remove: null remove: null,
tabTemplate: "<li><a href='#{href}'><span>#{label}</span></a></li>"
}); });
prototype.add = function( url, label, index ) { prototype.add = function( url, label, index ) {
@ -790,9 +792,7 @@ if ( $.uiBackCompat !== false ) {
// try to find an existing element before creating a new one // try to find an existing element before creating a new one
var $panel = self.element.find( "#" + id ); var $panel = self.element.find( "#" + id );
if ( !$panel.length ) { if ( !$panel.length ) {
$panel = $( o.panelTemplate ) $panel = self._createPanel( id );
.attr( "id", id )
.data( "destroy.tabs", true );
} }
$panel.addClass( "ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide" ); $panel.addClass( "ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide" );
@ -868,10 +868,30 @@ if ( $.uiBackCompat !== false ) {
// _tabId method // _tabId method
(function( $, prototype ) { (function( $, prototype ) {
$.extend( prototype.options, {
idPrefix: "ui-tabs-"
});
var _tabId = prototype._tabId; var _tabId = prototype._tabId;
prototype._tabId = function( a ) { prototype._tabId = function( a ) {
return a.title && a.title.replace( /\s/g, "_" ).replace( /[^\w\u00c0-\uFFFF-]/g, "" ) || return ( $( a ).attr( "aria-controls" ) || "" ).replace( /^#/ , "" ) ||
_tabId.apply( this, arguments ); a.title && a.title.replace( /\s/g, "_" ).replace( /[^\w\u00c0-\uFFFF-]/g, "" ) ||
this.options.idPrefix + getNextTabId();
};
}( jQuery, jQuery.ui.tabs.prototype ) );
// _tabId method
(function( $, prototype ) {
$.extend( prototype.options, {
panelTemplate: "<div></div>"
});
var _createPanel = prototype._createPanel;
prototype._createPanel = function( id ) {
return $( this.options.panelTemplate )
.attr( "id", id )
.addClass( "ui-tabs-panel ui-widget-content ui-corner-bottom" )
.data( "destroy.tabs", true );
}; };
}( jQuery, jQuery.ui.tabs.prototype ) ); }( jQuery, jQuery.ui.tabs.prototype ) );
} }