📄 quicksearch.js
字号:
for (i=0,j=0;(i<pointerToCollectionToUse.length);i++) { displayMatches = ((!standalone) && (j < siw.MAX_MATCHES)); entry = pointerToCollectionToUse[i]; mEntry = simplify(entry); mEntry = entry; if (!standalone && (mEntry.indexOf(userInput) == 0)) { userInput = userInput.replace(/\>/gi,'\\}').replace(/\< ?/gi,'\\{'); re = new RegExp("(" + userInput + ")","i"); if (displayMatches) { siw.matchCollection[j] = new smartInputMatch(entry, mEntry.replace(/\>/gi,'}').replace(/\< ?/gi,'{').replace(re,"<b>$1</b>")); } tempCollection[j] = entry; j++; } else if (mEntry.match(re1m)) { if (!standalone && displayMatches) { siw.matchCollection[j] = new smartInputMatch(entry, mEntry.replace(/\>/gi,'}').replace(/\</gi,'{').replace(re1,"$1<b>$2</b>")); } tempCollection[j] = entry; j++; } }//loop thru collection if (siw) { siw.lastUserInput = userInput; siw.revisedCollection = tempCollection.join(",").split(","); collectionIndex[userInput] = tempCollection.join(",").split(","); } if (standalone || siw.buildIndex) { collectionIndex[uifc] = tempCollection.join(",").split(","); if (siw) siw.buildIndex = false; }}//runMatchingLogicfunction setSmartInputData() { if (typeof(siw) != 'undefined') { if (siw) { orgUserInput = siw.inputBox.value; if(typeof(sqs_objects) != 'undefined' && typeof(sqs_id) != 'undefined' && typeof(sqs_objects[sqs_id]) != 'undefined' && sqs_objects[sqs_id]['multi']) orgUserInput = getUserInputToMatch(orgUserInput); userInput = orgUserInput;//.replace(/\(/gi,'').replace(/\)/gi,'').replace(/\\/gi,'').replace(/\[/gi,'').replace(/\./gi,'\.').replace(/\?/gi,''); if (userInput && (userInput != "") && (userInput != '"')) { runMatchingLogic(userInput); }//if userinput not blank and is meaningful else { siw.matchCollection = null; } }//siw exists }}//setSmartInputDatafunction getSmartInputBoxContent() { a = null; if (siw && siw.matchCollection && (siw.matchCollection.length > 0)) { a = ''; for (i = 0;i < siw.matchCollection.length; i++) { selectedString = siw.matchCollection[i].isSelected ? ' sqsSelectedSmartInputItem' : ''; a += '<p class="sqsMatchedSmartInputItem' + selectedString + '">' + siw.matchCollection[i].value.replace(/\{ */gi,"<").replace(/\} */gi,">") + '</p>'; } }//siw exists return a;}//getSmartInputBoxContentfunction modifySmartInputBoxContent(content) { if(!siw.blurring) { siw.floaterContent.innerHTML = '<div id="sqsSmartInputResults">' + content +'</div>'; resizeSmartInputIframe(); siw.matchListDisplay = document.getElementById("sqsSmartInputResults"); }}//modifySmartInputBoxContent()function selectFromMouseOver(o) { currentIndex = getCurrentlySelectedSmartInputItem(); if (currentIndex != null) deSelectSmartInputMatchItem(currentIndex); newIndex = getIndexFromElement(o); selectSmartInputMatchItem(newIndex); modifySmartInputBoxContent(getSmartInputBoxContent());}//selectFromMouseOverfunction selectFromMouseClick() { activateCurrentSmartInputMatch(); siw.inputBox.focus(); hideSmartInputFloater(true);}//selectFromMouseClickfunction getIndexFromElement(o) { index = 0; while(o = o.previousSibling) { index++; }// return index;}//getIndexFromElementfunction getCurrentlySelectedSmartInputItem() { answer = null; if(typeof(siw.matchCollection) != 'undefined' && typeof(siw.matchCollection.length) != 'undefined') { for (i = 0; ((i < siw.matchCollection.length) && !answer) ; i++) { if (siw.matchCollection[i].isSelected) answer = i; } } return answer;}//getCurrentlySelectedSmartInputItemfunction selectSmartInputMatchItem(index) { if(typeof(siw.matchCollection[index]) != 'undefined') siw.matchCollection[index].isSelected = true;}//selectSmartInputMatchItem()function deSelectSmartInputMatchItem(index) { siw.matchCollection[index].isSelected = false;}//deSelectSmartInputMatchItem()function selectNextSmartInputMatchItem() { currentIndex = getCurrentlySelectedSmartInputItem(); if (currentIndex != null) { deSelectSmartInputMatchItem(currentIndex); if ((currentIndex + 1) < siw.matchCollection.length) selectSmartInputMatchItem(currentIndex + 1); else selectSmartInputMatchItem(0); } else { selectSmartInputMatchItem(0); } modifySmartInputBoxContent(getSmartInputBoxContent());}//selectNextSmartInputMatchItemfunction selectPreviousSmartInputMatchItem() { currentIndex = getCurrentlySelectedSmartInputItem(); if (currentIndex != null) { deSelectSmartInputMatchItem(currentIndex); if ((currentIndex - 1) >= 0) selectSmartInputMatchItem(currentIndex - 1); else selectSmartInputMatchItem(siw.matchCollection.length - 1); } else { selectSmartInputMatchItem(siw.matchCollection.length - 1); } modifySmartInputBoxContent(getSmartInputBoxContent());}//selectPreviousSmartInputMatchItemvar selIndex;function activateCurrentSmartInputMatch() { baseValue = getUserInputBase(); if ((selIndex = getCurrentlySelectedSmartInputItem()) != null) { addedValue = siw.matchCollection[selIndex].cleanValue; theString = (baseValue ? baseValue : "") + addedValue; siw.inputBox.value = theString; runMatchingLogic(addedValue, true); // fill other fields in populate_list }}//activateCurrentSmartInputMatchfunction smartInputWindow () { this.originalInput = ''; this.customFloater = false; this.floater = document.getElementById("smartInputFloater"); this.floaterContent = document.getElementById("smartInputFloaterContent"); this.selectedSmartInputItem = null; this.MAX_MATCHES = 12; this.isGecko = (navigator.userAgent.indexOf("Gecko/200") != -1); this.isSafari = (navigator.userAgent.indexOf("Safari") != -1); this.isWinIE = ((navigator.userAgent.indexOf("Win") != -1 ) && (navigator.userAgent.indexOf("MSIE") != -1 )); this.floaterIframe = document.getElementById("smartInputFloaterIframe"); this.blurring = false; // is siw blurring this.internalCall = false; // internally calling focus/blur events}//smartInputWindow Objectfunction resizeSmartInputIframe() { // to adjust iframe//hack: for some reason IE sometimes doesn't see the CSS z-index //if (siw.floater.style.zIndex <= 0) siw.floater.style.zIndex = 3; //show Iframe, which can float over SELECTs, but below floater, so they both go on top of SELECT elements in IE siw.floaterIframe.style.width = siw.floater.offsetWidth; siw.floaterIframe.style.height = siw.floater.offsetHeight; siw.floaterIframe.style.top = siw.floater.style.top; siw.floaterIframe.style.left = siw.floater.style.left; siw.floaterIframe.style.zIndex = siw.floater.style.zIndex - 2;}//resizeSmartInputIframe()function registerSmartInputListeners() { inputs = document.getElementsByTagName("input"); texts = document.getElementsByTagName("textarea"); allinputs = new Array(); z = 0; y = 0; while(inputs[z]) { allinputs[z] = inputs[z]; z++; }// while(texts[y]) { allinputs[z] = texts[y]; z++; y++; }// for (i=0; i < allinputs.length;i++) { if ((c = allinputs[i].className) && (c.indexOf("sqsEnabled") != -1)) { allinputs[i].setAttribute("autocomplete","OFF"); allinputs[i].onfocus = handleFocus; allinputs[i].onblur = handleBlur; allinputs[i].onkeydown = handleKeyDown; allinputs[i].onkeyup = handleKeyPress;// allinputs[i].onpropertychange = handleOnPropertyChange; if(allinputs[i].addEventListener) allinputs[i].addEventListener("input", handleOnPropertyChange, true); } }//loop thru inputs}//registerSmartInputListenersif (document.addEventListener) { document.addEventListener("keydown", handleKeyDown, false); document.addEventListener("keyup", handleKeyPress, false); document.addEventListener("click", handleClick, false); document.addEventListener("mouseover", handleMouseOver, false);// document.addEventListener("focus", handleFocus, false);} else { document.onkeydown = handleKeyDown; document.onkeyup = handleKeyPress; document.onmouseup = handleClick; document.onmouseover = handleMouseOver;// document.onfocus = handleFocus;}// call if your input is generated with dhtmlfunction registerSingleSmartInputListener(input) { if ((c = input.className) && (c.indexOf("sqsEnabled") != -1)) { input.setAttribute("autocomplete","OFF"); input.onfocus = handleFocus; input.onblur = handleBlur; input.onkeydown = handleKeyDown; input.onkeyup = handleKeyPress;// input.onpropertychange = handleOnPropertyChange; if(input.addEventListener) input.addEventListener("input", handleOnPropertyChange, true); }}//registerSingleSmartInputListenerYAHOO.util.Event.addListener(window, "load", quicksearchInit);function quicksearchInit() { var floaterDiv = document.createElement('div'); floaterDiv.innerHTML = '<table id="smartInputFloater" class="sqsFloater" cellpadding="0" cellspacing="0"><tr><td id="smartInputFloaterContent" nowrap="nowrap">' +'<\/td><\/tr><\/table>' + '<iframe id="smartInputFloaterIframe" class="sqsFloater" name="smartInputFloaterIframeName" src="javascript:false;" scrolling="no" frameborder="0"></iframe>' + '<div class="sqsFloater" id="smartInputFloaterWait"><img src="' + sqsWaitGif + '"></div>'; document.body.appendChild(floaterDiv); floaterWait = document.getElementById("smartInputFloaterWait"); registerSmartInputListeners();}// SugarCRMfunction sqs_checkForm() { answer = true; if (siw && siw.selectingSomething) answer = false; return answer;}function SugarQS() { }// failed callSugarQS.prototype.fail = function(result) {}// successful callSugarQS.prototype.display = function(result) { if (typeof(result) == 'undefined') return; floaterWait.style.display="none"; floaterWait.style.visibility="hidden"; if(sqs_lookup_active && result.argument['id'] == sqs_request_id)sqs_lookup_active = false; if(upEl.value == '' || result.argument['id'] != sqs_request_id || (result.argument['query'] != sqs_query && sqs_query != '')){ return; } //alert(result.responseText); names = eval(result.responseText); collection = new Array(); collection_extended = new Array(); for(i = 0; i < names.length; i++) { escaped_name = names[i].fields[sqs_objects[sqs_id].field_list[0]].replace(/&/gi,'&').replace(/</gi,'<').replace(/>/gi,'>').replace(/'/gi,'\'').replace(/"/gi,'"'); collection[i] = escaped_name; collection_extended[escaped_name] = new Array(); for(j = 0; j < sqs_objects[sqs_id]['field_list'].length; j++) { // fill in populate list collection_extended[escaped_name][sqs_objects[sqs_id]['field_list'][j]] = names[i].fields[sqs_objects[sqs_id].field_list[j]]; } } processSmartInput(upEl, sqs_id);}SugarQuickSearchObject = new SugarQS();if(typeof(sqs_objects) == 'undefined') { sqs_objects = new Array();}siw = null;collectionIndex = new Array();collection_extended = new Array();sqs_object_id = '';sqs_original_value = '';rpc_timeout = 500;floaterWait = document.getElementById("smartInputFloaterWait");from_popup_return = false;sqs_request_id = 0;sqs_must_match = true;sqs_old_values = new Array();sqs_last_query = '';sqs_tab_action = false;sqs_lookup_active = false;// END SugarCRM
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -