Mercurial > repos > mingchen0919 > aurora_htseq
annotate vakata-jstree-3.3.5/src/sample.js @ 0:803f4888f36a draft
planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
author | mingchen0919 |
---|---|
date | Thu, 13 Dec 2018 22:46:23 -0500 |
parents | |
children |
rev | line source |
---|---|
0
803f4888f36a
planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff
changeset
|
1 /*global jQuery */ |
803f4888f36a
planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff
changeset
|
2 // wrap in IIFE and pass jQuery as $ |
803f4888f36a
planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff
changeset
|
3 (function ($, undefined) { |
803f4888f36a
planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff
changeset
|
4 "use strict"; |
803f4888f36a
planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff
changeset
|
5 |
803f4888f36a
planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff
changeset
|
6 // some private plugin stuff if needed |
803f4888f36a
planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff
changeset
|
7 var private_var = null; |
803f4888f36a
planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff
changeset
|
8 |
803f4888f36a
planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff
changeset
|
9 // extending the defaults |
803f4888f36a
planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff
changeset
|
10 $.jstree.defaults.sample = { |
803f4888f36a
planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff
changeset
|
11 sample_option : 'sample_val' |
803f4888f36a
planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff
changeset
|
12 }; |
803f4888f36a
planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff
changeset
|
13 |
803f4888f36a
planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff
changeset
|
14 // the actual plugin code |
803f4888f36a
planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff
changeset
|
15 $.jstree.plugins.sample = function (options, parent) { |
803f4888f36a
planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff
changeset
|
16 // own function |
803f4888f36a
planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff
changeset
|
17 this.sample_function = function (arg) { |
803f4888f36a
planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff
changeset
|
18 // you can chain this method if needed and available |
803f4888f36a
planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff
changeset
|
19 if(parent.sample_function) { parent.sample_function.call(this, arg); } |
803f4888f36a
planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff
changeset
|
20 }; |
803f4888f36a
planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff
changeset
|
21 |
803f4888f36a
planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff
changeset
|
22 // *SPECIAL* FUNCTIONS |
803f4888f36a
planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff
changeset
|
23 this.init = function (el, options) { |
803f4888f36a
planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff
changeset
|
24 // do not forget parent |
803f4888f36a
planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff
changeset
|
25 parent.init.call(this, el, options); |
803f4888f36a
planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff
changeset
|
26 }; |
803f4888f36a
planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff
changeset
|
27 // bind events if needed |
803f4888f36a
planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff
changeset
|
28 this.bind = function () { |
803f4888f36a
planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff
changeset
|
29 // call parent function first |
803f4888f36a
planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff
changeset
|
30 parent.bind.call(this); |
803f4888f36a
planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff
changeset
|
31 // do(stuff); |
803f4888f36a
planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff
changeset
|
32 }; |
803f4888f36a
planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff
changeset
|
33 // unbind events if needed (all in jquery namespace are taken care of by the core) |
803f4888f36a
planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff
changeset
|
34 this.unbind = function () { |
803f4888f36a
planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff
changeset
|
35 // do(stuff); |
803f4888f36a
planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff
changeset
|
36 // call parent function last |
803f4888f36a
planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff
changeset
|
37 parent.unbind.call(this); |
803f4888f36a
planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff
changeset
|
38 }; |
803f4888f36a
planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff
changeset
|
39 this.teardown = function () { |
803f4888f36a
planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff
changeset
|
40 // do not forget parent |
803f4888f36a
planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff
changeset
|
41 parent.teardown.call(this); |
803f4888f36a
planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff
changeset
|
42 }; |
803f4888f36a
planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff
changeset
|
43 // state management - get and restore |
803f4888f36a
planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff
changeset
|
44 this.get_state = function () { |
803f4888f36a
planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff
changeset
|
45 // always get state from parent first |
803f4888f36a
planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff
changeset
|
46 var state = parent.get_state.call(this); |
803f4888f36a
planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff
changeset
|
47 // add own stuff to state |
803f4888f36a
planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff
changeset
|
48 state.sample = { 'var' : 'val' }; |
803f4888f36a
planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff
changeset
|
49 return state; |
803f4888f36a
planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff
changeset
|
50 }; |
803f4888f36a
planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff
changeset
|
51 this.set_state = function (state, callback) { |
803f4888f36a
planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff
changeset
|
52 // only process your part if parent returns true |
803f4888f36a
planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff
changeset
|
53 // there will be multiple times with false |
803f4888f36a
planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff
changeset
|
54 if(parent.set_state.call(this, state, callback)) { |
803f4888f36a
planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff
changeset
|
55 // check the key you set above |
803f4888f36a
planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff
changeset
|
56 if(state.sample) { |
803f4888f36a
planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff
changeset
|
57 // do(stuff); // like calling this.sample_function(state.sample.var); |
803f4888f36a
planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff
changeset
|
58 // remove your part of the state, call again and RETURN FALSE, the next cycle will be TRUE |
803f4888f36a
planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff
changeset
|
59 delete state.sample; |
803f4888f36a
planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff
changeset
|
60 this.set_state(state, callback); |
803f4888f36a
planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff
changeset
|
61 return false; |
803f4888f36a
planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff
changeset
|
62 } |
803f4888f36a
planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff
changeset
|
63 // return true if your state is gone (cleared in the previous step) |
803f4888f36a
planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff
changeset
|
64 return true; |
803f4888f36a
planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff
changeset
|
65 } |
803f4888f36a
planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff
changeset
|
66 // parent was false - return false too |
803f4888f36a
planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff
changeset
|
67 return false; |
803f4888f36a
planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff
changeset
|
68 }; |
803f4888f36a
planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff
changeset
|
69 // node transportation |
803f4888f36a
planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff
changeset
|
70 this.get_json = function (obj, options, flat) { |
803f4888f36a
planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff
changeset
|
71 // get the node from the parent |
803f4888f36a
planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff
changeset
|
72 var tmp = parent.get_json.call(this, obj, options, flat), i, j; |
803f4888f36a
planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff
changeset
|
73 if($.isArray(tmp)) { |
803f4888f36a
planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff
changeset
|
74 for(i = 0, j = tmp.length; i < j; i++) { |
803f4888f36a
planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff
changeset
|
75 tmp[i].sample = 'value'; |
803f4888f36a
planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff
changeset
|
76 } |
803f4888f36a
planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff
changeset
|
77 } |
803f4888f36a
planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff
changeset
|
78 else { |
803f4888f36a
planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff
changeset
|
79 tmp.sample = 'value'; |
803f4888f36a
planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff
changeset
|
80 } |
803f4888f36a
planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff
changeset
|
81 // return the original / modified node |
803f4888f36a
planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff
changeset
|
82 return tmp; |
803f4888f36a
planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff
changeset
|
83 }; |
803f4888f36a
planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff
changeset
|
84 }; |
803f4888f36a
planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff
changeset
|
85 |
803f4888f36a
planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff
changeset
|
86 // attach to document ready if needed |
803f4888f36a
planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff
changeset
|
87 $(function () { |
803f4888f36a
planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff
changeset
|
88 // do(stuff); |
803f4888f36a
planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff
changeset
|
89 }); |
803f4888f36a
planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff
changeset
|
90 |
803f4888f36a
planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff
changeset
|
91 // you can include the sample plugin in all instances by default |
803f4888f36a
planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff
changeset
|
92 $.jstree.defaults.plugins.push("sample"); |
803f4888f36a
planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff
changeset
|
93 })(jQuery); |