Skip to content
This repository
Browse code

fixing storage again

  • Loading branch information...
commit b612f2433714d8b4ba6c8f960f37c2acfd5e851b 1 parent dd445ac
Rob G authored
21 js/jquery.tablesorter.widgets.js
@@ -30,25 +30,32 @@
30 30 alert(val); // "data1" if saved, or "" if not
31 31 */
32 32 $.tablesorter.storage = function(table, key, val){
33   - var d, k, o = {}, ls = false, v = {},
  33 + var d, k, ls = false, v = {},
34 34 id = table.id || $('.tablesorter').index( $(table) ),
35 35 url = window.location.pathname;
36 36 try { ls = !!(localStorage.getItem); } catch(e) {}
37 37 // *** get val ***
38 38 if ($.parseJSON) {
39 39 if (ls) {
40   - o = $.parseJSON(localStorage[key]) || {};
  40 + v = $.parseJSON(localStorage[key]) || {};
41 41 } else {
42 42 k = document.cookie.split(/[;\s|=]/); // cookie
43 43 d = $.inArray(key, k) + 1; // add one to get from the key to the value
44   - o = (d !== 0) ? $.parseJSON(k[d]) || {} : {};
  44 + v = (d !== 0) ? $.parseJSON(k[d]) || {} : {};
45 45 }
46 46 }
47 47 if (val && JSON && JSON.hasOwnProperty('stringify')) {
48 48 // add unique identifiers = url pathname > table ID/index on page > data
49   - v[url] = {};
50   - v[url][id] = val;
51   - v = $.extend( true, o, v );
  49 + if (v[url] && v[url][id]) {
  50 + v[url][id] = val;
  51 + } else {
  52 + if (v[url]) {
  53 + v[url][id] = val;
  54 + } else {
  55 + v[url] = {};
  56 + v[url][id] = val;
  57 + }
  58 + }
52 59 // *** set val ***
53 60 if (ls) {
54 61 localStorage[key] = JSON.stringify(v);
@@ -58,7 +65,7 @@ $.tablesorter.storage = function(table, key, val){
58 65 document.cookie = key + '=' + (JSON.stringify(v)).replace(/\"/g,'\"') + '; expires=' + d.toGMTString() + '; path=/';
59 66 }
60 67 } else {
61   - return ( o && o.hasOwnProperty(url) && o[url].hasOwnProperty(id) ) ? o[url][id] : {};
  68 + return ( v && v.hasOwnProperty(url) && v[url].hasOwnProperty(id) ) ? v[url][id] : {};
62 69 }
63 70 };
64 71
14 js/jquery.tablesorter.widgets.min.js
... ... @@ -1,10 +1,10 @@
1 1 /*! tableSorter 2.1 widgets - updated 4/2/2012 */
2 2 (function(b){
3   -b.tablesorter.storage=function(a,e,d){var c,i;c={};var j=!1,g={},a=a.id||b(".tablesorter").index(b(a)),f=window.location.pathname;try{j=!!localStorage.getItem}catch(h){}b.parseJSON&&(j?c=b.parseJSON(localStorage[e])||{}:(i=document.cookie.split(/[;\s|=]/),c=b.inArray(e,i)+1,c=0!==c?b.parseJSON(i[c])||{}:{}));if(d&&JSON&&JSON.hasOwnProperty("stringify"))g[f]={},g[f][a]=d,g=b.extend(!0,c,g),j?localStorage[e]=JSON.stringify(g):(c=new Date,c.setTime(c.getTime()+31536E6),document.cookie=e+ "="+JSON.stringify(g).replace(/\"/g,'"')+"; expires="+c.toGMTString()+"; path=/");else return c&&c.hasOwnProperty(f)&&c[f].hasOwnProperty(a)?c[f][a]:{}};
4   -b.tablesorter.addWidget({id:"uitheme",format:function(a){var e,d,c,i,j,g=b(a),f=a.config,h=f.widgetOptions,k=["ui-icon-arrowthick-2-n-s","ui-icon-arrowthick-1-s","ui-icon-arrowthick-1-n"],k=f.widgetUitheme&&f.widgetUitheme.hasOwnProperty("css")?f.widgetUitheme.css||k:h&&h.hasOwnProperty("uitheme")?h.uitheme:k;c=k.join(" ");f.debug&&(e=new Date);g.hasClass("ui-theme")|| (g.addClass("ui-widget ui-widget-content ui-corner-all ui-theme"),b.each(f.headerList,function(){b(this).addClass("ui-widget-header ui-corner-all ui-state-default").append('<span class="ui-icon"/>').wrapInner('<div class="tablesorter-inner"/>').hover(function(){b(this).addClass("ui-state-hover")},function(){b(this).removeClass("ui-state-hover")})}));b.each(f.headerList,function(a){i=b(this);if(this.sortDisabled)i.find("span.ui-icon").removeClass(c+" ui-icon");else{d=i.hasClass(f.cssAsc)?k[1]:i.hasClass(f.cssDesc)? k[2]:i.hasClass(f.cssHeader)?k[0]:"";j=g.hasClass("hasStickyHeaders")?g.find("tr."+(h.stickyHeaders||"tablesorter-stickyHeader")).find("th").eq(a).add(i):i;j[d===k[0]?"removeClass":"addClass"]("ui-state-active").find("span.ui-icon").removeClass(c).addClass(d)}});f.debug&&b.tablesorter.benchmark("Applying uitheme widget",e)}});
5   -b.tablesorter.addWidget({id:"columns",format:function(a){var e,d,c,i,j=a.config,g=j.sortList,f=g.length,h=["primary","secondary","tertiary"],h=j.widgetColumns&&j.widgetColumns.hasOwnProperty("css")? j.widgetColumns.css||h:j.widgetOptions&&j.widgetOptions.hasOwnProperty("columns")?j.widgetOptions.columns||h:h;c=h.length-1;i=h.join(" ");j.debug&&(d=new Date);g&&g[0]?b("tr:visible",a.tBodies[0]).each(function(a){e=b(this).children().removeClass(i);e.eq(g[0][0]).addClass(h[0]);if(1<f)for(a=1;a<f;a++)e.eq(g[a][0]).addClass(h[a]||h[c])}):b("td",a.tBodies[0]).removeClass(i);j.debug&&b.tablesorter.benchmark("Applying Columns widget",d)}});
6   -b.tablesorter.addWidget({id:"filter",format:function(a){if(!b(a).hasClass("hasFilters")){var e, d,c,i,j,g,f,h=a.config,k=h.widgetOptions,l=k.filter_cssFilter||"tablesorter-filter",n=h.headerList.length,m=b(a).addClass("hasFilters"),a='<tr class="'+l+'">',o;h.debug&&(o=new Date);for(e=0;e<n;e++)a+='<td><input type="search" data-col="'+e+'" class="'+l,a+=h.headers[e]&&h.headers[e].hasOwnProperty("filter")&&!1===h.headers[e].filter||b(h.headerList[e]).is(".filter-false")?' disabled" disabled':'"',a+="></td>";m.find("thead").append(a+="</tr>").find("input."+l).bind("keyup search",function(){d=m.find("thead").find("input."+ l).map(function(){return(b(this).val()||"").toLowerCase()}).get();""===d.join("")?m.find("tr").show():m.find("tbody").find("tr:not(."+h.cssChildRow+")").each(function(){c=!0;g=b(this).nextUntil("tr:not(."+h.cssChildRow+")");i=g.length&&(k&&k.hasOwnProperty("filter_childRows")&&"undefined"!==typeof k.filter_childRows?k.filter_childRows:1)?g.text():"";f=b(this).find("td");for(e=0;e<n;e++)j=(f.eq(e).text()+i).toLowerCase().indexOf(d[e]),""!==d[e]&&(!k.filter_startsWith&&0<=j||k.filter_startsWith&&0=== j)?c=c?!0:!1:""!==d[e]&&(c=!1);b(this)[c?"show":"hide"]();if(g.length)g[c?"show":"hide"]()});m.trigger("applyWidgets")});h.debug&&b.tablesorter.benchmark("Applying Filter widget",o)}}});
7   -b.tablesorter.addWidget({id:"stickyHeaders",format:function(a){if(!b(a).hasClass("hasStickyHeaders")){var e=b(a).addClass("hasStickyHeaders"),d=a.config.widgetOptions,c=b(window),i=b(a).find("thead"),j=i.find("tr").children(),g=d.stickyHeaders||"tablesorter-stickyHeader",f=j.eq(0),h=i.find("tr.tablesorter-header").clone().removeClass("tablesorter-header").addClass(g).css({width:i.outerWidth(!0), position:"fixed",left:f.offset().left,margin:0,top:0,visibility:"hidden",zIndex:10}),k=h.children(),l="";e.bind("sortEnd",function(a,c){var d=b(c).find("thead tr"),e=d.filter("."+g).children();d.filter(":not(."+g+")").children().each(function(a){e.eq(a).attr("class",b(this).attr("class"))})}).bind("pagerComplete",function(){c.resize()});j.each(function(a){var c=b(this);k.eq(a).bind("click",function(b){c.trigger(b)}).bind("mousedown",function(){this.onselectstart=function(){return!1};return!1}).find(".tablesorter-header-inner").width(c.find(".tablesorter-header-inner").width())}); i.prepend(h);c.scroll(function(){var b=f.offset(),a=c.scrollTop(),a=a>b.top&&a<b.top+e.find("tbody").height()?"visible":"hidden";h.css({left:b.left-c.scrollLeft(),visibility:a});a!==l&&(c.resize(),l=a)}).resize(function(){h.css({left:f.offset().left-c.scrollLeft(),width:i.outerWidth()});k.find(".tablesorter-header-inner").each(function(a){b(this).width(j.eq(a).find(".tablesorter-header-inner").width())})})}}});
8   -b.tablesorter.addWidget({id:"resizable",format:function(a){if(!b(a).hasClass("hasResizable")){b(a).addClass("hasResizable"); var e,d,c=a.config,i=b(c.headerList).filter(":gt(0)"),j=0,g=null,f=null,h=function(){j=0;g=f=null;b(window).trigger("resize")};if(d=b.tablesorter.storage?b.tablesorter.storage(a,"tablesorter-resizable"):"")for(e in d)!isNaN(e)&&e<c.headerList.length&&b(c.headerList[e]).width(d[e]);i.each(function(){b(this).append('<div class="tablesorter-resizer" style="cursor:w-resize;position:absolute;height:100%;width:20px;left:-20px;top:0;z-index:1;"></div>').wrapInner('<div style="position:relative;height:100%;width:100%"></div>')}).bind("mousemove", function(a){if(0!==j&&g){var b=a.pageX-j;g.width()<-b||f&&f.width()<=b||(f.width(f.width()+b),j=a.pageX)}}).bind("mouseup",function(){d&&b.tablesorter.storage&&g&&(d[f.index()]=f.width(),b.tablesorter.storage(a,"tablesorter-resizable",d));h();return!1}).find(".tablesorter-resizer").bind("mousedown",function(a){g=b(a.target).closest("th");f=g.prev();j=a.pageX});b(a).find("thead").bind("mouseup mouseleave",function(){h()})}}});
9   -b.tablesorter.addWidget({id:"saveSort",init:function(a,b,d){d.format(a,!0)}, format:function(a,e){var d,c,i=a.config;d={sortList:i.sortList};i.debug&&(c=new Date);b(a).hasClass("hasSaveSort")?a.hasInitialized&&b.tablesorter.storage&&(b.tablesorter.storage(a,"tablesorter-savesort",d),i.debug&&b.tablesorter.benchmark("saveSort widget: Saving last sort: "+i.sortList,c)):(b(a).addClass("hasSaveSort"),d="",b.tablesorter.storage&&(d=(d=b.tablesorter.storage(a,"tablesorter-savesort"))&&d.hasOwnProperty("sortList")&&b.isArray(d.sortList)?d.sortList:"",i.debug&&b.tablesorter.benchmark("saveSort: Last sort loaded: "+ d,c)),e&&d&&0<d.length?i.sortList=d:a.hasInitialized&&d&&0<d.length&&b(a).trigger("sorton",[d]))}})
  3 +b.tablesorter.storage=function(a,e,d){var c,g=!1;c={};var i=a.id||b(".tablesorter").index(b(a)),f=window.location.pathname;try{g=!!localStorage.getItem}catch(j){}b.parseJSON&&(g?c=b.parseJSON(localStorage[e])||{}:(c=document.cookie.split(/[;\s|=]/),a=b.inArray(e,c)+1,c=0!==a?b.parseJSON(c[a])||{}:{}));if(d&&JSON&&JSON.hasOwnProperty("stringify")){if(!c[f]||!c[f][i])c[f]||(c[f]={});c[f][i]=d;g?localStorage[e]=JSON.stringify(c):(a=new Date,a.setTime(a.getTime()+31536E6),document.cookie= e+"="+JSON.stringify(c).replace(/\"/g,'"')+"; expires="+a.toGMTString()+"; path=/")}else return c&&c.hasOwnProperty(f)&&c[f].hasOwnProperty(i)?c[f][i]:{}};
  4 +b.tablesorter.addWidget({id:"uitheme",format:function(a){var e,d,c,g,i,f=b(a),j=a.config,h=j.widgetOptions,k=["ui-icon-arrowthick-2-n-s","ui-icon-arrowthick-1-s","ui-icon-arrowthick-1-n"],k=j.widgetUitheme&&j.widgetUitheme.hasOwnProperty("css")?j.widgetUitheme.css||k:h&&h.hasOwnProperty("uitheme")?h.uitheme:k;c=k.join(" ");j.debug&&(e=new Date); f.hasClass("ui-theme")||(f.addClass("ui-widget ui-widget-content ui-corner-all ui-theme"),b.each(j.headerList,function(){b(this).addClass("ui-widget-header ui-corner-all ui-state-default").append('<span class="ui-icon"/>').wrapInner('<div class="tablesorter-inner"/>').hover(function(){b(this).addClass("ui-state-hover")},function(){b(this).removeClass("ui-state-hover")})}));b.each(j.headerList,function(a){g=b(this);if(this.sortDisabled)g.find("span.ui-icon").removeClass(c+" ui-icon");else{d=g.hasClass(j.cssAsc)? k[1]:g.hasClass(j.cssDesc)?k[2]:g.hasClass(j.cssHeader)?k[0]:"";i=f.hasClass("hasStickyHeaders")?f.find("tr."+(h.stickyHeaders||"tablesorter-stickyHeader")).find("th").eq(a).add(g):g;i[d===k[0]?"removeClass":"addClass"]("ui-state-active").find("span.ui-icon").removeClass(c).addClass(d)}});j.debug&&b.tablesorter.benchmark("Applying uitheme widget",e)}});
  5 +b.tablesorter.addWidget({id:"columns",format:function(a){var e,d,c,g,i=a.config,f=i.sortList,j=f.length,h=["primary","secondary","tertiary"],h=i.widgetColumns&& i.widgetColumns.hasOwnProperty("css")?i.widgetColumns.css||h:i.widgetOptions&&i.widgetOptions.hasOwnProperty("columns")?i.widgetOptions.columns||h:h;c=h.length-1;g=h.join(" ");i.debug&&(d=new Date);f&&f[0]?b("tr:visible",a.tBodies[0]).each(function(a){e=b(this).children().removeClass(g);e.eq(f[0][0]).addClass(h[0]);if(1<j)for(a=1;a<j;a++)e.eq(f[a][0]).addClass(h[a]||h[c])}):b("td",a.tBodies[0]).removeClass(g);i.debug&&b.tablesorter.benchmark("Applying Columns widget",d)}});
  6 +b.tablesorter.addWidget({id:"filter", format:function(a){if(!b(a).hasClass("hasFilters")){var e,d,c,g,i,f,j,h=a.config,k=h.widgetOptions,l=k.filter_cssFilter||"tablesorter-filter",n=h.headerList.length,m=b(a).addClass("hasFilters"),a='<tr class="'+l+'">',o;h.debug&&(o=new Date);for(e=0;e<n;e++)a+='<td><input type="search" data-col="'+e+'" class="'+l,a+=h.headers[e]&&h.headers[e].hasOwnProperty("filter")&&!1===h.headers[e].filter||b(h.headerList[e]).is(".filter-false")?' disabled" disabled':'"',a+="></td>";m.find("thead").append(a+="</tr>").find("input."+ l).bind("keyup search",function(){d=m.find("thead").find("input."+l).map(function(){return(b(this).val()||"").toLowerCase()}).get();""===d.join("")?m.find("tr").show():m.find("tbody").find("tr:not(."+h.cssChildRow+")").each(function(){c=!0;f=b(this).nextUntil("tr:not(."+h.cssChildRow+")");g=f.length&&(k&&k.hasOwnProperty("filter_childRows")&&"undefined"!==typeof k.filter_childRows?k.filter_childRows:1)?f.text():"";j=b(this).find("td");for(e=0;e<n;e++)i=(j.eq(e).text()+g).toLowerCase().indexOf(d[e]), ""!==d[e]&&(!k.filter_startsWith&&0<=i||k.filter_startsWith&&0===i)?c=c?!0:!1:""!==d[e]&&(c=!1);b(this)[c?"show":"hide"]();if(f.length)f[c?"show":"hide"]()});m.trigger("applyWidgets")});h.debug&&b.tablesorter.benchmark("Applying Filter widget",o)}}});
  7 +b.tablesorter.addWidget({id:"stickyHeaders",format:function(a){if(!b(a).hasClass("hasStickyHeaders")){var e=b(a).addClass("hasStickyHeaders"),d=a.config.widgetOptions,c=b(window),g=b(a).find("thead"),i=g.find("tr").children(),f=d.stickyHeaders||"tablesorter-stickyHeader", j=i.eq(0),h=g.find("tr.tablesorter-header").clone().removeClass("tablesorter-header").addClass(f).css({width:g.outerWidth(!0),position:"fixed",left:j.offset().left,margin:0,top:0,visibility:"hidden",zIndex:10}),k=h.children(),l="";e.bind("sortEnd",function(a,c){var d=b(c).find("thead tr"),e=d.filter("."+f).children();d.filter(":not(."+f+")").children().each(function(a){e.eq(a).attr("class",b(this).attr("class"))})}).bind("pagerComplete",function(){c.resize()});i.each(function(a){var c=b(this);k.eq(a).bind("click", function(a){c.trigger(a)}).bind("mousedown",function(){this.onselectstart=function(){return!1};return!1}).find(".tablesorter-header-inner").width(c.find(".tablesorter-header-inner").width())});g.prepend(h);c.scroll(function(){var a=j.offset(),b=c.scrollTop(),b=b>a.top&&b<a.top+e.find("tbody").height()?"visible":"hidden";h.css({left:a.left-c.scrollLeft(),visibility:b});b!==l&&(c.resize(),l=b)}).resize(function(){h.css({left:j.offset().left-c.scrollLeft(),width:g.outerWidth()});k.find(".tablesorter-header-inner").each(function(a){b(this).width(i.eq(a).find(".tablesorter-header-inner").width())})})}}});
  8 +b.tablesorter.addWidget({id:"resizable",format:function(a){if(!b(a).hasClass("hasResizable")){b(a).addClass("hasResizable");var e,d,c=a.config,g=b(c.headerList).filter(":gt(0)"),i=0,f=null,j=null,h=function(){i=0;f=j=null;b(window).trigger("resize")};if(d=b.tablesorter.storage?b.tablesorter.storage(a,"tablesorter-resizable"):"")for(e in d)!isNaN(e)&&e<c.headerList.length&&b(c.headerList[e]).width(d[e]);g.each(function(){b(this).append('<div class="tablesorter-resizer" style="cursor:w-resize;position:absolute;height:100%;width:20px;left:-20px;top:0;z-index:1;"></div>').wrapInner('<div style="position:relative;height:100%;width:100%"></div>')}).bind("mousemove", function(a){if(0!==i&&f){var b=a.pageX-i;f.width()<-b||j&&j.width()<=b||(j.width(j.width()+b),i=a.pageX)}}).bind("mouseup",function(){d&&b.tablesorter.storage&&f&&(d[j.index()]=j.width(),b.tablesorter.storage(a,"tablesorter-resizable",d));h();return!1}).find(".tablesorter-resizer").bind("mousedown",function(a){f=b(a.target).closest("th");j=f.prev();i=a.pageX});b(a).find("thead").bind("mouseup mouseleave",function(){h()})}}});
  9 +b.tablesorter.addWidget({id:"saveSort",init:function(a,b,d){d.format(a,!0)}, format:function(a,e){var d,c,g=a.config;d={sortList:g.sortList};g.debug&&(c=new Date);b(a).hasClass("hasSaveSort")?a.hasInitialized&&b.tablesorter.storage&&(b.tablesorter.storage(a,"tablesorter-savesort",d),g.debug&&b.tablesorter.benchmark("saveSort widget: Saving last sort: "+g.sortList,c)):(b(a).addClass("hasSaveSort"),d="",b.tablesorter.storage&&(d=(d=b.tablesorter.storage(a,"tablesorter-savesort"))&&d.hasOwnProperty("sortList")&&b.isArray(d.sortList)?d.sortList:"",g.debug&&b.tablesorter.benchmark("saveSort: Last sort loaded: "+ d,c)),e&&d&&0<d.length?g.sortList=d:a.hasInitialized&&d&&0<d.length&&b(a).trigger("sorton",[d]))}})
10 10 })(jQuery);

0 comments on commit b612f24

Please sign in to comment.
Something went wrong with that request. Please try again.