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

📄 bs_formutil.lib.js

📁 征服ajax+lucene书籍各章节源代码ajax部分
💻 JS
📖 第 1 页 / 共 2 页
字号:
	      document.forms[formName].elements[fieldName].focus();	    }	  }	} catch (e) {		//happens for example if field is not visible because the container is closed. 		//or with spiecial fields. never mind. it was worth a try.	}}/*** submits the form on hitting enter.* note: ie would not need the params, only netscape needs them.* example call: bsEnterSubmit(event,this.form);* @param object ev     (event object)* @param object myForm (form object)* @return bool true (or void if it submits the form.)*/function bsFormEnterSubmit(ev, myForm) {  var ev = ('object' == typeof(window.event)) ? window.event : ev;  //1st is for ie, 2nd for ns  if (ev && ev.keyCode == 13) {    //this.form.submit();    myForm.submit();  }  return true;}/*** stops the form from being submitted.* note: ie would not need the param, only mozilla needs it.* example call: bsNoEnter(event);* @param object ev (event object)* @return bool (false to avoid a form submit, true if enter was not hit.)*/function bsFormNoEnter(ev) {	if (typeof(ev) == 'undefined') ev = window.event;  //var ev = ('object' == typeof(window.event)) ? window.event : ev;  //1st is for ie, 2nd for ns  if (ev) return (ev.keyCode != 13);  return true;}/*** stops the form from being submitted and sets the focus to the next field.* * note: ie would not need the param e, only netscape needs it.* * example call: bsNoEnter(event);* @param  object ev (event object)* @return bool*/function bsFormEnterToTab(ev) {  ev = ('object' == typeof(window.event)) ? window.event : ev;  //1st is for ie, 2nd for ns  if ((ev && (ev.keyCode == 13)) || (ev.which && (ev.which == 13))) {		if ((typeof(ie) == 'undefined') || ie) {			//overwriting the keycode only works in ie. 			ev.keyCode = 9;		} else {			//this code works, but mozilla still submits. bummer. all the scripts on the web 			//fail as well. i hope they fix it ... the return false is ignored. 			//i see a solution by modifying the submit buttons. but it's work for the webmaster. 			//so drop it. 						var nextField = bsFormGetNextField(ev.srcElement);			if (nextField) {				try {					nextField.focus(); //.select()				} catch (e) {					//never mind, maybe not a field. 				}			}			return false;		}	}  return true; //important for all cases.}/*** fires the function functionName if enter was pressed.* @param  object ev (event object)* @return mixed (return value of functionName (that should be bool) if the function gets executed, bool true otherwise.)*/function bsFormHandleEnter(ev, functionName) {  var ev = ('object' == typeof(window.event)) ? window.event : ev;  //1st is for ie, 2nd for ns  if (ev && ev.keyCode == 13) {    //call function		return eval(functionName + '();');  }  return true; //important for all cases.}/*** * example usage: you have a form field, and onMouseOver you want the field to *                be active (focus) and the content selected. but if the focus *                is already there, you don't want that. that's why the 2nd *                param (force) is here.* * @param  mixed field (field id or field object* @param  bool force (if set to true then it will be done even if the focus is already there.)* @return bool (true on success, false on failure)* @todo looks like the force thingie does not work. behaves like it's always set to true.*/function bsFormFieldSetFocusAndSelect(field, force) {  if (typeof(field) == 'string') {    field = document.getElementById(field);  }  if (!field) return false;    try {    if (force || !field.hasFocus) {      field.focus();      field.select();    }  } catch (e) {    return false;  }  return true;}/*** decrypts all form field values needed.* @param  string formName* @param  string passPhraze* @return void* @dependencies javascript/core/crypt/Bs_Rc4Crypt.lib.js*/function rc4encryptFormValues(formName, passPhraze) {	for(var i=0;i<document[formName].length;++i) {		var elm = document[formName].elements[i];		if (typeof(elm.name) == 'undefined') continue;		if (elm.name.substr(0, 8) == 'bs_form[') continue;		if ((typeof(elm.value) != 'undefined') && (typeof(elm.value) != 'object') && (elm.value != '')) {			switch (elm.type) {				case 'text':				case 'password':				case 'hidden':					elm.value = '_crp_' + base64_encode(rc4crypt(passPhraze, elm.value));					break;			}		}	}}/*** alias for rc4encryptFormValues() to have an innocent function name.*/function flowerPower1(formName, passPhraze) {	rc4encryptFormValues(formName, passPhraze);}/*** decrypts all form field values needed.* @param  string formName* @param  string passPhraze* @return void* @dependencies javascript/core/crypt/Bs_Rc4Crypt.lib.js*/function rc4decryptFormValues(formName, passPhraze) {	for(var i=0;i<document[formName].length;++i) {		var elm = document[formName].elements[i];		if ((typeof(elm.value) != 'undefined') && (elm.value != '') && (elm.value.substr(0, 5) == '_crp_')) {			elm.value = rc4crypt(passPhraze, base64_decode(elm.value.substr(5)));			//elm.value = rc4(_bs_form_foo, elm.value.substr(5));			//elm.value = base64ToText(elm.value.substr(5));		}	}}/*** alias for rc4decryptFormValues() to have an innocent function name.*/function flowerPower2(formName, passPhraze) {	rc4decryptFormValues(formName, passPhraze);}/*** Creates a HTML form dynamically from the given data and submits it to the server.* * 'ToDo'-Philosophy of BlueShoes. See also Bs_ToDo.lib.php*   When designing pages that interact with the user (UI-pages), we need some standard *   structure to pass the information back to the server and making it available to the running*   PHP functions in a GLOBAL way. *   When following the 'ToDo'-Philosophy of BlueShoes you should be able to get the 'ToDo'-hash *   from anywhere in your code and you don't have to setup your own sturcture and peal the *   data out of PHP's global $_REQUEST. We intend support the 'ToDo'-Philosophy throughout BlueShoes.** We try to standarize the return values. ** Note; The dataHash can have any depth! Sample*       var hash = new Array();*           hash['markets'] = new Array();*           hash['markets']['012389'] = 2.5 *           hash['markets']['014359'] = 1.5 *                       : *           hash['sortCriteria'];*           hash['sortCriteria']['mt'] = 'ASC';*                       :** @param  string              exitScreen : The exit target (=this screen) we are leaving* @param  string OR vector    exitAction : string or vector of strings. The action(s) to perform. (e.g. 'save'). Empty string if no-action* @param  string              nextScreen : The next target (=next screen) to show* @param  string OR vector    nextAction : string or vector of strings. The action(s) to perform. (e.g. 'sort').  Empty string if no-action* @param  hash                dataHash   : Hash the may be needed for addition data (e.g. sort-criteria ). NULL if no-data* @param  string              submitToAction : the url to submit the form to.* @return no! does not return.* @dependencies core/html/Bs_HtmlUtil.lib.js*/function bsFormDoHiddenSubmit(exitScreen, exitAction, nextScreen, nextAction, dataHash, submitToAction) {  var formOutArray =  new Array();  var ii=0;    formOutArray[ii++] = '<form name="smSubmitForm" action="' + submitToAction + '" method="post">';    // nextScreen and exitScreen are simple strings  formOutArray[ii++] = '<input type="hidden" name="bs_todo[nextScreen]" value="' + nextScreen + '">';  formOutArray[ii++] = '<input type="hidden" name="bs_todo[exitScreen]" value="' + exitScreen + '">';    // nextAction and exitAction can be a simple string OR a vector of strings  switch (typeof(nextAction)) {    case 'string':      formOutArray[ii++] = '<input type="hidden" name="bs_todo[nextAction]" value="' + nextAction + '">';      break;    case 'object':      for (var key in nextAction) {        formOutArray[ii++] = '<input type="hidden" name="bs_todo[nextAction][' + key + ']" value="' + nextAction[key] + '">';      }    default:      // do nothing  }  switch (typeof(exitAction)) {    case 'string':      formOutArray[ii++] = '<input type="hidden" name="bs_todo[exitAction]" value="' + exitAction + '">';      break;    case 'object':      for (var key in exitAction) {        formOutArray[ii++] = '<input type="hidden" name="bs_todo[exitAction][' + key + ']" value="' + exitAction[key] + '">';      }    default:      // do nothing  }  	//dump(dataHash, false, false);  dataHash = _recursiveObj2Hash(dataHash);	//dump(dataHash, false, false);	  for (var matrixStr in dataHash) {		if (typeof(dataHash[matrixStr]) == 'function') continue; //that makes no sense.		    var valStr = bs_filterForHtml(dataHash[matrixStr] + ''); //convert to string and filter.    formOutArray[ii++] = '<input type="hidden" name="' + "bs_todo[dataHash]" + matrixStr + '" value="' + valStr +  '">';  }	//dump(formOutArray, false, false);    formOutArray[ii++] = '</form>';    var body = document.getElementsByTagName('body').item(0);  body.innerHTML = formOutArray.join('');  var form = document.smSubmitForm;   form.submit();  //dump(formOutArray.join(''));  //var body = document.getElementById('body');  //body.insertAdjacentHTML('beforeEnd', formOutArray.join(''));  //body.innerHTML = formOutArray.join('');  //dump(f.innerHTML);  //return;  //document.mySubmitForm.submit();}/*** Flaten an N-dimensional Hash (==JS-Object) * return is a hash of e.g.  ("[foo][bar]" => value)** @param  aObject   JS-object     * @param  matrixStr string (Only for internal use)    * @param  matrixStr string (Only for internal use)* @return a hash (see text above)*/function _recursiveObj2Hash(aObject, matrixStr, flatObjHash) {  if (!flatObjHash) { // first call    flatObjHash = new Object();    matrixStr = '';  }    if (typeof(aObject) != 'object') {    flatObjHash[matrixStr] = aObject;  } else {    for (var key in aObject) {       var newMatrixStr = matrixStr + '['+key+']';      _recursiveObj2Hash(aObject[key], newMatrixStr, flatObjHash);    }  }  return flatObjHash;}

⌨️ 快捷键说明

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