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

📄 common.js

📁 ZK 基础介绍 功能操作 模块 结合数据库操作
💻 JS
📖 第 1 页 / 共 4 页
字号:
	setTimeout("--zk.inAsyncSelect; zk.select($e('"+id+"'));",		timeout > 0? timeout: 0);};zk.inAsyncSelect = 0;/** Select to the specified component w/o throwing exception. */zk.select = function (cmp) {	if (cmp && cmp.select)		try {			cmp.select();		} catch (e) {			setTimeout(function() {				try {cmp.select();} catch (e) {}			}, 0);		}		//IE throws exception when focus() in some cases};/** Returns the selection range of the specified control */zk.getSelectionRange = function(inp) {		if (document.selection != null && inp.selectionStart == null) { //IE		var range = document.selection.createRange(); 		var rangetwo = inp.createTextRange(); 		var stored_range = ""; 		if(inp.type.toLowerCase() == "text"){			stored_range = rangetwo.duplicate();		}else{			 stored_range = range.duplicate(); 			 stored_range.moveToElementText(inp); 		}		stored_range.setEndPoint('EndToEnd', range); 		var start = stored_range.text.length - range.text.length; 		return [start, start + range.text.length];	} else { //Gecko		return [inp.selectionStart, inp.selectionEnd];	}}/** Inserts a node after another. */zk.insertAfter = function (el, ref) {	var sib = ref.nextSibling;	if (sib) ref.parentNode.insertBefore(el, sib);	else ref.parentNode.appendChild(el);};/** Inserts a node before another. */zk.insertBefore = function (el, ref) {	ref.parentNode.insertBefore(el, ref);};/** Inserts an unparsed HTML immediately before the specified element. * @param el the sibling before which to insert */zk.insertHTMLBefore = function (el, html) {	if (zk.ie || zk.opera) {		switch ($tag(el)) { //exclude TABLE		case "TD": case "TH": case "TR": case "CAPTION": case "COLGROUP":		case "TBODY": case "THEAD": case "TFOOT":			var ns = zk._tblCreateElements(html);			var p = el.parentNode;			for (var j = 0; j < ns.length; ++j)				p.insertBefore(ns[j], el);			return;		}	}	el.insertAdjacentHTML('beforeBegin', html);};/** Inserts an unparsed HTML immediately before the ending element. */zk.insertHTMLBeforeEnd = function (el, html) {	if (zk.ie || zk.opera) {		var tn = $tag(el);		switch (tn) {		case "TABLE": case "TR":		case "TBODY": case "THEAD": case "TFOOT": case "COLGROUP":		/*case "TH": case "TD": case "CAPTION":*/ //no need to handle them			var ns = zk._tblCreateElements(html);			if (tn == "TABLE" && ns.length && $tag(ns[0]) == "TR") {				var bd = el.tBodies;				if (!bd || !bd.length) {					bd = document.createElement("TBODY");					el.appendChild(bd);					el = bd;				} else {					el = bd[bd.length - 1];				}			}			for (var j = 0; j < ns.length; ++j)				el.appendChild(ns[j]);			return;		}	}	el.insertAdjacentHTML("beforeEnd", html);};/** Inserts an unparsed HTML immediately after the specified element. * @param el the sibling after which to insert */zk.insertHTMLAfter = function (el, html) {	if (zk.ie || zk.opera) {		switch ($tag(el)) { //exclude TABLE		case "TD": case "TH": case "TR": case "CAPTION":		case "TBODY": case "THEAD": case "TFOOT":		case "COLGROUP": case "COL":			var ns = zk._tblCreateElements(html);			var sib = el.nextSibling;			var p = el.parentNode;			for (var j = 0; j < ns.length; ++j)				if (sib != null) p.insertBefore(ns[j], sib);				else p.appendChild(ns[j]);			return;		}	}	el.insertAdjacentHTML('afterEnd', html);};/** Sets the inner HTML. */zk.setInnerHTML = function (el, html) {	if (zk.ie || zk.opera) {		var tn = $tag(el);		if (tn == "TR" || tn == "TABLE" || tn == "TBODY" || tn == "THEAD"		|| tn == "TFOOT" || tn == "COLGROUP" || tn == "COL") { //ignore TD/TH/CAPTION			var ns = zk._tblCreateElements(html);			if (tn == "TABLE" && ns.length && $tag(ns[0]) == "TR") {				var bd = el.tBodies;				if (!bd || !bd.length) {					bd = document.createElement("TBODY");					el.appendChild(bd);					el = bd;				} else {					el = bd[0];					while (el.nextSibling)						el.parentNode.removeChild(el.nextSibling);				}			}			while (el.firstChild)				el.removeChild(el.firstChild);			for (var j = 0; j < ns.length; ++j)				el.appendChild(ns[j]);			return;		}	}	el.innerHTML = html;};/** Sets the outer HTML. */zk.setOuterHTML = function (el, html) {	//NOTE: Safari doesn't support __defineSetter__	var p = el.parentNode;	if (zk.ie || zk.opera) {		var tn = $tag(el);		if (tn == "TD" || tn == "TH" || tn == "TABLE" || tn == "TR"		|| tn == "CAPTION" || tn == "TBODY" || tn == "THEAD"		|| tn == "TFOOT" || tn == "COLGROUP" || tn == "COL") {			var ns = zk._tblCreateElements(html);			var sib = el.nextSibling;			p.removeChild(el);			for (var j = 0; j < ns.length; ++j)				if (sib) p.insertBefore(ns[j], sib);				else p.appendChild(ns[j]);		} else {			el.outerHTML = html;		}	} else {		var r = el.ownerDocument.createRange();		r.setStartBefore(el);		var df = r.createContextualFragment(html);		p.replaceChild(df, el);	}	for (p = p.firstChild; p; p = p.nextSibling) {		if ($tag(p)) { //skip Text			if (!$visible(p)) zk._hideExtr(p);			else zk._showExtr(p);			break;		}	}};/** Returns the next sibling with the specified tag name, or null if not found. */zk.nextSibling = function (el, tagName) {	while (el && (el = el.nextSibling) != null && $tag(el) != tagName)		;	return el;};/** Returns the next sibling with the specified tag name, or null if not found. */zk.previousSibling = function (el, tagName) {	while (el && (el = el.previousSibling) != null && $tag(el) != tagName)		;	return el;};/** Returns the parent with the specified tag name, or null if not found. * <p>Unlike parentByTag, the search excludes el */zk.parentNode = function (el, tagName) {	while (el && (el = $parent(el))/*yes,assign*/ && $tag(el) != tagName)		;	return el;};/** Returns the first child of the specified node. */zk.firstChild = function (el, tagName, descendant) {	for (var n = el.firstChild; n; n = n.nextSibling)		if ($tag(n) == tagName)			return n;	if (descendant) {		for (var n = el.firstChild; n; n = n.nextSibling) {			var chd = zk.firstChild(n, tagName, descendant);			if (chd)				return chd;		}	}	return null;};/** Returns whether a node is an ancestor of another (including itself). * * @param checkuuid whether to check UUID is the same (i.e., whether * they are different part of the same component). */zk.isAncestor = function (p, c, checkuuid) {	if (checkuuid && $uuid(p) == $uuid(c))		return true;	p = $e(p);	c = $e(c);	for (; c; c = $parent(c))		if (p == c)			return true;	return false;};/** Returns whether a node is an ancestor of one of an array of elements. * * @param checkuuid whether to check UUID is the same (i.e., whether * they are different part of the same component). */zk.isAncestorX = function (p, ary, checkuuid) {	for (var j = 0; j < ary.length; ++j)		if (zk.isAncestor(p, ary[j], checkuuid))			return true;	return false;};/** Returns the enclosing tag for the specified HTML codes. */zk.tagOfHtml = function (html) {	if (!html) return "";	var j = html.indexOf('>'), k = html.lastIndexOf('<');	if (j < 0 || k < 0) {		zk.error("Unknown tag: "+html);		return "";	}	var head = html.substring(0, j);	j = head.indexOf('<') + 1;	j = head.skipWhitespaces(j);	k = head.nextWhitespace(j);	return head.substring(j, k).toUpperCase();};/** Appends an unparsed HTML immediately after the last child. * @param el the parent *///zk.appendHTMLChild = function (el, html) {//	el.insertAdjacentHTML('beforeEnd', html);//};///// fix inserting/updating TABLE/TR/TD ////if (zk.ie || zk.opera) {//IE don't support TABLE/TR/TD well.//20061109: Tom M. Yeh://Browser: Opera://Issue: When append TD with insertAdjacentHTML, it creates extra sibling,//TextNode.//Test: Live data of listbox in ZkDEMO	/** Creates TABLE/TD/TH/TR... with the specified HTML text.	 *	 * Thanks the contribution of Ilian Ianev, Barclays Global Investors,	 * for the following fix.	 */	zk._tblCreateElements = function (html) {		var level;		html = html.trim(); //If not trim, Opera will create TextNode!		var tag = zk.tagOfHtml(html)		switch (tag) {		case "TABLE":			level = 0;			break;		case "TR":			level = 2;			html = '<table>' + html + '</table>';			break;		case "TH": case "TD":			level = 3;			html = '<table><tr>' + html + '</tr></table>';			break;		case "COL":			level = 2;			html = '<table><colgroup>'+html+'</colgroup></table>';			break;		default://case "THEAD": case "TBODY": case "TFOOT": case "CAPTION": case "COLGROUP":			level = 1;			html = '<table>' + html + '</table>';			break;		}		//get the correct node		var el = document.createElement('DIV');		el.innerHTML = html;		while (--level >= 0)			el = el.firstChild;				//detach from parent and return		var ns = [];		for (var n; n = el.firstChild;) {			//IE creates extra tbody if add COLGROUP			//However, the following skip is dirty-fix, assuming html doesn't			//contain TBODY (unless it is the first tag)			var nt = $tag(n);			if (nt == tag || nt != "TBODY")				ns.push(n);			el.removeChild(n);		}		return ns;	};}/** Returns the element's value (by catenate all CDATA and text). */zk.getElementValue = function (el) {	var txt = ""	for (el = el.firstChild; el; el = el.nextSibling)		if (el.data) txt += el.data;	return txt;};/** Extends javascript for Non-IE */if (!zk.ie && !HTMLElement.prototype.insertAdjacentHTML) {	//insertAdjacentHTML	HTMLElement.prototype.insertAdjacentHTML = function (sWhere, sHTML) {		var df;   // : DocumentFragment		var r = this.ownerDocument.createRange();		switch (String(sWhere).toLowerCase()) {  // convert to string and unify case		case "beforebegin":			r.setStartBefore(this);			df = r.createContextualFragment(sHTML);			this.parentNode.insertBefore(df, this);			break;		case "afterbegin":			r.selectNodeContents(this);			r.collapse(true);			df = r.createContextualFragment(sHTML);			this.insertBefore(df, this.firstChild);			break;		case "beforeend":			r.selectNodeContents(this);			r.collapse(false);			df = r.createContextualFragment(sHTML);			this.appendChild(df);			break;		case "afterend":			r.setStartAfter(this);			df = r.createContextualFragment(sHTML);			zk.insertAfter(df, this);			break;		}	};};//-- Image utilities --///** Rename by changing the type (after -). * It works with url(/x/y.gif), too *url: the original URL *type: the type to rename to: open or closed *todo: support _zh_TW*/zk.renType = function (url, type) {	var j = url.lastIndexOf(';');	var suffix;	if (j >= 0) {		suffix = url.substring(j);		url = url.substring(0, j);	} else		suffix = "";	j = url.lastIndexOf('.');	if (j < 0) j = url.length; //no extension at all	var	k = url.lastIndexOf('-'),		m = url.lastIndexOf('/'),		ext = j <= m ? "": url.substring(j),		pref = k <= m ? j <= m ? url: url.substring(0, j): url.substring(0, k);	if (type) type = "-" + type;	else type = "";	return pref + type + ext + suffix;};/** Rename between / and . */zk.rename = function (url, name) {	var j = url.lastIndexOf(';');	var suffix;	if (j >= 0) {		suffix = url.substring(j);		url = url.substring(0, j);	} else		suffix = "";	j = url.lastIndexOf('.');	var k = url.lastIndexOf('/'),		ext = j <= k ? "": url.substring(j);	return url.substring(0, k + 1) + name + ext + suffix;};//-- special routines --//if (!zk._actg1) {	zk._actg1 = ["IFRAME"/*,"APPLET"*/]; //comment out APPLET for better performance	zk._actg2 = ["A","BUTTON","TEXTAREA","INPUT"];	if (zk.ie && !zk.ie7) { //ie7 solves the z-order issue of SELECT		zk._actg1.unshift("SELECT"); //change visibility is required	} else		zk._actg2.unshift("SELECT");	zk.coveredTagnames = zk._actg1; //backward compatible 2.4 or before	zk._disTags = []; //A list of {element: xx, what: xx}	zk._hidCvred = []; //A list of {element: xx, visibility: xx}}/** Disables all active tags. */zk.disableAll = function (parent) {	for (var j = 0; j < zk._actg1.length; j++)		zk._dsball(parent, document.getElementsByTagName(zk._actg1[j]), true);	if (!zk.ndbModal) //not disable-behind-modal		for (var j = 0; j < zk._actg2.length; j++)			zk._dsball(parent, document.getElementsByTagName(zk._actg2[j]));};zk._dsball = function (parent, els, visibility) {	l_els:	for (var k = 0 ; k < els.length; k++) {		var el = els[k];		if (zk.isAncestor(parent, el))			continue;		for(var m = 0; m < zk._disTags.length; ++m) {			var info = zk._disTags[m];			if (info.element == el)				continue l_els;		}		var what;		var tn = $tag(el);		if (visibility) { //_actg1			if (tn == "IFRAME" && getZKAttr(el, "autohide") != "true")				continue; //handle only autohide iframe			what = el.style.visibility;			el.style.visibility = "hidden";		} else if (zk.gecko && tn == "A") {//Firefox doesn't support the disable of A			what = "h:" + zkau.getStamp(el, "tabIndex") + ":" +				(el.tabIndex ? el.tabIndex: 0); //just in case (if null)			el.tabIndex = -1;		} else {			what = "d:" + zkau.getStamp(el, "disabled") + ":" + el.disabled;			el.disabled = true;		}		zk._disTags.push({element: el, what: what});	}};/** Restores tags being disabled by previous disableAll. If el is not null, * only el's children are enabled */zk.restoreDisabled = function (n) {	var skipped = [];	for (var bug1498895 = zk.ie; zk._disTags.length;) {		var info = zk._disTags.shift();		var el = info.element;		if (el && el.tagName) { //still exists			if (n && !zk.isAncestor(n, el)) { //not processed yet				skipped.push(info);				continue;			}			var what = info.what;			if (what.startsWith("d:")) {				var j = what.indexOf(':', 2);				if (what.substring(2, j) == zkau.getStamp(el, "disabled"))					el.disabled = what.substring(j + 1) == "true";			} else if (what.startsWith("h:")) {				var j = what.indexOf(':', 2);				if (what.substring(2, j) == zkau.getStamp(el, "href"))					el.tabIndex = what.substring(j + 1);			} else 				el.style.visibility = what;			//Workaround IE: Bug 1498895			if (bug1498895) {				var tn = $tag(el);				if ((tn == "INPUT" && (el.type == "text" || el.type == "password"))				||  tn == "TEXTAREA"){				//focus only visible (to prevent scroll)					try {						var ofs = Position.cumulativeOffset(el);						if (ofs[0] >= zk.innerX() && ofs[1] >= zk.innerY()						&& (ofs[0]+20) <= (zk.innerX()+zk.innerWidth())						&& (ofs[1]+20) <= (zk.innerY()+zk.innerHeight())) {							el.focus();							bug1498895 = false;						}					} catch (e) {					}				}			}		}	}	zk._disTags = skipped;};/** Hide select, iframe and applet if it is covered by any of ary * and not belonging to any of ary. * If ary is empty, it restores what have been hidden by last invocation * to this method. */zk.hideCovered = function (ary) {	if (!ary || ary.length == 0) {		while (zk._hidCvred.length) {			var info = zk._hidCvred.shift();			if (info.element.style)

⌨️ 快捷键说明

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