initial commit
43
WebRoot/dtree/css/dtree.css
Normal file
@@ -0,0 +1,43 @@
|
||||
/*--------------------------------------------------|
|
||||
| dTree 2.05 | www.destroydrop.com/javascript/tree/ |
|
||||
|---------------------------------------------------|
|
||||
| Copyright (c) 2002-2003 Geir Landr<64> |
|
||||
|--------------------------------------------------*/
|
||||
|
||||
.dtree {
|
||||
font-family:"微软雅黑", Arial, "宋体";
|
||||
font-size: 11px;
|
||||
color: #666;
|
||||
white-space: nowrap;
|
||||
BGCOLOR:TRANSPARENT;
|
||||
}
|
||||
.dtree img {
|
||||
border: 0px;
|
||||
vertical-align: middle;
|
||||
}
|
||||
.dtree a {
|
||||
color: #333;
|
||||
text-decoration: none;
|
||||
}
|
||||
.dtree a.node, .dtree a.nodeSel {
|
||||
white-space: nowrap;
|
||||
padding: 1px 2px 1px 2px;
|
||||
}
|
||||
.dtree a.node:hover, .dtree a.nodeSel:hover {
|
||||
color: #333;
|
||||
text-decoration: underline;
|
||||
}
|
||||
.dtree a.nodeSel {
|
||||
background-color: #c0d2ec;
|
||||
}
|
||||
.dtree .clip {
|
||||
overflow: hidden;
|
||||
}
|
||||
#main {
|
||||
background-color: #ECE9D8;
|
||||
background-repeat: no-repeat;
|
||||
padding: 0px;
|
||||
float: left;
|
||||
height: 1000px;
|
||||
width: 180px;
|
||||
}
|
||||
47
WebRoot/dtree/example01.html
Normal file
@@ -0,0 +1,47 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<title>Destroydrop » Javascripts » Tree</title>
|
||||
|
||||
<link rel="StyleSheet" href="css/dtree.css" type="text/css" />
|
||||
<script type="text/javascript" src="js/dtree.js"></script>
|
||||
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="dtree">
|
||||
|
||||
<p><a href="javascript: d.openAll();">open all</a> | <a href="javascript: d.closeAll();">close all</a></p>
|
||||
|
||||
<script type="text/javascript">
|
||||
<!--
|
||||
|
||||
d = new dTree('d');
|
||||
|
||||
d.add(0,-1,'<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>');
|
||||
d.add(1,0,'ϵͳ<CFB5><CDB3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>');
|
||||
d.add(2,1,'<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD>','infoconfig.html');
|
||||
d.add(2,0,'Node 2','example01.html');
|
||||
d.add(3,1,'Node 1.1');
|
||||
d.add(4,0,'Node 3','example01.html');
|
||||
d.add(5,3,'Node 1.1.1');
|
||||
d.add(6,5,'Node 1.1.1.1','example01.html');
|
||||
d.add(7,0,'Node 4','example01.html');
|
||||
d.add(8,1,'Node 1.2','example01.html');
|
||||
d.add(9,0,'My Pictures','','Pictures I\'ve taken over the years','','','img/imgfolder.gif');
|
||||
d.add(10,9,'The trip to Iceland','example01.html','Pictures of Gullfoss and Geysir');
|
||||
d.add(11,9,'Mom\'s birthday','example01.html');
|
||||
d.add(12,0,'Recycle Bin','example01.html','','','img/trash.gif');
|
||||
|
||||
document.write(d);
|
||||
|
||||
//-->
|
||||
</script>
|
||||
|
||||
</div>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
BIN
WebRoot/dtree/img/base.gif
Normal file
|
After Width: | Height: | Size: 1.0 KiB |
BIN
WebRoot/dtree/img/cd.gif
Normal file
|
After Width: | Height: | Size: 239 B |
BIN
WebRoot/dtree/img/empty.gif
Normal file
|
After Width: | Height: | Size: 62 B |
BIN
WebRoot/dtree/img/folder.gif
Normal file
|
After Width: | Height: | Size: 372 B |
BIN
WebRoot/dtree/img/folderopen.gif
Normal file
|
After Width: | Height: | Size: 376 B |
BIN
WebRoot/dtree/img/globe.gif
Normal file
|
After Width: | Height: | Size: 1.1 KiB |
BIN
WebRoot/dtree/img/imgfolder.gif
Normal file
|
After Width: | Height: | Size: 622 B |
BIN
WebRoot/dtree/img/join.gif
Normal file
|
After Width: | Height: | Size: 69 B |
BIN
WebRoot/dtree/img/joinbottom.gif
Normal file
|
After Width: | Height: | Size: 66 B |
BIN
WebRoot/dtree/img/line.gif
Normal file
|
After Width: | Height: | Size: 66 B |
BIN
WebRoot/dtree/img/minus.gif
Normal file
|
After Width: | Height: | Size: 86 B |
BIN
WebRoot/dtree/img/minusbottom.gif
Normal file
|
After Width: | Height: | Size: 85 B |
BIN
WebRoot/dtree/img/musicfolder.gif
Normal file
|
After Width: | Height: | Size: 633 B |
BIN
WebRoot/dtree/img/nolines_minus.gif
Normal file
|
After Width: | Height: | Size: 861 B |
BIN
WebRoot/dtree/img/nolines_plus.gif
Normal file
|
After Width: | Height: | Size: 870 B |
BIN
WebRoot/dtree/img/page.gif
Normal file
|
After Width: | Height: | Size: 582 B |
BIN
WebRoot/dtree/img/plus.gif
Normal file
|
After Width: | Height: | Size: 89 B |
BIN
WebRoot/dtree/img/plusbottom.gif
Normal file
|
After Width: | Height: | Size: 88 B |
BIN
WebRoot/dtree/img/question.gif
Normal file
|
After Width: | Height: | Size: 1.0 KiB |
BIN
WebRoot/dtree/img/trash.gif
Normal file
|
After Width: | Height: | Size: 1.0 KiB |
848
WebRoot/dtree/js/drag-drop-folder-tree.js
Normal file
@@ -0,0 +1,848 @@
|
||||
/************************************************************************************************************
|
||||
Drag and drop folder tree
|
||||
Copyright (C) 2006 DTHMLGoodies.com, Alf Magne Kalleland
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Dhtmlgoodies.com., hereby disclaims all copyright interest in this script
|
||||
written by Alf Magne Kalleland.
|
||||
|
||||
Alf Magne Kalleland, 2006
|
||||
Owner of DHTMLgoodies.com
|
||||
|
||||
|
||||
************************************************************************************************************/
|
||||
|
||||
var JSTreeObj;
|
||||
var treeUlCounter = 0;
|
||||
var nodeId = 1;
|
||||
|
||||
/* Constructor */
|
||||
function JSDragDropTree()
|
||||
{
|
||||
var idOfTree;
|
||||
var imageFolder;
|
||||
var folderImage;
|
||||
var folder;
|
||||
var plusImage;
|
||||
var minusImage;
|
||||
var maximumDepth;
|
||||
var dragNode_source;
|
||||
var dragNode_parent;
|
||||
var dragNode_sourceNextSib;
|
||||
var dragNode_noSiblings;
|
||||
var ajaxObjects;
|
||||
|
||||
var dragNode_destination;
|
||||
var floatingContainer;
|
||||
var dragDropTimer;
|
||||
var dropTargetIndicator;
|
||||
var insertAsSub;
|
||||
var indicator_offsetX;
|
||||
var indicator_offsetX_sub;
|
||||
var indicator_offsetY;
|
||||
|
||||
this.imageFolder = 'images/';
|
||||
this.folderImage = 'dhtmlgoodies_folder.gif';
|
||||
this.plusImage = 'dhtmlgoodies_plus.gif';
|
||||
this.minusImage = 'dhtmlgoodies_minus.gif';
|
||||
this.folder = 'img/folder.gif';
|
||||
this.maximumDepth = 6;
|
||||
var messageMaximumDepthReached;
|
||||
var filePathRenameItem;
|
||||
var filePathDeleteItem;
|
||||
var additionalRenameRequestParameters = {};
|
||||
var additionalDeleteRequestParameters = {};
|
||||
|
||||
var renameAllowed;
|
||||
var deleteAllowed;
|
||||
var currentlyActiveItem;
|
||||
var contextMenu;
|
||||
var currentItemToEdit; // Reference to item currently being edited(example: renamed)
|
||||
var helpObj;
|
||||
|
||||
this.contextMenu = false;
|
||||
this.floatingContainer = document.createElement('UL');
|
||||
this.floatingContainer.style.position = 'absolute';
|
||||
this.floatingContainer.style.display='none';
|
||||
this.floatingContainer.id = 'floatingContainer';
|
||||
this.insertAsSub = false;
|
||||
document.body.appendChild(this.floatingContainer);
|
||||
this.dragDropTimer = -1;
|
||||
this.dragNode_noSiblings = false;
|
||||
this.currentItemToEdit = false;
|
||||
|
||||
if(document.all){
|
||||
this.indicator_offsetX = 2; // Offset position of small black lines indicating where nodes would be dropped.
|
||||
this.indicator_offsetX_sub = 4;
|
||||
this.indicator_offsetY = 2;
|
||||
}else{
|
||||
this.indicator_offsetX = 1; // Offset position of small black lines indicating where nodes would be dropped.
|
||||
this.indicator_offsetX_sub = 3;
|
||||
this.indicator_offsetY = 2;
|
||||
}
|
||||
if(navigator.userAgent.indexOf('Opera')>=0){
|
||||
this.indicator_offsetX = 2; // Offset position of small black lines indicating where nodes would be dropped.
|
||||
this.indicator_offsetX_sub = 3;
|
||||
this.indicator_offsetY = -7;
|
||||
}
|
||||
|
||||
this.messageMaximumDepthReached = ''; // Use '' if you don't want to display a message
|
||||
|
||||
this.renameAllowed = true;
|
||||
this.deleteAllowed = true;
|
||||
this.currentlyActiveItem = false;
|
||||
this.filePathRenameItem = 'folderTree_updateItem.php';
|
||||
this.filePathDeleteItem = 'folderTree_updateItem.php';
|
||||
this.ajaxObjects = new Array();
|
||||
this.helpObj = false;
|
||||
|
||||
this.RENAME_STATE_BEGIN = 1;
|
||||
this.RENAME_STATE_CANCELED = 2;
|
||||
this.RENAME_STATE_REQUEST_SENDED = 3;
|
||||
this.renameState = null;
|
||||
}
|
||||
|
||||
|
||||
/* JSDragDropTree class */
|
||||
JSDragDropTree.prototype = {
|
||||
// {{{ addEvent()
|
||||
/**
|
||||
*
|
||||
* This function adds an event listener to an element on the page.
|
||||
*
|
||||
* @param Object whichObject = Reference to HTML element(Which object to assigne the event)
|
||||
* @param String eventType = Which type of event, example "mousemove" or "mouseup"
|
||||
* @param functionName = Name of function to execute.
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
addEvent : function(whichObject,eventType,functionName)
|
||||
{
|
||||
if(whichObject.attachEvent){
|
||||
whichObject['e'+eventType+functionName] = functionName;
|
||||
whichObject[eventType+functionName] = function(){whichObject['e'+eventType+functionName]( window.event );}
|
||||
whichObject.attachEvent( 'on'+eventType, whichObject[eventType+functionName] );
|
||||
} else
|
||||
whichObject.addEventListener(eventType,functionName,false);
|
||||
}
|
||||
// }}}
|
||||
,
|
||||
// {{{ removeEvent()
|
||||
/**
|
||||
*
|
||||
* This function removes an event listener from an element on the page.
|
||||
*
|
||||
* @param Object whichObject = Reference to HTML element(Which object to assigne the event)
|
||||
* @param String eventType = Which type of event, example "mousemove" or "mouseup"
|
||||
* @param functionName = Name of function to execute.
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
removeEvent : function(whichObject,eventType,functionName)
|
||||
{
|
||||
if(whichObject.detachEvent){
|
||||
whichObject.detachEvent('on'+eventType, whichObject[eventType+functionName]);
|
||||
whichObject[eventType+functionName] = null;
|
||||
} else
|
||||
whichObject.removeEventListener(eventType,functionName,false);
|
||||
}
|
||||
,
|
||||
Get_Cookie : function(name) {
|
||||
var start = document.cookie.indexOf(name+"=");
|
||||
var len = start+name.length+1;
|
||||
if ((!start) && (name != document.cookie.substring(0,name.length))) return null;
|
||||
if (start == -1) return null;
|
||||
var end = document.cookie.indexOf(";",len);
|
||||
if (end == -1) end = document.cookie.length;
|
||||
return unescape(document.cookie.substring(len,end));
|
||||
}
|
||||
,
|
||||
// This function has been slightly modified
|
||||
Set_Cookie : function(name,value,expires,path,domain,secure) {
|
||||
expires = expires * 60*60*24*1000;
|
||||
var today = new Date();
|
||||
var expires_date = new Date( today.getTime() + (expires) );
|
||||
var cookieString = name + "=" +escape(value) +
|
||||
( (expires) ? ";expires=" + expires_date.toGMTString() : "") +
|
||||
( (path) ? ";path=" + path : "") +
|
||||
( (domain) ? ";domain=" + domain : "") +
|
||||
( (secure) ? ";secure" : "");
|
||||
document.cookie = cookieString;
|
||||
}
|
||||
,
|
||||
setFileNameRename : function(newFileName)
|
||||
{
|
||||
this.filePathRenameItem = newFileName;
|
||||
}
|
||||
,
|
||||
setFileNameDelete : function(newFileName)
|
||||
{
|
||||
this.filePathDeleteItem = newFileName;
|
||||
}
|
||||
,
|
||||
setAdditionalRenameRequestParameters : function(requestParameters)
|
||||
{
|
||||
this.additionalRenameRequestParameters = requestParameters;
|
||||
}
|
||||
,
|
||||
setAdditionalDeleteRequestParameters : function(requestParameters)
|
||||
{
|
||||
this.additionalDeleteRequestParameters = requestParameters;
|
||||
}
|
||||
,setRenameAllowed : function(renameAllowed)
|
||||
{
|
||||
this.renameAllowed = renameAllowed;
|
||||
}
|
||||
,
|
||||
setDeleteAllowed : function(deleteAllowed)
|
||||
{
|
||||
this.deleteAllowed = deleteAllowed;
|
||||
}
|
||||
,setMaximumDepth : function(maxDepth)
|
||||
{
|
||||
this.maximumDepth = maxDepth;
|
||||
}
|
||||
,setMessageMaximumDepthReached : function(newMessage)
|
||||
{
|
||||
this.messageMaximumDepthReached = newMessage;
|
||||
}
|
||||
,
|
||||
setImageFolder : function(path)
|
||||
{
|
||||
this.imageFolder = path;
|
||||
}
|
||||
,
|
||||
setFolderImage : function(imagePath)
|
||||
{
|
||||
this.folderImage = imagePath;
|
||||
}
|
||||
,
|
||||
setFolder : function()
|
||||
{
|
||||
this.folder = 'img/folder.gif';
|
||||
}
|
||||
,
|
||||
setPlusImage : function(imagePath)
|
||||
{
|
||||
this.plusImage = imagePath;
|
||||
}
|
||||
,
|
||||
setMinusImage : function(imagePath)
|
||||
{
|
||||
this.minusImage = imagePath;
|
||||
}
|
||||
,
|
||||
setTreeId : function(idOfTree)
|
||||
{
|
||||
this.idOfTree = idOfTree;
|
||||
}
|
||||
,
|
||||
expandAll : function()
|
||||
{
|
||||
var menuItems = document.getElementById(this.idOfTree).getElementsByTagName('LI');
|
||||
for(var no=0;no<menuItems.length;no++){
|
||||
var subItems = menuItems[no].getElementsByTagName('UL');
|
||||
if(subItems.length>0 && subItems[0].style.display!='block'){
|
||||
JSTreeObj.showHideNode(false,menuItems[no].id);
|
||||
}
|
||||
}
|
||||
}
|
||||
,
|
||||
collapseAll : function()
|
||||
{
|
||||
var menuItems = document.getElementById(this.idOfTree).getElementsByTagName('LI');
|
||||
for(var no=0;no<menuItems.length;no++){
|
||||
var subItems = menuItems[no].getElementsByTagName('UL');
|
||||
if(subItems.length>0 && subItems[0].style.display=='block'){
|
||||
JSTreeObj.showHideNode(false,menuItems[no].id);
|
||||
}
|
||||
}
|
||||
}
|
||||
,
|
||||
/*
|
||||
Find top pos of a tree node
|
||||
*/
|
||||
getTopPos : function(obj){
|
||||
var top = obj.offsetTop/1;
|
||||
while((obj = obj.offsetParent) != null){
|
||||
if(obj.tagName!='HTML')top += obj.offsetTop;
|
||||
}
|
||||
if(document.all)top = top/1 + 13; else top = top/1 + 4;
|
||||
return top;
|
||||
}
|
||||
,
|
||||
/*
|
||||
Find left pos of a tree node
|
||||
*/
|
||||
getLeftPos : function(obj){
|
||||
var left = obj.offsetLeft/1 + 1;
|
||||
while((obj = obj.offsetParent) != null){
|
||||
if(obj.tagName!='HTML')left += obj.offsetLeft;
|
||||
}
|
||||
|
||||
if(document.all)left = left/1 - 2;
|
||||
return left;
|
||||
}
|
||||
|
||||
,
|
||||
showHideNode : function(e,inputId)
|
||||
{
|
||||
if(inputId){
|
||||
if(!document.getElementById(inputId))return;
|
||||
thisNode = document.getElementById(inputId).getElementsByTagName('IMG')[0];
|
||||
}else {
|
||||
thisNode = this;
|
||||
if(this.tagName=='A')thisNode = this.parentNode.getElementsByTagName('IMG')[0];
|
||||
|
||||
}
|
||||
if(thisNode.style.visibility=='hidden')return;
|
||||
var parentNode = thisNode.parentNode;
|
||||
inputId = parentNode.id.replace(/[^0-9]/g,'');
|
||||
if(thisNode.src.indexOf(JSTreeObj.plusImage)>=0){
|
||||
thisNode.src = thisNode.src.replace(JSTreeObj.plusImage,JSTreeObj.minusImage);
|
||||
var ul = parentNode.getElementsByTagName('UL')[0];
|
||||
ul.style.display='block';
|
||||
if(!initExpandedNodes)initExpandedNodes = ',';
|
||||
if(initExpandedNodes.indexOf(',' + inputId + ',')<0) initExpandedNodes = initExpandedNodes + inputId + ',';
|
||||
}else{
|
||||
thisNode.src = thisNode.src.replace(JSTreeObj.minusImage,JSTreeObj.plusImage);
|
||||
parentNode.getElementsByTagName('UL')[0].style.display='none';
|
||||
initExpandedNodes = initExpandedNodes.replace(',' + inputId,'');
|
||||
}
|
||||
JSTreeObj.Set_Cookie('dhtmlgoodies_expandedNodes',initExpandedNodes,500);
|
||||
return false;
|
||||
}
|
||||
,
|
||||
/* Initialize drag */
|
||||
initDrag : function(e)
|
||||
{
|
||||
if(document.all)e = event;
|
||||
|
||||
var subs = JSTreeObj.floatingContainer.getElementsByTagName('LI');
|
||||
|
||||
if(subs.length>0){
|
||||
|
||||
if(JSTreeObj.dragNode_sourceNextSib){
|
||||
JSTreeObj.dragNode_parent.insertBefore(JSTreeObj.dragNode_source,JSTreeObj.dragNode_sourceNextSib);
|
||||
}else{
|
||||
JSTreeObj.dragNode_parent.appendChild(JSTreeObj.dragNode_source);
|
||||
}
|
||||
}
|
||||
JSTreeObj.dragNode_source = this.parentNode;
|
||||
JSTreeObj.dragNode_parent = this.parentNode.parentNode;
|
||||
JSTreeObj.dragNode_sourceNextSib = false;
|
||||
|
||||
|
||||
if(JSTreeObj.dragNode_source.nextSibling)JSTreeObj.dragNode_sourceNextSib = JSTreeObj.dragNode_source.nextSibling;
|
||||
JSTreeObj.dragNode_destination = false;
|
||||
JSTreeObj.dragDropTimer = 0;
|
||||
JSTreeObj.timerDrag();
|
||||
return false;
|
||||
}
|
||||
,
|
||||
timerDrag : function()
|
||||
{
|
||||
if(this.dragDropTimer>=0 && this.dragDropTimer<10){
|
||||
this.dragDropTimer = this.dragDropTimer + 1;
|
||||
setTimeout('JSTreeObj.timerDrag()',20);
|
||||
return;
|
||||
}
|
||||
if(this.dragDropTimer==10)
|
||||
{
|
||||
JSTreeObj.floatingContainer.style.display='block';
|
||||
JSTreeObj.floatingContainer.appendChild(JSTreeObj.dragNode_source);
|
||||
}
|
||||
}
|
||||
,
|
||||
moveDragableNodes : function(e)
|
||||
{
|
||||
|
||||
if(JSTreeObj.dragDropTimer<10)return;
|
||||
if(document.all)e = event;
|
||||
dragDrop_x = e.clientX/1 + 5 + document.body.scrollLeft;
|
||||
dragDrop_y = e.clientY/1 + 5 + document.documentElement.scrollTop;
|
||||
|
||||
JSTreeObj.floatingContainer.style.left = dragDrop_x + 'px';
|
||||
JSTreeObj.floatingContainer.style.top = dragDrop_y + 'px';
|
||||
|
||||
var thisObj = this;
|
||||
if(thisObj.tagName=='A' || thisObj.tagName=='IMG')thisObj = thisObj.parentNode;
|
||||
|
||||
JSTreeObj.dragNode_noSiblings = false;
|
||||
var tmpVar = thisObj.getAttribute('noSiblings');
|
||||
if(!tmpVar)tmpVar = thisObj.noSiblings;
|
||||
if(tmpVar=='true')JSTreeObj.dragNode_noSiblings=true;
|
||||
|
||||
if(thisObj && thisObj.id)
|
||||
{
|
||||
JSTreeObj.dragNode_destination = thisObj;
|
||||
//var img = thisObj.getElementsByTagName('IMG')[1];
|
||||
var imgObj = thisObj.getElementsByTagName('IMG');
|
||||
|
||||
var img = imgObj[1];
|
||||
if(imgObj.length>2){
|
||||
img = imgObj[imgObj.length-1];
|
||||
}
|
||||
|
||||
img.src = 'img/folder.gif';//subNode changed supNode,img changed
|
||||
|
||||
//var img1 = document.createElement('IMG');
|
||||
//img1.src = "img/nolines_minus.gif";
|
||||
//var aTag = thisObj.getElementsByTagName('A')[0];
|
||||
//aTag.id = 'jd' + thisObj.id.replace(/[^0-9]/gi,'');
|
||||
//thisObj.insertBefore(img1,aTag);
|
||||
|
||||
var tmpObj= JSTreeObj.dropTargetIndicator;
|
||||
tmpObj.style.display='block';
|
||||
|
||||
var eventSourceObj = this;
|
||||
if(JSTreeObj.dragNode_noSiblings && eventSourceObj.tagName=='IMG')eventSourceObj = eventSourceObj.nextSibling;
|
||||
|
||||
var tmpImg = tmpObj.getElementsByTagName('IMG')[0];
|
||||
if(this.tagName=='A' || JSTreeObj.dragNode_noSiblings){
|
||||
tmpImg.src = tmpImg.src.replace('ind1','ind2');
|
||||
JSTreeObj.insertAsSub = true;
|
||||
tmpObj.style.left = (JSTreeObj.getLeftPos(eventSourceObj) + JSTreeObj.indicator_offsetX_sub) + 'px';
|
||||
}else{
|
||||
tmpImg.src = tmpImg.src.replace('ind2','ind1');
|
||||
JSTreeObj.insertAsSub = false;
|
||||
tmpObj.style.left = (JSTreeObj.getLeftPos(eventSourceObj) + JSTreeObj.indicator_offsetX) + 'px';
|
||||
}
|
||||
|
||||
|
||||
tmpObj.style.top = (JSTreeObj.getTopPos(thisObj) + JSTreeObj.indicator_offsetY) + 'px';
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
,
|
||||
dropDragableNodes:function()
|
||||
{
|
||||
if(JSTreeObj.dragDropTimer<10){
|
||||
JSTreeObj.dragDropTimer = -1;
|
||||
return;
|
||||
}
|
||||
var showMessage = false;
|
||||
if(JSTreeObj.dragNode_destination){ // Check depth
|
||||
var countUp = JSTreeObj.dragDropCountLevels(JSTreeObj.dragNode_destination,'up');
|
||||
var countDown = JSTreeObj.dragDropCountLevels(JSTreeObj.dragNode_source,'down');
|
||||
var countLevels = countUp/1 + countDown/1 + (JSTreeObj.insertAsSub?1:0);
|
||||
|
||||
if(countLevels>JSTreeObj.maximumDepth){
|
||||
JSTreeObj.dragNode_destination = false;
|
||||
showMessage = true; // Used later down in this function
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(JSTreeObj.dragNode_destination){
|
||||
if(JSTreeObj.insertAsSub){
|
||||
var uls = JSTreeObj.dragNode_destination.getElementsByTagName('UL');
|
||||
if(uls.length>0){
|
||||
ul = uls[0];
|
||||
ul.style.display='block';
|
||||
|
||||
var lis = ul.getElementsByTagName('LI');
|
||||
|
||||
if(lis.length>0){ // Sub elements exists - drop dragable node before the first one
|
||||
ul.insertBefore(JSTreeObj.dragNode_source,lis[0]);
|
||||
}else { // No sub exists - use the appendChild method - This line should not be executed unless there's something wrong in the HTML, i.e empty <ul>
|
||||
ul.appendChild(JSTreeObj.dragNode_source);
|
||||
}
|
||||
}else{
|
||||
var ul = document.createElement('UL');
|
||||
ul.style.display='block';
|
||||
JSTreeObj.dragNode_destination.appendChild(ul);
|
||||
ul.appendChild(JSTreeObj.dragNode_source);
|
||||
}
|
||||
//var img = JSTreeObj.dragNode_destination.getElementsByTagName('IMG')[0];
|
||||
// img.style.visibility='visible';
|
||||
// img.src = img.src.replace(JSTreeObj.plusImage,JSTreeObj.minusImage);
|
||||
|
||||
|
||||
}else{
|
||||
if(JSTreeObj.dragNode_destination.nextSibling){
|
||||
var nextSib = JSTreeObj.dragNode_destination.nextSibling;
|
||||
nextSib.parentNode.insertBefore(JSTreeObj.dragNode_source,nextSib);
|
||||
}else{
|
||||
JSTreeObj.dragNode_destination.parentNode.appendChild(JSTreeObj.dragNode_source);
|
||||
}
|
||||
}
|
||||
/* Clear parent object */
|
||||
var tmpObj = JSTreeObj.dragNode_parent;
|
||||
var lis = tmpObj.getElementsByTagName('LI');
|
||||
if(lis.length==0){
|
||||
//var img = tmpObj.parentNode.getElementsByTagName('IMG')[0];
|
||||
//img.style.visibility='hidden'; // Hide [+],[-] icon
|
||||
tmpObj.parentNode.removeChild(tmpObj);
|
||||
}
|
||||
|
||||
}else{
|
||||
// Putting the item back to it's original location
|
||||
|
||||
if(JSTreeObj.dragNode_sourceNextSib){
|
||||
JSTreeObj.dragNode_parent.insertBefore(JSTreeObj.dragNode_source,JSTreeObj.dragNode_sourceNextSib);
|
||||
}else{
|
||||
JSTreeObj.dragNode_parent.appendChild(JSTreeObj.dragNode_source);
|
||||
}
|
||||
|
||||
}
|
||||
JSTreeObj.dropTargetIndicator.style.display='none';
|
||||
JSTreeObj.dragDropTimer = -1;
|
||||
//if(showMessage && JSTreeObj.messageMaximumDepthReached)alert(JSTreeObj.messageMaximumDepthReached);//如果菜单有层数限制,则提示
|
||||
}
|
||||
,
|
||||
createDropIndicator : function()
|
||||
{
|
||||
this.dropTargetIndicator = document.createElement('DIV');
|
||||
this.dropTargetIndicator.style.position = 'absolute';
|
||||
this.dropTargetIndicator.style.display='none';
|
||||
var img = document.createElement('IMG');
|
||||
img.src = this.imageFolder + 'dragDrop_ind1.gif';
|
||||
img.id = 'dragDropIndicatorImage';
|
||||
this.dropTargetIndicator.appendChild(img);
|
||||
document.body.appendChild(this.dropTargetIndicator);
|
||||
|
||||
}
|
||||
,
|
||||
dragDropCountLevels : function(obj,direction,stopAtObject){
|
||||
var countLevels = 0;
|
||||
if(direction=='up'){
|
||||
while(obj.parentNode && obj.parentNode!=stopAtObject){
|
||||
obj = obj.parentNode;
|
||||
if(obj.tagName=='UL')countLevels = countLevels/1 +1;
|
||||
}
|
||||
return countLevels;
|
||||
}
|
||||
|
||||
if(direction=='down'){
|
||||
var subObjects = obj.getElementsByTagName('LI');
|
||||
for(var no=0;no<subObjects.length;no++){
|
||||
countLevels = Math.max(countLevels,JSTreeObj.dragDropCountLevels(subObjects[no],"up",obj));
|
||||
}
|
||||
return countLevels;
|
||||
}
|
||||
}
|
||||
,
|
||||
cancelEvent : function()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
,
|
||||
cancelSelectionEvent : function()
|
||||
{
|
||||
|
||||
if(JSTreeObj.dragDropTimer<10)return true;
|
||||
return false;
|
||||
}
|
||||
,getNodeOrders : function(initObj,saveString)
|
||||
{
|
||||
|
||||
if(!saveString)var saveString = '';
|
||||
if(!initObj){
|
||||
initObj = document.getElementById(this.idOfTree);
|
||||
|
||||
}
|
||||
var lis = initObj.getElementsByTagName('LI');
|
||||
|
||||
if(lis.length>0){
|
||||
|
||||
for(var i=0;i<lis.length;i++){
|
||||
var li = lis[i];
|
||||
if(li.id){
|
||||
var numericParentID = li.parentNode.parentNode.id.replace(/[^0-9]/gi,'');
|
||||
if(numericParentID!=''){
|
||||
if(saveString.length>0)saveString = saveString + ',';
|
||||
var numericID = li.id.replace(/[^0-9]/gi,'');
|
||||
|
||||
if(numericID.length==0)numericID='A';
|
||||
|
||||
if(numericID!='0'){
|
||||
saveString = saveString + numericID;
|
||||
saveString = saveString + '-';
|
||||
if(li.parentNode.id!=this.idOfTree)saveString = saveString + numericParentID; else saveString = saveString + '0';
|
||||
}
|
||||
}
|
||||
//var ul = li.getElementsByTagName('UL');
|
||||
//if(ul.length>0){
|
||||
// saveString = this.getNodeOrders(ul[0],saveString);
|
||||
//}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if(initObj.id == this.idOfTree){
|
||||
|
||||
return saveString;
|
||||
|
||||
}
|
||||
|
||||
return saveString;
|
||||
}
|
||||
,highlightItem : function(inputObj,e)
|
||||
{
|
||||
if(JSTreeObj.currentlyActiveItem)JSTreeObj.currentlyActiveItem.className = '';
|
||||
this.className = 'highlightedNodeItem';
|
||||
JSTreeObj.currentlyActiveItem = this;
|
||||
}
|
||||
,
|
||||
removeHighlight : function()
|
||||
{
|
||||
if(JSTreeObj.currentlyActiveItem)JSTreeObj.currentlyActiveItem.className = '';
|
||||
JSTreeObj.currentlyActiveItem = false;
|
||||
}
|
||||
,
|
||||
hasSubNodes : function(obj)
|
||||
{
|
||||
var subs = obj.getElementsByTagName('LI');
|
||||
if(subs.length>0)return true;
|
||||
return false;
|
||||
}
|
||||
,
|
||||
deleteItem : function(obj1,obj2)
|
||||
{
|
||||
var message = 'Click OK to delete item ' + obj2.innerHTML;
|
||||
if(this.hasSubNodes(obj2.parentNode)) message = message + ' and it\'s sub nodes';
|
||||
if(confirm(message)){
|
||||
this.__deleteItem_step2(obj2.parentNode); // Sending <LI> tag to the __deleteItem_step2 method
|
||||
}
|
||||
|
||||
}
|
||||
,
|
||||
__refreshDisplay : function(obj)
|
||||
{
|
||||
if(this.hasSubNodes(obj))return;
|
||||
|
||||
var img = obj.getElementsByTagName('IMG')[0];
|
||||
img.style.visibility = 'hidden';
|
||||
}
|
||||
,
|
||||
__deleteItem_step2 : function(obj)
|
||||
{
|
||||
|
||||
var saveString = obj.id.replace(/[^0-9]/gi,'');
|
||||
|
||||
var lis = obj.getElementsByTagName('LI');
|
||||
for(var no=0;no<lis.length;no++){
|
||||
saveString = saveString + ',' + lis[no].id.replace(/[^0-9]/gi,'');
|
||||
}
|
||||
|
||||
// Creating ajax object and send items
|
||||
var ajaxIndex = JSTreeObj.ajaxObjects.length;
|
||||
JSTreeObj.ajaxObjects[ajaxIndex] = new sack();
|
||||
JSTreeObj.ajaxObjects[ajaxIndex].method = "GET";
|
||||
JSTreeObj.ajaxObjects[ajaxIndex].setVar("deleteIds", saveString);
|
||||
JSTreeObj.__addAdditionalRequestParameters(JSTreeObj.ajaxObjects[ajaxIndex], JSTreeObj.additionalDeleteRequestParameters);
|
||||
JSTreeObj.ajaxObjects[ajaxIndex].requestFile = JSTreeObj.filePathDeleteItem; // Specifying which file to get
|
||||
JSTreeObj.ajaxObjects[ajaxIndex].onCompletion = function() { JSTreeObj.__deleteComplete(ajaxIndex,obj); } ; // Specify function that will be executed after file has been found
|
||||
JSTreeObj.ajaxObjects[ajaxIndex].runAJAX(); // Execute AJAX function
|
||||
|
||||
|
||||
}
|
||||
,
|
||||
__deleteComplete : function(ajaxIndex,obj)
|
||||
{
|
||||
if(this.ajaxObjects[ajaxIndex].response!='OK'){
|
||||
alert('ERROR WHEN TRYING TO DELETE NODE: ' + this.ajaxObjects[ajaxIndex].response); // Rename failed
|
||||
}else{
|
||||
var parentRef = obj.parentNode.parentNode;
|
||||
obj.parentNode.removeChild(obj);
|
||||
this.__refreshDisplay(parentRef);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
,
|
||||
__renameComplete : function(ajaxIndex)
|
||||
{
|
||||
if(this.ajaxObjects[ajaxIndex].response!='OK'){
|
||||
alert('ERROR WHEN TRYING TO RENAME NODE: ' + this.ajaxObjects[ajaxIndex].response); // Rename failed
|
||||
}
|
||||
}
|
||||
,
|
||||
__saveTextBoxChanges : function(e,inputObj)
|
||||
{
|
||||
if(!inputObj && this)inputObj = this;
|
||||
if(document.all)e = event;
|
||||
if(e.keyCode && e.keyCode==27){
|
||||
JSTreeObj.__cancelRename(e,inputObj);
|
||||
return;
|
||||
}
|
||||
inputObj.style.display='none';
|
||||
inputObj.nextSibling.style.visibility='visible';
|
||||
if(inputObj.value.length>0){
|
||||
inputObj.nextSibling.innerHTML = inputObj.value;
|
||||
// Send changes to the server.
|
||||
if (JSTreeObj.renameState != JSTreeObj.RENAME_STATE_BEGIN) {
|
||||
return;
|
||||
}
|
||||
JSTreeObj.renameState = JSTreeObj.RENAME_STATE_REQUEST_SENDED;
|
||||
|
||||
var ajaxIndex = JSTreeObj.ajaxObjects.length;
|
||||
JSTreeObj.ajaxObjects[ajaxIndex] = new sack();
|
||||
JSTreeObj.ajaxObjects[ajaxIndex].method = "GET";
|
||||
JSTreeObj.ajaxObjects[ajaxIndex].setVar("renameId", inputObj.parentNode.id.replace(/[^0-9]/gi,''));
|
||||
JSTreeObj.ajaxObjects[ajaxIndex].setVar("newName", inputObj.value);
|
||||
JSTreeObj.__addAdditionalRequestParameters(JSTreeObj.ajaxObjects[ajaxIndex], JSTreeObj.additionalRenameRequestParameters);
|
||||
JSTreeObj.ajaxObjects[ajaxIndex].requestFile = JSTreeObj.filePathRenameItem; // Specifying which file to get
|
||||
JSTreeObj.ajaxObjects[ajaxIndex].onCompletion = function() { JSTreeObj.__renameComplete(ajaxIndex); } ; // Specify function that will be executed after file has been found
|
||||
JSTreeObj.ajaxObjects[ajaxIndex].runAJAX(); // Execute AJAX function
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
,
|
||||
__cancelRename : function(e,inputObj)
|
||||
{
|
||||
JSTreeObj.renameState = JSTreeObj.RENAME_STATE_CANCELD;
|
||||
if(!inputObj && this)inputObj = this;
|
||||
inputObj.value = JSTreeObj.helpObj.innerHTML;
|
||||
inputObj.nextSibling.innerHTML = JSTreeObj.helpObj.innerHTML;
|
||||
inputObj.style.display = 'none';
|
||||
inputObj.nextSibling.style.visibility = 'visible';
|
||||
}
|
||||
,
|
||||
__renameCheckKeyCode : function(e)
|
||||
{
|
||||
if(document.all)e = event;
|
||||
if(e.keyCode==13){ // Enter pressed
|
||||
JSTreeObj.__saveTextBoxChanges(false,this);
|
||||
}
|
||||
if(e.keyCode==27){ // ESC pressed
|
||||
JSTreeObj.__cancelRename(false,this);
|
||||
}
|
||||
}
|
||||
,
|
||||
__createTextBox : function(obj)
|
||||
{
|
||||
var textBox = document.createElement('INPUT');
|
||||
textBox.className = 'folderTreeTextBox';
|
||||
textBox.value = obj.innerHTML;
|
||||
obj.parentNode.insertBefore(textBox,obj);
|
||||
textBox.id = 'textBox' + obj.parentNode.id.replace(/[^0-9]/gi,'');
|
||||
textBox.onblur = this.__saveTextBoxChanges;
|
||||
textBox.onkeydown = this.__renameCheckKeyCode;
|
||||
this.__renameEnableTextBox(obj);
|
||||
}
|
||||
,
|
||||
__renameEnableTextBox : function(obj)
|
||||
{
|
||||
JSTreeObj.renameState = JSTreeObj.RENAME_STATE_BEGIN;
|
||||
obj.style.visibility = 'hidden';
|
||||
obj.previousSibling.value = obj.innerHTML;
|
||||
obj.previousSibling.style.display = 'inline';
|
||||
obj.previousSibling.select();
|
||||
}
|
||||
,
|
||||
renameItem : function(obj1,obj2)
|
||||
{
|
||||
currentItemToEdit = obj2.parentNode; // Reference to the <li> tag.
|
||||
if(!obj2.previousSibling || obj2.previousSibling.tagName.toLowerCase()!='input'){
|
||||
this.__createTextBox(obj2);
|
||||
}else{
|
||||
this.__renameEnableTextBox(obj2);
|
||||
}
|
||||
this.helpObj.innerHTML = obj2.innerHTML;
|
||||
|
||||
}
|
||||
,
|
||||
initTree : function()
|
||||
{
|
||||
JSTreeObj = this;
|
||||
JSTreeObj.createDropIndicator();
|
||||
document.documentElement.onselectstart = JSTreeObj.cancelSelectionEvent;
|
||||
document.documentElement.ondragstart = JSTreeObj.cancelEvent;
|
||||
document.documentElement.onmousedown = JSTreeObj.removeHighlight;
|
||||
|
||||
/* Creating help object for storage of values */
|
||||
this.helpObj = document.createElement('DIV');
|
||||
this.helpObj.style.display = 'none';
|
||||
document.body.appendChild(this.helpObj);
|
||||
|
||||
var nodeId = 0;
|
||||
var dhtmlgoodies_tree = document.getElementById(this.idOfTree);
|
||||
var menuItems = dhtmlgoodies_tree.getElementsByTagName('LI'); // Get an array of all menu items
|
||||
|
||||
|
||||
for(var no=0;no<menuItems.length;no++){
|
||||
// No children var set ?
|
||||
var noChildren = false;
|
||||
var tmpVar = menuItems[no].getAttribute('noChildren');
|
||||
if(!tmpVar)tmpVar = menuItems[no].noChildren;
|
||||
if(tmpVar=='true')noChildren=true;
|
||||
// No drag var set ?
|
||||
var noDrag = false;
|
||||
var tmpVar = menuItems[no].getAttribute('noDrag');
|
||||
|
||||
if(!tmpVar)tmpVar = menuItems[no].noDrag;
|
||||
if(tmpVar=='true')noDrag=true;
|
||||
|
||||
nodeId++;
|
||||
var subItems = menuItems[no].getElementsByTagName('UL');
|
||||
//var img = document.createElement('IMG');
|
||||
//img.src = this.imageFolder + this.plusImage;
|
||||
// img.onclick = JSTreeObj.showHideNode;
|
||||
|
||||
//if(subItems.length==0)img.style.visibility='hidden';else{
|
||||
// subItems[0].id = 'tree_ul_' + treeUlCounter;
|
||||
// treeUlCounter++;
|
||||
//}
|
||||
var aTag = menuItems[no].getElementsByTagName('A')[0];
|
||||
aTag.id = 'nodeATag' + menuItems[no].id.replace(/[^0-9]/gi,'');
|
||||
|
||||
|
||||
//var t = menuItems[no].getElementsByTagName('img');
|
||||
//var image ;
|
||||
//if(t.length>0){
|
||||
// image = t[t.length-1];
|
||||
//alert(image.id);
|
||||
//}
|
||||
//image.id = 'nodeImgTag' + menuItems[no].id.replace(/[^0-9]/gi,'');
|
||||
|
||||
//aTag.onclick = JSTreeObj.showHideNode;
|
||||
|
||||
//menuItems[no].insertBefore(img,aTag);
|
||||
if(!noDrag)aTag.onmousedown = JSTreeObj.initDrag;
|
||||
if(!noChildren)aTag.onmousemove = JSTreeObj.moveDragableNodes;
|
||||
|
||||
this.addEvent(aTag,'contextmenu',this.highlightItem);
|
||||
|
||||
|
||||
|
||||
}
|
||||
initExpandedNodes = this.Get_Cookie('dhtmlgoodies_expandedNodes');
|
||||
if(initExpandedNodes){
|
||||
var nodes = initExpandedNodes.split(',');
|
||||
for(var no=0;no<nodes.length;no++){
|
||||
if(nodes[no])this.showHideNode(false,nodes[no]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
document.documentElement.onmousemove = JSTreeObj.moveDragableNodes;
|
||||
document.documentElement.onmouseup = JSTreeObj.dropDragableNodes;
|
||||
}
|
||||
,
|
||||
__addAdditionalRequestParameters : function(ajax, parameters)
|
||||
{
|
||||
for (var parameter in parameters) {
|
||||
ajax.setVar(parameter, parameters[parameter]);
|
||||
}
|
||||
}
|
||||
}
|
||||
693
WebRoot/dtree/js/dtree.js
Normal file
@@ -0,0 +1,693 @@
|
||||
/*--------------------------------------------------|
|
||||
|
||||
| dTree 2.05 | www.destroydrop.com/javascript/tree/ |
|
||||
|
||||
|---------------------------------------------------|
|
||||
|
||||
| Copyright (c) 2002-2003 Geir Landr? |
|
||||
|
||||
| |
|
||||
|
||||
| This script can be used freely as long as all |
|
||||
|
||||
| copyright messages are intact. |
|
||||
|
||||
| |
|
||||
|
||||
| Updated: 17.04.2003 |
|
||||
|
||||
|--------------------------------------------------*/
|
||||
|
||||
|
||||
|
||||
// Node object
|
||||
|
||||
function Node(id, pid, name, url, title, target, icon, iconOpen, open) {
|
||||
|
||||
this.id = id;
|
||||
|
||||
this.pid = pid;
|
||||
|
||||
this.name = name;
|
||||
|
||||
this.url = url;
|
||||
|
||||
this.title = title;
|
||||
|
||||
this.target = target;
|
||||
|
||||
this.icon = icon;
|
||||
|
||||
this.iconOpen = iconOpen;
|
||||
|
||||
this._io = open || false;
|
||||
|
||||
this._is = false;
|
||||
|
||||
this._ls = false;
|
||||
|
||||
this._hc = false;
|
||||
|
||||
this._ai = 0;
|
||||
|
||||
this._p;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
// Tree object
|
||||
|
||||
function dTree(objName) {
|
||||
|
||||
this.config = {
|
||||
|
||||
target : null,
|
||||
|
||||
folderLinks : true,
|
||||
|
||||
useSelection : true,
|
||||
|
||||
useCookies : true,
|
||||
|
||||
useLines : true,
|
||||
|
||||
useIcons : true,
|
||||
|
||||
useStatusText : false,
|
||||
|
||||
closeSameLevel : false,
|
||||
|
||||
inOrder : false
|
||||
|
||||
}
|
||||
|
||||
this.icon = {
|
||||
|
||||
root : '../images/base.gif',
|
||||
|
||||
folder : '../images/folder.gif',
|
||||
|
||||
folderOpen : '../images/folderopen.gif',
|
||||
|
||||
node : '../images/page.gif',
|
||||
|
||||
empty : '../images/empty.gif',
|
||||
|
||||
line : '../images/line.gif',
|
||||
|
||||
join : '../images/join.gif',
|
||||
|
||||
joinBottom : '../images/joinbottom.gif',
|
||||
|
||||
plus : '../images/plus.gif',
|
||||
|
||||
plusBottom : '../images/plusbottom.gif',
|
||||
|
||||
minus : '../images/minus.gif',
|
||||
|
||||
minusBottom : '../images/minusbottom.gif',
|
||||
|
||||
nlPlus : '../images/nolines_plus.gif',
|
||||
|
||||
nlMinus : '../images/nolines_minus.gif'
|
||||
|
||||
};
|
||||
|
||||
this.obj = objName;
|
||||
|
||||
this.aNodes = [];
|
||||
|
||||
this.aIndent = [];
|
||||
|
||||
this.root = new Node(0);//根节点以0开始,edit by zhangwei
|
||||
|
||||
this.selectedNode = null;
|
||||
|
||||
this.selectedFound = false;
|
||||
|
||||
this.completed = false;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
// Adds a new node to the node array
|
||||
|
||||
dTree.prototype.add = function(id, pid, name, url, title, target, icon, iconOpen, open) {
|
||||
|
||||
this.aNodes[this.aNodes.length] = new Node(id, pid, name, url, title, target, icon, iconOpen, open);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
// Open/close all nodes
|
||||
|
||||
dTree.prototype.openAll = function() {
|
||||
|
||||
this.oAll(true);
|
||||
|
||||
};
|
||||
|
||||
dTree.prototype.closeAll = function() {
|
||||
|
||||
this.oAll(false);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
// Outputs the tree to the page
|
||||
|
||||
dTree.prototype.toString = function() {
|
||||
|
||||
var str = '<div class="dtree">\n';
|
||||
|
||||
if (document.getElementById) {
|
||||
|
||||
if (this.config.useCookies) this.selectedNode = this.getSelected();
|
||||
|
||||
str += this.addNode(this.root);
|
||||
|
||||
} else str += 'Browser not supported.';
|
||||
|
||||
str += '</div>';
|
||||
|
||||
if (!this.selectedFound) this.selectedNode = null;
|
||||
|
||||
this.completed = true;
|
||||
|
||||
return str;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
// Creates the tree structure
|
||||
|
||||
dTree.prototype.addNode = function(pNode) {
|
||||
|
||||
var str = '';
|
||||
|
||||
var n=0;
|
||||
|
||||
if (this.config.inOrder) n = pNode._ai;
|
||||
|
||||
for (n; n<this.aNodes.length; n++) {
|
||||
|
||||
if (this.aNodes[n].pid == pNode.id) {
|
||||
|
||||
var cn = this.aNodes[n];
|
||||
|
||||
cn._p = pNode;
|
||||
|
||||
cn._ai = n;
|
||||
|
||||
this.setCS(cn);
|
||||
|
||||
if (!cn.target && this.config.target) cn.target = this.config.target;
|
||||
|
||||
if (cn._hc && !cn._io && this.config.useCookies) cn._io = this.isOpen(cn.id);
|
||||
|
||||
if (!this.config.folderLinks && cn._hc) cn.url = null;
|
||||
|
||||
if (this.config.useSelection && cn.id == this.selectedNode && !this.selectedFound) {
|
||||
|
||||
cn._is = true;
|
||||
|
||||
this.selectedNode = n;
|
||||
|
||||
this.selectedFound = true;
|
||||
|
||||
}
|
||||
|
||||
str += this.node(cn, n);
|
||||
|
||||
if (cn._ls) break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return str;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
// Creates the node icon, url and text
|
||||
|
||||
dTree.prototype.node = function(node, nodeId) {
|
||||
|
||||
var str = '<div class="dTreeNode">' + this.indent(node, nodeId);
|
||||
|
||||
if (this.config.useIcons) {
|
||||
|
||||
if (!node.icon) node.icon = (this.root.id == node.pid) ? this.icon.root : ((node._hc) ? this.icon.folder : this.icon.node);
|
||||
|
||||
if (!node.iconOpen) node.iconOpen = (node._hc) ? this.icon.folderOpen : this.icon.node;
|
||||
|
||||
if (this.root.id == node.pid) {
|
||||
|
||||
node.icon = this.icon.root;
|
||||
|
||||
node.iconOpen = this.icon.root;
|
||||
|
||||
}
|
||||
|
||||
str += '<img id="i' + this.obj + nodeId + '" src="' + ((node._io) ? node.iconOpen : node.icon) + '" alt="" />';
|
||||
|
||||
}
|
||||
|
||||
if (node.url) {
|
||||
|
||||
str += '<a id="s' + this.obj + nodeId + '" class="' + ((this.config.useSelection) ? ((node._is ? 'nodeSel' : 'node')) : 'node') + '" href="' + node.url + '"';
|
||||
|
||||
if (node.title) str += ' title="' + node.title + '"';
|
||||
|
||||
if (node.target) str += ' target="' + node.target + '"';
|
||||
|
||||
if (this.config.useStatusText) str += ' onmouseover="window.status=\'' + node.name + '\';return true;" onmouseout="window.status=\'\';return true;" ';
|
||||
|
||||
if (this.config.useSelection && ((node._hc && this.config.folderLinks) || !node._hc))
|
||||
|
||||
str += ' onclick="javascript: ' + this.obj + '.s(' + nodeId + ');"';
|
||||
|
||||
str += '>';
|
||||
|
||||
}
|
||||
|
||||
else if ((!this.config.folderLinks || !node.url) && node._hc && node.pid != this.root.id)
|
||||
|
||||
str += '<a href="javascript: ' + this.obj + '.o(' + nodeId + ');" class="node">';
|
||||
|
||||
str += node.name;
|
||||
|
||||
if (node.url || ((!this.config.folderLinks || !node.url) && node._hc)) str += '</a>';
|
||||
|
||||
str += '</div>';
|
||||
|
||||
if (node._hc) {
|
||||
|
||||
str += '<div id="d' + this.obj + nodeId + '" class="clip" style="display:' + ((this.root.id == node.pid || node._io) ? 'block' : 'none') + ';">';
|
||||
|
||||
str += this.addNode(node);
|
||||
|
||||
str += '</div>';
|
||||
|
||||
}
|
||||
|
||||
this.aIndent.pop();
|
||||
|
||||
return str;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
// Adds the empty and line icons
|
||||
|
||||
dTree.prototype.indent = function(node, nodeId) {
|
||||
|
||||
var str = '';
|
||||
|
||||
if (this.root.id != node.pid) {
|
||||
|
||||
for (var n=0; n<this.aIndent.length; n++)
|
||||
|
||||
str += '<img src="' + ( (this.aIndent[n] == 1 && this.config.useLines) ? this.icon.line : this.icon.empty ) + '" alt="" />';
|
||||
|
||||
(node._ls) ? this.aIndent.push(0) : this.aIndent.push(1);
|
||||
|
||||
if (node._hc) {
|
||||
|
||||
str += '<a href="javascript: ' + this.obj + '.o(' + nodeId + ');"><img id="j' + this.obj + nodeId + '" src="';
|
||||
|
||||
if (!this.config.useLines) str += (node._io) ? this.icon.nlMinus : this.icon.nlPlus;
|
||||
|
||||
else str += ( (node._io) ? ((node._ls && this.config.useLines) ? this.icon.minusBottom : this.icon.minus) : ((node._ls && this.config.useLines) ? this.icon.plusBottom : this.icon.plus ) );
|
||||
|
||||
str += '" alt="" /></a>';
|
||||
|
||||
} else str += '<img src="' + ( (this.config.useLines) ? ((node._ls) ? this.icon.joinBottom : this.icon.join ) : this.icon.empty) + '" alt="" />';
|
||||
|
||||
}
|
||||
|
||||
return str;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
// Checks if a node has any children and if it is the last sibling
|
||||
|
||||
dTree.prototype.setCS = function(node) {
|
||||
|
||||
var lastId;
|
||||
|
||||
for (var n=0; n<this.aNodes.length; n++) {
|
||||
|
||||
if (this.aNodes[n].pid == node.id) node._hc = true;
|
||||
|
||||
if (this.aNodes[n].pid == node.pid) lastId = this.aNodes[n].id;
|
||||
|
||||
}
|
||||
|
||||
if (lastId==node.id) node._ls = true;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
// Returns the selected node
|
||||
|
||||
dTree.prototype.getSelected = function() {
|
||||
|
||||
var sn = this.getCookie('cs' + this.obj);
|
||||
|
||||
return (sn) ? sn : null;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
// Highlights the selected node
|
||||
|
||||
dTree.prototype.s = function(id) {
|
||||
|
||||
if (!this.config.useSelection) return;
|
||||
|
||||
var cn = this.aNodes[id];
|
||||
|
||||
if (cn._hc && !this.config.folderLinks) return;
|
||||
|
||||
if (this.selectedNode != id) {
|
||||
|
||||
if (this.selectedNode || this.selectedNode==0) {
|
||||
|
||||
eOld = document.getElementById("s" + this.obj + this.selectedNode);
|
||||
|
||||
eOld.className = "node";
|
||||
|
||||
}
|
||||
|
||||
eNew = document.getElementById("s" + this.obj + id);
|
||||
|
||||
eNew.className = "nodeSel";
|
||||
|
||||
this.selectedNode = id;
|
||||
|
||||
if (this.config.useCookies) this.setCookie('cs' + this.obj, cn.id);
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
// Toggle Open or close
|
||||
|
||||
dTree.prototype.o = function(id) {
|
||||
|
||||
var cn = this.aNodes[id];
|
||||
|
||||
this.nodeStatus(!cn._io, id, cn._ls);
|
||||
|
||||
cn._io = !cn._io;
|
||||
|
||||
if (this.config.closeSameLevel) this.closeLevel(cn);
|
||||
|
||||
if (this.config.useCookies) this.updateCookie();
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
// Open or close all nodes
|
||||
|
||||
dTree.prototype.oAll = function(status) {
|
||||
|
||||
for (var n=0; n<this.aNodes.length; n++) {
|
||||
|
||||
if (this.aNodes[n]._hc && this.aNodes[n].pid != this.root.id) {
|
||||
|
||||
this.nodeStatus(status, n, this.aNodes[n]._ls)
|
||||
|
||||
this.aNodes[n]._io = status;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (this.config.useCookies) this.updateCookie();
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
// Opens the tree to a specific node
|
||||
|
||||
dTree.prototype.openTo = function(nId, bSelect, bFirst) {
|
||||
|
||||
if (!bFirst) {
|
||||
|
||||
for (var n=0; n<this.aNodes.length; n++) {
|
||||
|
||||
if (this.aNodes[n].id == nId) {
|
||||
|
||||
nId=n;
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
var cn=this.aNodes[nId];
|
||||
|
||||
if (cn.pid==this.root.id || !cn._p) return;
|
||||
|
||||
cn._io = true;
|
||||
|
||||
cn._is = bSelect;
|
||||
|
||||
if (this.completed && cn._hc) this.nodeStatus(true, cn._ai, cn._ls);
|
||||
|
||||
if (this.completed && bSelect) this.s(cn._ai);
|
||||
|
||||
else if (bSelect) this._sn=cn._ai;
|
||||
|
||||
this.openTo(cn._p._ai, false, true);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
// Closes all nodes on the same level as certain node
|
||||
|
||||
dTree.prototype.closeLevel = function(node) {
|
||||
|
||||
for (var n=0; n<this.aNodes.length; n++) {
|
||||
|
||||
if (this.aNodes[n].pid == node.pid && this.aNodes[n].id != node.id && this.aNodes[n]._hc) {
|
||||
|
||||
this.nodeStatus(false, n, this.aNodes[n]._ls);
|
||||
|
||||
this.aNodes[n]._io = false;
|
||||
|
||||
this.closeAllChildren(this.aNodes[n]);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Closes all children of a node
|
||||
|
||||
dTree.prototype.closeAllChildren = function(node) {
|
||||
|
||||
for (var n=0; n<this.aNodes.length; n++) {
|
||||
|
||||
if (this.aNodes[n].pid == node.id && this.aNodes[n]._hc) {
|
||||
|
||||
if (this.aNodes[n]._io) this.nodeStatus(false, n, this.aNodes[n]._ls);
|
||||
|
||||
this.aNodes[n]._io = false;
|
||||
|
||||
this.closeAllChildren(this.aNodes[n]);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Change the status of a node(open or closed)
|
||||
|
||||
dTree.prototype.nodeStatus = function(status, id, bottom) {
|
||||
|
||||
eDiv = document.getElementById('d' + this.obj + id);
|
||||
|
||||
eJoin = document.getElementById('j' + this.obj + id);
|
||||
|
||||
if (this.config.useIcons) {
|
||||
|
||||
eIcon = document.getElementById('i' + this.obj + id);
|
||||
|
||||
eIcon.src = (status) ? this.aNodes[id].iconOpen : this.aNodes[id].icon;
|
||||
|
||||
}
|
||||
|
||||
eJoin.src = (this.config.useLines)?
|
||||
|
||||
((status)?((bottom)?this.icon.minusBottom:this.icon.minus):((bottom)?this.icon.plusBottom:this.icon.plus)):
|
||||
|
||||
((status)?this.icon.nlMinus:this.icon.nlPlus);
|
||||
|
||||
eDiv.style.display = (status) ? 'block': 'none';
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// [Cookie] Clears a cookie
|
||||
|
||||
dTree.prototype.clearCookie = function() {
|
||||
|
||||
var now = new Date();
|
||||
|
||||
var yesterday = new Date(now.getTime() - 1000 * 60 * 60 * 24);
|
||||
|
||||
this.setCookie('co'+this.obj, 'cookieValue', yesterday);
|
||||
|
||||
this.setCookie('cs'+this.obj, 'cookieValue', yesterday);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
// [Cookie] Sets value in a cookie
|
||||
|
||||
dTree.prototype.setCookie = function(cookieName, cookieValue, expires, path, domain, secure) {
|
||||
|
||||
document.cookie =
|
||||
|
||||
escape(cookieName) + '=' + escape(cookieValue)
|
||||
|
||||
+ (expires ? '; expires=' + expires.toGMTString() : '')
|
||||
|
||||
+ (path ? '; path=' + path : '')
|
||||
|
||||
+ (domain ? '; domain=' + domain : '')
|
||||
|
||||
+ (secure ? '; secure' : '');
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
// [Cookie] Gets a value from a cookie
|
||||
|
||||
dTree.prototype.getCookie = function(cookieName) {
|
||||
|
||||
var cookieValue = '';
|
||||
|
||||
var posName = document.cookie.indexOf(escape(cookieName) + '=');
|
||||
|
||||
if (posName != -1) {
|
||||
|
||||
var posValue = posName + (escape(cookieName) + '=').length;
|
||||
|
||||
var endPos = document.cookie.indexOf(';', posValue);
|
||||
|
||||
if (endPos != -1) cookieValue = unescape(document.cookie.substring(posValue, endPos));
|
||||
|
||||
else cookieValue = unescape(document.cookie.substring(posValue));
|
||||
|
||||
}
|
||||
|
||||
return (cookieValue);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
// [Cookie] Returns ids of open nodes as a string
|
||||
|
||||
dTree.prototype.updateCookie = function() {
|
||||
|
||||
var str = '';
|
||||
|
||||
for (var n=0; n<this.aNodes.length; n++) {
|
||||
|
||||
if (this.aNodes[n]._io && this.aNodes[n].pid != this.root.id) {
|
||||
|
||||
if (str) str += '.';
|
||||
|
||||
str += this.aNodes[n].id;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
this.setCookie('co' + this.obj, str);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
// [Cookie] Checks if a node id is in a cookie
|
||||
|
||||
dTree.prototype.isOpen = function(id) {
|
||||
|
||||
var aOpen = this.getCookie('co' + this.obj).split('.');
|
||||
|
||||
for (var n=0; n<aOpen.length; n++)
|
||||
|
||||
if (aOpen[n] == id) return true;
|
||||
|
||||
return false;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
// If Push and pop is not implemented by the browser
|
||||
|
||||
if (!Array.prototype.push) {
|
||||
|
||||
Array.prototype.push = function array_push() {
|
||||
|
||||
for(var i=0;i<arguments.length;i++)
|
||||
|
||||
this[this.length]=arguments[i];
|
||||
|
||||
return this.length;
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
if (!Array.prototype.pop) {
|
||||
|
||||
Array.prototype.pop = function array_pop() {
|
||||
|
||||
lastElement = this[this.length-1];
|
||||
|
||||
this.length = Math.max(this.length-1,0);
|
||||
|
||||
return lastElement;
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
789
WebRoot/dtree/js/dtree_checkbox.js
Normal file
@@ -0,0 +1,789 @@
|
||||
/*--------------------------------------------------|
|
||||
|
||||
| dTree 2.05 | www.destroydrop.com/javascript/tree/ |
|
||||
|
||||
|---------------------------------------------------|
|
||||
|
||||
| Copyright (c) 2002-2003 Geir Landr? |
|
||||
|
||||
| |
|
||||
|
||||
| This script can be used freely as long as all |
|
||||
|
||||
| copyright messages are intact. |
|
||||
|
||||
| |
|
||||
|
||||
| Updated: 17.04.2003 |
|
||||
|
||||
|--------------------------------------------------*/
|
||||
|
||||
|
||||
|
||||
// Node object
|
||||
|
||||
function Node(id, pid, name, checked ,url, title, target, icon, iconOpen, open,mktype) {
|
||||
|
||||
this.id = id;
|
||||
|
||||
this.pid = pid;
|
||||
|
||||
this.name = name;
|
||||
|
||||
this.mktype = url;
|
||||
|
||||
this.url = url;
|
||||
|
||||
this.title = title;
|
||||
|
||||
this.target = target;
|
||||
|
||||
this.icon = icon;
|
||||
|
||||
this.iconOpen = iconOpen;
|
||||
|
||||
this._io = open || false;
|
||||
|
||||
this._is = false;
|
||||
|
||||
this._ls = false;
|
||||
|
||||
this._hc = false;
|
||||
|
||||
this._ai = 0;
|
||||
|
||||
this._p;
|
||||
this.checked = checked;//add by zhangwei
|
||||
};
|
||||
|
||||
// Tree object
|
||||
|
||||
function dTree(objName, iPath, formId) {
|
||||
|
||||
this.config = {
|
||||
|
||||
target : null,
|
||||
|
||||
folderLinks : true,
|
||||
|
||||
useSelection : true,
|
||||
|
||||
useCookies : true,
|
||||
|
||||
useLines : true,
|
||||
|
||||
useIcons : false,
|
||||
useCheckBox : true,
|
||||
|
||||
useStatusText : false,
|
||||
|
||||
closeSameLevel : false,
|
||||
|
||||
inOrder : false
|
||||
|
||||
}
|
||||
|
||||
this.icon = {
|
||||
|
||||
root : '../dtree/img/base.gif',
|
||||
|
||||
folder : '../dtree/img/folder.gif',
|
||||
|
||||
folderOpen : '../dtree/img/folderopen.gif',
|
||||
|
||||
node : '../dtree/img/page.gif',
|
||||
|
||||
empty : '../dtree/img/empty.gif',
|
||||
|
||||
line : '../dtree/img/line.gif',
|
||||
|
||||
join : '../dtree/img/join.gif',
|
||||
|
||||
joinBottom : '../dtree/img/joinbottom.gif',
|
||||
|
||||
plus : '../dtree/img/plus.gif',
|
||||
|
||||
plusBottom : '../dtree/img/plusbottom.gif',
|
||||
|
||||
minus : '../dtree/img/minus.gif',
|
||||
|
||||
minusBottom : '../dtree/img/minusbottom.gif',
|
||||
|
||||
nlPlus : '../dtree/img/nolines_plus.gif',
|
||||
|
||||
nlMinus : '../dtree/img/nolines_minus.gif'
|
||||
};
|
||||
this.parEnum = "";
|
||||
|
||||
this.obj = objName;
|
||||
|
||||
this.aNodes = [];
|
||||
|
||||
this.aIndent = [];
|
||||
|
||||
this.root = new Node(-1);
|
||||
|
||||
this.selectedNode = null;
|
||||
|
||||
this.selectedFound = false;
|
||||
|
||||
this.completed = false;
|
||||
|
||||
this.formId = (formId==null)?"dTreeForm":formId;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
// Adds a new node to the node array
|
||||
|
||||
dTree.prototype.add = function(id, pid, name, checked, url, title, target, icon, iconOpen, open) {
|
||||
|
||||
this.aNodes[this.aNodes.length] = new Node(id, pid, name, checked, url, title, target, icon, iconOpen, open);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
// Open/close all nodes
|
||||
|
||||
dTree.prototype.openAll = function() {
|
||||
|
||||
this.oAll(true);
|
||||
|
||||
};
|
||||
|
||||
dTree.prototype.closeAll = function() {
|
||||
|
||||
this.oAll(false);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
// Outputs the tree to the page
|
||||
|
||||
dTree.prototype.toString = function() {
|
||||
|
||||
var str = '<div class="dtree"><form id="'+this.formId+'">\n';
|
||||
|
||||
if (document.getElementById) {
|
||||
|
||||
if (this.config.useCookies) this.selectedNode = this.getSelected();
|
||||
|
||||
str += this.addNode(this.root);
|
||||
|
||||
} else str += 'Browser not supported.';
|
||||
|
||||
str += '</form></div>';
|
||||
//document.getElementById("test").value = str;
|
||||
//alert(str);
|
||||
if (!this.selectedFound) this.selectedNode = null;
|
||||
|
||||
this.completed = true;
|
||||
|
||||
return str;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
// Creates the tree structure
|
||||
|
||||
dTree.prototype.addNode = function(pNode) {
|
||||
|
||||
var str = '';
|
||||
|
||||
var n=0;
|
||||
if (this.config.inOrder) n = pNode._ai;
|
||||
|
||||
for (n; n<this.aNodes.length; n++) {
|
||||
if (this.aNodes[n].pid == pNode.id) {
|
||||
|
||||
if(this.aNodes[n].pid == 0){
|
||||
this.parEnum = "";
|
||||
}
|
||||
var cn = this.aNodes[n];
|
||||
|
||||
cn._p = pNode;
|
||||
|
||||
cn._ai = n;
|
||||
|
||||
this.setCS(cn);
|
||||
|
||||
if (!cn.target && this.config.target) cn.target = this.config.target;
|
||||
|
||||
if (cn._hc && !cn._io && this.config.useCookies) cn._io = this.isOpen(cn.id);
|
||||
|
||||
if (!this.config.folderLinks && cn._hc) cn.url = null;
|
||||
|
||||
if (this.config.useSelection && cn.id == this.selectedNode && !this.selectedFound) {
|
||||
|
||||
cn._is = true;
|
||||
|
||||
this.selectedNode = n;
|
||||
|
||||
this.selectedFound = true;
|
||||
|
||||
}
|
||||
|
||||
str += this.node(cn, n);
|
||||
|
||||
if (cn._ls) break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return str;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
// Creates the node icon, url and text
|
||||
|
||||
dTree.prototype.node = function(node, nodeId) {
|
||||
//alert("nodeId = " + nodeId + " | parentId = " + node.pid + " | nodeId = " + node.id);
|
||||
var str = '<div class="dTreeNode">' + this.indent(node, nodeId);
|
||||
|
||||
if (this.config.useIcons) {
|
||||
|
||||
if (!node.icon) node.icon = (this.root.id == node.pid) ? this.icon.root : ((node._hc) ? this.icon.folder : this.icon.node);
|
||||
|
||||
if (!node.iconOpen) node.iconOpen = (node._hc) ? this.icon.folderOpen : this.icon.node;
|
||||
|
||||
if (this.root.id == node.pid) {
|
||||
|
||||
node.icon = this.icon.root;
|
||||
|
||||
node.iconOpen = this.icon.root;
|
||||
|
||||
}
|
||||
|
||||
str += '<img id="i' + this.obj + nodeId + '" src="' + ((node._io) ? node.iconOpen : node.icon) + '" alt="" />';
|
||||
|
||||
}
|
||||
|
||||
|
||||
if(this.config.useCheckBox && nodeId!=0){
|
||||
if(node.pid==0){
|
||||
this.parEnum += node.id + "-";
|
||||
}
|
||||
else{
|
||||
//alert("parEnum1 = " + this.parEnum + "node id = " + node.pid);
|
||||
var pL = this.parEnum.indexOf(node.pid+"-");
|
||||
//alert(this.parEnum.substring(0,pL+(node.pid+"-").length))
|
||||
this.parEnum = this.parEnum.substring(0,pL+(node.pid+"-").length) + node.id + "-";
|
||||
//alert("parEnum2 = " + this.parEnum);
|
||||
}
|
||||
//name='mkid',此处name的内容根据具体需要修改,add by zhangwei
|
||||
str += '<input type="checkbox" name="mkid" id="c'+this.parEnum+'"'+node.checked+' onClick="caBox(\''+this.formId+'\',\'c'+this.parEnum+'\',\'c'+node.mktype+'\')" value="' + node.id +'" class="cx"/>';
|
||||
}
|
||||
|
||||
if (node.url) {
|
||||
|
||||
str += '<a id="s' + this.obj + nodeId + '" class="' + ((this.config.useSelection) ? ((node._is ? 'nodeSel' : 'node')) : 'node') + '" href="' + node.url + '"';
|
||||
|
||||
if (node.title) str += ' title="' + node.title + '"';
|
||||
|
||||
if (node.target) str += ' target="' + node.target + '"';
|
||||
|
||||
if (this.config.useStatusText) str += ' onmouseover="window.status=\'' + node.name + '\';return true;" onmouseout="window.status=\'\';return true;" ';
|
||||
|
||||
if (this.config.useSelection && ((node._hc && this.config.folderLinks) || !node._hc))
|
||||
|
||||
str += ' onclick="javascript: ' + this.obj + '.s(' + nodeId + ');"';
|
||||
|
||||
str += '>';
|
||||
|
||||
}
|
||||
|
||||
else if ((!this.config.folderLinks || !node.url) && node._hc && node.pid != this.root.id)
|
||||
|
||||
str += '<a href="javascript: ' + this.obj + '.o(' + nodeId + ');" class="node">';
|
||||
|
||||
str += node.name;
|
||||
if (node.url || ((!this.config.folderLinks || !node.url) && node._hc)) str += '</a>';
|
||||
|
||||
str += '</div>';
|
||||
|
||||
if (node._hc) {
|
||||
|
||||
str += '<div id="d' + this.obj + nodeId + '" class="clip" style="display:' + ((this.root.id == node.pid || node._io) ? 'block' : 'none') + ';">';
|
||||
|
||||
str += this.addNode(node);
|
||||
|
||||
str += '</div>';
|
||||
|
||||
}
|
||||
|
||||
this.aIndent.pop();
|
||||
|
||||
return str;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
// Adds the empty and line icons
|
||||
|
||||
dTree.prototype.indent = function(node, nodeId) {
|
||||
|
||||
var str = '';
|
||||
|
||||
if (this.root.id != node.pid) {
|
||||
|
||||
for (var n=0; n<this.aIndent.length; n++)
|
||||
|
||||
str += '<img src="' + ( (this.aIndent[n] == 1 && this.config.useLines) ? this.icon.line : this.icon.empty ) + '" alt="" />';
|
||||
|
||||
(node._ls) ? this.aIndent.push(0) : this.aIndent.push(1);
|
||||
|
||||
if (node._hc) {
|
||||
|
||||
str += '<a href="javascript: ' + this.obj + '.o(' + nodeId + ');"><img id="j' + this.obj + nodeId + '" src="';
|
||||
|
||||
if (!this.config.useLines) str += (node._io) ? this.icon.nlMinus : this.icon.nlPlus;
|
||||
|
||||
else str += ( (node._io) ? ((node._ls && this.config.useLines) ? this.icon.minusBottom : this.icon.minus) : ((node._ls && this.config.useLines) ? this.icon.plusBottom : this.icon.plus ) );
|
||||
|
||||
str += '" alt="" /></a>';
|
||||
|
||||
} else str += '<img src="' + ( (this.config.useLines) ? ((node._ls) ? this.icon.joinBottom : this.icon.join ) : this.icon.empty) + '" alt="" />';
|
||||
|
||||
}
|
||||
|
||||
|
||||
return str;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
// Checks if a node has any children and if it is the last sibling
|
||||
|
||||
dTree.prototype.setCS = function(node) {
|
||||
|
||||
var lastId;
|
||||
|
||||
for (var n=0; n<this.aNodes.length; n++) {
|
||||
|
||||
if (this.aNodes[n].pid == node.id) node._hc = true;
|
||||
|
||||
if (this.aNodes[n].pid == node.pid) lastId = this.aNodes[n].id;
|
||||
|
||||
}
|
||||
|
||||
if (lastId==node.id) node._ls = true;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
// Returns the selected node
|
||||
|
||||
dTree.prototype.getSelected = function() {
|
||||
|
||||
var sn = this.getCookie('cs' + this.obj);
|
||||
|
||||
return (sn) ? sn : null;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
// Highlights the selected node
|
||||
|
||||
dTree.prototype.s = function(id) {
|
||||
|
||||
if (!this.config.useSelection) return;
|
||||
|
||||
var cn = this.aNodes[id];
|
||||
|
||||
if (cn._hc && !this.config.folderLinks) return;
|
||||
|
||||
if (this.selectedNode != id) {
|
||||
|
||||
if (this.selectedNode || this.selectedNode==0) {
|
||||
|
||||
eOld = document.getElementById("s" + this.obj + this.selectedNode);
|
||||
|
||||
eOld.className = "node";
|
||||
|
||||
}
|
||||
|
||||
eNew = document.getElementById("s" + this.obj + id);
|
||||
|
||||
eNew.className = "nodeSel";
|
||||
|
||||
this.selectedNode = id;
|
||||
|
||||
if (this.config.useCookies) this.setCookie('cs' + this.obj, cn.id);
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
// Toggle Open or close
|
||||
|
||||
dTree.prototype.o = function(id) {
|
||||
|
||||
var cn = this.aNodes[id];
|
||||
|
||||
this.nodeStatus(!cn._io, id, cn._ls);
|
||||
|
||||
cn._io = !cn._io;
|
||||
|
||||
if (this.config.closeSameLevel) this.closeLevel(cn);
|
||||
|
||||
if (this.config.useCookies) this.updateCookie();
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
// Open or close all nodes
|
||||
|
||||
dTree.prototype.oAll = function(status) {
|
||||
|
||||
for (var n=0; n<this.aNodes.length; n++) {
|
||||
|
||||
if (this.aNodes[n]._hc && this.aNodes[n].pid != this.root.id) {
|
||||
|
||||
this.nodeStatus(status, n, this.aNodes[n]._ls)
|
||||
|
||||
this.aNodes[n]._io = status;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (this.config.useCookies) this.updateCookie();
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
// Opens the tree to a specific node
|
||||
|
||||
dTree.prototype.openTo = function(nId, bSelect, bFirst) {
|
||||
|
||||
if (!bFirst) {
|
||||
|
||||
for (var n=0; n<this.aNodes.length; n++) {
|
||||
|
||||
if (this.aNodes[n].id == nId) {
|
||||
|
||||
nId=n;
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
var cn=this.aNodes[nId];
|
||||
|
||||
if (cn.pid==this.root.id || !cn._p) return;
|
||||
|
||||
cn._io = true;
|
||||
|
||||
cn._is = bSelect;
|
||||
|
||||
if (this.completed && cn._hc) this.nodeStatus(true, cn._ai, cn._ls);
|
||||
|
||||
if (this.completed && bSelect) this.s(cn._ai);
|
||||
|
||||
else if (bSelect) this._sn=cn._ai;
|
||||
|
||||
this.openTo(cn._p._ai, false, true);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
// Closes all nodes on the same level as certain node
|
||||
|
||||
dTree.prototype.closeLevel = function(node) {
|
||||
|
||||
for (var n=0; n<this.aNodes.length; n++) {
|
||||
|
||||
if (this.aNodes[n].pid == node.pid && this.aNodes[n].id != node.id && this.aNodes[n]._hc) {
|
||||
|
||||
this.nodeStatus(false, n, this.aNodes[n]._ls);
|
||||
|
||||
this.aNodes[n]._io = false;
|
||||
|
||||
this.closeAllChildren(this.aNodes[n]);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Closes all children of a node
|
||||
|
||||
dTree.prototype.closeAllChildren = function(node) {
|
||||
|
||||
for (var n=0; n<this.aNodes.length; n++) {
|
||||
|
||||
if (this.aNodes[n].pid == node.id && this.aNodes[n]._hc) {
|
||||
|
||||
if (this.aNodes[n]._io) this.nodeStatus(false, n, this.aNodes[n]._ls);
|
||||
|
||||
this.aNodes[n]._io = false;
|
||||
|
||||
this.closeAllChildren(this.aNodes[n]);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Change the status of a node(open or closed)
|
||||
|
||||
dTree.prototype.nodeStatus = function(status, id, bottom) {
|
||||
|
||||
eDiv = document.getElementById('d' + this.obj + id);
|
||||
|
||||
eJoin = document.getElementById('j' + this.obj + id);
|
||||
|
||||
if (this.config.useIcons) {
|
||||
|
||||
eIcon = document.getElementById('i' + this.obj + id);
|
||||
|
||||
eIcon.src = (status) ? this.aNodes[id].iconOpen : this.aNodes[id].icon;
|
||||
|
||||
}
|
||||
|
||||
eJoin.src = (this.config.useLines)?
|
||||
|
||||
((status)?((bottom)?this.icon.minusBottom:this.icon.minus):((bottom)?this.icon.plusBottom:this.icon.plus)):
|
||||
|
||||
((status)?this.icon.nlMinus:this.icon.nlPlus);
|
||||
|
||||
eDiv.style.display = (status) ? 'block': 'none';
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// [Cookie] Clears a cookie
|
||||
|
||||
dTree.prototype.clearCookie = function() {
|
||||
|
||||
var now = new Date();
|
||||
|
||||
var yesterday = new Date(now.getTime() - 1000 * 60 * 60 * 24);
|
||||
|
||||
this.setCookie('co'+this.obj, 'cookieValue', yesterday);
|
||||
|
||||
this.setCookie('cs'+this.obj, 'cookieValue', yesterday);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
// [Cookie] Sets value in a cookie
|
||||
|
||||
dTree.prototype.setCookie = function(cookieName, cookieValue, expires, path, domain, secure) {
|
||||
|
||||
document.cookie =
|
||||
|
||||
escape(cookieName) + '=' + escape(cookieValue)
|
||||
|
||||
+ (expires ? '; expires=' + expires.toGMTString() : '')
|
||||
|
||||
+ (path ? '; path=' + path : '')
|
||||
|
||||
+ (domain ? '; domain=' + domain : '')
|
||||
|
||||
+ (secure ? '; secure' : '');
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
// [Cookie] Gets a value from a cookie
|
||||
|
||||
dTree.prototype.getCookie = function(cookieName) {
|
||||
|
||||
var cookieValue = '';
|
||||
|
||||
var posName = document.cookie.indexOf(escape(cookieName) + '=');
|
||||
|
||||
if (posName != -1) {
|
||||
|
||||
var posValue = posName + (escape(cookieName) + '=').length;
|
||||
|
||||
var endPos = document.cookie.indexOf(';', posValue);
|
||||
|
||||
if (endPos != -1) cookieValue = unescape(document.cookie.substring(posValue, endPos));
|
||||
|
||||
else cookieValue = unescape(document.cookie.substring(posValue));
|
||||
|
||||
}
|
||||
|
||||
return (cookieValue);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
// [Cookie] Returns ids of open nodes as a string
|
||||
|
||||
dTree.prototype.updateCookie = function() {
|
||||
|
||||
var str = '';
|
||||
|
||||
for (var n=0; n<this.aNodes.length; n++) {
|
||||
|
||||
if (this.aNodes[n]._io && this.aNodes[n].pid != this.root.id) {
|
||||
|
||||
if (str) str += '.';
|
||||
|
||||
str += this.aNodes[n].id;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
this.setCookie('co' + this.obj, str);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
// [Cookie] Checks if a node id is in a cookie
|
||||
|
||||
dTree.prototype.isOpen = function(id) {
|
||||
|
||||
var aOpen = this.getCookie('co' + this.obj).split('.');
|
||||
|
||||
for (var n=0; n<aOpen.length; n++)
|
||||
|
||||
if (aOpen[n] == id) return true;
|
||||
|
||||
return false;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
// If Push and pop is not implemented by the browser
|
||||
|
||||
if (!Array.prototype.push) {
|
||||
|
||||
Array.prototype.push = function array_push() {
|
||||
|
||||
for(var i=0;i<arguments.length;i++)
|
||||
|
||||
this[this.length]=arguments[i];
|
||||
|
||||
return this.length;
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
if (!Array.prototype.pop) {
|
||||
|
||||
Array.prototype.pop = function array_pop() {
|
||||
|
||||
lastElement = this[this.length-1];
|
||||
|
||||
this.length = Math.max(this.length-1,0);
|
||||
|
||||
return lastElement;
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/* checkbox tree */
|
||||
function caBox(formId, regx,mktype ) {
|
||||
if( document.getElementById( regx ).checked ){
|
||||
var form = document.getElementById(formId);
|
||||
var regxArray = regx.split("-");
|
||||
var elements = document.getElementsByTagName("input");//add by zhangwei
|
||||
for (var i=0; i<elements.length; i++) {
|
||||
var element = elements[i];
|
||||
//name='mkid',此处name的内容根据具体需要修改,add by zhangwei
|
||||
if (element.name == "mkid" && element.type=='checkbox'){
|
||||
// checked next node
|
||||
if(element.id.indexOf(regx)!=-1){
|
||||
element.checked = true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// checked prev node
|
||||
for(j=0;j<regxArray.length;j++){
|
||||
var pDiv = regx.substring(0,regx.indexOf(regxArray[regxArray.length-j-1]+"-"));
|
||||
if(document.getElementById(pDiv))
|
||||
document.getElementById(pDiv).checked=true;
|
||||
}
|
||||
}
|
||||
else{
|
||||
// unChecked
|
||||
var form = document.getElementById(formId);
|
||||
var regxArray = regx.split("-");
|
||||
var elements = document.getElementsByTagName("input");//add by zhangwei
|
||||
for (var i=0; i<elements.length; i++) {
|
||||
var element = elements[i];
|
||||
//name='mkid',此处name的内容根据具体需要修改,add by zhangwei
|
||||
if (element.name == "mkid" && element.type=='checkbox'){
|
||||
// elements's all child set checked false;
|
||||
if(element.id.indexOf(regx)!=-1){
|
||||
element.checked = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// checked prev node
|
||||
// c7 8
|
||||
for(j=0;j<regxArray.length-1;j++){
|
||||
if( !isCheckedByRec(form, regx.substring(0,regx.indexOf(regxArray[regxArray.length-j-2]+"-"))) ){
|
||||
var pDiv = regx.substring(0,regx.indexOf(regxArray[regxArray.length-j-2]+"-"));
|
||||
if(document.getElementById(pDiv)&&mktype!='c1')
|
||||
document.getElementById(pDiv).checked=false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
function isCheckedByRec( form ,regx){
|
||||
//alert("isCheckedByRec = " + regx);
|
||||
var elements = document.getElementsByTagName("input");//add by zhangwei
|
||||
for (var i=0; i<elements.length; i++) {
|
||||
var element = elements[i];
|
||||
//name='mkid',此处name的内容根据具体需要修改,add by zhangwei
|
||||
if (element.name == "mkid" && element.type=='checkbox'){
|
||||
// isChecked
|
||||
if(element.id.indexOf(regx)!=-1 && element.checked && element.id!=regx ){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
//alert("c1-7-".indexOf("1-"));
|
||||
//var st = "1-3-4-";
|
||||
//alert(st.split("-").length);
|
||||
///alert(st.split("-")[2]);
|
||||
//alert( st.lastIndexOf("-", st.lastIndexOf("-")) );
|
||||
782
WebRoot/dtree/js/dtree_checkbox_new.js
Normal file
@@ -0,0 +1,782 @@
|
||||
/*--------------------------------------------------|
|
||||
|
||||
| dTree 2.05 | www.destroydrop.com/javascript/tree/ |
|
||||
|
||||
|---------------------------------------------------|
|
||||
|
||||
| Copyright (c) 2002-2003 Geir Landr? |
|
||||
|
||||
| |
|
||||
|
||||
| This script can be used freely as long as all |
|
||||
|
||||
| copyright messages are intact. |
|
||||
|
||||
| |
|
||||
|
||||
| Updated: 17.04.2003 |
|
||||
|
||||
|--------------------------------------------------*/
|
||||
|
||||
|
||||
|
||||
// Node object
|
||||
|
||||
function Node(id, pid, name, checked ,url, title, target, icon, iconOpen, open) {
|
||||
|
||||
this.id = id;
|
||||
|
||||
this.pid = pid;
|
||||
|
||||
this.name = name;
|
||||
|
||||
this.url = url;
|
||||
|
||||
this.title = title;
|
||||
|
||||
this.target = target;
|
||||
|
||||
this.icon = icon;
|
||||
|
||||
this.iconOpen = iconOpen;
|
||||
|
||||
this._io = open || false;
|
||||
|
||||
this._is = false;
|
||||
|
||||
this._ls = false;
|
||||
|
||||
this._hc = false;
|
||||
|
||||
this._ai = 0;
|
||||
|
||||
this._p;
|
||||
this.checked = checked;//add by zhangwei
|
||||
};
|
||||
|
||||
// Tree object
|
||||
|
||||
function dTree(objName, iPath, formId) {
|
||||
this.config = {
|
||||
|
||||
target : null,
|
||||
|
||||
folderLinks : true,
|
||||
|
||||
useSelection : true,
|
||||
|
||||
useCookies : true,
|
||||
|
||||
useLines : true,
|
||||
|
||||
useIcons : false,
|
||||
useCheckBox : true,
|
||||
|
||||
useStatusText : false,
|
||||
|
||||
closeSameLevel : false,
|
||||
|
||||
inOrder : false
|
||||
|
||||
}
|
||||
|
||||
this.icon = {
|
||||
|
||||
root : '../images/base.gif',
|
||||
|
||||
folder : '../images/folder.gif',
|
||||
|
||||
folderOpen : '../images/folderopen.gif',
|
||||
|
||||
node : '../images/page.gif',
|
||||
|
||||
empty : '../images/empty.gif',
|
||||
|
||||
line : '../images/line.gif',
|
||||
|
||||
join : '../images/join.gif',
|
||||
|
||||
joinBottom : '../images/joinbottom.gif',
|
||||
|
||||
plus : '../images/plus.gif',
|
||||
|
||||
plusBottom : '../images/plusbottom.gif',
|
||||
|
||||
minus : '../images/minus.gif',
|
||||
|
||||
minusBottom : '../images/minusbottom.gif',
|
||||
|
||||
nlPlus : '../images/nolines_plus.gif',
|
||||
|
||||
nlMinus : '../images/nolines_minus.gif'
|
||||
};
|
||||
this.parEnum = "";
|
||||
|
||||
this.obj = objName;
|
||||
|
||||
this.aNodes = [];
|
||||
|
||||
this.aIndent = [];
|
||||
|
||||
this.root = new Node(-1);
|
||||
|
||||
this.selectedNode = null;
|
||||
|
||||
this.selectedFound = false;
|
||||
|
||||
this.completed = false;
|
||||
|
||||
this.formId = (formId==null)?"dTreeForm":formId;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
// Adds a new node to the node array
|
||||
|
||||
dTree.prototype.add = function(id, pid, name, checked, url, title, target, icon, iconOpen, open) {
|
||||
this.aNodes[this.aNodes.length] = new Node(id, pid, name, checked, url, title, target, icon, iconOpen, open);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
// Open/close all nodes
|
||||
|
||||
dTree.prototype.openAll = function() {
|
||||
|
||||
this.oAll(true);
|
||||
|
||||
};
|
||||
|
||||
dTree.prototype.closeAll = function() {
|
||||
|
||||
this.oAll(false);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
// Outputs the tree to the page
|
||||
|
||||
dTree.prototype.toString = function() {
|
||||
|
||||
var str = '<div class="dtree"><form id="'+this.formId+'">\n';
|
||||
|
||||
if (document.getElementById) {
|
||||
|
||||
if (this.config.useCookies) this.selectedNode = this.getSelected();
|
||||
|
||||
str += this.addNode(this.root);
|
||||
|
||||
} else str += 'Browser not supported.';
|
||||
|
||||
str += '</form></div>';
|
||||
//document.getElementById("test").value = str;
|
||||
//alert(str);
|
||||
if (!this.selectedFound) this.selectedNode = null;
|
||||
|
||||
this.completed = true;
|
||||
|
||||
return str;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
// Creates the tree structure
|
||||
|
||||
dTree.prototype.addNode = function(pNode) {
|
||||
|
||||
var str = '';
|
||||
|
||||
var n=0;
|
||||
if (this.config.inOrder) n = pNode._ai;
|
||||
|
||||
for (n; n<this.aNodes.length; n++) {
|
||||
if (this.aNodes[n].pid == pNode.id) {
|
||||
|
||||
if(this.aNodes[n].pid == 0){
|
||||
this.parEnum = "";
|
||||
}
|
||||
var cn = this.aNodes[n];
|
||||
|
||||
cn._p = pNode;
|
||||
|
||||
cn._ai = n;
|
||||
|
||||
this.setCS(cn);
|
||||
|
||||
if (!cn.target && this.config.target) cn.target = this.config.target;
|
||||
|
||||
if (cn._hc && !cn._io && this.config.useCookies) cn._io = this.isOpen(cn.id);
|
||||
|
||||
if (!this.config.folderLinks && cn._hc) cn.url = null;
|
||||
|
||||
if (this.config.useSelection && cn.id == this.selectedNode && !this.selectedFound) {
|
||||
|
||||
cn._is = true;
|
||||
|
||||
this.selectedNode = n;
|
||||
|
||||
this.selectedFound = true;
|
||||
|
||||
}
|
||||
|
||||
str += this.node(cn, n);
|
||||
|
||||
if (cn._ls) break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return str;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
// Creates the node icon, url and text
|
||||
|
||||
dTree.prototype.node = function(node, nodeId) {
|
||||
//alert("nodeId = " + nodeId + " | parentId = " + node.pid + " | nodeId = " + node.id);
|
||||
var str = '<div class="dTreeNode">' + this.indent(node, nodeId);
|
||||
|
||||
if (this.config.useIcons) {
|
||||
|
||||
if (!node.icon) node.icon = (this.root.id == node.pid) ? this.icon.root : ((node._hc) ? this.icon.folder : this.icon.node);
|
||||
|
||||
if (!node.iconOpen) node.iconOpen = (node._hc) ? this.icon.folderOpen : this.icon.node;
|
||||
|
||||
if (this.root.id == node.pid) {
|
||||
|
||||
node.icon = this.icon.root;
|
||||
|
||||
node.iconOpen = this.icon.root;
|
||||
|
||||
}
|
||||
|
||||
str += '<img id="i' + this.obj + nodeId + '" src="' + ((node._io) ? node.iconOpen : node.icon) + '" alt="" />';
|
||||
|
||||
}
|
||||
|
||||
|
||||
if(this.config.useCheckBox && nodeId!=0){
|
||||
if(node.pid==0){
|
||||
this.parEnum += node.id + "-";
|
||||
}
|
||||
else{
|
||||
//alert("parEnum1 = " + this.parEnum + "node id = " + node.pid);
|
||||
var pL = this.parEnum.indexOf(node.pid+"-");
|
||||
//alert(this.parEnum.substring(0,pL+(node.pid+"-").length))
|
||||
this.parEnum = this.parEnum.substring(0,pL+(node.pid+"-").length) + node.id + "-";
|
||||
//alert("parEnum2 = " + this.parEnum);
|
||||
}
|
||||
//name='mkid',此处name的内容根据具体需要修改,add by zhangwei
|
||||
str += '<input type="checkbox" name="mkid" id="c'+this.parEnum+'"'+node.checked+' onClick="caBox(\''+this.formId+'\',\'c'+this.parEnum+'\');getparentMk(\''+node.id+","+node.name+","+node.pid+'\');" value="' + node.id +'" class="cx"/>';
|
||||
}
|
||||
|
||||
if (node.url) {
|
||||
|
||||
str += '<a id="s' + this.obj + nodeId + '" class="' + ((this.config.useSelection) ? ((node._is ? 'nodeSel' : 'node')) : 'node') + '" href="' + node.url + '"';
|
||||
|
||||
if (node.title) str += ' title="' + node.title + '"';
|
||||
|
||||
if (node.target) str += ' target="' + node.target + '"';
|
||||
|
||||
if (this.config.useStatusText) str += ' onmouseover="window.status=\'' + node.name + '\';return true;" onmouseout="window.status=\'\';return true;" ';
|
||||
|
||||
if (this.config.useSelection && ((node._hc && this.config.folderLinks) || !node._hc))
|
||||
|
||||
str += ' onclick="javascript: ' + this.obj + '.s(' + nodeId + ');"';
|
||||
|
||||
str += '>';
|
||||
|
||||
}
|
||||
|
||||
else if ((!this.config.folderLinks || !node.url) && node._hc && node.pid != this.root.id)
|
||||
|
||||
str += '<a href="javascript: ' + this.obj + '.o(' + nodeId + ');" class="node">';
|
||||
|
||||
str += node.name;
|
||||
if (node.url || ((!this.config.folderLinks || !node.url) && node._hc)) str += '</a>';
|
||||
|
||||
str += '</div>';
|
||||
|
||||
if (node._hc) {
|
||||
|
||||
str += '<div id="d' + this.obj + nodeId + '" class="clip" style="display:' + ((this.root.id == node.pid || node._io) ? 'block' : 'none') + ';">';
|
||||
|
||||
str += this.addNode(node);
|
||||
|
||||
str += '</div>';
|
||||
|
||||
}
|
||||
|
||||
this.aIndent.pop();
|
||||
|
||||
return str;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
// Adds the empty and line icons
|
||||
|
||||
dTree.prototype.indent = function(node, nodeId) {
|
||||
|
||||
var str = '';
|
||||
|
||||
if (this.root.id != node.pid) {
|
||||
|
||||
for (var n=0; n<this.aIndent.length; n++)
|
||||
|
||||
str += '<img src="' + ( (this.aIndent[n] == 1 && this.config.useLines) ? this.icon.line : this.icon.empty ) + '" alt="" />';
|
||||
|
||||
(node._ls) ? this.aIndent.push(0) : this.aIndent.push(1);
|
||||
|
||||
if (node._hc) {
|
||||
|
||||
str += '<a href="javascript: ' + this.obj + '.o(' + nodeId + ');"><img id="j' + this.obj + nodeId + '" src="';
|
||||
|
||||
if (!this.config.useLines) str += (node._io) ? this.icon.nlMinus : this.icon.nlPlus;
|
||||
|
||||
else str += ( (node._io) ? ((node._ls && this.config.useLines) ? this.icon.minusBottom : this.icon.minus) : ((node._ls && this.config.useLines) ? this.icon.plusBottom : this.icon.plus ) );
|
||||
|
||||
str += '" alt="" /></a>';
|
||||
|
||||
} else str += '<img src="' + ( (this.config.useLines) ? ((node._ls) ? this.icon.joinBottom : this.icon.join ) : this.icon.empty) + '" alt="" />';
|
||||
|
||||
}
|
||||
|
||||
|
||||
return str;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
// Checks if a node has any children and if it is the last sibling
|
||||
|
||||
dTree.prototype.setCS = function(node) {
|
||||
|
||||
var lastId;
|
||||
|
||||
for (var n=0; n<this.aNodes.length; n++) {
|
||||
|
||||
if (this.aNodes[n].pid == node.id) node._hc = true;
|
||||
|
||||
if (this.aNodes[n].pid == node.pid) lastId = this.aNodes[n].id;
|
||||
|
||||
}
|
||||
|
||||
if (lastId==node.id) node._ls = true;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
// Returns the selected node
|
||||
|
||||
dTree.prototype.getSelected = function() {
|
||||
|
||||
var sn = this.getCookie('cs' + this.obj);
|
||||
|
||||
return (sn) ? sn : null;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
// Highlights the selected node
|
||||
|
||||
dTree.prototype.s = function(id) {
|
||||
|
||||
if (!this.config.useSelection) return;
|
||||
|
||||
var cn = this.aNodes[id];
|
||||
|
||||
if (cn._hc && !this.config.folderLinks) return;
|
||||
|
||||
if (this.selectedNode != id) {
|
||||
|
||||
if (this.selectedNode || this.selectedNode==0) {
|
||||
|
||||
eOld = document.getElementById("s" + this.obj + this.selectedNode);
|
||||
|
||||
eOld.className = "node";
|
||||
|
||||
}
|
||||
|
||||
eNew = document.getElementById("s" + this.obj + id);
|
||||
|
||||
eNew.className = "nodeSel";
|
||||
|
||||
this.selectedNode = id;
|
||||
|
||||
if (this.config.useCookies) this.setCookie('cs' + this.obj, cn.id);
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
// Toggle Open or close
|
||||
|
||||
dTree.prototype.o = function(id) {
|
||||
|
||||
var cn = this.aNodes[id];
|
||||
|
||||
this.nodeStatus(!cn._io, id, cn._ls);
|
||||
|
||||
cn._io = !cn._io;
|
||||
|
||||
if (this.config.closeSameLevel) this.closeLevel(cn);
|
||||
|
||||
if (this.config.useCookies) this.updateCookie();
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
// Open or close all nodes
|
||||
|
||||
dTree.prototype.oAll = function(status) {
|
||||
|
||||
for (var n=0; n<this.aNodes.length; n++) {
|
||||
|
||||
if (this.aNodes[n]._hc && this.aNodes[n].pid != this.root.id) {
|
||||
|
||||
this.nodeStatus(status, n, this.aNodes[n]._ls)
|
||||
|
||||
this.aNodes[n]._io = status;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (this.config.useCookies) this.updateCookie();
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
// Opens the tree to a specific node
|
||||
|
||||
dTree.prototype.openTo = function(nId, bSelect, bFirst) {
|
||||
|
||||
if (!bFirst) {
|
||||
|
||||
for (var n=0; n<this.aNodes.length; n++) {
|
||||
|
||||
if (this.aNodes[n].id == nId) {
|
||||
|
||||
nId=n;
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
var cn=this.aNodes[nId];
|
||||
|
||||
if (cn.pid==this.root.id || !cn._p) return;
|
||||
|
||||
cn._io = true;
|
||||
|
||||
cn._is = bSelect;
|
||||
|
||||
if (this.completed && cn._hc) this.nodeStatus(true, cn._ai, cn._ls);
|
||||
|
||||
if (this.completed && bSelect) this.s(cn._ai);
|
||||
|
||||
else if (bSelect) this._sn=cn._ai;
|
||||
|
||||
this.openTo(cn._p._ai, false, true);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
// Closes all nodes on the same level as certain node
|
||||
|
||||
dTree.prototype.closeLevel = function(node) {
|
||||
|
||||
for (var n=0; n<this.aNodes.length; n++) {
|
||||
|
||||
if (this.aNodes[n].pid == node.pid && this.aNodes[n].id != node.id && this.aNodes[n]._hc) {
|
||||
|
||||
this.nodeStatus(false, n, this.aNodes[n]._ls);
|
||||
|
||||
this.aNodes[n]._io = false;
|
||||
|
||||
this.closeAllChildren(this.aNodes[n]);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Closes all children of a node
|
||||
|
||||
dTree.prototype.closeAllChildren = function(node) {
|
||||
|
||||
for (var n=0; n<this.aNodes.length; n++) {
|
||||
|
||||
if (this.aNodes[n].pid == node.id && this.aNodes[n]._hc) {
|
||||
|
||||
if (this.aNodes[n]._io) this.nodeStatus(false, n, this.aNodes[n]._ls);
|
||||
|
||||
this.aNodes[n]._io = false;
|
||||
|
||||
this.closeAllChildren(this.aNodes[n]);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Change the status of a node(open or closed)
|
||||
|
||||
dTree.prototype.nodeStatus = function(status, id, bottom) {
|
||||
|
||||
eDiv = document.getElementById('d' + this.obj + id);
|
||||
|
||||
eJoin = document.getElementById('j' + this.obj + id);
|
||||
|
||||
if (this.config.useIcons) {
|
||||
|
||||
eIcon = document.getElementById('i' + this.obj + id);
|
||||
|
||||
eIcon.src = (status) ? this.aNodes[id].iconOpen : this.aNodes[id].icon;
|
||||
|
||||
}
|
||||
|
||||
eJoin.src = (this.config.useLines)?
|
||||
|
||||
((status)?((bottom)?this.icon.minusBottom:this.icon.minus):((bottom)?this.icon.plusBottom:this.icon.plus)):
|
||||
|
||||
((status)?this.icon.nlMinus:this.icon.nlPlus);
|
||||
|
||||
eDiv.style.display = (status) ? 'block': 'none';
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// [Cookie] Clears a cookie
|
||||
|
||||
dTree.prototype.clearCookie = function() {
|
||||
|
||||
var now = new Date();
|
||||
|
||||
var yesterday = new Date(now.getTime() - 1000 * 60 * 60 * 24);
|
||||
|
||||
this.setCookie('co'+this.obj, 'cookieValue', yesterday);
|
||||
|
||||
this.setCookie('cs'+this.obj, 'cookieValue', yesterday);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
// [Cookie] Sets value in a cookie
|
||||
|
||||
dTree.prototype.setCookie = function(cookieName, cookieValue, expires, path, domain, secure) {
|
||||
|
||||
document.cookie =
|
||||
|
||||
escape(cookieName) + '=' + escape(cookieValue)
|
||||
|
||||
+ (expires ? '; expires=' + expires.toGMTString() : '')
|
||||
|
||||
+ (path ? '; path=' + path : '')
|
||||
|
||||
+ (domain ? '; domain=' + domain : '')
|
||||
|
||||
+ (secure ? '; secure' : '');
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
// [Cookie] Gets a value from a cookie
|
||||
|
||||
dTree.prototype.getCookie = function(cookieName) {
|
||||
|
||||
var cookieValue = '';
|
||||
|
||||
var posName = document.cookie.indexOf(escape(cookieName) + '=');
|
||||
|
||||
if (posName != -1) {
|
||||
|
||||
var posValue = posName + (escape(cookieName) + '=').length;
|
||||
|
||||
var endPos = document.cookie.indexOf(';', posValue);
|
||||
|
||||
if (endPos != -1) cookieValue = unescape(document.cookie.substring(posValue, endPos));
|
||||
|
||||
else cookieValue = unescape(document.cookie.substring(posValue));
|
||||
|
||||
}
|
||||
|
||||
return (cookieValue);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
// [Cookie] Returns ids of open nodes as a string
|
||||
|
||||
dTree.prototype.updateCookie = function() {
|
||||
|
||||
var str = '';
|
||||
|
||||
for (var n=0; n<this.aNodes.length; n++) {
|
||||
|
||||
if (this.aNodes[n]._io && this.aNodes[n].pid != this.root.id) {
|
||||
|
||||
if (str) str += '.';
|
||||
|
||||
str += this.aNodes[n].id;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
this.setCookie('co' + this.obj, str);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
// [Cookie] Checks if a node id is in a cookie
|
||||
|
||||
dTree.prototype.isOpen = function(id) {
|
||||
|
||||
var aOpen = this.getCookie('co' + this.obj).split('.');
|
||||
|
||||
for (var n=0; n<aOpen.length; n++)
|
||||
|
||||
if (aOpen[n] == id) return true;
|
||||
|
||||
return false;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
// If Push and pop is not implemented by the browser
|
||||
|
||||
if (!Array.prototype.push) {
|
||||
|
||||
Array.prototype.push = function array_push() {
|
||||
|
||||
for(var i=0;i<arguments.length;i++)
|
||||
|
||||
this[this.length]=arguments[i];
|
||||
|
||||
return this.length;
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
if (!Array.prototype.pop) {
|
||||
|
||||
Array.prototype.pop = function array_pop() {
|
||||
|
||||
lastElement = this[this.length-1];
|
||||
|
||||
this.length = Math.max(this.length-1,0);
|
||||
|
||||
return lastElement;
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/* checkbox tree */
|
||||
function caBox(formId, regx ) {
|
||||
if( document.getElementById( regx ).checked ){
|
||||
var form = document.getElementById(formId);
|
||||
var regxArray = regx.split("-");
|
||||
var elements = document.getElementsByTagName("input");//add by zhangwei
|
||||
for (var i=0; i<elements.length; i++) {
|
||||
var element = elements[i];
|
||||
//name='mkid',此处name的内容根据具体需要修改,add by zhangwei
|
||||
if (element.name == "mkid" && element.type=='checkbox'){
|
||||
// checked next node
|
||||
element.checked = false;
|
||||
}
|
||||
}
|
||||
|
||||
// checked prev node
|
||||
for(j=0;j<regxArray.length;j++){
|
||||
var pDiv = regx.substring(0,regx.indexOf(regxArray[regxArray.length-j-1]+"-"));
|
||||
if(document.getElementById(pDiv))
|
||||
document.getElementById(pDiv).checked=false;
|
||||
}
|
||||
}
|
||||
else{
|
||||
// unChecked
|
||||
var form = document.getElementById(formId);
|
||||
var regxArray = regx.split("-");
|
||||
var elements = document.getElementsByTagName("input");//add by zhangwei
|
||||
for (var i=0; i<elements.length; i++) {
|
||||
var element = elements[i];
|
||||
//name='mkid',此处name的内容根据具体需要修改,add by zhangwei
|
||||
if (element.name == "mkid" && element.type=='checkbox'){
|
||||
// elements's all child set checked false;
|
||||
if(element.id.indexOf(regx)!=-1){
|
||||
element.checked = false; }
|
||||
}
|
||||
}
|
||||
|
||||
// checked prev node
|
||||
// c7 8
|
||||
for(j=0;j<regxArray.length-1;j++){
|
||||
if( !isCheckedByRec(form, regx.substring(0,regx.indexOf(regxArray[regxArray.length-j-2]+"-"))) ){
|
||||
var pDiv = regx.substring(0,regx.indexOf(regxArray[regxArray.length-j-2]+"-"));
|
||||
if(document.getElementById(pDiv))
|
||||
document.getElementById(pDiv).checked=false;
|
||||
}
|
||||
}
|
||||
}
|
||||
document.getElementById(regx).checked= true;
|
||||
}
|
||||
|
||||
|
||||
function isCheckedByRec( form ,regx){
|
||||
//alert("isCheckedByRec = " + regx);
|
||||
var elements = document.getElementsByTagName("input");//add by zhangwei
|
||||
for (var i=0; i<elements.length; i++) {
|
||||
var element = elements[i];
|
||||
//name='mkid',此处name的内容根据具体需要修改,add by zhangwei
|
||||
if (element.name == "mkid" && element.type=='checkbox'){
|
||||
// isChecked
|
||||
if(element.id.indexOf(regx)!=-1 && element.checked && element.id!=regx ){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
//alert("c1-7-".indexOf("1-"));
|
||||
//var st = "1-3-4-";
|
||||
//alert(st.split("-").length);
|
||||
///alert(st.split("-")[2]);
|
||||
//alert( st.lastIndexOf("-", st.lastIndexOf("-")) );
|
||||