-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathjstree-actions.min.js
1 lines (1 loc) · 2.13 KB
/
jstree-actions.min.js
1
!function(t){"use strict";"function"==typeof define&&define.amd?define(["jquery"],t):"undefined"!=typeof module&&module.exports?module.exports=t(require("jquery")):t(jQuery)}(function(t){"use strict";t.jstree.defaults.actions=t.noop,t.jstree.plugins.actions=function(t,e){this._actions={},this.add_action=function(t,e){for(var n=this,i="object"==typeof t?t:[t],o=i.indexOf("all")>-1,a=0;a<i.length;a++){var r=i[a],c=n._actions[r]=n._actions[r]||[];n._has_action(r,e.id)||(c.push(e),o||this.redraw_node(r))}o&&this.redraw(!0)},this.remove_action=function(t,e){for(var n=this,i="object"==typeof t?t:"all"===t?Object.keys(this._actions):[t],o=i.indexOf("all")>-1,a=0;a<i.length;a++){t=i[a];for(var r=n._actions[t]||[],c=[],s=0;s<r.length;s++){var l=r[s];l.id!==e&&"all"!==e&&c.push(l)}var f=r.map(function(t){return t.id}),u=c.map(function(t){return t.id});(f.length!=u.length||f.filter(function(t){return-1===u.indexOf(t)}).length)&&(n._actions[t]=c,o||this.redraw_node(t))}o&&this.redraw(!0)},this._create_action=function(t,e){var n=this,i=this._get_action(t,e);if(null===i)return null;var o=document.createElement("i");return o.className=i["class"],o.textContent=i.text,i.title&&i.title.length>0&&(o.title=i.title),o.onclick=function(){var a=n.get_node(o);i.callback(t,a,e,o)},{action:i,action_el:o}},this._get_action=function(t,e){for(var n=this._actions[t]||[],i=null,o=0;o<n.length;o++){var a=n[o];a.id===e&&(i=a)}return i},this._set_action=function(t,e,n){if(null!==n){var i=e.querySelector(n.action.selector);n.action.after?i.parentNode.insertBefore(n.action_el,i.nextSibling):e.insertBefore(n.action_el,i)}},this._has_action=function(t,e){var n=!1,i=this._actions;if(i.hasOwnProperty(t))for(var o=0;o<i[t].length;o++)i[t][o].id===e&&(n=!0);if(this._actions.hasOwnProperty("all"))for(o=0;o<i.all.length;o++)i.all[o].id===e&&(n=!0);return n},this.redraw_node=function(t,n,i,o){var a=this,r="object"==typeof t?t.id:t,c=e.redraw_node.call(this,t,n,i,o);if(c){for(var s=this._actions[r]||[],l=0;l<s.length;l++){var f=a._create_action(r,s[l].id);a._set_action(r,c,f)}for(s=this._actions.all||[],l=0;l<s.length;l++)f=a._create_action("all",s[l].id),a._set_action(r,c,f)}return c}}});