comparison vakata-jstree-3.3.5/src/jstree.changed.js @ 0:a42e58c71e5b draft default tip

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