updated dhtmlxtree to version 2.6

This commit is contained in:
Ralf Becker
2010-10-15 10:04:07 +00:00
parent 77bede9db4
commit 197fdee2a4
1114 changed files with 79484 additions and 0 deletions

View File

@ -0,0 +1,75 @@
//v.2.6 build 100722
/*
Copyright DHTMLX LTD. http://www.dhtmlx.com
You allowed to use this component or parts of it under GPL terms
To use it on other terms or get Professional edition of the component please contact us at sales@dhtmlx.com
*/
/**
* @desc: adds drag-n-drop capabilities (with possibility to drop into dhtmlxTree) to HTML object.
* @param: obj - HTML object, or HTML object ID
* @param: func - custom drag processor function, optional
* @type: public
* @topic: 0
*/
dhtmlXTreeObject.prototype.makeDraggable=function(obj,func){
if (typeof(obj)!="object")
obj=document.getElementById(obj);
dragger=new dhtmlDragAndDropObject();
dropper=new dhx_dragSomethingInTree();
dragger.addDraggableItem(obj,dropper);
obj.dragLanding=null;
obj.ondragstart=dropper._preventNsDrag;
obj.onselectstart=new Function("return false;");
obj.parentObject=new Object;
obj.parentObject.img=obj;
obj.parentObject.treeNod=dropper;
dropper._customDrop=func;
}
dhtmlXTreeObject.prototype.makeDragable=dhtmlXTreeObject.prototype.makeDraggable;
/**
* @desc: adds drag-n-drop capabilities (with possibility to drop into dhtmlxTree) to all HTML items with dragInDhtmlXTree attribute
* @param: func - custom drag processor function, optional
* @type: public
* @topic: 0
*/
dhtmlXTreeObject.prototype.makeAllDraggable=function(func){
var z=document.getElementsByTagName("div");
for (var i=0; i<z.length; i++)
if (z[i].getAttribute("dragInDhtmlXTree"))
this.makeDragable(z[i],func);
}
function dhx_dragSomethingInTree(){
this.lWin=window;
//this function creates a HTML object which will be used while drag-n-drop
this._createDragNode=function(node){
var dragSpan=document.createElement('div');
dragSpan.style.position="absolute";
dragSpan.innerHTML=node.innerHTML;
dragSpan.className="dragSpanDiv";
return dragSpan;
};
//this function necessary for correct browser support
//doesn't change anything in it
this._preventNsDrag=function(e){
(e||window.event).cancelBubble=true;
if ((e)&&(e.preventDefault)) { e.preventDefault(); return false; }
return false;
}
//this function contains a reaction on drop operation
//the tree don't know what to do with custom item
//so you must define this reaction
this._nonTrivialNode=function(tree,item,bitem,source){
if (this._customDrop) return this._customDrop(tree,source.img.id,item.id,bitem?bitem.id:null);
var image=(source.img.getAttribute("image")||"");
var id=source.img.id||"new";
var text=(source.img.getAttribute("text")||(_isIE?source.img.innerText:source.img.textContent));
tree[bitem?"insertNewNext":"insertNewItem"](bitem?bitem.id:item.id,id,text,"",image,image,image);
}
}
//(c)dhtmlx ltd. www.dhtmlx.com

View File

