Tabs: Removed cookie option. Fixes #7162 - Tabs: Remove cookie option.

This commit is contained in:
Scott González 2012-10-25 05:36:24 -04:00
parent 723d3e0040
commit 0429532ad1
5 changed files with 0 additions and 178 deletions

View File

@ -1,89 +0,0 @@
/*jslint browser: true */ /*global jQuery: true */
/**
* jQuery Cookie plugin
*
* Copyright (c) 2010 Klaus Hartl (stilbuero.de)
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*
*/
// TODO JsDoc
/**
* Create a cookie with the given key and value and other optional parameters.
*
* @example $.cookie('the_cookie', 'the_value');
* @desc Set the value of a cookie.
* @example $.cookie('the_cookie', 'the_value', { expires: 7, path: '/', domain: 'jquery.com', secure: true });
* @desc Create a cookie with all available options.
* @example $.cookie('the_cookie', 'the_value');
* @desc Create a session cookie.
* @example $.cookie('the_cookie', null);
* @desc Delete a cookie by passing null as value. Keep in mind that you have to use the same path and domain
* used when the cookie was set.
*
* @param String key The key of the cookie.
* @param String value The value of the cookie.
* @param Object options An object literal containing key/value pairs to provide optional cookie attributes.
* @option Number|Date expires Either an integer specifying the expiration date from now on in days or a Date object.
* If a negative value is specified (e.g. a date in the past), the cookie will be deleted.
* If set to null or omitted, the cookie will be a session cookie and will not be retained
* when the the browser exits.
* @option String path The value of the path atribute of the cookie (default: path of page that created the cookie).
* @option String domain The value of the domain attribute of the cookie (default: domain of page that created the cookie).
* @option Boolean secure If true, the secure attribute of the cookie will be set and the cookie transmission will
* require a secure protocol (like HTTPS).
* @type undefined
*
* @name $.cookie
* @cat Plugins/Cookie
* @author Klaus Hartl/klaus.hartl@stilbuero.de
*/
/**
* Get the value of a cookie with the given key.
*
* @example $.cookie('the_cookie');
* @desc Get the value of a cookie.
*
* @param String key The key of the cookie.
* @return The value of the cookie.
* @type String
*
* @name $.cookie
* @cat Plugins/Cookie
* @author Klaus Hartl/klaus.hartl@stilbuero.de
*/
jQuery.cookie = function (key, value, options) {
// key and value given, set cookie...
if (arguments.length > 1 && (value === null || typeof value !== "object")) {
options = jQuery.extend({}, options);
if (value === null) {
options.expires = -1;
}
if (typeof options.expires === 'number') {
var days = options.expires, t = options.expires = new Date();
t.setDate(t.getDate() + days);
}
return (document.cookie = [
encodeURIComponent(key), '=',
options.raw ? String(value) : encodeURIComponent(String(value)),
options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
options.path ? '; path=' + options.path : '',
options.domain ? '; domain=' + options.domain : '',
options.secure ? '; secure' : ''
].join(''));
}
// key and possibly options given, get cookie...
options = value || {};
var result, decode = options.raw ? function (s) { return s; } : decodeURIComponent;
return (result = new RegExp('(?:^|; )' + encodeURIComponent(key) + '=([^;]*)').exec(document.cookie)) ? decode(result[1]) : null;
};

View File

@ -2,7 +2,6 @@ TestHelpers.commonWidgetTests( "tabs", {
defaults: { defaults: {
active: null, active: null,
collapsible: false, collapsible: false,
cookie: null,
disabled: false, disabled: false,
event: "click", event: "click",
heightStyle: "content", heightStyle: "content",

View File

@ -5,7 +5,6 @@
<title>jQuery UI Tabs Test Suite</title> <title>jQuery UI Tabs Test Suite</title>
<script src="../../jquery.js"></script> <script src="../../jquery.js"></script>
<script src="../../../external/jquery.cookie.js"></script>
<link rel="stylesheet" href="../../../external/qunit.css"> <link rel="stylesheet" href="../../../external/qunit.css">
<script src="../../../external/qunit.js"></script> <script src="../../../external/qunit.js"></script>
<script src="../../jquery.simulate.js"></script> <script src="../../jquery.simulate.js"></script>

View File

@ -66,41 +66,6 @@ test( "tabTemplate + panelTemplate", function() {
ok( element.find( "#new" ).hasClass( "customPanel" ), "panel custom class" ); ok( element.find( "#new" ).hasClass( "customPanel" ), "panel custom class" );
}); });
test( "cookie", function() {
expect( 6 );
var element = $( "#tabs1" ),
cookieName = "tabs_test",
cookieObj = { name: cookieName };
$.cookie( cookieName, null );
function cookie() {
return parseInt( $.cookie( cookieName ), 10 );
}
element.tabs({ cookie: cookieObj });
equal( cookie(), 0, "initial cookie value" );
element.tabs( "destroy" );
element.tabs({ active: 1, cookie: cookieObj });
equal( cookie(), 1, "initial cookie value, from active property" );
element.tabs( "option", "active", 2 );
equal( cookie(), 2, "cookie value updated after activating" );
element.tabs( "destroy" );
$.cookie( cookieName, 1 );
element.tabs({ cookie: cookieObj });
equal( cookie(), 1, "initial cookie value, from existing cookie" );
element.tabs( "destroy" );
element.tabs({ cookie: cookieObj, collapsible: true });
element.tabs( "option", "active", false );
equal( cookie(), -1, "cookie value for all tabs unselected" );
element.tabs( "destroy" );
ok( $.cookie( cookieName ) === null, "erase cookie after destroy" );
});
asyncTest( "spinner", function() { asyncTest( "spinner", function() {
expect( 2 ); expect( 2 );

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

@ -1144,58 +1144,6 @@ if ( $.uiBackCompat !== false ) {
} }
}); });
// cookie option
(function() {
var listId = 0;
$.widget( "ui.tabs", $.ui.tabs, {
options: {
cookie: null // e.g. { expires: 7, path: '/', domain: 'jquery.com', secure: true }
},
_create: function() {
var options = this.options,
active;
if ( options.active == null && options.cookie ) {
active = parseInt( this._cookie(), 10 );
if ( active === -1 ) {
active = false;
}
options.active = active;
}
this._super();
},
_cookie: function( active ) {
var cookie = [ this.cookie ||
( this.cookie = this.options.cookie.name || "ui-tabs-" + (++listId) ) ];
if ( arguments.length ) {
cookie.push( active === false ? -1 : active );
cookie.push( this.options.cookie );
}
return $.cookie.apply( null, cookie );
},
_refresh: function() {
this._super();
if ( this.options.cookie ) {
this._cookie( this.options.active, this.options.cookie );
}
},
_eventHandler: function() {
this._superApply( arguments );
if ( this.options.cookie ) {
this._cookie( this.options.active, this.options.cookie );
}
},
_destroy: function() {
this._super();
if ( this.options.cookie ) {
this._cookie( null, this.options.cookie );
}
}
});
})();
// load event // load event
$.widget( "ui.tabs", $.ui.tabs, { $.widget( "ui.tabs", $.ui.tabs, {
_trigger: function( type, event, data ) { _trigger: function( type, event, data ) {