https://www.mssg.ch/cache-buster-1692707147/static/vendor/jquery-autocomplete/jquery.autocomplete.js
vendor: 36,574 bytes, lines 1-1168
1/** 2 * @preserve jQuery Autocomplete plugin v1.2.6 3 * @homepage http://xdsoft.net/jqplugins/autocomplete/ 4 * @license MIT - MIT-LICENSE.txt 5 * (c) 2014, Chupurnov Valeriy <[email protected]> 6 */ 7(function ($) { 8 'use strict'; 9 var ARROWLEFT = 37, 10 ARROWRIGHT = 39, 11 ARROWUP = 38, 12 ARROWDOWN = 40, 13 TAB = 9, 14 CTRLKEY = 17, 15 SHIFTKEY = 16, 16 DEL = 46, 17 ENTER = 13, 18 ESC = 27, 19 BACKSPACE = 8, 20 AKEY = 65, 21 CKEY = 67, 22 VKEY = 86, 23 ZKEY = 90, 24 YKEY = 89, 25 defaultSetting = {}, 26 //currentInput = false, 27 ctrlDown = false, 28 shiftDown = false, 29 publics = {}, 30 accent_map = { 31 'áº':'a','Ã':'a','á':'a','Ã':'a','à ':'a','Ä':'a','Ä':'a','Ắ':'a','ắ':'a','Ằ':'a','ằ':'a','Ẵ':'a','ẵ':'a','Ẳ':'a', 32 'Ẫ':'a','ẫ':'a','Ẩ':'a','ẩ':'a','Ç':'a','Ç':'a','à ':'a','Ã¥':'a','Ǻ':'a','Ç»':'a','Ã':'a','ä':'a','Ç':'a','Ç':'a', 33 'Ã':'a','ã':'a','Ȧ':'a','ȧ':'a','Ç ':'a','Ç¡':'a','Ä':'a','Ä ':'a','Ä':'a','Ä':'a','Ả':'a','ả':'a','È':'a','È':'a', 34 'È':'a','È':'a','Ạ':'a','ạ':'a','Ặ':'a','ặ':'a','Ậ':'a','áº':'a','á¸':'a','á¸':'a','Ⱥ':'a','â±¥':'a','Ǽ':'a','ǽ':'a', 35 'Ç¢':'a','Ç£':'a','á¸':'b','á¸':'b','á¸':'b','Ḡ':'b','á¸':'b','á¸':'b','É':'b','Æ':'b','ᵬ':'b','Æ':'b','É':'b','Æ':'b', 36 'Æ':'b','Ä':'c','Ä':'c','Ä':'c','Ä':'c','Ä':'c','Ä':'c','Ä':'c','Ä':'c','Ã':'c','ç':'c','á¸':'c','á¸':'c','È»':'c', 37 'ȼ':'c','Æ':'c','Æ':'c','É':'c','Ä':'d','Ä':'d','á¸':'d','á¸':'d','á¸':'d','á¸':'d','á¸':'d','á¸':'d','á¸':'d','á¸':'d', 38 'á¸':'d','á¸':'d','Ä':'d','Ä':'d','áµ':'d','Æ':'d','É':'d','Æ':'d','É':'d','Æ':'d','Æ':'d','È¡':'d','ð':'d','Ã':'e', 39 'Æ':'e','Æ':'e','Ç':'e','é':'e','Ã':'e','è':'e','Ä':'e','Ä':'e','Ã':'e','ê':'e','Ế':'e','ế':'e','á»':'e','á»':'e', 40 'á»':'e','á» ':'e','á»':'e','á»':'e','Ä':'e','Ä':'e','Ã':'e','ë':'e','Ẽ':'e','ẽ':'e','Ä':'e','Ä':'e','Ȩ':'e','È©':'e', 41 'á¸':'e','á¸':'e','Ä':'e','Ä':'e','Ä':'e','Ä':'e','á¸':'e','á¸':'e','á¸':'e','á¸':'e','Ẻ':'e','ẻ':'e','È':'e','È ':'e', 42 'È':'e','È':'e','Ẹ':'e','ẹ':'e','á»':'e','á»':'e','á¸':'e','á¸':'e','á¸':'e','á¸':'e','É':'e','É':'e','É':'e','É':'e', 43 'á¸':'f','á¸':'f','áµ®':'f','Æ':'f','Æ':'f','Ç´':'g','ǵ':'g','Ä':'g','Ä':'g','Ä':'g','Ä':'g','Ǧ':'g','ǧ':'g','Ä ':'g', 44 'Ä¡':'g','Ä¢':'g','Ä£':'g','Ḡ':'g','ḡ':'g','Ǥ':'g','Ç¥':'g','Æ':'g','É ':'g','Ĥ':'h','Ä¥':'h','È':'h','È':'h','Ḧ':'h', 45 'ḧ':'h','Ḣ':'h','ḣ':'h','Ḩ':'h','ḩ':'h','Ḥ':'h','ḥ':'h','Ḫ':'h','ḫ':'h','H':'h','̱':'h','áº':'h','Ħ':'h','ħ':'h', 46 'â±§':'h','ⱨ':'h','Ã':'i','Ã':'i','Ã':'i','ì':'i','Ĭ':'i','Ä':'i','Ã':'i','î':'i','Ç':'i','Ç':'i','Ã':'i','ï':'i', 47 'Ḯ':'i','ḯ':'i','Ĩ':'i','Ä©':'i','İ':'i','i':'i','Ä®':'i','į':'i','Ī':'i','Ä«':'i','á»':'i','á»':'i','È':'i','È':'i', 48 'È':'i','È':'i','á»':'i','á»':'i','Ḭ':'i','á¸':'i','I':'i','ı':'i','Æ':'i','ɨ':'i','Ä´':'j','ĵ':'j','J':'j','Ì':'j', 49 'ǰ':'j','È·':'j','É':'j','É':'j','Ê':'j','É':'j','Ê':'j','Ḱ':'k','ḱ':'k','Ǩ':'k','Ç©':'k','Ķ':'k','Ä·':'k','Ḳ':'k', 50 'ḳ':'k','Ḵ':'k','ḵ':'k','Æ':'k','Æ':'k','Ⱪ':'k','ⱪ':'k','Ĺ':'a','ĺ':'l','Ľ':'l','ľ':'l','Ä»':'l','ļ':'l','Ḷ':'l', 51 'ḷ':'l','Ḹ':'l','ḹ':'l','Ḽ':'l','ḽ':'l','Ḻ':'l','ḻ':'l','Å':'l','Å':'l','Ì£':'l','Ä¿':'l', 52 'Å':'l','Ƚ':'l','Æ':'l','â± ':'l','ⱡ':'l','â±¢':'l','É«':'l','ɬ':'l','É':'l','È´':'l','Ḿ':'m','ḿ':'m','á¹':'m','á¹':'m', 53 'á¹':'m','á¹':'m','ɱ':'m','Å':'n','Å':'n','Ǹ':'n','ǹ':'n','Å':'n','Å':'n','Ã':'n','ñ':'n','á¹':'n','á¹ ':'n','Å ':'n', 54 'Å':'n','á¹':'n','á¹':'n','á¹':'n','á¹':'n','á¹':'n','á¹':'n','Æ':'n','ɲ':'n','È ':'n','Æ':'n','ɳ':'n','ȵ':'n','N':'n', 55 'Ì':'n','n':'n','Ã':'o','ó':'o','Ã':'o','ò':'o','Å':'o','Å':'o','Ã':'o','ô':'o','á»':'o','á»':'o','á»':'o', 56 'á»':'o','á»':'o','á»':'o','á»':'o','á»':'o','Ç':'o','Ç':'o','Ã':'o','ö':'o','Ȫ':'o','È«':'o','Å':'o','Å':'o','Ã':'o', 57 'õ':'o','á¹':'o','á¹':'o','á¹':'o','á¹':'o','Ȭ':'o','È':'o','È®':'o','ȯ':'o','Ȱ':'o','ȱ':'o','Ã':'o','ø':'o','Ǿ':'o', 58 'Ç¿':'o','Ǫ':'o','Ç«':'o','Ǭ':'o','Ç':'o','Å':'o','Å':'o','á¹':'o','á¹':'o','á¹':'o','á¹':'o','á»':'o','á»':'o','È':'o', 59 'È':'o','È':'o','È':'o','Æ ':'o','Æ¡':'o','á»':'o','á»':'o','á»':'o','á»':'o','á» ':'o','ỡ':'o','á»':'o','á»':'o','Ợ':'o', 60 'ợ':'o','á»':'o','á»':'o','á»':'o','á»':'o','Æ':'o','ɵ':'o','á¹':'p','á¹':'p','á¹':'p','á¹':'p','â±£':'p','Ƥ':'p','Æ¥':'p', 61 'P':'p','Ì':'p','p':'p','Ê ':'q','É':'q','É':'q','Å':'r','Å':'r','Å':'r','Å':'r','á¹':'r','á¹':'r','Å':'r', 62 'Å':'r','È':'r','È':'r','È':'r','È':'r','á¹':'r','á¹':'r','á¹':'r','á¹':'r','á¹':'r','á¹':'r','É':'r','É':'r','áµ²':'r', 63 'ɼ':'r','Ɽ':'r','ɽ':'r','ɾ':'r','áµ³':'r','Ã':'s','Å':'s','Å':'s','Ṥ':'s','á¹¥':'s','Å':'s','Å':'s','Å ':'s','Å¡':'s', 64 'Ṧ':'s','á¹§':'s','á¹ ':'s','ṡ':'s','áº':'s','Å':'s','Å':'s','á¹¢':'s','á¹£':'s','Ṩ':'s','ṩ':'s','È':'s','È':'s','Ê':'s', 65 'S':'s','Ì©':'s','s':'s','Ã':'t','þ':'t','Ť':'t','Å¥':'t','T':'t','áº':'t','Ṫ':'t','ṫ':'t','Å¢':'t','Å£':'t','Ṭ':'t', 66 'á¹':'t','È':'t','È':'t','á¹°':'t','á¹±':'t','á¹®':'t','ṯ':'t','Ŧ':'t','ŧ':'t','Ⱦ':'t','ⱦ':'t','áµµ':'t', 67 'Æ«':'t','Ƭ':'t','Æ':'t','Æ®':'t','Ê':'t','ȶ':'t','Ã':'u','ú':'u','Ã':'u','ù':'u','Ŭ':'u','Å':'u','Ã':'u','û':'u', 68 'Ç':'u','Ç':'u','Å®':'u','ů':'u','Ã':'u','ü':'u','Ç':'u','Ç':'u','Ç':'u','Ç':'u','Ç':'u','Ç':'u','Ç':'u','Ç':'u', 69 'Ű':'u','ű':'u','Ũ':'u','Å©':'u','Ṹ':'u','á¹¹':'u','Ų':'u','ų':'u','Ū':'u','Å«':'u','Ṻ':'u','á¹»':'u','Ủ':'u','á»§':'u', 70 'È':'u','È':'u','È':'u','È':'u','Ư':'u','ư':'u','Ứ':'u','ứ':'u','Ừ':'u','ừ':'u','á»®':'u','ữ':'u','Ử':'u','á»':'u', 71 'á»°':'u','á»±':'u','Ụ':'u','ụ':'u','á¹²':'u','á¹³':'u','á¹¶':'u','á¹·':'u','á¹´':'u','á¹µ':'u','É':'u','Ê':'u','á¹¼':'v','á¹½':'v', 72 'á¹¾':'v','ṿ':'v','Ʋ':'v','Ê':'v','áº':'w','áº':'w','áº':'w','áº':'w','Å´':'w','ŵ':'w','W':'w','Ì':'w','áº':'w','áº':'w', 73 'Ạ':'w','áº':'w','áº':'w','áº':'w','áº':'w','áº':'x','áº':'x','áº':'x','áº':'x','Ã':'y','ý':'y','Ỳ':'y','ỳ':'y','Ŷ':'y', 74 'Å·':'y','Y':'y','áº':'y','Ÿ':'y','ÿ':'y','Ỹ':'y','ỹ':'y','áº':'y','áº':'y','Ȳ':'y','ȳ':'y','á»¶':'y','á»·':'y', 75 'á»´':'y','ỵ':'y','Ê':'y','É':'y','É':'y','Ƴ':'y','Æ´':'y','Ź':'z','ź':'z','áº':'z','áº':'z','Ž':'z','ž':'z','Å»':'z', 76 'ż':'z','áº':'z','áº':'z','áº':'z','áº':'z','Ƶ':'z','ƶ':'z','Ȥ':'z','È¥':'z','Ê':'z','Ê':'z','Ⱬ':'z','ⱬ':'z','Ç®':'z', 77 'ǯ':'z','ƺ':'z','ï¼':'2','ï¼':'6','ï¼¢':'B','F':'F','J':'J','ï¼®':'N','ï¼²':'R','ï¼¶':'V','Z':'Z','ï½':'b','ï½':'f','ï½':'j', 78 'ï½':'n','ï½':'r','ï½':'v','ï½':'z','ï¼':'1','ï¼':'5','ï¼':'9','A':'A','ï¼¥':'E','I':'I','ï¼':'M','ï¼±':'Q','ï¼µ':'U','ï¼¹':'Y', 79 'ï½':'a','ï½ ':'e','ï½':'i','ï½':'m','ï½':'q','ï½':'u','ï½':'y','ï¼':'0','ï¼':'4','ï¼':'8','D':'D','H':'H','L':'L','ï¼°':'P', 80 'ï¼´':'T','X':'X','ï½':'d','ï½':'h','ï½':'l','ï½':'p','ï½':'t','ï½':'x','ï¼':'3','ï¼':'7','ï¼£':'C','ï¼§':'G','K':'K','O':'O', 81 'ï¼³':'S','ï¼·':'W','ï½':'c','ï½':'g','ï½':'k','ï½':'o','ï½':'s','ï½':'w','ẳ':'a','Ã':'a','â':'a','Ấ':'a','ấ':'a','Ầ':'a','ầ':'a' 82 }; 83 84 if (window.getComputedStyle === undefined) { 85 window.getComputedStyle = (function () { 86 function getPixelSize(element, style, property, fontSize) { 87 var sizeWithSuffix = style[property], 88 size = parseFloat(sizeWithSuffix), 89 suffix = sizeWithSuffix.split(/\d/)[0], 90 rootSize; 91 92 fontSize = fontSize !== null ? fontSize : /%|em/.test(suffix) && element.parentElement ? getPixelSize(element.parentElement, element.parentElement.currentStyle, 'fontSize', null) : 16; 93 rootSize = property === 'fontSize' ? fontSize : /width/i.test(property) ? element.clientWidth : element.clientHeight; 94 95 return (suffix === 'em') ? size * fontSize : (suffix === 'in') ? size * 96 : (suffix === 'pt') ? size * 96 / 72 : (suffix === '%') ? size / 100 * rootSize : size; 96 } 97 98 function setShortStyleProperty(style, property) { 99 var borderSuffix = property === 'border' ? 'Width' : '', 100 t = property + 'Top' + borderSuffix, 101 r = property + 'Right' + borderSuffix, 102 b = property + 'Bottom' + borderSuffix, 103 l = property + 'Left' + borderSuffix; 104 105 style[property] = (style[t] === style[r] === style[b] === style[l] ? [style[t]] 106 : style[t] === style[b] && style[l] === style[r] ? [style[t], style[r]] 107 : style[l] === style[r] ? [style[t], style[r], style[b]] 108 : [style[t], style[r], style[b], style[l]]).join(' '); 109 } 110 111 function CSSStyleDeclaration(element) { 112 var currentStyle = element.currentStyle, 113 style = this, 114 property, 115 fontSize = getPixelSize(element, currentStyle, 'fontSize', null); 116 117 for (property in currentStyle) { 118 if (Object.prototype.hasOwnProperty.call(currentStyle, property)) { 119 if (/width|height|margin.|padding.|border.+W/.test(property) && style[property] !== 'auto') { 120 style[property] = getPixelSize(element, currentStyle, property, fontSize) + 'px'; 121 } else if (property === 'styleFloat') { 122 style.float = currentStyle[property]; 123 } else { 124 style[property] = currentStyle[property]; 125 } 126 } 127 } 128 129 setShortStyleProperty(style, 'margin'); 130 setShortStyleProperty(style, 'padding'); 131 setShortStyleProperty(style, 'border'); 132 133 style.fontSize = fontSize + 'px'; 134 135 return style; 136 } 137 138 CSSStyleDeclaration.prototype = { 139 constructor: CSSStyleDeclaration, 140 getPropertyPriority: function () {}, 141 getPropertyValue: function (prop) { 142 return this[prop] || ''; 143 }, 144 item: function () {}, 145 removeProperty: function () {}, 146 setProperty: function () {}, 147 getPropertyCSSValue: function () {} 148 }; 149 150 function getComputedStyle(element) { 151 return new CSSStyleDeclaration(element); 152 } 153 154 return getComputedStyle; 155 }(this)); 156 } 157 158 159 $(document) 160 .on('keydown.xdsoftctrl', function (e) { 161 if (e.keyCode === CTRLKEY) { 162 ctrlDown = true; 163 } 164 if (e.keyCode === SHIFTKEY) { 165 ctrlDown = true; 166 } 167 }) 168 .on('keyup.xdsoftctrl', function (e) { 169 if (e.keyCode === CTRLKEY) { 170 ctrlDown = false; 171 } 172 if (e.keyCode === SHIFTKEY) { 173 ctrlDown = false; 174 } 175 }); 176 177 function accentReplace (s) { 178 if (!s) { return ''; } 179 var ret = '',i; 180 for (i=0; i < s.length; i+=1) { 181 ret += accent_map[s.charAt(i)] || s.charAt(i); 182 } 183 return ret; 184 } 185 186 function escapeRegExp (str) { 187 return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); 188 } 189 190 function getCaretPosition(input) { 191 if (!input) { 192 return; 193 } 194 if (input.selectionStart) { 195 return input.selectionStart; 196 } 197 if (document.selection) { 198 input.focus(); 199 var sel = document.selection.createRange(), 200 selLen = document.selection.createRange().text.length; 201 sel.moveStart('character', -input.value.length); 202 return sel.text.length - selLen; 203 } 204 } 205 206 function setCaretPosition(input, pos) { 207 if (input.setSelectionRange) { 208 input.focus(); 209 input.setSelectionRange(pos, pos); 210 } else if (input.createTextRange) { 211 var range = input.createTextRange(); 212 range.collapse(true); 213 range.moveEnd('character', pos); 214 range.moveStart('character', pos); 215 range.select(); 216 } 217 } 218 219 function isset(value) { 220 return value !== undefined; 221 } 222 223 function safe_call(callback, args, callback2, defaultValue) { 224 if (isset(callback) && !$.isArray(callback)) { 225 return $.isFunction(callback) ? callback.apply(this,args):defaultValue; 226 } 227 if(isset(callback2)) { 228 return safe_call.call(this,callback2,args); 229 } 230 return defaultValue; 231 }; 232 233 function __safe( callbackName,source,args,defaultValue ){ 234 var undefinedVar; 235 return safe_call.call( this, (isset(this.source[source])&& 236 Object.prototype.hasOwnProperty.call(this.source[source], callbackName)) ? this.source[source][callbackName] : undefinedVar, args, function(){ 237 return safe_call.call(this, 238 isset(this[callbackName][source])? 239 this[callbackName][source]:( 240 isset(this[callbackName][0])? 241 this[callbackName][0]:( 242 Object.prototype.hasOwnProperty.call(this, callbackName)? 243 this[callbackName]: 244 undefinedVar 245 ) 246 ), 247 args, 248 defaultSetting[callbackName][source]||defaultSetting[callbackName][0]||defaultSetting[callbackName], 249 defaultValue 250 ); 251 },defaultValue); 252 }; 253 254 function __get( property,source ){ 255 if(!isset(source)) 256 source = 0; 257 258 if( $.isArray(this.source) && isset(this.source[source]) && isset(this.source[source][property])) 259 return this.source[source][property]; 260 261 if( isset(this[property]) ){ 262 if( $.isArray(this[property]) ){ 263 if( isset(this[property][source]) ) 264 return this[property][source]; 265 if( isset(this[property][0]) ) 266 return this[property][0]; 267 return null; 268 } 269 return this[property]; 270 } 271 272 return null; 273 }; 274 275 function loadRemote( url,sourceObject,done,debug ){ 276 if (sourceObject.xhr) { 277 sourceObject.xhr.abort(); 278 } 279 sourceObject.xhr = $.ajax($.extend(true,{ 280 url : url, 281 type : 'GET' , 282 async:true, 283 cache :false, 284 dataType : 'json' 285 },sourceObject.ajax)) 286 287 .done(function( data ){ 288 done&&done.apply(this,$.makeArray(arguments)); 289 }) 290 291 .fail(function( jqXHR, textStatus ){ 292 if( debug ) 293 console.log("Request failed: " + textStatus); 294 }); 295 } 296 297 298 function findRight( data,query ){ 299 var right = false,source; 300 301 for (source = 0;source < data.length;source += 1) { 302 if( right = __safe.call(this,"findRight",source,[data[source],query,source]) ){ 303 return {right:right,source:source}; 304 } 305 } 306 307 return false; 308 } 309 310 function processData( data,query ){ 311 var source; 312 preparseData 313 .call( this,data,query ); 314 315 for (source = 0;source < data.length;source += 1) { 316 data[source] = __safe.call(this, 317 'filter', 318 source, 319 [data[source], query, source], 320 data[source] 321 ); 322 } 323 }; 324 325 326 function collectData( query,datasource,callback ){ 327 var options = this,source; 328 329 if( $.isFunction(options.source) ){ 330 options.source.apply(options,[query,function(items){ 331 datasource = [items]; 332 safe_call.call(options,callback,[query]); 333 },datasource,0]); 334 }else{ 335 for (source = 0;source < options.source.length;source += 1) { 336 if ($.isArray(options.source[source])) { 337 datasource[source] = options.source[source]; 338 } else if ($.isFunction(options.source[source])) { 339 (function (source) { 340 options.source[source].apply(options,[query, function(items){ 341 if (!datasource[source]) { 342 datasource[source] = []; 343 } 344 345 if (items && $.isArray(items)) { 346 switch (options.appendMethod) { 347 case 'replace': 348 datasource[source] = items; 349 break; 350 default: 351 datasource[source] = datasource[source].concat(items); 352 } 353 } 354 355 safe_call.call(options,callback,[query]); 356 }, datasource,source]); 357 }(source)); 358 } else { 359 switch (options.source[source].type) { 360 case 'remote': 361 if (isset(options.source[source].url)) { 362 if (!isset(options.source[source].minLength) || query.length >= options.source[source].minLength){ 363 var url = __safe.call(options,'replace',source,[options.source[source].url,query],''); 364 if (!datasource[source]) { 365 datasource[source] = []; 366 } 367 (function (source) { 368 loadRemote(url,options.source[source], function(resp){ 369 datasource[source] = resp; 370 safe_call.call(options,callback,[query]); 371 },options.debug); 372 }(source)); 373 } 374 } 375 break; 376 default: 377 if( isset(options.source[source]['data']) ){ 378 datasource[source] = options.source[source]['data']; 379 }else{ 380 datasource[source] = options.source[source]; 381 } 382 } 383 } 384 } 385 } 386 safe_call.call(options,callback,[query]); 387 }; 388 389 function preparseData( data,query ){ 390 for( var source=0;source<data.length;source++ ){ 391 data[source] = __safe.call(this, 392 'preparse', 393 source, 394 [data[source],query], 395 data[source] 396 ); 397 } 398 }; 399 400 function renderData( data,query ){ 401 var source, i, $div, $divs = []; 402 403 for (source = 0;source < data.length;source += 1) { 404 for (i = 0;i < data[source].length;i += 1) { 405 if( $divs.length>=this.limit ) 406 break; 407 408 $div = $(__safe.call(this, 409 'render',source, 410 [data[source][i],source,i,query], 411 '' 412 )); 413 414 $div.data('source',source); 415 $div.data('pid',i); 416 $div.data('item',data[source][i]); 417 418 $divs.push($div); 419 } 420 } 421 422 return $divs; 423 }; 424 425 function getItem( $div,dataset ){ 426 if( isset($div.data('source')) && 427 isset($div.data('pid')) && 428 isset(dataset[$div.data('source')]) && 429 isset(dataset[$div.data('source')][$div.data('pid')]) 430 ){ 431 return dataset[$div.data('source')][$div.data('pid')]; 432 } 433 return false; 434 }; 435 436 function getValue( $div,dataset ){ 437 var item = getItem($div,dataset); 438 439 if( item ){ 440 return __safe.call(this, 441 'getValue',$div.data('source'), 442 [item,$div.data('source')] 443 ); 444 }else{ 445 if( isset($div.data('value')) ){ 446 return decodeURIComponent($div.data('value')); 447 }else{ 448 return $div.html(); 449 } 450 } 451 }; 452 453 defaultSetting = { 454 minLength: 0, 455 valueKey: 'value', 456 titleKey: 'title', 457 highlight: true, 458 459 showHint: true, 460 461 dropdownWidth: '100%', 462 dropdownStyle: {}, 463 itemStyle: {}, 464 hintStyle: false, 465 style: false, 466 467 debug: true, 468 openOnFocus: false, 469 closeOnBlur: true, 470 471 autoselect: false, 472 473 accents: true, 474 replaceAccentsForRemote: true, 475 476 limit: 20, 477 visibleLimit: 20, 478 visibleHeight: 0, 479 defaultHeightItem: 30, 480 481 timeoutUpdate: 10, 482 483 get: function (property, source) { 484 return __get.call(this,property,source); 485 }, 486 487 replace: [ 488 function (url, query) { 489 if (this.replaceAccentsForRemote) { 490 query = accentReplace(query); 491 } 492 return url.replace('%QUERY%',encodeURIComponent(query)); 493 } 494 ], 495 496 equal:function( value,query ){ 497 return query.toLowerCase()==value.substr(0,query.length).toLowerCase(); 498 }, 499 500 findRight:[ 501 function(items,query,source){ 502 var results = [],value = '',i; 503 if (items) { 504 for (i = 0;i < items.length;i += 1) { 505 value = __safe.call(this,'getValue',source,[items[i],source]); 506 if (__safe.call(this, 'equal', source, [value,query,source], false)) { 507 return items[i]; 508 } 509 } 510 } 511 return false; 512 } 513 ], 514 515 valid:[ 516 function (value, query) { 517 if (this.accents) { 518 value = accentReplace(value); 519 query = accentReplace(query); 520 } 521 return value.toLowerCase().indexOf(query.toLowerCase())!=-1; 522 523 } 524 ], 525 526 filter:[ 527 function (items, query, source) { 528 var results = [], value = '',i; 529 if (items) { 530 for (i = 0;i < items.length;i += 1) { 531 value = isset(items[i][this.get('valueKey', source)]) ? items[i][this.get('valueKey', source)] : items[i].toString(); 532 if (__safe.call(this, 'valid', source, [value, query])) { 533 results.push(items[i]); 534 } 535 } 536 } 537 return results; 538 } 539 ], 540 541 preparse:function(items){ 542 return items; 543 }, 544 545 getValue: [ 546 function (item, source) { 547 return isset(item[this.get('valueKey',source)])?item[this.get('valueKey',source)]:item.toString(); 548 } 549 ], 550 551 getTitle: [ 552 function (item, source) { 553 return isset(item[this.get('titleKey',source)])?item[this.get('titleKey',source)]:item.toString(); 554 } 555 ], 556 557 render: [ 558 function (item, source, pid, query) { 559 var value = __safe.call(this, "getValue", source, [item, source], defaultSetting.getValue[0].call(this, item, source)), 560 title = __safe.call(this, "getTitle", source, [item, source], defaultSetting.getTitle[0].call(this, item, source)), 561 _value = '', 562 _query = '', 563 _title = '', 564 hilite_hints = '', 565 highlighted = '', 566 c, h, i, 567 spos = 0; 568 569 if (this.highlight) { 570 if (!this.accents) { 571 title = title.replace(new RegExp('('+escapeRegExp(query)+')','i'),'<b>$1</b>'); 572 }else{ 573 _title = accentReplace(title).toLowerCase().replace(/[<>]+/g, ''), 574 _query = accentReplace(query).toLowerCase().replace(/[<>]+/g, ''); 575 576 hilite_hints = _title.replace(new RegExp(escapeRegExp(_query), 'g'), '<'+_query+'>'); 577 for (i=0;i < hilite_hints.length;i += 1) { 578 c = title.charAt(spos); 579 h = hilite_hints.charAt(i); 580 if (h === '<') { 581 highlighted += '<b>'; 582 } else if (h === '>') { 583 highlighted += '</b>'; 584 } else { 585 spos += 1; 586 highlighted += c; 587 } 588 } 589 title = highlighted; 590 } 591 } 592 593 return '<div '+(value==query?'class="active"':'')+' data-value="'+encodeURIComponent(value)+'">' 594 +title+ 595 '</div>'; 596 } 597 ], 598 appendMethod: 'concat', // supported merge and replace 599 source:[], 600 afterSelected: function() { 601 } 602 }; 603 function init( that,options ){ 604 if( $(that).hasClass('xdsoft_input') ) 605 return; 606 607 var $box = $('<div class="xdsoft_autocomplete"></div>'), 608 $dropdown = $('<div class="xdsoft_autocomplete_dropdown"></div>'), 609 $hint = $('<input readonly class="xdsoft_autocomplete_hint"/>'), 610 $input = $(that), 611 timer1 = 0, 612 intervalForVisibility, 613 dataset = [], 614 iOpen = false, 615 value = '', 616 currentValue = '', 617 currentSelect = '', 618 active = null, 619 pos = 0; 620 621 //it can be used to access settings 622 $input.data('autocomplete_options', options); 623 624 $dropdown 625 .on('mousedown', function(e) { 626 e.preventDefault(); 627 e.stopPropagation(); 628 }) 629 .on('updatescroll.xdsoft', function() { 630 var _act = $dropdown.find('.active'); 631 if (!_act.length) { 632 return; 633 } 634 635 var top = _act.position().top, 636 actHght = _act.outerHeight(true), 637 scrlTop = $dropdown.scrollTop(), 638 hght = $dropdown.height(); 639 640 if (top <0) { 641 $dropdown.scrollTop(scrlTop-Math.abs(top)); 642 } else if (top+actHght>hght) { 643 $dropdown.scrollTop(scrlTop+top+actHght-hght); 644 } 645 }); 646 647 $box 648 .css({ 649 'display':$input.css('display'), 650 'width':$input.css('width') 651 }); 652 653 if( options.style ) 654 $box.css(options.style); 655 656 $input 657 .addClass('xdsoft_input') 658 .attr('autocomplete','off'); 659 660 var xDown = null; 661 var yDown = null; 662 var isSwipe = false; 663 $dropdown 664 .on('mousemove','div',function(){ 665 if( $(this).hasClass('active') ) 666 return true; 667 $dropdown.find('div').removeClass('active'); 668 $(this).addClass('active'); 669 }) 670 .on('mousedown','div',function(e){ 671 $dropdown.find('div').removeClass('active'); 672 $(this).addClass('active'); 673 $input.trigger('pick.xdsoft'); 674 }) 675 .on('touchstart','div',function(e){ 676 xDown = e.originalEvent.touches[0].clientX; 677 yDown = e.originalEvent.touches[0].clientY; 678 }) 679 .on('touchend','div',function(e){ 680 if(isSwipe === false) { 681 $dropdown.find('div').removeClass('active'); 682 $(this).addClass('active'); 683 $input.trigger('pick.xdsoft'); 684 } 685 686 isSwipe = false; 687 }) 688 .on('touchmove','div',function(e){ 689 if ( ! xDown || ! yDown ) { 690 return; 691 } 692 693 var xUp = e.originalEvent.touches[0].clientX; 694 var yUp = e.originalEvent.touches[0].clientY; 695 696 var xDiff = xDown - xUp; 697 var yDiff = yDown - yUp; 698 699 if ( Math.abs( xDiff ) > Math.abs( yDiff ) ) { 700 if ( xDiff > 0 ) { 701 isSwipe = 'left'; 702 } else { 703 isSwipe = 'right'; 704 } 705 } else { 706 if ( yDiff > 0 ) { 707 isSwipe = 'top'; 708 } else { 709 isSwipe = 'bottm'; 710 } 711 } 712 713 xDown = null; 714 yDown = null; 715 }); 716 717 function manageData(){ 718 if ($input.val()!=currentValue){ 719 currentValue = $input.val(); 720 } else { 721 return; 722 } 723 if (currentValue.length < options.minLength) { 724 $input.trigger('close.xdsoft'); 725 return; 726 } 727 collectData.call(options,currentValue,dataset,function( query ){ 728 if (query != currentValue) { 729 return; 730 } 731 var right; 732 processData.call(options, dataset,query); 733 734 $input.trigger('updateContent.xdsoft'); 735 736 if (options.showHint && currentValue.length && currentValue.length<=$input.prop('size') && (right = findRight.call(options,dataset,currentValue))) { 737 var title = __safe.call(options,'getTitle',right.source,[right.right,right.source]); 738 title = query + title.substr(query.length); 739 $hint.val(title); 740 } else { 741 $hint.val(''); 742 } 743 }); 744 745 return; 746 } 747 748 function manageKey (event) { 749 var key = event.keyCode, right; 750 751 switch( key ){ 752 case AKEY: case CKEY: case VKEY: case ZKEY: case YKEY: 753 if (event.shiftKey || event.ctrlKey) { 754 return true; 755 } 756 break; 757 case SHIFTKEY: 758 case CTRLKEY: 759 return true; 760 break; 761 case ARROWRIGHT: 762 case ARROWLEFT: 763 if (ctrlDown || shiftDown || event.shiftKey || event.ctrlKey) { 764 return true; 765 } 766 value = $input.val(); 767 pos = getCaretPosition($input[0]); 768 if (key === ARROWRIGHT && pos === value.length) { 769 if (right = findRight.call(options, dataset, value)){ 770 $input.trigger('pick.xdsoft', [ 771 __safe.call(options, 772 'getValue', right.source, 773 [right.right, right.source] 774 ) 775 ]); 776 } else { 777 $input.trigger('pick.xdsoft'); 778 } 779 event.preventDefault(); 780 return false; 781 } 782 return true; 783 case TAB: 784 return true; 785 case ENTER: 786 if (iOpen) { 787 $input.trigger('pick.xdsoft'); 788 event.preventDefault(); 789 return false; 790 } else { 791 return true; 792 } 793 break; 794 case ESC: 795 $input 796 .val(currentValue) 797 .trigger('close.xdsoft'); 798 event.preventDefault(); 799 return false; 800 case ARROWDOWN: 801 case ARROWUP: 802 if (!iOpen) { 803 $input.trigger('open.xdsoft'); 804 $input.trigger('updateContent.xdsoft'); 805 event.preventDefault(); 806 return false; 807 } 808 809 active = $dropdown.find('div.active'); 810 811 var next = key==ARROWDOWN?'next':'prev', timepick = true; 812 813 if( active.length ){ 814 active.removeClass('active'); 815 if( active[next]().length ){ 816 active[next]().addClass('active'); 817 }else{ 818 $input.val(currentValue); 819 timepick = false; 820 } 821 }else{ 822 $dropdown.children().eq(key==ARROWDOWN?0:-1).addClass('active'); 823 } 824 825 if( timepick ){ 826 $input.trigger('timepick.xdsoft'); 827 } 828 829 $dropdown 830 .trigger('updatescroll.xdsoft'); 831 832 event.preventDefault(); 833 return false; 834 } 835 return; 836 } 837 838 $input 839 .data('xdsoft_autocomplete',dataset) 840 .after($box) 841 .on('pick.xdsoft', function( event,_value ){ 842 843 $input.trigger('timepick.xdsoft',_value); 844 845 currentSelect = currentValue = $input.val(); 846 847 $input.trigger('close.xdsoft'); 848 849 //currentInput = false; 850 851 active = $dropdown.find('div.active').eq(0); 852 853 if( !active.length ) 854 active = $dropdown.children().first(); 855 856 $input.trigger('selected.xdsoft',[getItem(active,dataset)]); 857 858 if (options.afterSelected) 859 options.afterSelected(); 860 }) 861 .on('timepick.xdsoft', function( event,_value ){ 862 active = $dropdown.find('div.active'); 863 864 if( !active.length ) 865 active = $dropdown.children().first(); 866 867 if( active.length ){ 868 if( !isset(_value) ){ 869 $input.val(getValue.call(options,active,dataset)); 870 }else{ 871 $input.val(_value); 872 } 873 $input.trigger('autocompleted.xdsoft',[getItem(active,dataset)]); 874 $hint.val(''); 875 setCaretPosition($input[0],$input.val().length); 876 } 877 }) 878 .on('keydown.xdsoft input.xdsoft cut.xdsoft paste.xdsoft', function( event ){ 879 var ret = manageKey(event); 880 881 if (ret === false || ret === true) { 882 return ret; 883 } 884 885 setTimeout(function(){ 886 manageData(); 887 },1); 888 889 manageData(); 890 }) 891 .on('change.xdsoft', function( event ){ 892 currentValue = $input.val(); 893 }); 894 895 currentValue = $input.val(); 896 897 collectData.call(options, $input.val(),dataset,function( query ){ 898 processData.call(options,dataset,query); 899 }); 900 901 if( options.openOnFocus ){ 902 $input.on('focusin.xdsoft',function(){ 903 $input.trigger('open.xdsoft'); 904 $input.trigger('updateContent.xdsoft'); 905 }); 906 } 907 908 if( options.closeOnBlur ) 909 $input.on('focusout.xdsoft',function(){ 910 $input.trigger('close.xdsoft'); 911 }); 912 913 $box 914 .append($input) 915 .append($dropdown); 916 917 918 var olderBackground = false, 919 timerUpdate = 0; 920 921 $input 922 .on('updateHelperPosition.xdsoft',function(){ 923 clearTimeout(timerUpdate); 924 timerUpdate = setTimeout(function(){ 925 $box.css({ 926 'display':$input.css('display'), 927 'width':$input.css('width') 928 }); 929 $dropdown.css($.extend(true,{ 930 left:$input.position().left, 931 top:$input.position().top + parseInt($input.css('marginTop'))+parseInt($input[0].offsetHeight), 932 marginLeft:$input.css('marginLeft'), 933 marginRight:$input.css('marginRight'), 934 width:options.dropdownWidth=='100%'?$input[0].offsetWidth:options.dropdownWidth 935 },options.dropdownStyle)); 936 937 if (options.showHint) { 938 var style = getComputedStyle($input[0], ""); 939 940 $hint[0].style.cssText = style.cssText; 941 942 $hint.css({ 943 'box-sizing':style.boxSizing, 944 borderStyle:'solid', 945 borderCollapse:style.borderCollapse, 946 borderLeftWidth:style.borderLeftWidth, 947 borderRightWidth:style.borderRightWidth, 948 borderTopWidth:style.borderTopWidth, 949 borderBottomWidth:style.borderBottomWidth, 950 paddingBottom:style.paddingBottom, 951 marginBottom:style.marginBottom, 952 paddingTop:style.paddingTop, 953 marginTop:style.marginTop, 954 paddingLeft:style.paddingLeft, 955 marginLeft:style.marginLeft, 956 paddingRight:style.paddingRight, 957 marginRight:style.marginRight, 958 maxHeight:style.maxHeight, 959 minHeight:style.minHeight, 960 maxWidth:style.maxWidth, 961 minWidth:style.minWidth, 962 width:style.width, 963 letterSpacing:style.letterSpacing, 964 lineHeight:style.lineHeight, 965 outlineWidth:style.outlineWidth, 966 fontFamily:style.fontFamily, 967 fontVariant:style.fontVariant, 968 fontStyle:$input.css('fontStyle'), 969 fontSize:$input.css('fontSize'), 970 fontWeight:$input.css('fontWeight'), 971 flex:style.flex, 972 justifyContent:style.justifyContent, 973 borderRadius:style.borderRadius, 974 '-webkit-box-shadow':'none', 975 'box-shadow':'none' 976 }); 977 978 $input.css('font-size',$input.css('fontSize'))// fix bug with em font size 979 980 $hint.innerHeight($input.innerHeight()); 981 982 $hint.css($.extend(true,{ 983 position:'absolute', 984 zIndex:'1', 985 borderColor:'transparent', 986 outlineColor:'transparent', 987 left:$input.position().left, 988 top:$input.position().top, 989 background:$input.css('background') 990 },options.hintStyle)); 991 992 993 if( olderBackground!==false ){ 994 $hint.css('background',olderBackground); 995 }else{ 996 olderBackground = $input.css('background'); 997 } 998 999 try{ 1000 $input[0].style.setProperty('background', 'transparent', 'important'); 1001 } catch(e) { 1002 $input.css('background','transparent') 1003 } 1004 1005 $box 1006 .append($hint); 1007 } 1008 }, options.timeoutUpdate||1); 1009 }); 1010 1011 if ($input.is(':visible')) { 1012 $input 1013 .trigger('updateHelperPosition.xdsoft'); 1014 } else { 1015 intervalForVisibility = setInterval(function () { 1016 if ($input.is(':visible')) { 1017 $input 1018 .trigger('updateHelperPosition.xdsoft'); 1019 clearInterval(intervalForVisibility); 1020 } 1021 },100); 1022 } 1023 1024 $(window).on('resize',function () { 1025 $box.css({ 1026 'width':'auto' 1027 }); 1028 $input 1029 .trigger('updateHelperPosition.xdsoft'); 1030 }) 1031 1032 $input 1033 .on('close.xdsoft',function(){ 1034 if (!iOpen) { 1035 return; 1036 } 1037 1038 $dropdown 1039 .hide(); 1040 1041 $hint 1042 .val(''); 1043 1044 if (!options.autoselect) { 1045 $input.val(currentValue); 1046 } 1047 1048 iOpen = false; 1049 1050 //currentInput = false; 1051 }) 1052 1053 .on('updateContent.xdsoft',function(){ 1054 var out = renderData.call(options,dataset,$input.val()), 1055 hght = 10; 1056 1057 if (out.length) { 1058 $input.trigger('open.xdsoft'); 1059 } else { 1060 $input.trigger('close.xdsoft'); 1061 return; 1062 } 1063 1064 $(out).each(function(){ 1065 this.css($.extend(true,{ 1066 paddingLeft:$input.css('paddingLeft'), 1067 paddingRight:$input.css('paddingRight') 1068 },options.itemStyle)); 1069 }); 1070 1071 $dropdown 1072 .html(out); 1073 1074 if (options.visibleHeight){ 1075 hght = options.visibleHeight; 1076 } else { 1077 hght = options.visibleLimit * ((out[0] ? out[0].outerHeight(true) : 0) || options.defaultHeightItem) + 5; 1078 } 1079 1080 $dropdown 1081 .css('maxHeight', hght+'px') 1082 }) 1083 1084 .on('open.xdsoft',function(){ 1085 if( iOpen ) 1086 return; 1087 1088 $dropdown 1089 .show(); 1090 1091 iOpen = true; 1092 1093 //currentInput = $input; 1094 }) 1095 .on('destroy.xdsoft',function(){ 1096 $input.removeClass('xdsoft'); 1097 $box.after($input); 1098 $box.remove(); 1099 clearTimeout(timer1); 1100 clearTimeout(intervalForVisibility); 1101 //currentInput = false; 1102 $input.data('xdsoft_autocomplete',null); 1103 $input 1104 .off('.xdsoft') 1105 }); 1106 }; 1107 1108 publics = { 1109 destroy: function () { 1110 return this.trigger('destroy.xdsoft'); 1111 }, 1112 update: function () { 1113 return this.trigger('updateHelperPosition.xdsoft'); 1114 }, 1115 options: function (_options) { 1116 if (this.data('autocomplete_options') && $.isPlainObject(_options)) { 1117 this.data('autocomplete_options', $.extend(true, this.data('autocomplete_options'), _options)); 1118 } 1119 return this; 1120 }, 1121 setSource: function (_newsource, id) { 1122 if(this.data('autocomplete_options') && ($.isPlainObject(_newsource) || $.isFunction(_newsource) || $.isArray(_newsource))) { 1123 var options = this.data('autocomplete_options'), 1124 dataset = this.data('xdsoft_autocomplete'), 1125 source = options.source; 1126 if (id!==undefined && !isNaN(id)) { 1127 if ($.isPlainObject(_newsource) || $.isArray(_newsource)) { 1128 source[id] = $.extend(true,$.isArray(_newsource) ? [] : {}, _newsource); 1129 } else { 1130 source[id] = _newsource; 1131 } 1132 } else { 1133 if ($.isFunction(_newsource)) { 1134 this.data('autocomplete_options').source = _newsource; 1135 } else { 1136 $.extend(true, source, _newsource); 1137 } 1138 } 1139 1140 collectData.call(options, this.val(), dataset,function( query ){ 1141 processData.call(options,dataset,query); 1142 }); 1143 } 1144 return this; 1145 }, 1146 getSource: function (id) { 1147 if (this.data('autocomplete_options')) { 1148 var source = this.data('autocomplete_options').source; 1149 if (id!==undefined && !isNaN(id) &&source[id]) { 1150 return source[id]; 1151 } else { 1152 return source; 1153 } 1154 } 1155 return null; 1156 } 1157 }; 1158 1159 $.fn.autocomplete = function(_options, _second, _third){ 1160 if ($.type(_options) === 'string' && publics[_options]) { 1161 return publics[_options].call(this, _second, _third); 1162 } 1163 return this.each(function () { 1164 var options = $.extend(true, {}, defaultSetting, _options); 1165 init(this, options); 1166 }); 1167 }; 1168}(jQuery));
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.