@ -0,0 +1,196 @@
//v.2.6 build 100722
/*
Copyright DHTMLX LTD. http://www.dhtmlx.com
You allowed to use this component or parts of it under GPL terms
To use it on other terms or get Professional edition of the component please contact us at sales@dhtmlx.com
*/
/*
Purpose: item edit extension
*/
/**
* @desc: enable editing of item text
* @param: mode - true/false
* @type: public
* @topic: 0
*/
dhtmlXTreeObject.prototype.enableItemEditor=function(mode){
this._eItEd=convertStringToBoolean(mode);
if (!this._eItEdFlag){
this._edn_click_IE=true;
this._edn_dblclick=true;
this._ie_aFunc=this.aFunc;
this._ie_dblclickFuncHandler=this.dblclickFuncHandler;
this.setOnDblClickHandler(function (a,b) {
if (this._edn_dblclick) this._editItem(a,b);
return true;
});
this.setOnClickHandler(function (a,b) {
this._stopEditItem(a,b);
if ((this.ed_hist_clcik==a)&&(this._edn_click_IE))
this._editItem(a,b);
this.ed_hist_clcik=a;
return true;
});
this._eItEdFlag=true;
}
};
/**
* @desc: set onEdit handler ( multi handler event)
* @param: func - function which will be called on edit related events
* @type: depricated
* @event: onEdit
* @depricated: use grid.attachEvent("onEdit",func); instead
* @eventdesc: Event occurs on 4 different stages of edit process: before editing started (cancelable), after editing started, before closing (cancelable), after closed
* @eventparam: state - 0 before editing started , 1 after editing started, 2 before closing, 3 after closed
* @eventparam: id - id of edited items
* @eventparam: tree - tree object
* @eventparam: value - for stage 0 and 2, value of editor
* @eventreturn: for stages 0 and 2; true - confirm opening/closing, false - deny opening/closing; text - edit value
* @topic: 0
*/
dhtmlXTreeObject.prototype.setOnEditHandler=function(func){
this.attachEvent("onEdit",func);
};
/**
* @desc: define which events must start editing
* @param: click_IE - click on already selected item - true/false [true by default]
* @param: dblclick - on double click
* @type: public
* @topic: 0
*/
dhtmlXTreeObject.prototype.setEditStartAction=function(click_IE, dblclick){
this._edn_click_IE=convertStringToBoolean(click_IE);
this._edn_dblclick=convertStringToBoolean(dblclick);
};
dhtmlXTreeObject.prototype._stopEdit=function(a){
if (this._editCell){
this.dADTempOff=this.dADTempOffEd;
if (this._editCell.id!=a){
var editText=true;
editText=this.callEvent("onEdit",[2,this._editCell.id,this,this._editCell.span.childNodes[0].value]);
if (editText===true)
editText=this._editCell.span.childNodes[0].value;
else if (editText===false) editText=this._editCell._oldValue;
var changed = (editText!=this._editCell._oldValue);
this._editCell.span.innerHTML=editText;
this._editCell.label=this._editCell.span.innerHTML;
var cSS=this._editCell.i_sel?"selectedTreeRow":"standartTreeRow";
this._editCell.span.className=cSS;
this._editCell.span.parentNode.className="standartTreeRow";
this._editCell.span.style.paddingRight=this._editCell.span.style.paddingLeft='5px';
this._editCell.span.onclick=this._editCell.span.ondblclick=function(){};
var id=this._editCell.id;
if (this.childCalc) this._fixChildCountLabel(this._editCell);
this._editCell=null;
this.callEvent("onEdit",[3,id,this,changed]);
if (this._enblkbrd){
this.parentObject.lastChild.focus();
this.parentObject.lastChild.focus();
}
}
}
}
dhtmlXTreeObject.prototype._stopEditItem=function(id,tree){
this._stopEdit(id);
};
/**
* @desc: switch currently edited item back to normal view
* @type: public
* @topic: 0
*/
dhtmlXTreeObject.prototype.stopEdit=function(){
if (this._editCell)
this._stopEdit(this._editCell.id+"_non");
}
/**
* @desc: open editor for specified item
* @param: id - item ID
* @type: public
* @topic: 0
*/
dhtmlXTreeObject.prototype.editItem=function(id){
this._editItem(id,this);
}
dhtmlXTreeObject.prototype._editItem=function(id,tree){
if (this._eItEd){
this._stopEdit();
var temp=this._globalIdStorageFind(id);
if (!temp) return;
editText=this.callEvent("onEdit",[0,id,this,temp.span.innerHTML]);
if (editText===true)
editText=temp.label;
else if (editText===false) return;
this.dADTempOffEd=this.dADTempOff;
this.dADTempOff=false;
this._editCell=temp;
temp._oldValue=editText;
temp.span.innerHTML="<input type='text' class='intreeeditRow' />";
temp.span.style.paddingRight=temp.span.style.paddingLeft='0px';
temp.span.onclick = temp.span.ondblclick= function(e){
(e||event).cancelBubble = true;
}
temp.span.childNodes[0].value=editText;
temp.span.childNodes[0].onselectstart=function(e){
(e||event).cancelBubble=true;
return true;
}
temp.span.childNodes[0].onmousedown=function(e){
(e||event).cancelBubble=true;
return true;
}
temp.span.childNodes[0].focus();
temp.span.childNodes[0].focus();
// temp.span.childNodes[0].select();
temp.span.onclick=function (e){ (e||event).cancelBubble=true; return false; };
temp.span.className="";
temp.span.parentNode.className="";
var self=this;
temp.span.childNodes[0].onkeydown=function(e){
if (!e) e=window.event;
if (e.keyCode==13){
e.cancelBubble=true;
self._stopEdit(window.undefined);
}
else if (e.keyCode==27){
self._editCell.span.childNodes[0].value=self._editCell._oldValue;
self._stopEdit(window.undefined);
}
(e||event).cancelBubble=true;
}
this.callEvent("onEdit",[1,id,this]);
}
};
//(c)dhtmlx ltd. www.dhtmlx.com

