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

📄 tree.js

📁 ZK 基础介绍 功能操作 模块 结合数据库操作
💻 JS
📖 第 1 页 / 共 2 页
字号:
/* tree.js{{IS_NOTE	Purpose:			Description:			History:		Fri Jul  8 12:57:05     2005, Created by tomyeh}}IS_NOTECopyright (C) 2005 Potix Corporation. All Rights Reserved.{{IS_RIGHT	This program is distributed under GPL Version 2.0 in the hope that	it will be useful, but WITHOUT ANY WARRANTY.}}IS_RIGHT*/zk.load("zul.sel");//////Customization/** Returns HTML for the pagination. * * @param row the parent treerow owns this paging * @param pgc # of pages * @param pgi the active page * @param end whether it is the end pagination or the begin pagination */if (!window.Tree_paging) { //not customized	window.Tree_paging = function (row, pgc, pgi, pgsz, end) {		var html = "";		if (end) {			html += zkTrow._genimg("dn", "zkTrow._onpg(1");			var v = pgc - pgi;			if (v > 2) {				html += zkTrow._genimg(v > 3 ? "dn2": "btm", "zkTrow._onpg(2");				if (v > 3)					html += zkTrow._genimg("btm", "zkTrow._onpg(9");			}		} else {			html += zkTrow._genimg("up", "zkTrow._onpg(-1");			if (pgi > 1) {				html += zkTrow._genimg(pgi > 2 ? "up2": "top", "zkTrow._onpg(-2");				if (pgi > 2)					html += zkTrow._genimg("top", "zkTrow._onpg(-9");			}		}		html += '<img src="' + zk.getUpdateURI("/web/zul/img/tree/spacer.gif") + '" width="15" height="1"/>';		if (pgsz < 50)			html += zkTrow._genimg("zoomin", "zkTrow._onzoom(10");		if (pgsz > 10)			html += zkTrow._genimg("zoomout", "zkTrow._onzoom(-10");		return html;	};}//when this executes, sel.js might not be loaded yet, so we have to delay//the creation of zk.Tree until zkTree.initfunction zkTreeNewClass() {	if (zk.Tree) return;zk.Tree = Class.create();Object.extend(Object.extend(zk.Tree.prototype, zk.Selectable.prototype), {	/** Overrides what is defined in zk.Selectable. */	getItemUuid: function (row) {		return getZKAttr(row, "pitem");	},	/** Returns the type of the row. */	_rowType: function () {		return "Trow";	},	/** Overrides what is defined in zk.Selectable. */	_doLeft: function (row) {		if (zkTree.isOpen(row))			this._openItem(row, null, false);	},	/** Overrides what is defined in zk.Selectable. */	_doRight: function (row) {		if (!zkTree.isOpen(row))			this._openItem(row, null, true);	},	/** Toggle the open/close status. */	toggleOpen: function (evt, target) {		var row = zk.parentNode(target, "TR");		if (!row) return; //incomplete structure		var toOpen = !zkTree.isOpen(row); //toggle		this._openItem(row, target, toOpen);		var el = $e(row.id + "!sel");		if (!el) el = $e(el + "!cm");		if (el) zk.asyncFocus(el.id);		Event.stop(evt);	},	/** Opens an item */	_openItem: function (row, img, toOpen) {		if (!img) {			img = $e(row.id + "!open");			if (!img) return;		}		img.className = zk.renType(img.className, toOpen ? "open": "close");		setZKAttr(row, "open", toOpen ? "true": "false"); //change it value		this._showKids(row, toOpen);		if (toOpen && this.realsize() == 0)			this._calcSize();			//_calcSize depends on the current size, so it is not easy			//to make it smaller when closing some items.			//Thus, we only handle 'enlargement', i.e., toOpen is true		zkau.send({uuid: getZKAttr(row, "pitem"),			cmd: "onOpen", data: [toOpen]},			zkau.asapTimeout(row, "onOpen"));			//always send since the client has to update Openable	},	/** Shows or hides all children	 * @param toOpen whether to toOpen	 */	_showKids: function (row, toOpen, silent) {		var uuid = getZKAttr(row, "pitem");		do {			var r = row.nextSibling;			if ($tag(r) == "TR") {				var pid = getZKAttr(r, "gpitem");				if (uuid != pid) return row; //not my child				if (!silent)					r.style.display = toOpen ? "": "none";				r = this._showKids(r, toOpen,					toOpen && (silent || !zkTree.isOpen(r)));			}		} while (row = r);	},	stripe: function () { //disable stripe	}});}////// tree //zkTree = {};/** Init (and re-init) a tree. */zkTree.init = function (cmp) {	var meta = zkau.getMeta(cmp);	if (meta) meta.init();	else {		zkTreeNewClass();		meta = new zk.Tree(cmp);		if (meta.body)			zk.listen(meta.body, "keydown", zkTree.bodyonkeydown);	}	//we have re-paginate since treechild might be invalidated	if (meta.bodytbl)		zkTrow._pgnt(cmp, meta.bodytbl.rows);};zkTree.cleanup = function (cmp) {	zkTrow._pgclean(cmp);};/** Called when a tree becomes visible because of its parent. */zkTree.onVisi = zkTree.onSize = function (cmp) {	var meta = zkau.getMeta(cmp);	if (meta) meta.init();};/** Called when the body got a key stroke. */zkTree.bodyonkeydown = function (evt) {	if (!evt) evt = window.event;	var target = Event.element(evt);	var meta = zkau.getMetaByType(target, "Tree");	return !meta || meta.dobodykeydown(evt, target);};/** Called when a listitem got a key stroke. */zkTree.onkeydown = function (evt) {	if (!evt) evt = window.event;	var target = Event.element(evt);	var meta = zkau.getMetaByType(target, "Tree");	return !meta || meta.dokeydown(evt, target);};/** Called when mouse click. */zkTree.onclick = function (evt) {	if (!evt) evt = window.event;	var target = Event.element(evt);	var meta = zkau.getMetaByType(target, "Tree");	if (meta) meta.doclick(evt, target);};/** Called when focus command is received. */zkTree.focus = function (cmp) {	var meta = zkau.getMeta(cmp);	if (meta) meta._refocus();	return true;};/** Process the setAttr cmd sent from the server, and returns whether to * continue the processing of this cmd */zkTree.setAttr = function (cmp, nm, val) {	var meta = zkau.getMeta(cmp);	if (meta) {		if ("z.pgInfo" == nm) {			zkTrow._setPgInfo(cmp, val);			if (meta.bodytbl)				zkTrow._pgnt(cmp, meta.bodytbl.rows);			return true;		}		return meta.setAttr(nm, val);	}};/** Called when the +/- button is clicked. */zkTree.ontoggle = function (evt) {	if (!evt) evt = window.event;	var target = Event.element(evt);	var meta = zkau.getMetaByType(target, "Tree");	if (meta) meta.toggleOpen(evt, target);};zkTree.isOpen = function (row) {	return getZKAttr(row, "open") == "true";};zkTrow = {}; //TreerowzkTrow.init = function (cmp) {	//zk.disableSelection(cmp);	//Tom Yeh: 20060106: side effect: unable to select textbox if turned on	zk.listen(cmp, "click", zkTree.onclick);	zk.listen(cmp, "keydown", zkTree.onkeydown);	zk.listen(cmp, "mouseover", zkSel.onover);	zk.listen(cmp, "mouseout", zkSel.onout);	_zktrx.init(cmp, "ptch");	_zktrx.init(cmp, "pitem");	var sib = getZKAttr(cmp, "tchsib");	if (sib) _zktrx.sib[sib] = cmp.id;	zkTrow._pgnt(cmp);};zkTrow.cleanup = zkTrow._pgclean = function (cmp) {	zk.remove($e(cmp.id + "!ph"));	zk.remove($e(cmp.id + "!pt"));	_zktrx.cleanup(cmp, "ptch");	_zktrx.cleanup(cmp, "pitem");	delete _zktrx.sib[getZKAttr(cmp, "tchsib")];};zkTrow.setAttr = function (cmp, nm, val) {	if ("open" == nm) {		var toOpen = "true" == val;		if (toOpen != zkTree.isOpen(cmp)) {			var meta = zkau.getMeta($parentByType(cmp, "Tree"));			if (meta)				meta._openItem(cmp, null, toOpen);		}		return true; //no more processing	} else if ("z.pgInfo" == nm) {		zkTrow._setPgInfo(cmp, val);		zkTrow._pgnt(cmp);		return true;	}	return false;};zkTrow._setPgInfo = function (cmp, pgInfo) {	var j = pgInfo.indexOf(','), k = pgInfo.indexOf(',', j + 1);	setZKAttr(cmp, "pgc", pgInfo.substring(0, j).trim());	setZKAttr(cmp, "pgi", pgInfo.substring(j + 1, k).trim());	setZKAttr(cmp, "pgsz", pgInfo.substring(k + 1).trim());}/** Opens a treeitem. * @param {String or Element} n the ID of treeitem or treerow, or the treerow * itself. * @since 3.0.0 */zkTrow.open = function (n, open) {	if (typeof n == 'string') {		var p = $e(n);		n = p ? p: $e(_zktrx.sib[n]);

⌨️ 快捷键说明

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