⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 webfxtreeitem.jsc

📁 管理公司合同
💻 JSC
字号:
# language: JSVM2

/**
 * @fileoverview com.eae.webfx.xtree.WebFXTreeItem class {@link http://jsvm.homolo.com/}
 * @file		WebFXTreeItem.jsc
 * @author	Emil A Eklund
 * @Modifier: Changhua Wan
 * @version	1.1, 07/01/05
 */

package com.eae.webfx.xtree;

import js.lang.StringBuffer;

import com.eae.webfx.xtree.WebFXTreeConfig;
import com.eae.webfx.xtree.WebFXTreeHandler;
import com.eae.webfx.xtree.WebFXTreeAbstractNode;

/**
 * Create a new WebFXLoadTreeItem instance.
 * Inherit from WebFXTreeAbstractNode
 * @author	Emil A Eklund (Modified by Wan Changhua)
 * @version	1.1, 07/01/05
 * @extends WebFXTreeAbstractNode
 * @class This is the webfx tree item class.  
 * @constructor
 * @param {String} sText
 * @param {String} sAction
 * @param {String} eParent
 * @param {String} sIcon
 * @param {String} sOpenIcon
 * @param {String} sRadio
 * @param {String} sCheckBox
 * @param {String} sValue
 * @param {String} sChecked
 * @return A new WebFXTreeItem object
 */

class WebFXTreeItem extends WebFXTreeAbstractNode (sText, sAction, eParent, sIcon, sOpenIcon,sRadio,sCheckBox,sValue,sChecked)
{
	//this.base = WebFXTreeAbstractNode;
	//this.base(sText, sAction);
	super.call(this, sText, sAction);

	this.radio = sRadio;
	this.checkbox = sCheckBox;
	this.value = sValue;
	this.checked = sChecked;

	/* Defaults to close */
	if (WebFXTreeConfig.usePersistence) {
		this.open = (WebFXTreeHandler.cookies.getValue(this.id.substr(18,this.id.length - 18)) == '1')?true:false;
	} else { this.open = false; }
	if (sIcon) { this.icon = sIcon; }
	if (sOpenIcon) { this.openIcon = sOpenIcon; }
	if (eParent) { eParent.add(this); }
}

//WebFXTreeItem.prototype = new WebFXTreeAbstractNode;

/**
 * Removes self from parent node
 */
WebFXTreeItem.prototype.remove = function()
{
	var iconSrc = document.getElementById(this.id + '-plus').src;
	var parentNode = this.parentNode;
	var prevSibling = this.getPreviousSibling(true);
	var nextSibling = this.getNextSibling(true);
	var folder = this.parentNode.folder;
	var last = ((nextSibling) && (nextSibling.parentNode) && (nextSibling.parentNode.id == parentNode.id))?false:true;
	this.getPreviousSibling().focus();
	this._remove();
	if (parentNode.childNodes.length == 0) {
		document.getElementById(parentNode.id + '-cont').style.display = 'none';
		parentNode.doCollapse();
		parentNode.folder = false;
		parentNode.open = false;
	}
	if (!nextSibling || last) { parentNode.indent(null, true, last, this._level, parentNode.childNodes.length); }
	if ((prevSibling == parentNode) && !(parentNode.childNodes.length)) {
		prevSibling.folder = false;
		prevSibling.open = false;
		iconSrc = document.getElementById(prevSibling.id + '-plus').src;
		iconSrc = iconSrc.replace('minus', '').replace('plus', '');
		document.getElementById(prevSibling.id + '-plus').src = iconSrc;
		document.getElementById(prevSibling.id + '-icon').src = WebFXTreeConfig.fileIcon;
	}
	if (document.getElementById(prevSibling.id + '-plus')) {
		if (parentNode == prevSibling.parentNode) {
			iconSrc = iconSrc.replace('minus', '').replace('plus', '');
			document.getElementById(prevSibling.id + '-plus').src = iconSrc;
}	}	}

/**
 * @private
 */
WebFXTreeItem.prototype._remove = function() {
	for (var i = this.childNodes.length - 1; i >= 0; i--) {
		this.childNodes[i]._remove();
 	}
	for (var i = 0; i < this.parentNode.childNodes.length; i++) {
		if (this == this.parentNode.childNodes[i]) {
			for (var j = i; j < this.parentNode.childNodes.length; j++) {
				this.parentNode.childNodes[j] = this.parentNode.childNodes[j+1];
			}
			this.parentNode.childNodes.length -= 1;
			if (i + 1 == this.parentNode.childNodes.length) { this.parentNode._last = true; }
			break;
	}	}
	WebFXTreeHandler.all[this.id] = null;
	var tmp = document.getElementById(this.id);
	if (tmp) { tmp.parentNode.removeChild(tmp); }
	tmp = document.getElementById(this.id + '-cont');
	if (tmp) { tmp.parentNode.removeChild(tmp); }
}

