Mercurial > repos > mingchen0919 > aurora_star_site
annotate vakata-jstree-3.3.5/src/jstree.changed.js @ 4:804fe260ee6c draft default tip
planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
author | mingchen0919 |
---|---|
date | Sun, 30 Dec 2018 14:04:22 -0500 |
parents | c12e291895ff |
children |
rev | line source |
---|---|
0
c12e291895ff
planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff
changeset
|
1 /** |
c12e291895ff
planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff
changeset
|
2 * ### Changed plugin |
c12e291895ff
planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff
changeset
|
3 * |
c12e291895ff
planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff
changeset
|
4 * This plugin adds more information to the `changed.jstree` event. The new data is contained in the `changed` event data property, and contains a lists of `selected` and `deselected` nodes. |
c12e291895ff
planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff
changeset
|
5 */ |
c12e291895ff
planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff
changeset
|
6 /*globals jQuery, define, exports, require, document */ |
c12e291895ff
planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff
changeset
|
7 (function (factory) { |
c12e291895ff
planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff
changeset
|
8 "use strict"; |
c12e291895ff
planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff
changeset
|
9 if (typeof define === 'function' && define.amd) { |
c12e291895ff
planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff
changeset
|
10 define('jstree.changed', ['jquery','jstree'], factory); |
c12e291895ff
planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff
changeset
|
11 } |
c12e291895ff
planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff
changeset
|
12 else if(typeof exports === 'object') { |
c12e291895ff
planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff
changeset
|
13 factory(require('jquery'), require('jstree')); |
c12e291895ff
planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff
changeset
|
14 } |
c12e291895ff
planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff
changeset
|
15 else { |
c12e291895ff
planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff
changeset
|
16 factory(jQuery, jQuery.jstree); |
c12e291895ff
planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff
changeset
|
17 } |
c12e291895ff
planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff
changeset
|
18 }(function ($, jstree, undefined) { |
c12e291895ff
planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff
changeset
|
19 "use strict"; |
c12e291895ff
planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff
changeset
|
20 |
c12e291895ff
planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff
changeset
|
21 if($.jstree.plugins.changed) { return; } |
c12e291895ff
planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff
changeset
|
22 |
c12e291895ff
planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff
changeset
|
23 $.jstree.plugins.changed = function (options, parent) { |
c12e291895ff
planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff
changeset
|
24 var last = []; |
c12e291895ff
planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff
changeset
|
25 this.trigger = function (ev, data) { |
c12e291895ff
planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff
changeset
|
26 var i, j; |
c12e291895ff
planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff
changeset
|
27 if(!data) { |
c12e291895ff
planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff
changeset
|
28 data = {}; |
c12e291895ff
planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff
changeset
|
29 } |
c12e291895ff
planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff
changeset
|
30 if(ev.replace('.jstree','') === 'changed') { |
c12e291895ff
planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff
changeset
|
31 data.changed = { selected : [], deselected : [] }; |
c12e291895ff
planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff
changeset
|
32 var tmp = {}; |
c12e291895ff
planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff
changeset
|
33 for(i = 0, j = last.length; i < j; i++) { |
c12e291895ff
planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff
changeset
|
34 tmp[last[i]] = 1; |
c12e291895ff
planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff
changeset
|
35 } |
c12e291895ff
planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff
changeset
|
36 for(i = 0, j = data.selected.length; i < j; i++) { |
c12e291895ff
planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff
changeset
|
37 if(!tmp[data.selected[i]]) { |
c12e291895ff
planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff
changeset
|
38 data.changed.selected.push(data.selected[i]); |
c12e291895ff
planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff
changeset
|
39 } |
c12e291895ff
planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff
changeset
|
40 else { |
c12e291895ff
planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff
changeset
|
41 tmp[data.selected[i]] = 2; |
c12e291895ff
planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff
changeset
|
42 } |
c12e291895ff
planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff
changeset
|
43 } |
c12e291895ff
planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff
changeset
|
44 for(i = 0, j = last.length; i < j; i++) { |
c12e291895ff
planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff
changeset
|
45 if(tmp[last[i]] === 1) { |
c12e291895ff
planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff
changeset
|
46 data.changed.deselected.push(last[i]); |
c12e291895ff
planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff
changeset
|
47 } |
c12e291895ff
planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff
changeset
|
48 } |
c12e291895ff
planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff
changeset
|
49 last = data.selected.slice(); |
c12e291895ff
planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff
changeset
|
50 } |
c12e291895ff
planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff
changeset
|
51 /** |
c12e291895ff
planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff
changeset
|
52 * triggered when selection changes (the "changed" plugin enhances the original event with more data) |
c12e291895ff
planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff
changeset
|
53 * @event |
c12e291895ff
planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff
changeset
|
54 * @name changed.jstree |
c12e291895ff
planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff
changeset
|
55 * @param {Object} node |
c12e291895ff
planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff
changeset
|
56 * @param {Object} action the action that caused the selection to change |
c12e291895ff
planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff
changeset
|
57 * @param {Array} selected the current selection |
c12e291895ff
planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff
changeset
|
58 * @param {Object} changed an object containing two properties `selected` and `deselected` - both arrays of node IDs, which were selected or deselected since the last changed event |
c12e291895ff
planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff
changeset
|
59 * @param {Object} event the event (if any) that triggered this changed event |
c12e291895ff
planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff
changeset
|
60 * @plugin changed |
c12e291895ff
planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff
changeset
|
61 */ |
c12e291895ff
planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff
changeset
|
62 parent.trigger.call(this, ev, data); |
c12e291895ff
planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff
changeset
|
63 }; |
c12e291895ff
planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff
changeset
|
64 this.refresh = function (skip_loading, forget_state) { |
c12e291895ff
planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff
changeset
|
65 last = []; |
c12e291895ff
planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff
changeset
|
66 return parent.refresh.apply(this, arguments); |
c12e291895ff
planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff
changeset
|
67 }; |
c12e291895ff
planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff
changeset
|
68 }; |
c12e291895ff
planemo upload commit 104ae24ee30761a0099eeb91362ed1e3e13aba4b
mingchen0919
parents:
diff
changeset
|
69 })); |