Mercurial > repos > mingchen0919 > aurora_skewer
annotate vakata-jstree-3.3.5/src/jstree.state.js @ 0:0358f6f78adf draft
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
author | mingchen0919 |
---|---|
date | Fri, 14 Dec 2018 00:40:15 -0500 |
parents | |
children |
rev | line source |
---|---|
0
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
1 /** |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
2 * ### State plugin |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
3 * |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
4 * Saves the state of the tree (selected nodes, opened nodes) on the user's computer using available options (localStorage, cookies, etc) |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
5 */ |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
6 /*globals jQuery, define, exports, require */ |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
7 (function (factory) { |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
8 "use strict"; |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
9 if (typeof define === 'function' && define.amd) { |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
10 define('jstree.state', ['jquery','jstree'], factory); |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
11 } |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
12 else if(typeof exports === 'object') { |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
13 factory(require('jquery'), require('jstree')); |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
14 } |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
15 else { |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
16 factory(jQuery, jQuery.jstree); |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
17 } |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
18 }(function ($, jstree, undefined) { |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
19 "use strict"; |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
20 |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
21 if($.jstree.plugins.state) { return; } |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
22 |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
23 var to = false; |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
24 /** |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
25 * stores all defaults for the state plugin |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
26 * @name $.jstree.defaults.state |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
27 * @plugin state |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
28 */ |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
29 $.jstree.defaults.state = { |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
30 /** |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
31 * A string for the key to use when saving the current tree (change if using multiple trees in your project). Defaults to `jstree`. |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
32 * @name $.jstree.defaults.state.key |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
33 * @plugin state |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
34 */ |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
35 key : 'jstree', |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
36 /** |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
37 * A space separated list of events that trigger a state save. Defaults to `changed.jstree open_node.jstree close_node.jstree`. |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
38 * @name $.jstree.defaults.state.events |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
39 * @plugin state |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
40 */ |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
41 events : 'changed.jstree open_node.jstree close_node.jstree check_node.jstree uncheck_node.jstree', |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
42 /** |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
43 * Time in milliseconds after which the state will expire. Defaults to 'false' meaning - no expire. |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
44 * @name $.jstree.defaults.state.ttl |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
45 * @plugin state |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
46 */ |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
47 ttl : false, |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
48 /** |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
49 * A function that will be executed prior to restoring state with one argument - the state object. Can be used to clear unwanted parts of the state. |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
50 * @name $.jstree.defaults.state.filter |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
51 * @plugin state |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
52 */ |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
53 filter : false, |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
54 /** |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
55 * Should loaded nodes be restored (setting this to true means that it is possible that the whole tree will be loaded for some users - use with caution). Defaults to `false` |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
56 * @name $.jstree.defaults.state.preserve_loaded |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
57 * @plugin state |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
58 */ |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
59 preserve_loaded : false |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
60 }; |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
61 $.jstree.plugins.state = function (options, parent) { |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
62 this.bind = function () { |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
63 parent.bind.call(this); |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
64 var bind = $.proxy(function () { |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
65 this.element.on(this.settings.state.events, $.proxy(function () { |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
66 if(to) { clearTimeout(to); } |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
67 to = setTimeout($.proxy(function () { this.save_state(); }, this), 100); |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
68 }, this)); |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
69 /** |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
70 * triggered when the state plugin is finished restoring the state (and immediately after ready if there is no state to restore). |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
71 * @event |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
72 * @name state_ready.jstree |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
73 * @plugin state |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
74 */ |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
75 this.trigger('state_ready'); |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
76 }, this); |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
77 this.element |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
78 .on("ready.jstree", $.proxy(function (e, data) { |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
79 this.element.one("restore_state.jstree", bind); |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
80 if(!this.restore_state()) { bind(); } |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
81 }, this)); |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
82 }; |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
83 /** |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
84 * save the state |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
85 * @name save_state() |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
86 * @plugin state |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
87 */ |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
88 this.save_state = function () { |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
89 var tm = this.get_state(); |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
90 if (!this.settings.state.preserve_loaded) { |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
91 delete tm.core.loaded; |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
92 } |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
93 var st = { 'state' : tm, 'ttl' : this.settings.state.ttl, 'sec' : +(new Date()) }; |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
94 $.vakata.storage.set(this.settings.state.key, JSON.stringify(st)); |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
95 }; |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
96 /** |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
97 * restore the state from the user's computer |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
98 * @name restore_state() |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
99 * @plugin state |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
100 */ |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
101 this.restore_state = function () { |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
102 var k = $.vakata.storage.get(this.settings.state.key); |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
103 if(!!k) { try { k = JSON.parse(k); } catch(ex) { return false; } } |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
104 if(!!k && k.ttl && k.sec && +(new Date()) - k.sec > k.ttl) { return false; } |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
105 if(!!k && k.state) { k = k.state; } |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
106 if(!!k && $.isFunction(this.settings.state.filter)) { k = this.settings.state.filter.call(this, k); } |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
107 if(!!k) { |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
108 if (!this.settings.state.preserve_loaded) { |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
109 delete k.core.loaded; |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
110 } |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
111 this.element.one("set_state.jstree", function (e, data) { data.instance.trigger('restore_state', { 'state' : $.extend(true, {}, k) }); }); |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
112 this.set_state(k); |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
113 return true; |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
114 } |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
115 return false; |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
116 }; |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
117 /** |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
118 * clear the state on the user's computer |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
119 * @name clear_state() |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
120 * @plugin state |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
121 */ |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
122 this.clear_state = function () { |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
123 return $.vakata.storage.del(this.settings.state.key); |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
124 }; |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
125 }; |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
126 |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
127 (function ($, undefined) { |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
128 $.vakata.storage = { |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
129 // simply specifying the functions in FF throws an error |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
130 set : function (key, val) { return window.localStorage.setItem(key, val); }, |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
131 get : function (key) { return window.localStorage.getItem(key); }, |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
132 del : function (key) { return window.localStorage.removeItem(key); } |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
133 }; |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
134 }($)); |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
135 |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
136 // include the state plugin by default |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
137 // $.jstree.defaults.plugins.push("state"); |
0358f6f78adf
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff
changeset
|
138 })); |