| 1 | /************************************************************************************************************ |
|---|
| 2 | (C) www.dhtmlgoodies.com, April 2006 |
|---|
| 3 | |
|---|
| 4 | This is a script from www.dhtmlgoodies.com. You will find this and a lot of other scripts at our website. |
|---|
| 5 | |
|---|
| 6 | Terms of use: |
|---|
| 7 | You are free to use this script as long as the copyright message is kept intact. However, you may not |
|---|
| 8 | redistribute, sell or repost it without our permission. |
|---|
| 9 | |
|---|
| 10 | Thank you! |
|---|
| 11 | |
|---|
| 12 | www.dhtmlgoodies.com |
|---|
| 13 | Alf Magne Kalleland |
|---|
| 14 | |
|---|
| 15 | ************************************************************************************************************/ |
|---|
| 16 | |
|---|
| 17 | var ajaxBox_offsetX = 0; |
|---|
| 18 | var ajaxBox_offsetY = 0; |
|---|
| 19 | var ajax_list_externalFile = flutter_path+'ajax-list-field-names.php?panel_id='+panel_id+'&'; // Path to external file |
|---|
| 20 | var minimumLettersBeforeLookup = 1; // Number of letters entered before a lookup is performed. |
|---|
| 21 | var valueSelectedFunction = "copyField()"; |
|---|
| 22 | |
|---|
| 23 | var ajax_list_objects = new Array(); |
|---|
| 24 | var ajax_list_cachedLists = new Array(); |
|---|
| 25 | var ajax_list_activeInput = false; |
|---|
| 26 | var ajax_list_activeItem; |
|---|
| 27 | var ajax_list_optionDivFirstItem = false; |
|---|
| 28 | var ajax_list_currentLetters = new Array(); |
|---|
| 29 | var ajax_optionDiv = false; |
|---|
| 30 | var ajax_optionDiv_iframe = false; |
|---|
| 31 | |
|---|
| 32 | var ajax_list_MSIE = false; |
|---|
| 33 | if(navigator.userAgent.indexOf('MSIE')>=0 && navigator.userAgent.indexOf('Opera')<0)ajax_list_MSIE=true; |
|---|
| 34 | |
|---|
| 35 | var currentListIndex = 0; |
|---|
| 36 | |
|---|
| 37 | function ajax_getTopPos(inputObj) |
|---|
| 38 | { |
|---|
| 39 | |
|---|
| 40 | var returnValue = inputObj.offsetTop; |
|---|
| 41 | while((inputObj = inputObj.offsetParent) != null){ |
|---|
| 42 | returnValue += inputObj.offsetTop; |
|---|
| 43 | } |
|---|
| 44 | return returnValue; |
|---|
| 45 | } |
|---|
| 46 | function ajax_list_cancelEvent() |
|---|
| 47 | { |
|---|
| 48 | return false; |
|---|
| 49 | } |
|---|
| 50 | |
|---|
| 51 | function ajax_getLeftPos(inputObj) |
|---|
| 52 | { |
|---|
| 53 | var returnValue = inputObj.offsetLeft; |
|---|
| 54 | while((inputObj = inputObj.offsetParent) != null)returnValue += inputObj.offsetLeft; |
|---|
| 55 | |
|---|
| 56 | return returnValue; |
|---|
| 57 | } |
|---|
| 58 | |
|---|
| 59 | function ajax_option_setValue(e,inputObj) |
|---|
| 60 | { |
|---|
| 61 | if(!inputObj)inputObj=this; |
|---|
| 62 | var tmpValue = inputObj.innerHTML; |
|---|
| 63 | if(ajax_list_MSIE)tmpValue = inputObj.innerText;else tmpValue = inputObj.textContent; |
|---|
| 64 | if(!tmpValue)tmpValue = inputObj.innerHTML; |
|---|
| 65 | ajax_list_activeInput.value = tmpValue; |
|---|
| 66 | if(document.getElementById(ajax_list_activeInput.name + '_hidden')){ |
|---|
| 67 | document.getElementById(ajax_list_activeInput.name + '_hidden').value = inputObj.id; |
|---|
| 68 | // CHANGES specific for Flutter |
|---|
| 69 | eval(valueSelectedFunction); |
|---|
| 70 | } |
|---|
| 71 | ajax_options_hide(); |
|---|
| 72 | } |
|---|
| 73 | |
|---|
| 74 | function ajax_options_hide() |
|---|
| 75 | { |
|---|
| 76 | if(ajax_optionDiv)ajax_optionDiv.style.display='none'; |
|---|
| 77 | if(ajax_optionDiv_iframe)ajax_optionDiv_iframe.style.display='none'; |
|---|
| 78 | } |
|---|
| 79 | |
|---|
| 80 | function ajax_options_rollOverActiveItem(item,fromKeyBoard) |
|---|
| 81 | { |
|---|
| 82 | if(ajax_list_activeItem)ajax_list_activeItem.className='optionDiv'; |
|---|
| 83 | item.className='optionDivSelected'; |
|---|
| 84 | ajax_list_activeItem = item; |
|---|
| 85 | |
|---|
| 86 | if(fromKeyBoard){ |
|---|
| 87 | if(ajax_list_activeItem.offsetTop>ajax_optionDiv.offsetHeight){ |
|---|
| 88 | ajax_optionDiv.scrollTop = ajax_list_activeItem.offsetTop - ajax_optionDiv.offsetHeight + ajax_list_activeItem.offsetHeight + 2 ; |
|---|
| 89 | } |
|---|
| 90 | if(ajax_list_activeItem.offsetTop<ajax_optionDiv.scrollTop) |
|---|
| 91 | { |
|---|
| 92 | ajax_optionDiv.scrollTop = 0; |
|---|
| 93 | } |
|---|
| 94 | } |
|---|
| 95 | } |
|---|
| 96 | |
|---|
| 97 | function ajax_option_list_buildList(letters,paramToExternalFile) |
|---|
| 98 | { |
|---|
| 99 | |
|---|
| 100 | ajax_optionDiv.innerHTML = ''; |
|---|
| 101 | ajax_list_activeItem = false; |
|---|
| 102 | if(ajax_list_cachedLists[paramToExternalFile][letters.toLowerCase()].length<=1){ |
|---|
| 103 | ajax_options_hide(); |
|---|
| 104 | return; |
|---|
| 105 | } |
|---|
| 106 | |
|---|
| 107 | |
|---|
| 108 | |
|---|
| 109 | ajax_list_optionDivFirstItem = false; |
|---|
| 110 | var optionsAdded = false; |
|---|
| 111 | for(var no=0;no<ajax_list_cachedLists[paramToExternalFile][letters.toLowerCase()].length;no++){ |
|---|
| 112 | if(ajax_list_cachedLists[paramToExternalFile][letters.toLowerCase()][no].length==0)continue; |
|---|
| 113 | optionsAdded = true; |
|---|
| 114 | var div = document.createElement('DIV'); |
|---|
| 115 | var items = ajax_list_cachedLists[paramToExternalFile][letters.toLowerCase()][no].split(/###/gi); |
|---|
| 116 | |
|---|
| 117 | if(ajax_list_cachedLists[paramToExternalFile][letters.toLowerCase()].length==1 && ajax_list_activeInput.value == items[0]){ |
|---|
| 118 | ajax_options_hide(); |
|---|
| 119 | return; |
|---|
| 120 | } |
|---|
| 121 | |
|---|
| 122 | |
|---|
| 123 | div.innerHTML = items[items.length-1]; |
|---|
| 124 | div.id = items[0]; |
|---|
| 125 | div.className='optionDiv'; |
|---|
| 126 | div.onmouseover = function(){ ajax_options_rollOverActiveItem(this,false) } |
|---|
| 127 | div.onclick = ajax_option_setValue; |
|---|
| 128 | if(!ajax_list_optionDivFirstItem)ajax_list_optionDivFirstItem = div; |
|---|
| 129 | ajax_optionDiv.appendChild(div); |
|---|
| 130 | } |
|---|
| 131 | if(optionsAdded){ |
|---|
| 132 | ajax_optionDiv.style.display='block'; |
|---|
| 133 | if(ajax_optionDiv_iframe)ajax_optionDiv_iframe.style.display=''; |
|---|
| 134 | ajax_options_rollOverActiveItem(ajax_list_optionDivFirstItem,true); |
|---|
| 135 | } |
|---|
| 136 | |
|---|
| 137 | } |
|---|
| 138 | |
|---|
| 139 | function ajax_option_list_showContent(ajaxIndex,inputObj,paramToExternalFile,whichIndex) |
|---|
| 140 | { |
|---|
| 141 | if(whichIndex!=currentListIndex)return; |
|---|
| 142 | var letters = inputObj.value; |
|---|
| 143 | var content = ajax_list_objects[ajaxIndex].response; |
|---|
| 144 | var elements = content.split('|'); |
|---|
| 145 | ajax_list_cachedLists[paramToExternalFile][letters.toLowerCase()] = elements; |
|---|
| 146 | ajax_option_list_buildList(letters,paramToExternalFile); |
|---|
| 147 | |
|---|
| 148 | } |
|---|
| 149 | |
|---|
| 150 | function ajax_option_resize(inputObj) |
|---|
| 151 | { |
|---|
| 152 | ajax_optionDiv.style.top = (ajax_getTopPos(inputObj) + inputObj.offsetHeight + ajaxBox_offsetY) + 'px'; |
|---|
| 153 | ajax_optionDiv.style.left = (ajax_getLeftPos(inputObj) + ajaxBox_offsetX) + 'px'; |
|---|
| 154 | if(ajax_optionDiv_iframe){ |
|---|
| 155 | ajax_optionDiv_iframe.style.left = ajax_optionDiv.style.left; |
|---|
| 156 | ajax_optionDiv_iframe.style.top = ajax_optionDiv.style.top; |
|---|
| 157 | } |
|---|
| 158 | |
|---|
| 159 | } |
|---|
| 160 | |
|---|
| 161 | function ajax_showOptions(inputObj,paramToExternalFile,e) |
|---|
| 162 | { |
|---|
| 163 | if(e.keyCode==13 || e.keyCode==9)return; |
|---|
| 164 | if(ajax_list_currentLetters[inputObj.name]==inputObj.value)return; |
|---|
| 165 | if(!ajax_list_cachedLists[paramToExternalFile])ajax_list_cachedLists[paramToExternalFile] = new Array(); |
|---|
| 166 | ajax_list_currentLetters[inputObj.name] = inputObj.value; |
|---|
| 167 | if(!ajax_optionDiv){ |
|---|
| 168 | ajax_optionDiv = document.createElement('DIV'); |
|---|
| 169 | ajax_optionDiv.id = 'ajax_listOfOptions'; |
|---|
| 170 | document.body.appendChild(ajax_optionDiv); |
|---|
| 171 | |
|---|
| 172 | if(ajax_list_MSIE){ |
|---|
| 173 | ajax_optionDiv_iframe = document.createElement('IFRAME'); |
|---|
| 174 | ajax_optionDiv_iframe.border='0'; |
|---|
| 175 | ajax_optionDiv_iframe.style.width = ajax_optionDiv.clientWidth + 'px'; |
|---|
| 176 | ajax_optionDiv_iframe.style.height = ajax_optionDiv.clientHeight + 'px'; |
|---|
| 177 | ajax_optionDiv_iframe.id = 'ajax_listOfOptions_iframe'; |
|---|
| 178 | |
|---|
| 179 | document.body.appendChild(ajax_optionDiv_iframe); |
|---|
| 180 | } |
|---|
| 181 | |
|---|
| 182 | var allInputs = document.getElementsByTagName('INPUT'); |
|---|
| 183 | for(var no=0;no<allInputs.length;no++){ |
|---|
| 184 | if(!allInputs[no].onkeyup)allInputs[no].onfocus = ajax_options_hide; |
|---|
| 185 | } |
|---|
| 186 | var allSelects = document.getElementsByTagName('SELECT'); |
|---|
| 187 | for(var no=0;no<allSelects.length;no++){ |
|---|
| 188 | allSelects[no].onfocus = ajax_options_hide; |
|---|
| 189 | } |
|---|
| 190 | |
|---|
| 191 | var oldonkeydown=document.body.onkeydown; |
|---|
| 192 | if(typeof oldonkeydown!='function'){ |
|---|
| 193 | document.body.onkeydown=ajax_option_keyNavigation; |
|---|
| 194 | }else{ |
|---|
| 195 | document.body.onkeydown=function(){ |
|---|
| 196 | oldonkeydown(); |
|---|
| 197 | ajax_option_keyNavigation() ;} |
|---|
| 198 | } |
|---|
| 199 | var oldonresize=document.body.onresize; |
|---|
| 200 | if(typeof oldonresize!='function'){ |
|---|
| 201 | document.body.onresize=function() {ajax_option_resize(inputObj); }; |
|---|
| 202 | }else{ |
|---|
| 203 | document.body.onresize=function(){oldonresize(); |
|---|
| 204 | ajax_option_resize(inputObj) ;} |
|---|
| 205 | } |
|---|
| 206 | |
|---|
| 207 | } |
|---|
| 208 | |
|---|
| 209 | if(inputObj.value.length<minimumLettersBeforeLookup){ |
|---|
| 210 | ajax_options_hide(); |
|---|
| 211 | return; |
|---|
| 212 | } |
|---|
| 213 | |
|---|
| 214 | |
|---|
| 215 | ajax_optionDiv.style.top = (ajax_getTopPos(inputObj) + inputObj.offsetHeight + ajaxBox_offsetY) + 'px'; |
|---|
| 216 | ajax_optionDiv.style.left = (ajax_getLeftPos(inputObj) + ajaxBox_offsetX) + 'px'; |
|---|
| 217 | if(ajax_optionDiv_iframe){ |
|---|
| 218 | ajax_optionDiv_iframe.style.left = ajax_optionDiv.style.left; |
|---|
| 219 | ajax_optionDiv_iframe.style.top = ajax_optionDiv.style.top; |
|---|
| 220 | } |
|---|
| 221 | |
|---|
| 222 | ajax_list_activeInput = inputObj; |
|---|
| 223 | ajax_optionDiv.onselectstart = ajax_list_cancelEvent; |
|---|
| 224 | currentListIndex++; |
|---|
| 225 | if(ajax_list_cachedLists[paramToExternalFile][inputObj.value.toLowerCase()]){ |
|---|
| 226 | ajax_option_list_buildList(inputObj.value,paramToExternalFile,currentListIndex); |
|---|
| 227 | }else{ |
|---|
| 228 | var tmpIndex=currentListIndex/1; |
|---|
| 229 | ajax_optionDiv.innerHTML = ''; |
|---|
| 230 | var ajaxIndex = ajax_list_objects.length; |
|---|
| 231 | ajax_list_objects[ajaxIndex] = new sack(); |
|---|
| 232 | var url = ajax_list_externalFile + paramToExternalFile + '=1&letters=' + inputObj.value.replace(" ","+"); |
|---|
| 233 | ajax_list_objects[ajaxIndex].requestFile = url; // Specifying which file to get |
|---|
| 234 | ajax_list_objects[ajaxIndex].onCompletion = function(){ ajax_option_list_showContent(ajaxIndex,inputObj,paramToExternalFile,tmpIndex); }; // Specify function that will be executed after file has been found |
|---|
| 235 | ajax_list_objects[ajaxIndex].runAJAX(); // Execute AJAX function |
|---|
| 236 | } |
|---|
| 237 | |
|---|
| 238 | |
|---|
| 239 | } |
|---|
| 240 | |
|---|
| 241 | function ajax_option_keyNavigation(e) |
|---|
| 242 | { |
|---|
| 243 | if(document.all)e = event; |
|---|
| 244 | |
|---|
| 245 | if(!ajax_optionDiv)return; |
|---|
| 246 | if(ajax_optionDiv.style.display=='none')return; |
|---|
| 247 | |
|---|
| 248 | if(e.keyCode==38){ // Up arrow |
|---|
| 249 | if(!ajax_list_activeItem)return; |
|---|
| 250 | if(ajax_list_activeItem && !ajax_list_activeItem.previousSibling)return; |
|---|
| 251 | ajax_options_rollOverActiveItem(ajax_list_activeItem.previousSibling,true); |
|---|
| 252 | } |
|---|
| 253 | |
|---|
| 254 | if(e.keyCode==40){ // Down arrow |
|---|
| 255 | if(!ajax_list_activeItem){ |
|---|
| 256 | ajax_options_rollOverActiveItem(ajax_list_optionDivFirstItem,true); |
|---|
| 257 | }else{ |
|---|
| 258 | if(!ajax_list_activeItem.nextSibling)return; |
|---|
| 259 | ajax_options_rollOverActiveItem(ajax_list_activeItem.nextSibling,true); |
|---|
| 260 | } |
|---|
| 261 | } |
|---|
| 262 | |
|---|
| 263 | if(e.keyCode==13 || e.keyCode==9){ // Enter key or tab key |
|---|
| 264 | if(ajax_list_activeItem && ajax_list_activeItem.className=='optionDivSelected')ajax_option_setValue(false,ajax_list_activeItem); |
|---|
| 265 | if(e.keyCode==13)return false; else return true; |
|---|
| 266 | } |
|---|
| 267 | if(e.keyCode==27){ // Escape key |
|---|
| 268 | ajax_options_hide(); |
|---|
| 269 | } |
|---|
| 270 | } |
|---|
| 271 | |
|---|
| 272 | |
|---|
| 273 | document.documentElement.onclick = autoHideList; |
|---|
| 274 | |
|---|
| 275 | function autoHideList(e) |
|---|
| 276 | { |
|---|
| 277 | if(document.all)e = event; |
|---|
| 278 | |
|---|
| 279 | if (e.target) source = e.target; |
|---|
| 280 | else if (e.srcElement) source = e.srcElement; |
|---|
| 281 | if (source.nodeType == 3) // defeat Safari bug |
|---|
| 282 | source = source.parentNode; |
|---|
| 283 | if(source.tagName.toLowerCase()!='input' && source.tagName.toLowerCase()!='textarea')ajax_options_hide(); |
|---|
| 284 | |
|---|
| 285 | } |
|---|