- Jquery Tool: Keep selected tab on refresh or save data
- $(function() {
- // setup ul.tabs to work as tabs for each div directly under div.panes
- $("ul.tabs").tabs("div.panes > div");
- });
- function getCookie(c_name) {
- var i, x, y, ARRcookies = document.cookie.split(";");
- for (i = 0; i < ARRcookies.length; i++) {
- x = ARRcookies[i].substr(0, ARRcookies[i].indexOf("="));
- y = ARRcookies[i].substr(ARRcookies[i].indexOf("=") + 1);
- x = x.replace(/^s+|s+$/g, "");
- if (x == c_name) {
- return unescape(y);
- }
- }
- }
- function setCookie(c_name, value, exdays) {
- var exdate = new Date();
- exdate.setDate(exdate.getDate() + exdays);
- var c_value = escape(value) + ((exdays == null) ? "" : "; expires=" + exdate.toUTCString());
- document.cookie = c_name + "=" + c_value;
- }
- $(function() {
- // retrieve cookie value on page load
- var $tabs = $('ul.tabs').tabs();
- $tabs.tabs('select', getCookie("selectedtab"));
- // set cookie on tab select
- $("ul.tabs").bind('tabsselect', function (event, ui) {
- setCookie("selectedtab", ui.index + 1, 365);
- });
- });
- $(function() {
- //instantiate tabs object
- $("ul.tabs").tabs("div.panes > div");
- // get handle to the api (must have been constructed before this call)
- var api = $("ul.tabs").data("tabs");
- // set cookie when tabs are clicked
- api.onClick(function(e, index) {
- setCookie("selectedtab", index + 1, 365);
- });
- // retrieve cookie value on page load
- var selectedTab = getCookie("selectedtab");
- if (selectedTab != "undefined") {
- api.click( parseInt(selectedTab) ); // must parse string to int for api to work
- }
- });
- function getCookie(c_name) {
- var i, x, y, ARRcookies = document.cookie.split(";");
- for (i = 0; i < ARRcookies.length; i++) {
- x = ARRcookies[i].substr(0, ARRcookies[i].indexOf("="));
- y = ARRcookies[i].substr(ARRcookies[i].indexOf("=") + 1);
- x = x.replace(/^s+|s+$/g, "");
- if (x == c_name) {
- return unescape(y);
- }
- }
- }
- function setCookie(c_name, value, exdays) {
- var exdate = new Date();
- exdate.setDate(exdate.getDate() + exdays);
- var c_value = escape(value) + ((exdays === null) ? "" : "; expires=" + exdate.toUTCString());
- document.cookie = c_name + "=" + c_value;
- }