mirror of
https://github.com/haiwen/seahub.git
synced 2025-06-24 14:12:03 +00:00
3 lines
56 KiB
JavaScript
3 lines
56 KiB
JavaScript
|
/* jsTree 1.0-rc3 */
|
||
|
"use strict";(function(){if(jQuery&&jQuery.jstree){return;}var is_ie6=false,is_ie7=false,is_ff2=false;(function($){$.vakata={};$.vakata.css={get_css:function(rule_name,delete_flag,sheet){rule_name=rule_name.toLowerCase();var css_rules=sheet.cssRules||sheet.rules,j=0;do{if(css_rules.length&&j>css_rules.length+5){return false;}if(css_rules[j].selectorText&&css_rules[j].selectorText.toLowerCase()==rule_name){if(delete_flag===true){if(sheet.removeRule){sheet.removeRule(j);}if(sheet.deleteRule){sheet.deleteRule(j);}return true;}else{return css_rules[j];}}}while(css_rules[++j]);return false;},add_css:function(rule_name,sheet){if($.jstree.css.get_css(rule_name,false,sheet)){return false;}if(sheet.insertRule){sheet.insertRule(rule_name+" { }",0);}else{sheet.addRule(rule_name,null,0);}return $.vakata.css.get_css(rule_name);},remove_css:function(rule_name,sheet){return $.vakata.css.get_css(rule_name,true,sheet);},add_sheet:function(opts){var tmp=false,is_new=true;if(opts.str){if(opts.title){tmp=$("style[id='"+opts.title+"-stylesheet']")[0];}if(tmp){is_new=false;}else{tmp=document.createElement("style");tmp.setAttribute("type","text/css");if(opts.title){tmp.setAttribute("id",opts.title+"-stylesheet");}}if(tmp.styleSheet){if(is_new){document.getElementsByTagName("head")[0].appendChild(tmp);tmp.styleSheet.cssText=opts.str;}else{tmp.styleSheet.cssText=tmp.styleSheet.cssText+" "+opts.str;}}else{tmp.appendChild(document.createTextNode(opts.str));document.getElementsByTagName("head")[0].appendChild(tmp);}return tmp.sheet||tmp.styleSheet;}if(opts.url){if(document.createStyleSheet){try{tmp=document.createStyleSheet(opts.url);}catch(e){}}else{tmp=document.createElement("link");tmp.rel="stylesheet";tmp.type="text/css";tmp.media="all";tmp.href=opts.url;document.getElementsByTagName("head")[0].appendChild(tmp);return tmp.styleSheet;}}}};var instances=[],focused_instance=-1,plugins={},prepared_move={};$.fn.jstree=function(settings){var isMethodCall=(typeof settings=="string"),args=Array.prototype.slice.call(arguments,1),returnValue=this;if(isMethodCall){if(settings.substring(0,1)=="_"){return returnValue;}this.each(function(){var instance=instances[$.data(this,"jstree-instance-id")],methodValue=(instance&&$.isFunction(instance[settings]))?instance[settings].apply(instance,args):instance;if(typeof methodValue!=="undefined"&&(settings.indexOf("is_")===0||(methodValue!==true&&methodValue!==false))){returnValue=methodValue;return false;}});}else{this.each(function(){var instance_id=$.data(this,"jstree-instance-id"),a=[],b=settings?$.extend({},true,settings):{},c=$(this),s=false,t=[];a=a.concat(args);if(c.data("jstree")){a.push(c.data("jstree"));}b=a.length?$.extend.apply(null,[true,b].concat(a)):b;if(typeof instance_id!=="undefined"&&instances[instance_id]){instances[instance_id].destroy();}instance_id=parseInt(instances.push({}),10)-1;$.data(this,"jstree-instance-id",instance_id);b.plugins=$.isArray(b.plugins)?b.plugins:$.jstree.defaults.plugins.slice();b.plugins.unshift("core");b.plugins=b.plugins.sort().join(",,").replace(/(,|^)([^,]+)(,,\2)+(,|$)/g,"$1$2$4").replace(/,,+/g,",").replace(/,$/,"").split(",");s=$.extend(true,{},$.jstree.defaults,b);s.plugins=b.plugins;$.each(plugins,function(i,val){if($.inArray(i,s.plugins)===-1){s[i]=null;delete s[i];}else{t.push(i);}});s.plugins=t;instances[instance_id]=new $.jstree._instance(instance_id,$(this).addClass("jstree jstree-"+instance_id),s);$.each(instances[instance_id]._get_settings().plugins,function(i,val){instances[instance_id].data[val]={};});$.each(instances[instance_id]._get_settings().plugins,function(i,val){if(plugins[val]){plugins[val].__init.apply(instances[instance_id]);}});setTimeout(function(){instances[instance_id].init();},0);});}return returnValue;};$.jstree={defaults:{plugins:[]},_focused:function(){return instances[focused_instance]||null;},_reference:function(needle){if(instances[needle]){return instances[needle];}var o=$(needle);if(!o.length&&typeof needle==="string"){o=$("#"+needle);}if(!o.length){return null;}return instances[o.closest(".jstree").data("jstree-instance-id")]||n
|