mirror of
https://github.com/Mottie/tablesorter.git
synced 2025-01-12 15:24:21 +00:00
Storage: Add storage_storageType
& deprecate
Deprecate `storage_useSessionStorage`
This commit is contained in:
parent
fb07b98f08
commit
b45daa1ad4
@ -2112,7 +2112,10 @@ $(function(){
|
||||
stickyHeaders_zIndex: 2,
|
||||
|
||||
// *** STORAGE WIDGET ***
|
||||
// allows switching between using local & session storage
|
||||
// set storage type; this overrides any storage_useSessionStorage setting
|
||||
// use the first letter of (l)ocal, (s)ession or (c)ookie
|
||||
storage_storageType: '',
|
||||
// DEPRECATED: allows switching between using local & session storage
|
||||
storage_useSessionStorage: false,
|
||||
// alternate table id (set if grouping multiple tables together)
|
||||
storage_tableId: '',
|
||||
@ -3958,13 +3961,42 @@ $('table').trigger('search', false);</pre></div>
|
||||
<td><a href="example-widget-savesort.html">Example</a></td>
|
||||
</tr>
|
||||
|
||||
<tr id="widget-storage-storage-type">
|
||||
<td><a href="#" class="permalink">storage_storageType</a></td>
|
||||
<td>String</td>
|
||||
<td>""</td>
|
||||
<td>
|
||||
Storage widget: Set this option to the first letter of the desired storage type (<span class="version">v2.28.8</span>).
|
||||
<div class="collapsible">
|
||||
<p>If <em>any</em> value is set in this option, the deprecated <a href="#widget-storage-use-session-storage"><code>"storage_useSessionStorage"</code></a> is completely ignored.</p>
|
||||
<ul>
|
||||
<li>When set to <code>"s"</code> (session), all saved variables for the table use <code>sessionStorage</code>. This means once the user closes the browser, all saved variables are lost.</li>
|
||||
<li>When set to <code>"c"</code> (cookie), all saved variables for the table will use cookies.</li>
|
||||
<li>Any other setting will switch to using the default <code>localStorage</code> type.</li>
|
||||
</ul>
|
||||
Use the <a href="#widget-storage-storage-type"><code>"storage_storageType"</code></a> option as follows:
|
||||
<pre class="prettyprint lang-js">$(function(){
|
||||
$("table").tablesorter({
|
||||
widgets: ["saveSort"],
|
||||
widgetOptions : {
|
||||
// This sets session storage; only the first letter is required
|
||||
storage_storageType : "session"
|
||||
}
|
||||
});
|
||||
});</pre></div>
|
||||
</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
|
||||
<tr id="widget-storage-use-session-storage">
|
||||
<td><a href="#" class="permalink">storage_useSessionStorage</a></td>
|
||||
<td><a href="#" class="permalink alert">storage_useSessionStorage</a></td>
|
||||
<td>Boolean</td>
|
||||
<td>false</td>
|
||||
<td>
|
||||
Storage widget: If this option is set to <code>false</code>, all saved variables for the table will be within local storage (<span class="version">v2.21.3</span>).
|
||||
Storage widget: This option was <span class="label label-danger">deprecated</span> in <span class="version updated">v2.28.8</span>.
|
||||
<div class="collapsible">
|
||||
<p>In <span class="version">v2.28.8</span>, this option is replaced by the <a href="#widget-storage-storage-type"><code>"storage_storageType"</code></a> option and will be completely ignored if that option has <em>any</em> setting.</p>
|
||||
<p>If this option is set to <code>false</code>, all saved variables for the table will be within local storage (<span class="version">v2.21.3</span>).</p>
|
||||
<p>If <code>true</code>, all saved variables for the table will be within the session storage. This means once the user closes the browser, all saved variables are lost.</p>
|
||||
Use the <a href="#widget-storage-use-session-storage"><code>"storage_useSessionStorage"</code></a> option to switch to session storage as follows:
|
||||
<pre class="prettyprint lang-js">$(function(){
|
||||
|
@ -1,4 +1,4 @@
|
||||
/*! Widget: storage - updated 11/26/2016 (v2.28.0) */
|
||||
/*! Widget: storage - updated 4/18/2017 (v2.28.8) */
|
||||
/*global JSON:false */
|
||||
;(function ($, window, document) {
|
||||
'use strict';
|
||||
@ -12,6 +12,7 @@
|
||||
storage_fixedUrl: '',
|
||||
storage_group: '',
|
||||
storage_page: '',
|
||||
storage_storageType: '',
|
||||
storage_tableId: '',
|
||||
storage_useSessionStorage: ''
|
||||
}
|
||||
@ -43,8 +44,12 @@
|
||||
values = {},
|
||||
c = table.config,
|
||||
wo = c && c.widgetOptions,
|
||||
storageType = ( options && options.useSessionStorage ) || ( wo && wo.storage_useSessionStorage ) ?
|
||||
'sessionStorage' : 'localStorage',
|
||||
storageType = (
|
||||
( options && options.storageType ) || ( wo && wo.storage_storageType )
|
||||
).toString().charAt(0).toLowerCase(),
|
||||
// deprecating "useSessionStorage"; any storageType setting overrides it
|
||||
session = storageType ? '' :
|
||||
( options && options.useSessionStorage ) || ( wo && wo.storage_useSessionStorage ),
|
||||
$table = $(table),
|
||||
// id from (1) options ID, (2) table 'data-table-group' attribute, (3) widgetOptions.storage_tableId,
|
||||
// (4) table ID, then (5) table index
|
||||
@ -56,18 +61,26 @@
|
||||
url = options && options.url ||
|
||||
$table.attr(options && options.page || wo && wo.storage_page || 'data-table-page') ||
|
||||
wo && wo.storage_fixedUrl || c && c.fixedUrl || window.location.pathname;
|
||||
// https://gist.github.com/paulirish/5558557
|
||||
if (storageType in window) {
|
||||
try {
|
||||
window[storageType].setItem('_tmptest', 'temp');
|
||||
hasStorage = true;
|
||||
window[storageType].removeItem('_tmptest');
|
||||
} catch (error) {
|
||||
if (c && c.debug) {
|
||||
console.warn( storageType + ' is not supported in this browser' );
|
||||
|
||||
// skip if using cookies
|
||||
if (storageType !== 'c') {
|
||||
storageType = (storageType === 's' || session) ? 'sessionStorage' : 'localStorage';
|
||||
// https://gist.github.com/paulirish/5558557
|
||||
if (storageType in window) {
|
||||
try {
|
||||
window[storageType].setItem('_tmptest', 'temp');
|
||||
hasStorage = true;
|
||||
window[storageType].removeItem('_tmptest');
|
||||
} catch (error) {
|
||||
if (c && c.debug) {
|
||||
console.warn( storageType + ' is not supported in this browser' );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (c.debug) {
|
||||
console.log('Storage widget using', hasStorage ? storageType : 'cookies');
|
||||
}
|
||||
// *** get value ***
|
||||
if ($.parseJSON) {
|
||||
if (hasStorage) {
|
||||
|
Loading…
Reference in New Issue
Block a user