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

📄 form-utils.js

📁 zapatec suite 最新版 20070204,非常棒的ajax widgets 工具包
💻 JS
📖 第 1 页 / 共 2 页
字号:
// $Id: form-utils.js 7459 2007-06-19 12:20:22Z andrew $/** * * Copyright (c) 2004-2006 by Zapatec, Inc. * http://www.zapatec.com * 1700 MLK Way, Berkeley, California, * 94709, U.S.A. * All rights reserved. */// various form functionsZapatec.Form.Utils = [];/** * @private * function for retrieving pairs of key=value from string * TODO: extend description */Zapatec.Form.Utils.getTokens = function(className, separator){	if(typeof(separator) != 'string' || separator.length == 0){		// setting default value		separator = " ";	}	var arr = {};	if(className != null && className.length > 0){		var isInQuotes = false;		var quoteChar = null;		var key = "";		var value = "";		var isInValue = false;		for(var ii = 0; ii < className.length; ii++){			var currChar = className.charAt(ii);			if(currChar == "\\"){				// if current char is \ - store next char in any case				ii++;				currChar = className.charAt(ii);			} else if(!isInValue && currChar == "="){				// if current char is = - this means that key is finished - all				// other before next space is value				isInValue = true;				var nextChar = className.charAt(ii + 1);				// supporting old behaviour - value could be putted into quotes				if(nextChar == "'" || nextChar == '"'){					quoteChar = nextChar;					ii++;				}				continue;			} else if(currChar == " "){				if(key.length == 0){					continue;				}				// if this is space - then current pair of key&value is				// ready.				if(quoteChar != null){					// supporting old behaviour:					//	if last character is same as quote after '=' - ignore					//		last symbol.					//	in other case - add quote after '=' to value					if(quoteChar == value.charAt(value.length - 1)){						quoteChar = null;						value = value.substr(0, value.length - 1);					} else {						value = quoteChar + value;					}				}				// store pair				arr[key] = value.length == 0 ? null : value;				//clear variables				isInValue = false;				key = "";				value = "";				quoteChar = null;				continue;			}			if(ii < className.length){				// if we are here - currChar is non-system char. Store it.				if(isInValue){					value += currChar;				} else {					key += currChar;				}			}		}		// processing last argument		if(key.length > 0){			if(quoteChar != null){				// supporting old behaviour:				//	if last character is same as quote after '=' - ignore				//		last symbol.				//	in other case - add quote after '=' to value				if(quoteChar == value.charAt(value.length - 1)){					quoteChar = null;					value = value.substr(0, value.length - 1);				} else {					value = quoteChar + value;				}			}			arr[key] = (value.length == 0 ? null : value);		}	}	return arr;};/*** Toggle visibility of given element and disable/enable all form elements* inside given element.* @param field [Object] reference to element - DOM or String ID* @param show {boolean} if true - show element. Otherwise - hide.* @param useVisibility {boolean} if true - field visibility would be changed*	using field.style.visibility property. Otherwise - field.style.display*/Zapatec.Form.Utils.toggleFormElements = function(field, show, useVisibility){	field = Zapatec.Widget.getElementById(field);	if(field == null){		return null;	}	var inputs = Zapatec.Form.Utils.getFormElements(field);	for(var ii = 0; ii < inputs.length; ii++){		var input = inputs[ii];				if(show){			if(typeof(input.zpOrigDisabled) != 'undefined'){				input.disabled = input.zpOrigDisabled;						var undef;				input.zpOrigDisabled = undef;			}		} else {			if(typeof(input.zpOrigDisabled) == 'undefined'){				input.zpOrigDisabled = input.getAttribute("disabled");				input.disabled = true;			}		}		// if we are showing Zapatec.Form.Field - we must validate it.		if(show && input.zpFormField != null){			input.zpFormField.validate();		}	}	if(useVisibility){		field.style.visibility = (show ? 'visible' : 'hidden');	} else {		field.style.display = (show ? '' : 'none');	}};/** * @private * Returns array of form elements inside given element. * @param el {Object} reference to element - DOM element or string ID. * @return array of form elements inside given element. * @type Object */Zapatec.Form.Utils.getFormElements = function(el){	el = Zapatec.Widget.getElementById(el);	if(el == null){		return null;	}	var inputs = [];	var children = el.all ? el.all : el.getElementsByTagName("*");	for(var ii = 0; ii < children.length; ii++){		if(Zapatec.Form.Utils.isInputField(children[ii])){			inputs.push(children[ii]);		}	}	return inputs;};/** * Returns value of given element * @param element {Object} reference to element. DOM reference or string ID. * @return Field value * @type String */Zapatec.Form.Utils.getValue = function(element) {	element = Zapatec.Widget.getElementById(element);	if(element == null || typeof(element.tagName) == 'undefined'){		return null;	}	switch (element.tagName.toLowerCase()) {		case "select":			if(element.selectedIndex < 0){				// IE weird. Sometimes selectedIndex is -1				return "";			}						var option = element.options[element.selectedIndex];			if(option != null){				return option.value;			} else {				return "";			}		case "input":			return element.value;		case "textarea":			return element.value;	}	return null;};/** * Sets given value for given element * @param element {Object} reference to element. DOM reference or string ID * @param value - [string] value */Zapatec.Form.Utils.setValue = function(element, value) {	element = Zapatec.Widget.getElementById(element);	if(element == null || typeof(element.tagName) == 'undefined'){		return null;	}	switch (element.tagName.toLowerCase()) {		case "input":			if(element.type.toLowerCase() != "file"){				element.value = value;			}			break;		case "textarea":			element.value = value;			break;		case "select":			for(var i = 0; i < element.options.length; i++){				if (element.options[i].value == value){					element.selectedIndex = i;					break;				}			}	}	return value;};/** * @private * Check if given element is form field. * @return true, if current field is input-able field. * @type boolean */Zapatec.Form.Utils.isInputField = function(el){	if(el.nodeType != 1){		return false;	}		var nodeName = el.nodeName.toLowerCase();		return (		nodeName == 'input' ||		nodeName == 'textarea' ||		nodeName == 'select'	);};	/** * @private * Should we ignore this field. * @param field {Object} reference to element. DOM element or string ID. * @return true if Zapatec.Form shouldn't process this field. * @type boolean */Zapatec.Form.Utils.ignoreField = function(field) {	field = Zapatec.Widget.getElementById(field);	if(		!field ||		field.nodeType != 1 ||		( // if field className has "zpIgnoreField" - do not process this field.			field.className &&			/\bzpIgnoreField\b/.test(field.className)		) ||		!Zapatec.Form.Utils.isInputField(field) ||		( // IE bug - it thinks that <FIELDSET> is form element			field.nodeType == 1 &&			field.nodeName.toLowerCase() == 'fieldset'		)	){		return true;	}	var type = field.type.toLowerCase();	var ignoreList = ['submit', 'reset', 'button'];	for (var ii = 0; ii < ignoreList.length; ii++) {		if (type.toLowerCase() == ignoreList[ii]) {			return true; //ignore		}	}	return false; //not in the list; don't ignore};/** * @private * zpFormMask related function. * Checks if key that was pressed is not alphanumeric key. * @param charCode {int} data, retrieved from this.getInputData()[0] * @param newChar {char} data, retrieved from this.getInputData()[1] * @return true if key that was pressed is not alphanumeric key. * @type boolean */Zapatec.Form.Utils.isSpecialKey = function(charCode, newChar){	return (		(			newChar == null &&			charCode != 8 &&			charCode != 46		) ||		charCode == 9	|| // tab		charCode == 13	|| // enter		charCode == 16	|| // shift		charCode == 17	|| // ctrl		charCode == 18	|| // alt		charCode == 20	|| // caps lock		charCode == 27	|| // escape		charCode == 33	|| // page up		charCode == 34	|| // page down		charCode == 35	|| // home		charCode == 36	|| // end		charCode == 37	|| // left arrow		charCode == 38	|| // up arrow		charCode == 39	|| // right arrow		charCode == 40	|| // down arrow		charCode == 45	|| // insert		charCode == 144	|| // num lock		charCode > 256 // Safari strange bug	);};/** * @private * Function for initializing multiple elements in form. * @param currEl {Object} link to DOM element, that is processed. * @param firstRun {boolean} Should be setted to true, if this function is * called at first time.(in other case you would get problems with table layout) * @param form {Object} reference to Zapatec.Form instance */Zapatec.Form.Utils.initMultipleField = function(currEl, firstRun, form){	var md = null;	// check if this element can be copied

⌨️ 快捷键说明

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