annotate vakata-jstree-3.3.5/src/jstree.changed.js @ 0:803f4888f36a draft

planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
author mingchen0919
date Thu, 13 Dec 2018 22:46:23 -0500
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
803f4888f36a planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff changeset
1 /**
803f4888f36a planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff changeset
2 * ### Changed plugin
803f4888f36a planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff changeset
3 *
803f4888f36a planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
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.
803f4888f36a planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff changeset
5 */
803f4888f36a planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff changeset
6 /*globals jQuery, define, exports, require, document */
803f4888f36a planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff changeset
7 (function (factory) {
803f4888f36a planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff changeset
8 "use strict";
803f4888f36a planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff changeset
9 if (typeof define === 'function' && define.amd) {
803f4888f36a planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff changeset
10 define('jstree.changed', ['jquery','jstree'], factory);
803f4888f36a planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff changeset
11 }
803f4888f36a planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff changeset
12 else if(typeof exports === 'object') {
803f4888f36a planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff changeset
13 factory(require('jquery'), require('jstree'));
803f4888f36a planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff changeset
14 }
803f4888f36a planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff changeset
15 else {
803f4888f36a planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff changeset
16 factory(jQuery, jQuery.jstree);
803f4888f36a planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff changeset
17 }
803f4888f36a planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff changeset
18 }(function ($, jstree, undefined) {
803f4888f36a planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff changeset
19 "use strict";
803f4888f36a planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff changeset
20
803f4888f36a planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff changeset
21 if($.jstree.plugins.changed) { return; }
803f4888f36a planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff changeset
22
803f4888f36a planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff changeset
23 $.jstree.plugins.changed = function (options, parent) {
803f4888f36a planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff changeset
24 var last = [];
803f4888f36a planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff changeset
25 this.trigger = function (ev, data) {
803f4888f36a planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff changeset
26 var i, j;
803f4888f36a planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff changeset
27 if(!data) {
803f4888f36a planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff changeset
28 data = {};
803f4888f36a planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff changeset
29 }
803f4888f36a planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff changeset
30 if(ev.replace('.jstree','') === 'changed') {
803f4888f36a planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff changeset
31 data.changed = { selected : [], deselected : [] };
803f4888f36a planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff changeset
32 var tmp = {};
803f4888f36a planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff changeset
33 for(i = 0, j = last.length; i < j; i++) {
803f4888f36a planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff changeset
34 tmp[last[i]] = 1;
803f4888f36a planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff changeset
35 }
803f4888f36a planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff changeset
36 for(i = 0, j = data.selected.length; i < j; i++) {
803f4888f36a planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff changeset
37 if(!tmp[data.selected[i]]) {
803f4888f36a planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff changeset
38 data.changed.selected.push(data.selected[i]);
803f4888f36a planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff changeset
39 }
803f4888f36a planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff changeset
40 else {
803f4888f36a planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff changeset
41 tmp[data.selected[i]] = 2;
803f4888f36a planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff changeset
42 }
803f4888f36a planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff changeset
43 }
803f4888f36a planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff changeset
44 for(i = 0, j = last.length; i < j; i++) {
803f4888f36a planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff changeset
45 if(tmp[last[i]] === 1) {
803f4888f36a planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff changeset
46 data.changed.deselected.push(last[i]);
803f4888f36a planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff changeset
47 }
803f4888f36a planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff changeset
48 }
803f4888f36a planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff changeset
49 last = data.selected.slice();
803f4888f36a planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff changeset
50 }
803f4888f36a planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff changeset
51 /**
803f4888f36a planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff changeset
52 * triggered when selection changes (the "changed" plugin enhances the original event with more data)
803f4888f36a planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff changeset
53 * @event
803f4888f36a planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff changeset
54 * @name changed.jstree
803f4888f36a planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff changeset
55 * @param {Object} node
803f4888f36a planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff changeset
56 * @param {Object} action the action that caused the selection to change
803f4888f36a planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff changeset
57 * @param {Array} selected the current selection
803f4888f36a planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
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
803f4888f36a planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff changeset
59 * @param {Object} event the event (if any) that triggered this changed event
803f4888f36a planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff changeset
60 * @plugin changed
803f4888f36a planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff changeset
61 */
803f4888f36a planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff changeset
62 parent.trigger.call(this, ev, data);
803f4888f36a planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff changeset
63 };
803f4888f36a planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff changeset
64 this.refresh = function (skip_loading, forget_state) {
803f4888f36a planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff changeset
65 last = [];
803f4888f36a planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff changeset
66 return parent.refresh.apply(this, arguments);
803f4888f36a planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff changeset
67 };
803f4888f36a planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff changeset
68 };
803f4888f36a planemo upload commit 004a320fc0619c234164b44c64ba5dce205734e1
mingchen0919
parents:
diff changeset
69 }));