View File

@ -0,0 +1,79 @@
//v.2.6 build 100722
/*
Copyright DHTMLX LTD. http://www.dhtmlx.com
You allowed to use this component or parts of it under GPL terms
To use it on other terms or get Professional edition of the component please contact us at sales@dhtmlx.com
*/
var _all_used_trees=new Array();
dhtmlXTreeObject.prototype._createSelfA2=dhtmlXTreeObject.prototype._createSelf;
dhtmlXTreeObject.prototype._createSelf=function(){
_all_used_trees[_all_used_trees.length]=this;
return this._createSelfA2();
}
window.onerror=function (a,b,c,d){
var d=document.createElement("DIV");
d.style.cssText="position:absolute; background-color:white; top:10px; left:10px; z-index:20; width:500px; border: 2px silver outset;";
var dh="<div style='width:100%; color:red; font-size:8pt; font-family:Arial; font-weight:bold; '>Javascript Error</div>";
dh+="<div style='width:100%; font-size:8pt; font-family:Arial; '>The next error ocured :<br/> <strong>"+a+"</strong> in <strong>"+b+"</strong> at line <strong>"+c+"</strong></div>";
dh+="<div style='width:100%; font-size:8pt; font-family:Arial; '>If you think that error can be caused by dhtmlxtree press the 'Generate report' button and send generated report to <a href='email:support@dhtmlx.com'>support@dhtmlx.com</a> </div>";
dh+="<input style='font-size:8pt; font-family:Arial; ' onclick='dhtmlxtreeReport(this)' type='button' value='Generate report'/><input style='font-size:8pt; font-family:Arial; ' type='button' value='Close' onclick='this.parentNode.parentNode.removeChild(this.parentNode);'/>";
dh+="<div/>";
d.innerHTML=dh;
document.body.appendChild(d);
return true;
};
function dhtmlxtreeErrorReport(a,b,c){
var str=a+" ["+b+"]";
if (a=='LoadXML')
{
str+="<br/>"+c[0].responseText+"</br>"+c[0].status;
}
window.onerror(str, "none", "none");
}
function dhtmlxtreeReport(node){
var that=node.parentNode;
that.lastChild.innerHTML="<textarea style='width:100%; height:300px;'></textarea>";
var rep=that.childNodes[1].innerHTML;
for (var a=0; a<_all_used_trees.length; a++){
var atree=_all_used_trees[a];
rep+="\n\n Tree "+a+"\n";
for (b in atree){
if (typeof(atree[b])=="function") continue;
rep+=b+"="+atree[b]+"\n";
}
rep+="---------------------\n";
if (atree.XMLLoader){
try{
var z=atree.XMLLoader.getXMLTopNode("tree")
if (document.all)
rep+=z.xml+"\n";
else{
var xmlSerializer = new XMLSerializer();
rep+=xmlSerializer.serializeToString(z)+"\n";
}
}
catch(e){
rep+="XML not recognised\n";
}
}
rep+="---------------------\n";
for (var i in atree._idpull){
var n=atree._idpull[i];
if (typeof(n)!='object') continue;
rep+="Node: "+n.id;
rep+=" Childs: "+n.childsCount;
for (var j=0; j<n.childsCount; j++)
rep+=" ch"+j+":"+n.childNodes[j].id;
rep+="\n";
}
}
that.lastChild.childNodes[0].value=rep;
}
dhtmlxError.catchError("ALL",dhtmlxtreeErrorReport);
//(c)dhtmlx ltd. www.dhtmlx.com

View File

