mirror of
https://github.com/jquery/jquery-ui.git
synced 2024-11-21 11:04:24 +00:00
Tabs: Deprecate cookie option. Fixes #7144 Tabs: Deprecate cookie option
This commit is contained in:
parent
c6a6ef5ee6
commit
cb0588f2dd
@ -7,7 +7,6 @@ var tabs_defaults = {
|
||||
beforeload: null,
|
||||
beforeActivate: null,
|
||||
collapsible: false,
|
||||
cookie: null,
|
||||
disabled: false,
|
||||
event: "click",
|
||||
fx: null,
|
||||
|
@ -36,6 +36,42 @@ test('panelTemplate', function() {
|
||||
ok(false, "missing test - untested code is broken code.");
|
||||
});
|
||||
|
||||
test('cookie', function() {
|
||||
expect(6);
|
||||
|
||||
el = $('#tabs1');
|
||||
var cookieName = 'tabs_test', cookieObj = { name: cookieName };
|
||||
$.cookie(cookieName, null); // blank state
|
||||
var cookie = function() {
|
||||
return parseInt($.cookie(cookieName), 10);
|
||||
};
|
||||
|
||||
el.tabs({ cookie: cookieObj });
|
||||
equals(cookie(), 0, 'initial cookie value');
|
||||
|
||||
el.tabs('destroy');
|
||||
el.tabs({ active: 1, cookie: cookieObj });
|
||||
equals(cookie(), 1, 'initial cookie value, from active property');
|
||||
|
||||
el.tabs('option', 'active', 2);
|
||||
equals(cookie(), 2, 'cookie value updated after activating');
|
||||
|
||||
el.tabs('destroy');
|
||||
$.cookie(cookieName, 1);
|
||||
el.tabs({ cookie: cookieObj });
|
||||
equals(cookie(), 1, 'initial cookie value, from existing cookie');
|
||||
|
||||
el.tabs('destroy');
|
||||
el.tabs({ cookie: cookieObj, collapsible: true });
|
||||
el.tabs('option', 'active', false);
|
||||
equals(cookie(), -1, 'cookie value for all tabs unselected');
|
||||
|
||||
el.tabs('destroy');
|
||||
ok($.cookie(cookieName) === null, 'erase cookie after destroy');
|
||||
|
||||
});
|
||||
|
||||
|
||||
test('spinner', function() {
|
||||
expect(4);
|
||||
stop();
|
||||
|
@ -22,41 +22,6 @@ test('collapsible', function() {
|
||||
|
||||
});
|
||||
|
||||
test('cookie', function() {
|
||||
expect(6);
|
||||
|
||||
el = $('#tabs1');
|
||||
var cookieName = 'tabs_test', cookieObj = { name: cookieName };
|
||||
$.cookie(cookieName, null); // blank state
|
||||
var cookie = function() {
|
||||
return parseInt($.cookie(cookieName), 10);
|
||||
};
|
||||
|
||||
el.tabs({ cookie: cookieObj });
|
||||
equals(cookie(), 0, 'initial cookie value');
|
||||
|
||||
el.tabs('destroy');
|
||||
el.tabs({ active: 1, cookie: cookieObj });
|
||||
equals(cookie(), 1, 'initial cookie value, from active property');
|
||||
|
||||
el.tabs('option', 'active', 2);
|
||||
equals(cookie(), 2, 'cookie value updated after activating');
|
||||
|
||||
el.tabs('destroy');
|
||||
$.cookie(cookieName, 1);
|
||||
el.tabs({ cookie: cookieObj });
|
||||
equals(cookie(), 1, 'initial cookie value, from existing cookie');
|
||||
|
||||
el.tabs('destroy');
|
||||
el.tabs({ cookie: cookieObj, collapsible: true });
|
||||
el.tabs('option', 'active', false);
|
||||
equals(cookie(), -1, 'cookie value for all tabs unselected');
|
||||
|
||||
el.tabs('destroy');
|
||||
ok($.cookie(cookieName) === null, 'erase cookie after destroy');
|
||||
|
||||
});
|
||||
|
||||
test('disabled', function() {
|
||||
expect(4);
|
||||
|
||||
|
87
ui/jquery.ui.tabs.js
vendored
87
ui/jquery.ui.tabs.js
vendored
@ -29,7 +29,6 @@ $.widget( "ui.tabs", {
|
||||
activate: null,
|
||||
beforeload: null,
|
||||
beforeActivate: null,
|
||||
cookie: null, // e.g. { expires: 7, path: '/', domain: 'jquery.com', secure: true }
|
||||
collapsible: false,
|
||||
disabled: false,
|
||||
event: "click",
|
||||
@ -50,8 +49,7 @@ $.widget( "ui.tabs", {
|
||||
// Selected tab
|
||||
// use "selected" option or try to retrieve:
|
||||
// 1. from fragment identifier in url
|
||||
// 2. from cookie
|
||||
// 3. from selected class attribute on <li>
|
||||
// 2. from selected class attribute on <li>
|
||||
if ( o.active === undefined ) {
|
||||
if ( location.hash ) {
|
||||
this.anchors.each(function( i, a ) {
|
||||
@ -61,9 +59,6 @@ $.widget( "ui.tabs", {
|
||||
}
|
||||
});
|
||||
}
|
||||
if ( typeof o.active !== "number" && o.cookie ) {
|
||||
o.active = parseInt( self._cookie(), 10 );
|
||||
}
|
||||
if ( typeof o.active !== "number" && this.lis.filter( ".ui-tabs-selected" ).length ) {
|
||||
o.active = this.lis.index( this.lis.filter( ".ui-tabs-selected" ) );
|
||||
}
|
||||
@ -139,12 +134,6 @@ $.widget( "ui.tabs", {
|
||||
return hash.replace( /:/g, "\\:" );
|
||||
},
|
||||
|
||||
_cookie: function() {
|
||||
var cookie = this.cookie ||
|
||||
( this.cookie = this.options.cookie.name || "ui-tabs-" + getNextListId() );
|
||||
return $.cookie.apply( null, [ cookie ].concat( $.makeArray( arguments ) ) );
|
||||
},
|
||||
|
||||
_ui: function( tab, panel ) {
|
||||
return {
|
||||
tab: tab,
|
||||
@ -189,11 +178,6 @@ $.widget( "ui.tabs", {
|
||||
o.disabled = false;
|
||||
}
|
||||
|
||||
// set or update cookie after init and add/remove respectively
|
||||
if ( o.cookie ) {
|
||||
this._cookie( o.active, o.cookie );
|
||||
}
|
||||
|
||||
// disable tabs
|
||||
for ( var i = 0, li; ( li = this.lis[ i ] ); i++ ) {
|
||||
$( li ).toggleClass( "ui-state-disabled", $.inArray( i, o.disabled ) != -1 );
|
||||
@ -382,10 +366,6 @@ $.widget( "ui.tabs", {
|
||||
o.active = -1;
|
||||
self.active = null;
|
||||
|
||||
if ( o.cookie ) {
|
||||
self._cookie( o.active, o.cookie );
|
||||
}
|
||||
|
||||
self.element.queue( "tabs", function() {
|
||||
self._hideTab( clicked, $hide );
|
||||
}).dequeue( "tabs" );
|
||||
@ -393,10 +373,6 @@ $.widget( "ui.tabs", {
|
||||
clicked[ 0 ].blur();
|
||||
return;
|
||||
} else if ( !$hide.length ) {
|
||||
if ( o.cookie ) {
|
||||
self._cookie( o.active, o.cookie );
|
||||
}
|
||||
|
||||
self.element.queue( "tabs", function() {
|
||||
self._showTab( clicked, $show, event );
|
||||
});
|
||||
@ -409,10 +385,6 @@ $.widget( "ui.tabs", {
|
||||
}
|
||||
}
|
||||
|
||||
if ( o.cookie ) {
|
||||
self._cookie( o.active, o.cookie );
|
||||
}
|
||||
|
||||
// show new tab
|
||||
if ( $show.length ) {
|
||||
if ( $hide.length ) {
|
||||
@ -507,10 +479,6 @@ $.widget( "ui.tabs", {
|
||||
}
|
||||
});
|
||||
|
||||
if ( o.cookie ) {
|
||||
this._cookie( null, o.cookie );
|
||||
}
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
@ -974,6 +942,59 @@ if ( $.uiBackCompat !== false ) {
|
||||
this.anchors.eq( index ).trigger( this.options.event + ".tabs" );
|
||||
};
|
||||
}( jQuery, jQuery.ui.tabs.prototype ) );
|
||||
|
||||
// cookie option
|
||||
(function( $, prototype ) {
|
||||
$.extend( prototype.options, {
|
||||
cookie: null // e.g. { expires: 7, path: '/', domain: 'jquery.com', secure: true }
|
||||
});
|
||||
|
||||
var _create = prototype._create,
|
||||
_refresh = prototype._refresh,
|
||||
_eventHandler = prototype._eventHandler,
|
||||
_destroy = prototype._destroy;
|
||||
|
||||
prototype._create = function() {
|
||||
var o = this.options;
|
||||
if ( o.active === undefined ) {
|
||||
if ( typeof o.active !== "number" && o.cookie ) {
|
||||
o.active = parseInt( this._cookie(), 10 );
|
||||
}
|
||||
}
|
||||
_create.call( this );
|
||||
};
|
||||
|
||||
prototype._cookie = function() {
|
||||
var cookie = this.cookie ||
|
||||
( this.cookie = this.options.cookie.name || "ui-tabs-" + getNextListId() );
|
||||
return $.cookie.apply( null, [ cookie ].concat( $.makeArray( arguments ) ) );
|
||||
};
|
||||
|
||||
prototype._refresh = function() {
|
||||
_refresh.call( this );
|
||||
|
||||
// set or update cookie after init and add/remove respectively
|
||||
if ( this.options.cookie ) {
|
||||
this._cookie( this.options.active, this.options.cookie );
|
||||
}
|
||||
};
|
||||
|
||||
prototype._eventHandler = function( event ) {
|
||||
_eventHandler.apply( this, arguments );
|
||||
|
||||
if ( this.options.cookie ) {
|
||||
this._cookie( this.options.active, this.options.cookie );
|
||||
}
|
||||
};
|
||||
|
||||
prototype._destroy = function() {
|
||||
_destroy.call( this );
|
||||
|
||||
if ( this.options.cookie ) {
|
||||
this._cookie( null, this.options.cookie );
|
||||
}
|
||||
};
|
||||
}( jQuery, jQuery.ui.tabs.prototype ) );
|
||||
}
|
||||
|
||||
})( jQuery );
|
||||
|
Loading…
Reference in New Issue
Block a user