tablesorter/dist/js/widgets/widget-sort2Hash.min.js

2 lines
1.1 KiB
JavaScript
Raw Normal View History

/*! Widget: sort2Hash */
!function(a){"use strict";var b=a.tablesorter||{},c={init:function(a,b){var d,e,f,g,h,i=c.getSort(a,b);if(i){for(d=i.split(b.sort2Hash_separator),f=d.length,i=[],e=0;f>e;e++)g=d[e++],h=d[e],"undefined"!=typeof h&&i.push([g,h]);i.length&&(a.sortList=i)}a.$table.on("sortEnd.sort2hash",function(){c.setHash(a,b)})},getTableId:function(b,c){return c.sort2Hash_tableId||b.table.id||"table"+a("table").index(b.$table)},getSort:function(a,b,d){var e=c.getTableId(a,b).replace(/[\[]/,"\\[").replace(/[\]]/,"\\]"),f=new RegExp("[\\#&]"+e+"=([^&]*)").exec(window.location.hash);return null===f?"":(d&&(window.location.hash=window.location.hash.replace("&"+e+"="+f[1],"")),f[1])},setHash:function(a,b){var d=c.getTableId(a,b)+"=",e=a.sortList||[],f=e.length;f&&(c.getSort(a,b,!0),window.location.hash+=(window.location.hash.length?"":b.sort2Hash_hash)+"&"+d+[].concat.apply([],e).join(b.sort2Hash_separator))}};b.addWidget({id:"sort2Hash",options:{sort2Hash_hash:"#",sort2Hash_separator:"-",sort2Hash_tableId:null},init:function(a,b,d,e){c.init(d,e)},remove:function(a,b){b.$table.off("sortEnd.sort2hash")}})}(jQuery);