@ -0,0 +1,226 @@
//v.2.6 build 100722
/*
Copyright DHTMLX LTD. http://www.dhtmlx.com
You allowed to use this component or parts of it under GPL terms
To use it on other terms or get Professional edition of the component please contact us at sales@dhtmlx.com
*/
function jsonPointer(data,parent){
this.d=data;
this.dp=parent;
}
jsonPointer.prototype={
text:function(){ var afff=function(n){ var p=[]; for(var i=0; i<n.length; i++) p.push("{"+sfff(n[i])+"}"); return p.join(","); }; var sfff=function(n){ var p=[]; for (var a in n) if (typeof(n[a])=="object"){ if (a.length) p.push('"'+a+'":['+afff(n[a])+"]"); else p.push('"'+a+'":{'+sfff(n[a])+"}"); }else p.push('"'+a+'":"'+n[a]+'"'); return p.join(","); }; return "{"+sfff(this.d)+"}"; },
get:function(name){return this.d[name]; },
exists:function(){return !!this.d },
content:function(){return this.d.content; },
each:function(name,f,t){ var a=this.d[name]; var c=new jsonPointer(); if (a) for (var i=0; i<a.length; i++) { c.d=a[i]; f.apply(t,[c,i]); } },
get_all:function(){ return this.d; },
sub:function(name){ return new jsonPointer(this.d[name],this.d) },
sub_exists:function(name){ return !!this.d[name]; },
each_x:function(name,rule,f,t,i){ var a=this.d[name]; var c=new jsonPointer(0,this.d); if (a) for (i=i||0; i<a.length; i++) if (a[i][rule]) { c.d=a[i]; if(f.apply(t,[c,i])==-1) return; } },
up:function(name){ return new jsonPointer(this.dp,this.d); },
set:function(name,val){ this.d[name]=val; },
clone:function(name){ return new jsonPointer(this.d,this.dp); },
through:function(name,rule,v,f,t){ var a=this.d[name]; if (a.length) for (var i=0; i<a.length; i++) { if (a[i][rule]!=null && a[i][rule]!="" && (!v || a[i][rule]==v )) {
var c=new jsonPointer(a[i],this.d); f.apply(t,[c,i]); } var w=this.d; this.d=a[i];
if (this.sub_exists(name)) this.through(name,rule,v,f,t); this.d=w; } }
}
/**
* @desc: load tree from js array file|stream
* @type: public
* @param: file - link to JSArray file
* @param: afterCall - function which will be called after xml loading
* @topic: 0
*/
dhtmlXTreeObject.prototype.loadJSArrayFile=function(file,afterCall){
if (!this.parsCount) this.callEvent("onXLS",[this,this._ld_id]); this._ld_id=null; this.xmlstate=1;
var that=this;
this.XMLLoader=new dtmlXMLLoaderObject(function(){
eval("var z="+arguments[4].xmlDoc.responseText);
that.loadJSArray(z);
},this,true,this.no_cashe);
if (afterCall) this.XMLLoader.waitCall=afterCall;
this.XMLLoader.loadXML(file);
};
/**
* @desc: load tree from csv file|stream
* @type: public
* @param: file - link to CSV file
* @param: afterCall - function which will be called after xml loading
* @topic: 0
*/
dhtmlXTreeObject.prototype.loadCSV=function(file,afterCall){
if (!this.parsCount) this.callEvent("onXLS",[this,this._ld_id]); this._ld_id=null; this.xmlstate=1;
var that=this;
this.XMLLoader=new dtmlXMLLoaderObject(function(){
that.loadCSVString(arguments[4].xmlDoc.responseText);
},this,true,this.no_cashe);
if (afterCall) this.XMLLoader.waitCall=afterCall;
this.XMLLoader.loadXML(file);
};
/**
* @desc: load tree from js array object
* @type: public
* @param: ar - js array
* @param: afterCall - function which will be called after xml loading
* @topic: 0
*/
dhtmlXTreeObject.prototype.loadJSArray=function(ar,afterCall){
//array id,parentid,text
var z=[];
for (var i=0; i<ar.length; i++){
if (!z[ar[i][1]]) z[ar[i][1]]=[];
z[ar[i][1]].push({id:ar[i][0],text:ar[i][2]});
}
var top={id: this.rootId};
var f=function(top,f){
if (z[top.id]){
top.item=z[top.id];
for (var j=0; j<top.item.length; j++)
f(top.item[j],f);
}
}
f(top,f);
this.loadJSONObject(top,afterCall);
}
/**
* @desc: load tree from csv string
* @type: public
* @param: csv - csv string
* @param: afterCall - function which will be called after xml loading
* @topic: 0
*/
dhtmlXTreeObject.prototype.loadCSVString=function(csv,afterCall){
//array id,parentid,text
var z=[];
var ar=csv.split("\n");
for (var i=0; i<ar.length; i++){
var t=ar[i].split(",");
if (!z[t[1]]) z[t[1]]=[];
z[t[1]].push({id:t[0],text:t[2]});
}
var top={id: this.rootId};
var f=function(top,f){
if (z[top.id]){
top.item=z[top.id];
for (var j=0; j<top.item.length; j++)
f(top.item[j],f);
}
}
f(top,f);
this.loadJSONObject(top,afterCall);
}
/**
* @desc: load tree from json object
* @type: public
* @param: json - json object
* @param: afterCall - function which will be called after xml loading
* @topic: 0
*/
dhtmlXTreeObject.prototype.loadJSONObject=function(json,afterCall){
if (!this.parsCount) this.callEvent("onXLS",[this,null]);this.xmlstate=1;
var p=new jsonPointer(json);
this._parse(p);
this._p=p;
if (afterCall) afterCall();
};
/**
* @desc: load tree from json file
* @type: public
* @param: file - link to JSON file
* @param: afterCall - function which will be called after xml loading
* @topic: 0
*/
dhtmlXTreeObject.prototype.loadJSON=function(file,afterCall){
if (!this.parsCount) this.callEvent("onXLS",[this,this._ld_id]); this._ld_id=null; this.xmlstate=1;
var that=this;
this.XMLLoader=new dtmlXMLLoaderObject(function(){
try {
eval("var t="+arguments[4].xmlDoc.responseText);
} catch(e){
dhtmlxError.throwError("LoadXML", "Incorrect JSON", [
(arguments[4].xmlDoc),
this
]);
return;
}
var p=new jsonPointer(t);
that._parse(p);
that._p=p;
},this,true,this.no_cashe);
if (afterCall) this.XMLLoader.waitCall=afterCall;
this.XMLLoader.loadXML(file);
};
/**
* @desc: return tree as json string
* @type: public
* @topic: 0
*/
dhtmlXTreeObject.prototype.serializeTreeToJSON=function(){
var out=['{"id":"'+this.rootId+'", "item":['];
var p=[];
for (var i=0; i<this.htmlNode.childsCount; i++)
p.push(this._serializeItemJSON(this.htmlNode.childNodes[i]));
out.push(p.join(","));
out.push("]}");
return out.join("");
};
dhtmlXTreeObject.prototype._serializeItemJSON=function(itemNode){
var out=[];
if (itemNode.unParsed)
return (itemNode.unParsed.text());
if (this._selected.length)
var lid=this._selected[0].id;
else lid="";
var text=itemNode.span.innerHTML;
if (this._xescapeEntities)
for (var i=0; i<this._serEnts.length; i++)
text=text.replace(this._serEnts[i][2],this._serEnts[i][1]);
if (!this._xfullXML)
out.push('{ "id":"'+itemNode.id+'", '+(this._getOpenState(itemNode)==1?' "open":"1", ':'')+(lid==itemNode.id?' "select":"1",':'')+' "text":"'+text+'"'+( ((this.XMLsource)&&(itemNode.XMLload==0))?', "child":"1" ':''));
else
out.push('{ "id":"'+itemNode.id+'", '+(this._getOpenState(itemNode)==1?' "open":"1", ':'')+(lid==itemNode.id?' "select":"1",':'')+' "text":"'+text+'", "im0":"'+itemNode.images[0]+'", "im1":"'+itemNode.images[1]+'", "im2":"'+itemNode.images[2]+'" '+(itemNode.acolor?(', "aCol":"'+itemNode.acolor+'" '):'')+(itemNode.scolor?(', "sCol":"'+itemNode.scolor+'" '):'')+(itemNode.checkstate==1?', "checked":"1" ':(itemNode.checkstate==2?', "checked":"-1"':''))+(itemNode.closeable?', "closeable":"1" ':'')+( ((this.XMLsource)&&(itemNode.XMLload==0))?', "child":"1" ':''));
if ((this._xuserData)&&(itemNode._userdatalist))
{
out.push(', "userdata":[');
var names=itemNode._userdatalist.split(",");
var p=[];
for (var i=0; i<names.length; i++)
p.push('{ "name":"'+names[i]+'" , "content":"'+itemNode.userData["t_"+names[i]]+'" }');
out.push(p.join(",")); out.push("]");
}
if (itemNode.childsCount){
out.push(', "item":[');
var p=[];
for (var i=0; i<itemNode.childsCount; i++)
p.push(this._serializeItemJSON(itemNode.childNodes[i]));
out.push(p.join(","));
out.push("]\n");
}
out.push("}\n")
return out.join("");
}
//(c)dhtmlx ltd. www.dhtmlx.com

