Blame | Letzte Änderung | Log anzeigen | RSS feed
/*global jQuery */// wrap in IIFE and pass jQuery as $(function ($, undefined) {"use strict";// some private plugin stuff if neededvar private_var = null;// extending the defaults$.jstree.defaults.sample = {sample_option : 'sample_val'};// the actual plugin code$.jstree.plugins.sample = function (options, parent) {// own functionthis.sample_function = function (arg) {// you can chain this method if needed and availableif(parent.sample_function) { parent.sample_function.call(this, arg); }};// *SPECIAL* FUNCTIONSthis.init = function (el, options) {// do not forget parentparent.init.call(this, el, options);};// bind events if neededthis.bind = function () {// call parent function firstparent.bind.call(this);// do(stuff);};// unbind events if needed (all in jquery namespace are taken care of by the core)this.unbind = function () {// do(stuff);// call parent function lastparent.unbind.call(this);};this.teardown = function () {// do not forget parentparent.teardown.call(this);};// state management - get and restorethis.get_state = function () {// always get state from parent firstvar state = parent.get_state.call(this);// add own stuff to statestate.sample = { 'var' : 'val' };return state;};this.set_state = function (state, callback) {// only process your part if parent returns true// there will be multiple times with falseif(parent.set_state.call(this, state, callback)) {// check the key you set aboveif(state.sample) {// do(stuff); // like calling this.sample_function(state.sample.var);// remove your part of the state, call again and RETURN FALSE, the next cycle will be TRUEdelete state.sample;this.set_state(state, callback);return false;}// return true if your state is gone (cleared in the previous step)return true;}// parent was false - return false tooreturn false;};// node transportationthis.get_json = function (obj, options, flat) {// get the node from the parentvar tmp = parent.get_json.call(this, obj, options, flat), i, j;if($.isArray(tmp)) {for(i = 0, j = tmp.length; i < j; i++) {tmp[i].sample = 'value';}}else {tmp.sample = 'value';}// return the original / modified nodereturn tmp;};};// attach to document ready if needed$(function () {// do(stuff);});// you can include the sample plugin in all instances by default$.jstree.defaults.plugins.push("sample");})(jQuery);