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

📄 utils.js

📁 尚洋仓库管理系统,对仓库
💻 JS
📖 第 1 页 / 共 3 页
字号:
 */Zapatec.Utils.loadPref = function(txt) {	var obj = null;	try {		eval("obj={" + txt + "}");	} catch(e) {}	return obj;};/** * Merges the values of the source object into the destination object. * * @param dest [Object] the destination object. * @param src [Object] the source object. */Zapatec.Utils.mergeObjects = function(dest, src) {	for (var i in src)		dest[i] = src[i];};// based on the WCH idea// http://www.aplus.co.yu/WCH/code3/WCH.js/// \defgroup WCH functions//@{Zapatec.Utils.__wch_id = 0;	/**< [number, static] used to create ID-s for the WCH objects *//** * Create an WCH object.  This function does nothing if the browser is not * IE5.5 or IE6.0.  A WCH object is one of the most bizarre tricks to avoid a * notorious IE bug: IE normally shows "windowed controls" on top of any HTML * elements, regardless of any z-index that might be specified in CSS.  This * technique is described at: http://www.aplus.co.yu/WCH/ * * A "WCH object" is actually an HTMLIFrame element having a certain "CSS * filter" (proprietary MSIE extension) that forces opacity zero.  This object, * displayed on top of a windowed control such as a select box, will completely * hide the select box, allowing us to place other HTMLElement objects above. * * WCH stands for "Windowed Controls Hider". * * @param element [HTMLElement, optional] -- Create the WCH IFRAME inside this. * * * @return [HTMLIFrame or null] a new WCH object if the browser is "supported", null otherwise. */Zapatec.Utils.createWCH = function(element) {	var f = null;	element = element || window.self.document.body;	if (Zapatec.is_ie && !Zapatec.is_ie5) {		var filter = 'filter:progid:DXImageTransform.Microsoft.alpha(style=0,opacity=0);';		var id = "WCH" + (++Zapatec.Utils.__wch_id);		element.insertAdjacentHTML			('beforeEnd', '<iframe id="' + id + '" scroll="no" frameborder="0" ' +			 'style="z-index:0;position:absolute;visibility:hidden;' + filter +			 'border:0;top:0;left:0;width:0;height:0;" ' +			 'src="javascript:false;"></iframe>');		f = window.self.document.getElementById(id);	}	return f;};/** * Configure a given WCH object to be displayed on top of the given element. * Optionally, a second element can be passed, and in this case it will setup * the WCH object to cover both elements. * * @param f [HTMLIFrame] the WCH object * @param el [HTMLElement] the element to cover. * @param el2 [HTMLElement, optional] another element to cover. */Zapatec.Utils.setupWCH_el = function(f, el, el2) {	if (f) {		var pos = Zapatec.Utils.getAbsolutePos(el),			X1 = pos.x,			Y1 = pos.y,			X2 = X1 + el.offsetWidth,			Y2 = Y1 + el.offsetHeight;		if (el2) {			var p2 = Zapatec.Utils.getAbsolutePos(el2),				XX1 = p2.x,				YY1 = p2.y,				XX2 = XX1 + el2.offsetWidth,				YY2 = YY1 + el2.offsetHeight;			if (X1 > XX1)				X1 = XX1;			if (Y1 > YY1)				Y1 = YY1;			if (X2 < XX2)				X2 = XX2;			if (Y2 < YY2)				Y2 = YY2;		}		Zapatec.Utils.setupWCH(f, X1, Y1, X2-X1, Y2-Y1);	}};/** * Configure a WCH object to cover a certain part of the screen. * * @param f [HTMLIFrame] the WCH object. * @param x [number] the X coordinate. * @param y [number] the Y coordinate. * @param w [number] the width of the area. * @param h [number] the height of the area. */Zapatec.Utils.setupWCH = function(f, x, y, w, h) {	if (f) {		var s = f.style;		(typeof x != "undefined") && (s.left = x + "px");		(typeof y != "undefined") && (s.top = y + "px");		(typeof w != "undefined") && (s.width = w + "px");		(typeof h != "undefined") && (s.height = h + "px");		s.visibility = "inherit";	}};/** * Hide a WCH object. * * @param f [HTMLIFrame] object to hide. */Zapatec.Utils.hideWCH = function(f) {	if (f)		f.style.visibility = "hidden";};//@}/// \defgroup Scroll-with-window functions//@{/** * A generic Utils function that returns the current scroll position. * */Zapatec.Utils.getPageScrollY = function() {	return window.pageYOffset ||			document.documentElement.scrollTop ||			(document.body ? document.body.scrollTop : 0) ||			0;};// Object setup.Zapatec.ScrollWithWindow = {};Zapatec.ScrollWithWindow.list = [];// Set to a number between 0 and 1, lower means longer scrolling.Zapatec.ScrollWithWindow.stickiness = 0.25;/** * Registers a given object to have its style.top set equal to the window * scroll position as the browser scrolls. * * @param node [HTMLElement] -- a reference to the node to scroll. */Zapatec.ScrollWithWindow.register = function(node) {	var top = parseInt(node.style.top) || 0;	var scrollY = window.pageYOffset || document.body.scrollTop ||		document.documentElement.scrollTop || 0;	top -= scrollY;	if (top < 0) top = 0;	Zapatec.ScrollWithWindow.list[Zapatec.ScrollWithWindow.list.length] = {		node: node,		origTop: top	};};/** * Unregisters a given object. * * @param node [HTMLElement] -- a reference to the node to scroll. */Zapatec.ScrollWithWindow.unregister = function(node) {	for (var count = 0; count < Zapatec.ScrollWithWindow.list.length; count++) {		var elm = Zapatec.ScrollWithWindow.list[count];		if (node == elm.node) {			Zapatec.ScrollWithWindow.list.splice(count, 1);			return;		}	}};/** * \internal Called each time the window is scrolled to set objects' positions. * * @param newScrollY [number] -- the new window scroll position. */Zapatec.ScrollWithWindow.handler = function(newScrollY) {	// Move oldScrollY towards newScrollY, evening up if the difference is small.	oldScrollY += ((newScrollY - oldScrollY) * this.stickiness);	if (Math.abs(oldScrollY - newScrollY) <= 1) oldScrollY = newScrollY;	for (var count = 0; count < Zapatec.ScrollWithWindow.list.length; count++) {		var elm = Zapatec.ScrollWithWindow.list[count];		var node = elm.node;		if (!elm.origTop) {			elm.origTop = Zapatec.Utils.getAbsolutePos(node).y;			node.style.position = 'absolute';		}		node.style.top = elm.origTop + parseInt(oldScrollY) + 'px';	}};// Processed scroll position & Event hook.var oldScrollY = Zapatec.Utils.getPageScrollY();setInterval(	'var newScrollY = Zapatec.Utils.getPageScrollY(); ' +	'if (newScrollY != oldScrollY) { ' +		'Zapatec.ScrollWithWindow.handler(newScrollY); ' +	'}', 50);//@}/** * Destroys the given element (remove it from the DOM tree) if it's not null * and it's parent is not null. * * @param el [HTMLElement] the element to destroy. */Zapatec.Utils.destroy = function(el) {	if (el && el.parentNode)		el.parentNode.removeChild(el);};/** * Opens a new window at a certain URL and having some properties. * * @param url [string] the URL to open a new window to. * @param windowName [string] the name of the new window (as for target attribute). * @param width [number] the width of the new window in pixels. * @param height [number] the height of the new window in pixels. * @param scrollbars [string] "yes" or "no" for scrollbars. * * @return [object] the new window */Zapatec.Utils.newCenteredWindow = function(url, windowName, width, height, scrollbars){	var leftPosition = 0;	var topPosition = 0;	if (screen.width)		leftPosition = (screen.width -  width)/2;	if (screen.height)		topPosition = (screen.height -  height)/2;	var winArgs =		'height=' + height +		',width=' + width +		',top=' + topPosition +		',left=' + leftPosition +		',scrollbars=' + scrollbars +		',resizable';	var win = window.open(url,windowName,winArgs);	return win;};/** * Finds the size of the current web page. This is the usable size * and does not include the browser's menu and buttons. * * @return [object] dimension with the height and width of the window */Zapatec.Utils.getWindowSize = function() {  var iWidth = 0;  var iHeight = 0;  if (document.compatMode && document.compatMode == 'CSS1Compat') {    // Standards-compliant mode    if (window.opera) {    	iWidth = document.body.clientWidth || 0;    	iHeight = document.body.clientHeight || 0;    } else {    	iWidth = document.documentElement.clientWidth || 0;    	iHeight = document.documentElement.clientHeight || 0;    }  } else {    // Non standards-compliant mode  	iWidth = window.innerWidth || document.body.clientWidth ||  	 document.documentElement.clientWidth || 0;  	iHeight = window.innerHeight || document.body.clientHeight ||  	 document.documentElement.clientHeight || 0;  }	return {	  width: iWidth,	  height: iHeight	};};/** * Given a reference to a select element, this function will select the option * having the given value and optionally will call the default handler for * "onchange". * * @param sel [HTMLSelectElement] reference to the SELECT element. * @param val [string] the value that we should select. * @param call_default [boolean] true if the default onchange should be called. */Zapatec.Utils.selectOption = function(sel, val, call_default) {	var a = sel.options, i, o;	for (i = a.length; --i >= 0;) {		o = a[i];		o.selected = (o.val == val);	}	sel.value = val;	if (call_default) {		if (typeof sel.onchange == "function")			sel.onchange();		else if (typeof sel.onchange == "string")			eval(sel.onchange);	}};/** * A more flexible way to get the "nextSibling" of a given element.  If the * "tag" argument is passed, then this function will return the next sibling * that has a certain tag.  Otherwise it will simply return el.nextSibling. * * @param el [HTMLElement] reference to the anchor element. * @param tag [string] the tag name of the returned node. * @param alternateTag [string] the alternate tag name of the returned node. * * @return [HTMLElement or null] el.nextSibling if tag is not passed, or the * first element after el having the specified tag.  Null is returned if no * element could be found. */Zapatec.Utils.getNextSibling = function(el, tag, alternateTag) {	el = el.nextSibling;	if (!tag) {		return el;	}	tag = tag.toLowerCase();	if (alternateTag) alternateTag = alternateTag.toLowerCase();	while (el) {		if (el.nodeType == 1 && (el.tagName.toLowerCase() == tag ||		 (alternateTag && el.tagName.toLowerCase() == alternateTag))) {			return el;		}		el = el.nextSibling;	}	return el;};/** * Similar to Zapatec.Utils.getNextSibling(), this function will return the * first child of the given element that has a specified tag. * * @param el [HTMLElement] reference to the anchor element. * @param tag [string] the tag name of the returned node. * @param alternateTag [string] the alternate tag name of the returned node. * * @return [HTMLElement] reference to the found node, or null if none could be * found. */Zapatec.Utils.getFirstChild = function(el, tag, alternateTag) {

⌨️ 快捷键说明

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