View File

@ -0,0 +1,104 @@
//v.2.6 build 100722
/*
Copyright DHTMLX LTD. http://www.dhtmlx.com
You allowed to use this component or parts of it under GPL terms
To use it on other terms or get Professional edition of the component please contact us at sales@dhtmlx.com
*/
function dhtmlXTreeFromHTML(obj){
if (typeof(obj)!="object")
obj=document.getElementById(obj);
var n=obj;
var id=n.id;
var cont="";
for (var j=0; j<obj.childNodes.length; j++)
if (obj.childNodes[j].nodeType=="1"){
if (obj.childNodes[j].tagName=="XMP"){
var cHead=obj.childNodes[j];
for (var m=0; m<cHead.childNodes.length; m++)
cont+=cHead.childNodes[m].data;
}
else if (obj.childNodes[j].tagName.toLowerCase()=="ul")
cont=dhx_li2trees(obj.childNodes[j],new Array(),0);
break;
}
obj.innerHTML="";
var t=new dhtmlXTreeObject(obj,"100%","100%",0);
var z_all=new Array();
for ( b in t )
z_all[b.toLowerCase()]=b;
var atr=obj.attributes;
for (var a=0; a<atr.length; a++)
if ((atr[a].name.indexOf("set")==0)||(atr[a].name.indexOf("enable")==0)){
var an=atr[a].name;
if (!t[an])
an=z_all[atr[a].name];
t[an].apply(t,atr[a].value.split(","));
}
if (typeof(cont)=="object"){
t.XMLloadingWarning=1;
for (var i=0; i<cont.length; i++){
var n=t.insertNewItem(cont[i][0],cont[i][3],cont[i][1]);
if (cont[i][2]) t._setCheck(n,cont[i][2]);
}
t.XMLloadingWarning=0;
t.lastLoadedXMLId=0;
t._redrawFrom(t);
}
else
t.loadXMLString("<tree id='0'>"+cont+"</tree>");
window[id]=t;
var oninit = obj.getAttribute("oninit");
if (oninit) eval(oninit);
return t;
}
function dhx_init_trees(){
var z=document.getElementsByTagName("div");
for (var i=0; i<z.length; i++)
if (z[i].className=="dhtmlxTree")
dhtmlXTreeFromHTML(z[i])
}
function dhx_li2trees(tag,data,ind){
for (var i=0; i<tag.childNodes.length; i++){
var z=tag.childNodes[i];
if ((z.nodeType==1)&&(z.tagName.toLowerCase()=="li")){
var c=""; var ul=null;
var check=z.getAttribute("checked");
for (var j=0; j<z.childNodes.length; j++){
var zc=z.childNodes[j];
if (zc.nodeType==3) c+=zc.data;
else if (zc.tagName.toLowerCase()!="ul") c+=dhx_outer_html(zc);
else ul=zc;
}
data[data.length]=[ind,c,check,(z.id||(data.length+1))];
if (ul)
data=dhx_li2trees(ul,data,(z.id||data.length));
}
}
return data;
}
function dhx_outer_html(node){
if (node.outerHTML) return node.outerHTML;
var temp=document.createElement("DIV");
temp.appendChild(node.cloneNode(true));
temp=temp.innerHTML;
return temp;
}
if (window.addEventListener) window.addEventListener("load",dhx_init_trees,false);
else if (window.attachEvent) window.attachEvent("onload",dhx_init_trees);
//(c)dhtmlx ltd. www.dhtmlx.com