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

📄 sel.js

📁 ZK 基础介绍 功能操作 模块 结合数据库操作
💻 JS
📖 第 1 页 / 共 3 页
字号:
			}			var rows = this.bodyrows;			for (var j = 0; j < rows.length; ++j)				this._changeSelect(rows[j], sels[rows[j].id] == true);			return true;		case "z.vflex":		if (val == "true") {			if (zk.ie) this.element.style.overflow = "hidden"; 			// added by Jumper for IE to get a correct offsetHeight so we need 			// to add this command faster than the this._calcSize() function.			var hgh = this.element.style.height;			if (!hgh || hgh == "auto") this.element.style.height = "99%"; // avoid border 1px;		} else {			if (zk.ie) this.element.style.overflow = ""; // cleanup style 		}		case "z.size":			zkau.setAttr(this.element, nm, val);			this.recalcSize(true);			return true;		case "style":		case "style.width":		case "style.height":			if (!this.paging) {				zkau.setAttr(this.element, nm, val);				this.init();				return true;			}			break;		case "scrollTop":			if (!this.paging && this.body) {				this.body.scrollTop = val;				return true;			}			break;		case "scrollLeft":			if (!this.paging && this.body) {				this.body.scrollLeft = val;				return true;			}			break;		case "z.scOddRow":			zkau.setAttr(this.element, nm, val);			this.stripe();			return true;		case "z.render":			this._render(0);			return true;		}		return false;	},	/** Returns the item's UUID containing the specified row. */	getItemUuid: function (row) {		return row.id;	},	/** Selects an item, notify server and change focus if necessary. */	select: function (row) {		if (this._selectOne(row, true)) {			//notify server			zkau.send({				uuid: this.id, cmd: "onSelect", data: [this.getItemUuid(row)]},				zkau.asapTimeout(this.element, "onSelect"));		}	},	/** Toggle the selection and notifies server. */	toggleSelect: function (row, toSel) {		this._changeSelect(row, toSel);		this.focus(row);		//maintain z.selId		var selId = this._getSelectedId();		if (this._isMultiple()) {			if (row.id == selId)				this._fixSelelectedId();		} else if (selId) {			var sel = $e(selId);			if (sel) this._changeSelect(sel, false);		}		//notify server		this._sendSelect();	},	/** Selects a range from the last focus up to the specified one.	 * Callable only if multiple	 */	selectUpto: function (row) {		if (this._isSelected(row)) {			this.focus(row);			return; //nothing changed		}		var focusfound = false, rowfound = false;		for (var j = 0; j < this.bodyrows.length; ++j) {			var r = this.bodyrows[j];			if (focusfound) {				this._changeSelect(r, true);				if (r == row)					break;			} else if (rowfound) {				this._changeSelect(r, true);				if (this._isFocus(r))					break;			} else {				rowfound = r == row;				focusfound = this._isFocus(r);				if (rowfound || focusfound) {					this._changeSelect(r, true);					if (rowfound && focusfound)						break;				}			}		}		this.focus(row);		this._fixSelelectedId();		this._sendSelect();	},	/** Changes the specified row as focused. */	focus: function (row) {		this._unsetFocusExcept(row);		this._setFocus(row, true);	},	/** Sets focus to the specified row if it has the anchor. */	_focusToAnc: function (row) {		if (!row) return;		var uuid = typeof row == 'string' ? row: row.id;		var el = $e(uuid + "!cm");		if (!el) el = $e(uuid + "!sel");		if (el && el.tabIndex != -1) //disabled due to modal, see zk.disableAll			zk.asyncFocus(el.id);	},	/** Selects one and deselect others, and return whehter any changes.	 * It won't notify the server.	 * @param row the row to select. Unselect all if null	 * @param toFocus whether to change focus	 */	_selectOne: function (row, toFocus) {		row = $e(row);		var selId = this._getSelectedId();		if (this._isMultiple()) {			if (row && toFocus) this._unsetFocusExcept(row);			var changed = this._unsetSelectAllExcept(row);			if (!changed && row && selId == row.id) {				if (toFocus) this._setFocus(row, true);				return false; //not changed			}		} else {			if (selId) {				if (row && selId == row.id) {					if (toFocus) this._setFocus(row, true);					return false; //not changed				}				var sel = $e(selId);				if (sel) {					this._changeSelect(sel, false);					if (row)						if(toFocus) this._setFocus(sel, false);						else this._fixAnc(sel, false); //Bug 1505786 (called by setAttr with "selected")				}			} else {				if (row && toFocus) this._unsetFocusExcept(row);			}		}		//we always invoke _changeSelect to change focus		if (row) {			this._changeSelect(row, true);			if (toFocus) this._setFocus(row, true);			else this._fixAnc(row, true); //Bug 1505786			this._setSelectedId(row.id);		} else {			this._setSelectedId(null);		}		return true;	},	/** Changes the selected status of an item without affecting other items	 * and return true if the status is really changed.	 */	_changeSelect: function (row, toSel) {		if (!this._isValid(row)) return false;		var changed = this._isSelected(row) != toSel;		if (changed) {			var el = $e(row.id + "!cm");			if (toSel) {				if (el) el.checked = true;				zk.addClass(row, "seld");				zkSel.onoutTo(row);				setZKAttr(row, "sel", "true");			} else {				if (el) el.checked = false;				zk.rmClass(row, "seld");				zkSel.onoutTo(row);				setZKAttr(row, "sel", "false");			}		}		return changed;	},	/** Changes the focus status, and return whether it is changed. */	_setFocus: function (row, toFocus) {		if (!this._isValid(row)) return false;		var changed = this._isFocus(row) != toFocus;		if (changed) {			this._fixAnc(row, toFocus);			if (toFocus) {				var el = $e(row.id + "!cm");				if (!el) el = $e(row.id + "!sel");				if (el && el.tabIndex != -1) //disabled due to modal, see zk.disableAll					zk.asyncFocus(el.id);				zkSel.cmonfocusTo(row);				if (!this.paging && zk.gecko) this._render(5);					//Firefox doesn't call onscroll when we moving by cursor, so...			} else {				zkSel.cmonblurTo(row);			}		}		return changed;	},	_fixAnc: function (row, toAnc) {		var el = $e(row.id + "!sel");		if (toAnc) {			if (!el && !$e(row.id + "!cm") && row.cells.length > 0) {				el = document.createElement("A");				el.href = "javascript:;";				el.id = row.id + "!sel";				el.innerHTML = " ";				el.onfocus = zkSel.cmonfocus;				el.onblur = zkSel.cmonblur;				$e(row.cells[0].id+ "!cave").appendChild(el);			}		} else {			zk.remove(el);		}	},	/** Cleans selected except the specified one, and returns any selected status	 * is changed.	 */	_unsetSelectAllExcept: function (row) {		var changed = false;		for (var j = 0; j < this.bodyrows.length; ++j) {			var r = this.bodyrows[j];			if (r != row && this._changeSelect(r, false))				changed = true;		}		return changed;	},	/** Cleans selected except the specified one, and returns any selected status	 * is changed.	 */	_unsetFocusExcept: function (row) {		var changed = false;		for (var j = 0; j < this.bodyrows.length; ++j) {			var r = this.bodyrows[j];			if (r != row && this._setFocus(r, false))				changed = true;		}		return changed;	},	/** Renders listitems that become visible by scrolling.	 */	_render: function (timeout) {		setTimeout("zkSel._renderNow('"+this.id+"')", timeout);	},	_renderNow: function () {		var rows = this.bodyrows;		if (!rows || !rows.length || getZKAttr(this.element, "model") != "true") return;		//Note: we have to calculate from top to bottom because each row's		//height might diff (due to different content)		var data = "";		var min = this.body.scrollTop, max = min + this.body.offsetHeight;		for (var j = 0; j < rows.length; ++j) {			var r = rows[j];			if ($visible(r)) {				var top = zk.offsetTop(r);				if (top + zk.offsetHeight(r) < min) continue;				if (top > max) break; //Bug 1822517: max might be 0				if (getZKAttr(r, "loaded") != "true")					data += "," + this.getItemUuid(r);			}		}		if (data) {			data = data.substring(1);			zkau.send({uuid: this.id, cmd: "onRender", data: [data]}, 0);		}	},	/** Calculates the size. */	_calcSize: function () {		this._calcHgh();		if (this.paging) {// Bug #1826101			if (this.bodytbl && this.bodytbl.rows.length) {				var head;				for (var j = 0; j < this.bodytbl.rows.length; j++) {					if ($type(this.bodytbl.rows[j]) == "Lhrs") {						head = this.bodytbl.rows[j];						break;					}				}				if (head) {					for (var j = 0; j < head.cells.length; j++) {						var d = head.cells[j];						var cave = $e(d.id + "!cave");						if (cave) {							var wd =  d.style.width;														if (!wd || wd == "auto" || wd.indexOf('%') > -1) 								d.style.width = zk.revisedSize(d, d.offsetWidth) + "px";															var w = $int(d.style.width);							cave.style.width = zk.revisedSize(cave, w) + "px";
						}
					}
				}
			}			return; //nothing to adjust since single table		}		//Bug 1553937: wrong sibling location		//Otherwise,		//IE: element's width will be extended to fit body		//FF and IE: sometime a horizontal scrollbar appear (though it shalln't)		//		//Bug 1616056: we have to use style.width, if possible, since clientWidth		//is sometime too big		var wd = this.element.style.width;		if (!wd || wd == "auto" || wd.indexOf('%') >= 0) {			wd = zk.revisedSize(this.element, this.element.offsetWidth) - (wd == "100%" ? 2 : 0);			if (wd < 0) wd = 0;			if (wd) wd += "px";		}		if (wd) {			this.body.style.width = wd;			if (this.head) this.head.style.width = wd;			if (this.foot) this.foot.style.width = wd;		}		var tblwd = this.body.clientWidth;		if (zk.ie) //By experimental: see zk-blog.txt			if (tblwd && this.body.offsetWidth - tblwd > 11) {				if (--tblwd < 0) tblwd = 0;				this.bodytbl.style.width = tblwd + "px";			} else				this.bodytbl.style.width = "";		if (this.headtbl) {			if (tblwd) this.head.style.width = tblwd + 'px';			if (this.headtbl.rows.length) {				var head;				var j =0				for(; j < this.headtbl.rows.length; j++) {					var type = $type(this.headtbl.rows[j]);					if (type == "Lhrs" || type == "Tcols") {						head = this.headtbl.rows[j];						break;					}				}				zk.cpCellWidth(head, this.bodyrows, this);					var fake = $e(head.id + "!fake");				if (!fake || fake.cells.length != head.cells.length) {					if (fake) fake.parentNode.removeChild(fake);					var src = document.createElement("TR");					src.id = head.id + "!fake";					src.style.height = "0px";						//Note: we cannot use display="none" (offsetWidth won't be right)					for (var j = head.cells.length; --j >= 0;)						src.appendChild(document.createElement("TD"));										this.headtbl.rows[0].parentNode.insertBefore(src, this.headtbl.rows[0]);										}				var row = this.headtbl.rows[0];				var cells = row.cells;				for (var k =0, z = 0; k < cells.length; k++) {					var s = cells[k], d = head.cells[k];					var wd =  d.style.width;												if (!wd || wd == "auto" || wd.indexOf('%') > -1) // Bug #1822564						d.style.width = zk.revisedSize(d, d.offsetWidth) + "px";										wd = d.style.width;					if (zk.isVisible(d))						s.style.width = $int(wd) + zk.sumStyles(d, "lr", zk.borders) + zk.sumStyles(d, "lr", zk.paddings) + "px";					else s.style.display = "none";				} 						}			if (this.foottbl && this.foottbl.rows.length)				zk.cpCellWidth(this.headtbl.rows[0], this.foottbl.rows, this);		} else if (this.foottbl) {			if (tblwd) this.foot.style.width = tblwd + 'px';			if (this.foottbl.rows.length)				zk.cpCellWidth(this.foottbl.rows[0], this.bodyrows, this); //assign foot's col width		}	},	/** Returns the visible row at the specified index. */	_visiRowAt: function (index) {		if (index >= 0) {			var rows = this.bodyrows;			for (var j = 0; j < rows.length; ++j) {				var r = rows[j];				if ($visible(r) && --index < 0)					return r;			}		}		return null;	},	_calcHgh: function () {		var rows = this.bodyrows;		var len = 0, lastVisiRow, firstVisiRow;		for (var j = 0; j < rows.length; ++j) { //tree might collapse some items			var r = rows[j];			if ($visible(r)) {				if (!firstVisiRow) firstVisiRow = r;				lastVisiRow = r;				++len;			}		}		var hgh = this.element.style.height;		if (hgh && hgh != "auto" && hgh.indexOf('%') < 0) {			hgh = $int(hgh);			if (hgh) {				hgh -= this._headHgh(0);				if (hgh < 20) hgh = 20;				var sz = 0;				for (var h, j = 0;; ++sz, ++j) {					if (sz == len) {						sz = Math.ceil(sz && h ? (hgh * sz)/h: hgh/this._headHgh(20));						break;					}					//next visible row					var r;

⌨️ 快捷键说明

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