/**
 * Expands self.
 */
WebFXTreeItem.prototype.expand = function() {
	this.doExpand();
	document.getElementById(this.id + '-plus').src = this.minusIcon;
}

/**
 * Collapses self.
 */
WebFXTreeItem.prototype.collapse = function(b) {
	if (!b) { this.focus(); }
	this.doCollapse();
	document.getElementById(this.id + '-plus').src = this.plusIcon;
}

/**
 * The first child of this node. If there is no such node, this returns 
 * <code>null</code>.
 */
WebFXTreeItem.prototype.getFirst = function() {
	return this.childNodes[0];
}

/**
 * The last child of this node. If there is no such node, this returns 
 * <code>null</code>.
 */
WebFXTreeItem.prototype.getLast = function() {
	if (this.childNodes[this.childNodes.length - 1].open) { return this.childNodes[this.childNodes.length - 1].getLast(); }
	else { return this.childNodes[this.childNodes.length - 1]; }
}

/**
 * The node immediately following this node. If there is no such node, 
 * this returns <code>null</code>.
 */
WebFXTreeItem.prototype.getNextSibling = function() {
	for (var i = 0; i < this.parentNode.childNodes.length; i++) {
		if (this == this.parentNode.childNodes[i]) { break; }
	}
	if (++i == this.parentNode.childNodes.length) { return this.parentNode.getNextSibling(); }
	else { return this.parentNode.childNodes[i]; }
}


/**
 * The node immediately preceding this node. If there is no such node, 
 * this returns <code>null</code>.
 */
WebFXTreeItem.prototype.getPreviousSibling = function(b) {
	for (var i = 0; i < this.parentNode.childNodes.length; i++) {
		if (this == this.parentNode.childNodes[i]) { break; }
	}
	if (i == 0) { return this.parentNode; }
	else {
		if ((this.parentNode.childNodes[--i].open) || (b && this.parentNode.childNodes[i].folder)) { return this.parentNode.childNodes[i].getLast(); }
		else { return this.parentNode.childNodes[i]; }
} }


/**
 * Disposes the keydown event.
 * @private
 */
WebFXTreeItem.prototype.keydown = function(key)
{
	if ((key == 39) && (this.folder)) {
		if (!this.open) { this.expand(); }
		else { this.getFirst().select(); }
		return false;
	}
	else if (key == 37) {
		if (this.open) { this.collapse(); }
		else { this.parentNode.select(); }
		return false;
	}
	else if (key == 40) {
		if (this.open) { this.getFirst().select(); }
		else {
			var sib = this.getNextSibling();
			if (sib) { sib.select(); }
		}
		return false;
	}
	else if (key == 38) { this.getPreviousSibling().select(); return false; }
	return true;
}

/**
 * Returns a string representation of the object.
 * @returns  a html string of the object.
 * @type String
 */
