tablesorter/dist/js/widgets/widget-saveSort.min.js
2015-10-31 11:06:09 -05:00

18 lines
1.4 KiB
JavaScript

/*! Widget: saveSort - updated 10/31/2015 (v2.24.0) */
/*
* Requires tablesorter v2.16+
* by Rob Garrison
*/
!function(a){"use strict";var b=a.tablesorter||{};
// this widget saves the last sort only if the
// saveSort widget option is true AND the
// $.tablesorter.storage function is included
// **************************
b.addWidget({id:"saveSort",priority:20,options:{saveSort:!0},init:function(a,b,c,d){
// run widget format before all other widgets are applied to the table
b.format(a,c,d,!0)},format:function(c,d,e,f){var g,h,i=d.$table,j=e.saveSort!==!1,// make saveSort active/inactive; default to true
k={sortList:d.sortList};d.debug&&(h=new Date),i.hasClass("hasSaveSort")?j&&c.hasInitialized&&b.storage&&(b.storage(c,"tablesorter-savesort",k),d.debug&&console.log("saveSort widget: Saving last sort: "+d.sortList+b.benchmark(h))):(
// set table sort on initial run of the widget
i.addClass("hasSaveSort"),k="",b.storage&&(g=b.storage(c,"tablesorter-savesort"),k=g&&g.hasOwnProperty("sortList")&&a.isArray(g.sortList)?g.sortList:"",d.debug&&console.log('saveSort: Last sort loaded: "'+k+'"'+b.benchmark(h)),i.bind("saveSortReset",function(a){a.stopPropagation(),b.storage(c,"tablesorter-savesort","")})),f&&k&&k.length>0?d.sortList=k:c.hasInitialized&&k&&k.length>0&&b.sortOn(d,k))},remove:function(a,c){c.$table.removeClass("hasSaveSort"),
// clear storage
b.storage&&b.storage(a,"tablesorter-savesort","")}})}(jQuery);