WebFXTreeItem.prototype.toString = function (nItem, nItemCount)
{
	var foo = this.parentNode;
	var indent = '';
	if (nItem + 1 == nItemCount) { this.parentNode._last = true; }
	var i = 0;

	while (foo.parentNode) {
		foo = foo.parentNode;
		indent = "<img id=\"" + this.id + "-indent-" + i + "\" src=\"" + ((foo._last)?WebFXTreeConfig.blankIcon:WebFXTreeConfig.iIcon) + "\">" + indent;
		i++;
	}

	this._level = i;
	if (this.childNodes.length) { this.folder = 1; }
	else { this.open = false; }
	if ((this.folder) || (WebFXTreeHandler.behavior != 'classic')) {
		if (!this.icon) { this.icon = WebFXTreeConfig.folderIcon; }
		if (!this.openIcon) { this.openIcon = WebFXTreeConfig.openFolderIcon; }
	}
	else if (!this.icon) { this.icon = WebFXTreeConfig.fileIcon; }
	//var label = this.text.replace(/</g, '&lt;').replace(/>/g, '&gt;');
	var label = this.text;
	var sb = new StringBuffer();
	sb.append("<div id=\"" + this.id + "\" ondblclick=\"com.eae.webfx.xtree.WebFXTreeHandler.toggle(this);\" class=\"webfx-tree-item\" onkeydown=\"return com.eae.webfx.xtree.WebFXTreeHandler.keydown(this, event)\">" +
		indent +
		"<img id=\"" + this.id + "-plus\" src=\"" + ((this.folder)?((this.open)?((this.parentNode._last)?WebFXTreeConfig.lMinusIcon:WebFXTreeConfig.tMinusIcon):((this.parentNode._last)?WebFXTreeConfig.lPlusIcon:WebFXTreeConfig.tPlusIcon)):((this.parentNode._last)?WebFXTreeConfig.lIcon:WebFXTreeConfig.tIcon)) + "\" onclick=\"com.eae.webfx.xtree.WebFXTreeHandler.toggle(this);\">" +
		"<img id=\"" + this.id + "-icon\" class=\"webfx-tree-icon\" src=\"" + ((WebFXTreeHandler.behavior == 'classic' && this.open)?this.openIcon:this.icon) + "\" onclick=\"com.eae.webfx.xtree.WebFXTreeHandler.select(this);\">");
	var svalue = this.value;
	var selectedstr = "";
	if(svalue==null){
		svalue=this.text;
	}

	if(this.radio=="Y"||this.radion=="y"||this.radio=="true"){
		sb.append("<input type=\"Radio\" id=\"" +  this.id + "-radio\" oid=\"" + this.id + "\" name=\"" + WebFXTreeConfig.elementPrefix + "selRadioObj\" value=\""+svalue+"\" "); //"+selectedstr+"
		sb.append("onclick=\"com.eae.webfx.xtree.WebFXTreeHandler.check(arguments[0]);\" >");
	}else if(this.checkbox=="Y"||this.checkbox=="y"||this.checkbox=="true"){
		if(this.checked=="Y"||this.checked=="y"||this.checked=="true"){
			selectedstr="checked";
		}
		sb.append("<input type=\"Checkbox\" id=\"" +  this.id + "-check\" oid=\"" + this.id + "\" name=\"" + WebFXTreeConfig.elementPrefix + "selCheckObj\" value=\""+svalue+"\" "+selectedstr+" ");
		sb.append("onclick=\"com.eae.webfx.xtree.WebFXTreeHandler.check(arguments[0]);\" >");
	}
	var isScript = (this.action.indexOf("javascript:") == 0);
	var hrefstr = isScript ? "#" : this.action;
	var clickstr = isScript ? (this.action.substring(11) + ";return false;") : "";
	sb.append("<a href=\"" + hrefstr + "\" id=\"" + this.id + "-anchor\" oid=\"" + this.id + "\" onfocus=\"com.eae.webfx.xtree.WebFXTreeHandler.focus(this);\" onblur=\"com.eae.webfx.xtree.WebFXTreeHandler.blur(this);\"" +
		(this.target ? " target=\"" + this.target + "\"" : "") +
		" onclick=\"" + clickstr + "\"" +
		">" + label + "</a></div>" +
		"<div id=\"" + this.id + "-cont\" class=\"webfx-tree-container\" style=\"display: " + ((this.open)?'block':'none') + ";\">");
	for (var i = 0; i < this.childNodes.length; i++) {
		sb.append(this.childNodes[i].toString(i,this.childNodes.length));
	}
	this.plusIcon = ((this.parentNode._last)?WebFXTreeConfig.lPlusIcon:WebFXTreeConfig.tPlusIcon);
	this.minusIcon = ((this.parentNode._last)?WebFXTreeConfig.lMinusIcon:WebFXTreeConfig.tMinusIcon);
	//if(this.text=="1.3.1.1")
	//	alert(str + sb.join("") + "</div>");
	sb.append("</div>");
	return sb.toString();
}


// added by wanchanghua (05-12-01)
WebFXTreeItem.prototype.isChecked = function (bChecked)
{
	var elm = document.getElementById(this.id + "-radio") || 
		document.getElementById(this.id + "-check");
	return (elm != null)? elm.checked : null;
}

// added by wanchanghua (05-12-01)
WebFXTreeItem.prototype.check = function (bChecked)
{
	if (bChecked == null)
	{
		bChecked = true;
	}
	var elm = document.getElementById(this.id + "-radio") || 
		document.getElementById(this.id + "-check");
	if (elm != null)
	{
		elm.checked = bChecked;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -