1<!-- 2 3waJSQuery(window).load(function () { 4 initializeAllWA_search(); 5}); 6 7function initializeAllWA_search() 8{ 9 //search 10 waJSQuery(".wa-search-engine").each(function(i) 11 { 12 var _engine = waJSQuery(this); 13 14 var _hackSearchBalise = false; 15 16 if (isWebKit()==true) 17 { 18 _hackSearchBalise = true 19 } 20 21 if (_hackSearchBalise) 22 { 23 var _code = _engine.html(); 24 _code = _code.replace(/type="text"/gi,"type=\"search\"") 25 _engine.html(_code) 26 } 27 28 var _but = _engine.find("button") 29 var _input = _engine.find("input") 30 31 _input.attr("results","0"); 32 _input.attr("placeholder",""); 33 34 35 if (isWindowsOS()&&((BrowserDetect.browser=="Chrome") || (BrowserDetect.browser=="Safari"))) 36 { 37 var _h = _input.height(); 38 _h = Math.max(_h,22) 39 _input.css({"height":""+_h+"px"}) 40 } 41 42 var _yInput = (_engine.height()-_input.outerHeight())/2 43 _input.css("top",_yInput) 44 //alert(_yInput) 45 46 _input.keypress(function(e) { 47 if (e.which=='13') 48 { 49 _WA_launchSearch(_input) 50 } 51 52 }); 53 var _lnk = _but.parent(); 54 _lnk.css("cursor","pointer") 55 _but.css("cursor","pointer") 56 57 _lnk.click(function() 58 { 59 // alert('search') 60 _WA_launchSearch(_input) 61 //// 62 }); 63 64 if (_hackSearchBalise) 65 { 66 waActivateOverButton(_lnk) 67 } 68 // 69 70 }); 71 72 73 //waActivateOverButtons() 74} 75 76function WA_declareSearchIndex(_search_index_js) 77{ 78 document.const_wa_search_index_js=_search_index_js 79} 80 81function _stringIsEmpty( str ) { 82 return waJSQuery.trim( str ).length === 0; 83} 84 85//// 86function _WA_launchSearch(_input) 87{ 88 WA_openSearchDialog(_input,document.const_wa_search_index_js) 89} 90 91 92function _WA_SearchIndexLoaded(_params) 93{ 94 document.wa_search_index_js_loaded = true; 95 var _w=_params[0] 96 97 _WA_SearchInitialisation(); 98 _w._loading_index_in_progress=false; 99 _w._onSearch() 100} 101 102function WA_onClickSearch() 103{ 104 var _w=WA_Dialog.getCurrent() 105 if (!_w)return; 106 if (_w._loading_index_in_progress==true) return; 107 108 _w._currentFilter = waJSQuery("#"+_w._name_select_filter+" ").val() 109 _w._onSearch() 110} 111 112function _WA_formatSearchQuery(_input) 113{ 114 115 116 var _globalVar = window.CONST_WA_SEARCH_INDEX2 117 118 if ( !_globalVar ) { 119 return 120 } 121 122 123 124 var _input_value = _input.val() 125 126 127 var _search_string = _input_value; 128 129 //alert(_input_value) 130 _search_string = removeAccentsFromString(_search_string); 131 _search_string = waJSQuery.trim(_search_string); 132 var _list_separator=[",",";","\\.","'",":","/","`","\\?"]; 133 for (var c = 0;c < _list_separator.length;c++) 134 { 135 var reg=new RegExp(_list_separator[c], "g"); 136 _search_string = _search_string.replace(reg," ") 137 } 138 139 140 var _list_search0 = _search_string.toLowerCase().split(" "); 141 var _list_search2 = new Array(); 142 for (var i=0;i<_list_search0.length;i++) 143 { 144 var w = waJSQuery.trim(_list_search0[i]); 145 146 if ( typeof( w ) != 'undefined' ) 147 { 148 149 var _number = Number(w); 150 if (isNaN(_number)) 151 { 152 if (w.length >= _globalVar.min_lenght_word) _list_search2.push(w); 153 } 154 else 155 { 156 if (w.length >= _globalVar.min_lenght_number) _list_search2.push(w); 157 } 158 159 } 160 } 161 _list_search2 = _list_search2.sort(_WA_sort_fct_string_by_length); 162 163 164 165 166 167 var _list_search = new Array() 168 for (var i=0;i<_list_search2.length;i++) 169 { 170 var w = _list_search2[i]; 171 /* 172 \u65e5 173 174 日仏辞 175 */ 176 var _w2 = "" 177 for (var i2 = 0;i2<w.length;i2++) 178 { 179 var _code = w.charCodeAt(i2); 180 181 if (((_code>125)&&(_code<255))||(_code == 38)||(_code == '<')||(_code == '>')||(_code=='"')) 182 { 183 //_w2+="&#"+_code+";" // a revoir 184 } 185 else 186 { 187 _w2+=w.charAt(i2); 188 } 189 190 191 } 192 // alert(_w2) 193 _list_search.push(_w2); 194 } 195 196 var _list_search_for_formating = new Array(); 197 for (var i=0;i<_list_search.length;i++) 198 { 199 var _w = _list_search[i]; 200 var _b_valid = true; 201 for (var i2=i+1;i2<_list_search.length;i2++) 202 { 203 var _w2 = _list_search[i2]; 204 if (_w2.indexOf(_w)>-1) 205 { 206 _b_valid = false; 207 break; 208 } 209 } 210 if (_b_valid) _list_search_for_formating.push(_w); 211 } 212 return _list_search_for_formating; 213} 214 215 216function WA_openSearchDialog(_input,_search_index_js) 217{ 218 219 220 var _w = new WA_Dialog(); 221 _w._field_input=_input 222 _w._lyImage = 40; 223 _w._currentFilter="-1" 224 225 _w._displaySearchWindows=function(_input_value) 226 { 227 // 228 this._name_input='search-dialog-input' 229 this._name_select_filter='search-dialog-select-filter' 230 this._name_windows_title_result="wa-result-windows-title" 231 this._name_windows_result="wa-result-windows" 232 233 var _bgTitleColor = "rgba(0,0,0,0.5)" 234 235 var _css_label="font-weight:bold;font-size:12px;" 236 this.initializeWindow(600,500) 237 238 var _s ="" 239 _s+="<table border=0 cellpadding=0 cellspacing=0 style='width:100%;'>"; 240 _s+="<tr><td align=left style='"+_css_label+"'>" 241 _s+="<input type=text results=0 placeholder='' id='"+this._name_input+"' > " 242 _s+="<input type=button value='"+Translator.tr("Search")+"' onclick='WA_onClickSearch()'>" 243 _s+=" " 244 245 // alert('display '+window.CONST_WA_SEARCH_INDEX2) 246 _s+="<span id='search-filter-select' ></span>" 247 248 _s+="<br><br>" 249 _s+="</td>" 250 _s+="</tr>"; 251 _s+="</table>" 252 253 _s+="<div id='"+this._name_windows_title_result+"' style='" 254 _s+="font-family:Arial;color:#ffffff;font-weight:bold;text-align:right;font-size:13px;"; 255 _s+="height:20px;line-height:20px;width:100%;" 256 _s+="' ></div>" 257 258 _s+="<div id='"+this._name_windows_result+"' style='";
259 260 _s+="position:relative;overflow:auto;" 261 _s+="border-style:solid;border-width:1px;border-color:"+_bgTitleColor+";" 262 _s+="background-color:#ffffff;width:10px;height:10px;'></div>" 263 this.writeContent(_s) 264 265 waJSQuery("#"+this._name_windows_title_result).css({"backgroundColor":"#000000","opacity":0.5}) 266 267 //this._updateFilterSelect() 268 this.customUpdate() 269 waJSQuery("#"+this._name_input).val(_input_value) 270 } 271 272 273 _w._formatStringWithQuery = function(s) 274 { 275 var _list_search = this._list_query 276 var title_ref =s; 277 var title2 = removeAccentsFromString(title_ref.toLowerCase()); 278 279 var result =title_ref; 280 var result2 =title2; 281 282 for (var i=0;i<_list_search.length;i++) 283 { 284 var w = waJSQuery.trim(_list_search[i]); 285 //alert("formatStringWithQuery "+s+" "+w) 286 var len_w = w.length; 287 if (len_w>1) 288 { 289 var nb = 0; 290 var ind0 = 0; 291 var ind_search = 0; 292 var ind = 0; 293 do 294 { 295 ind = result2.indexOf(w,ind_search); 296 if (ind>-1) 297 { 298 var index_1 = ind+len_w; 299 300 var s0 = result.substring(ind0,ind); 301 var sw = result.substring(ind,ind+len_w); 302 var s1 = result.substring(index_1); 303 304 var s2_0 = result2.substring(ind0,ind); 305 var s2_1 = result2.substring(index_1); 306 307 result = s0+"<b>"+sw+"</b>"+s1; 308 result2 = s2_0+"<b>"+w+"</b>"+s2_1; 309 ind_search=index_1+7; 310 } 311 nb++; 312 313 } 314 while (ind>0); 315 } 316 } 317 //alert(result) 318 return result; 319 } 320 321 322 _w._updateFilterSelect=function(_params) 323 { 324 var _selectDiv = waJSQuery("#search-filter-select") 325 326 var _globalVar = window.CONST_WA_SEARCH_INDEX2 327 328 329 var _nbChoices = 0; 330 if (_params.hasPagesIndex==true) _nbChoices++; 331 if (_params.hasMarketItemIndex==true) _nbChoices++; 332 if (_params.hasImagesIndex==true) _nbChoices++; 333 if (_params.hasPrestashopIndex==true) _nbChoices++; 334 335 if (_nbChoices<=1) 336 { 337 _selectDiv.html("") 338 return; 339 } 340 341 //var _filter = waJSQuery("#"+this._name_select_filter+" ").val() 342 343 344 _selectDiv.data("initialized",true) 345 var _s="" 346 347 348 _s+="<select id='"+this._name_select_filter+"' onchange='WA_onClickSearch()'>" 349 _s+="<option value='-1' "+((this._currentFilter=="-1")?"selected":"")+">"+Translator.tr("All results")+"</option>" 350 if (_params.hasPagesIndex==true) 351 { 352 _s+="<option value='0'"+((this._currentFilter=="0")?"selected":"")+">"+Translator.tr("Pages results")+"</option>" 353 } 354 if (_params.hasImagesIndex==true) 355 { 356 _s+="<option value='2'"+((this._currentFilter=="2")?"selected":"")+">"+Translator.tr("Photos results")+"</option>" 357 } 358 if (_params.hasMarketItemIndex==true) 359 { 360 _s+="<option value='1'"+((this._currentFilter=="1")?"selected":"")+">"+Translator.tr("Articles results")+"</option>" 361 } 362 if (_params.hasPrestashopIndex==true) 363 { 364 _s+="<option value='3'"+((this._currentFilter=="3")?"selected":"")+">"+Translator.tr("PrestaShop results")+"</option>" 365 } 366 367 _s+="</select>" 368 _selectDiv.html(_s) 369 } 370 371 372 373 _w._setResultTitle=function(_s) 374 { 375 waJSQuery("#"+this._name_windows_title_result).html(_s+" ") 376 } 377 378 _w.closeWin=function() 379 { 380 this._field_input.focus() 381 this.intern_closeWin() 382 } 383 384 _w.onCustomKeypress=function(_k) 385 { 386 387 if (_k==13) 388 { 389 this._onSearch() 390 return true; 391 } 392 /* 393 if (_k!=27) 394 { 395 this._setResult("") 396 this._setResultTitle("");//Translator.tr("No results")) 397 } 398 */ 399 // alert(_k) 400 return false; 401 } 402 403 _w.customUpdate=function() 404 { 405 // alert("customUpdate"+this._widthSearchResult()) 406 waJSQuery("#"+this._name_windows_result).css({width:this.m_content_lx-2,height:this.m_content_ly-63}) 407 } 408 _w._setResult=function(_s) 409 { 410 waJSQuery("#"+this._name_windows_result).html(_s) 411 } 412 413 414 _w._buildItemResultHTML=function(_n,_title,_desc,_url,_htmlImage,_scoring) 415 { 416 var _shart_url = _url; 417 var _pos = _url.indexOf( 'prestashop_' ); 418 419 if ( _pos != -1 ) { 420 _shart_url = _url.substr( _pos ); 421 } 422 423 if (_title.length==0) 424 { 425 _title="Untitled" 426 } 427 else 428 { 429 _title = this._formatStringWithQuery(_title) 430 } 431 var _css_search_result_title="color:#212121;text-decoration:underline;font-size:15px;"; 432 var _css_search_result_description="color:#000000;font-size:13px;"; 433 var _css_search_result_url="color:#999999;font-size:13px;"; 434 var _css_search_result_annex_url="color:#990099;font-size:12px;"; 435 var _s="" 436 _s +="<table border=0 width=100% cellspacing=0 cellpadding=0>" 437 _s +="<tr>" 438 if (_htmlImage.length>0) 439 { 440 //alert(this._lyImage) 441 _s +="<td align=center valign=top width="+this._lyImage+"px style=''>" 442 _s += _htmlImage 443 444 _s +="</td>" 445 } 446 _s +="<td" 447 if (_htmlImage.length==0) 448 { 449 _s +="colspan=2" 450 } 451 _s +=">" 452 _s+= "<a style='"+_css_search_result_title+"' href='"+_url+"'>"+_title+"</a>"; 453 _s+="<br>"; 454 if (_desc.length>0) 455 { 456 _s+="<span style='"+_css_search_result_description+"'>"+this._formatStringWithQuery(_desc)+"</span><br>"; 457 }
458 _s+="<a style='"+_css_search_result_url+"' href='"+_url+"'>"+_shart_url +"</a>"; 459 _s +="</td>" 460 461 462 _s +="</tr>" 463 _s +="</table >"; 464 465 return _s; 466 } 467 468 _w._loadItemMarketResult=function(_objResult,_pageInfos,_urlInfo,_idMarket,_item,i,_scoring) 469 { 470 // alert("_loadItemMarketResult") 471 var _root = this 472 waJSQuery.getJSON(_urlInfo ,{}, function(_json) 473 { 474 var _it = _json.products[i] 475 var _url = _pageInfos.url+"?wa_key="+"wa_"+_objResult.info.p+"/market_"+_objResult.info.id 476 var _htmlImage ="" 477 var _ly = _root._lyImage; 478 479 480 481 if (_it.img_thumb.length>0) 482 { 483 var _size = new Size(_it.size_thumb[0],_it.size_thumb[1]); 484 _size.scale(new Size(_ly,_ly),true) 485 486 _htmlImage="<img src=\""+_it.img_thumb+"\" width=\""+_size.width()+"px\" height=\""+_size.height()+"px\" border=0 style='margin-right:10px;'>" 487 } 488 489 var _html = _root._buildItemResultHTML(i,_it.title,_it.sub_title,_url,_htmlImage,_scoring) 490 _item.html(_html) 491 }); 492 } 493 494 _w._loadItemPhotoResult=function(_objResult,_pageInfos,_urlInfo,_idFolder,_item,i,_scoring) 495 { 496 // alert("_loadItemPhotoResult") 497 var _root = this 498 waJSQuery.getJSON(_urlInfo ,{}, function(_json) 499 { 500 var _it = _json.images[i] 501 var _htmlImage ="" 502 var _ly = _root._lyImage; 503 504 var _sizeMax = new Size(_ly,_ly) 505 var _size = null 506 var _galType = _json.global_config.gallery_type 507 var _prefixe="th_" 508 if (_galType==0) 509 { 510 _size = _sizeMax 511 } 512 if ((_galType==1)&&(_json.global_config.open_popup_when_clicking==1)) 513 { 514 _prefixe="big_" 515 _size = new Size(_it.size.w,_it.size.h); 516 _size.scale(_sizeMax,true) 517 518 } 519 520 _htmlImage="<img src=\""+_idFolder+"/"+_prefixe+_it.fn+"\" width=\""+_size.width()+"px\" height=\""+_size.height()+"px\" border=0 style='margin-right:10px;'>" 521 522 523 524 var _url = _pageInfos.url+"?wa_key="+"wa_"+_objResult.info.p+"/pa_"+_objResult.info.id 525 var _html = _root._buildItemResultHTML(i,_it.comment,"",_url,_htmlImage,_scoring) 526 _item.html(_html) 527 }); 528 } 529 530 _w._onSearch=function() { 531 if ( typeof( prestaBase ) == 'undefined' || _stringIsEmpty( prestaBase ) ) { 532 _w._onSearchTerminated( null ); 533 } 534 else { 535 var _input = waJSQuery( '#' +this._name_input ); 536 var _list_query = _WA_formatSearchQuery( _input ); 537 var _url = prestaBase +'/wa/?service=info&lang=' +Translator.m_lang +'&q=products&exp=' +_list_query +'&pn=1&ps=1000'; 538 var _context = this; 539 540 _w._setResultTitle( 'Loading search index...' ); 541 _w._setResult( '<div align=center style="padding:20px;">' +htmlDynamicLoader( true, 100, 100 ) +'</div>' ); 542 waActivateDynamicLoader( waJSQuery( '#' +_w._name_windows_result ), true ); 543 544 waJSQuery.getJSON( _url, {}, function( _json ) { 545 _w._onSearchTerminated( _json ); 546 }); 547 } 548 } 549 550 _w._onSearchTerminated=function(_prestashopResults) 551 { 552 var _globalVar = window.CONST_WA_SEARCH_INDEX2; 553 554 if ( typeof( _globalVar ) == 'undefined' ) { 555 return; 556 } 557 558 559 var _m_array_page_infos = _globalVar.page_info; 560 var _filter = this._currentFilter; 561 562 if ( typeof( _filter ) == 'undefined' ) { 563 _filter = ''; 564 } 565 566 var _input = waJSQuery("#"+this._name_input) 567 568 this._field_input.val(_input.val()) 569 570 // alert(_input.length) 571 var _list_query = _WA_formatSearchQuery(_input) 572 this._list_query = _list_query; 573 574 575 // alert("_onSearch "+_filter) 576 var _paramsChoices = {} 577 var _list_final_results = _WA_onSearchInIndex(_list_query,_filter,_paramsChoices,_prestashopResults) 578 579 if ( typeof( _list_final_results ) == 'undefined' ) return; 580 581 var _s="" 582 var _css_common="font-family:Arial;"; 583 584 var _css_search_result_title="color:#212121;text-decoration:underline;font-size:15px;"; 585 var _css_search_result_description="color:#000000;font-size:13px;"; 586 var _css_search_result_url="color:#999999;font-size:13px;"; 587 var _css_search_result_annex_url="color:#990099;font-size:12px;"; 588 589 var l_image=40;//35; 590 for (var i = 0;i<_list_final_results.length;i++) 591 { 592 var _objFinalResult = _list_final_results[i] 593 var _objSearchResult = _objFinalResult._objSearchResult; 594 var _objResult = _objSearchResult.objResult; 595 596 var _pageInfos = _m_array_page_infos[_objResult.p];//_obj.page_info 597 598 if ( typeof( _pageInfos ) == 'undefined' ) { 599 _pageInfos = { 600 title: '', 601 desc: '', 602 url: '' 603 }; 604 } 605 606 var _title = _pageInfos.title 607 var desc =_pageInfos.desc 608 var url = _pageInfos.url 609 610 if ( typeof( _title ) == 'undefined' ) _title=""
611 if ( typeof( desc ) == 'undefined' ) desc="" 612 if ( typeof( url ) == 'undefined' ) url="" 613 614 if (_objResult.typ==0) 615 { 616 // _hasPagesIndex = true; 617 } 618 619 if (_objResult.typ==1) 620 { 621 desc="market "+_pageInfos.info 622 url="market?item="+_pageInfos.info 623 // _hasMarketItemIndex = true; 624 } 625 if (_objResult.typ==2) 626 { 627 desc="img "+_pageInfos.info 628 // _hasImagesIndex = true; 629 } 630 if (_objResult.typ==3) 631 { 632 url = _objResult.info.link; 633 _title = _objResult.info.name; 634 desc = ''; 635 // hasPrestashopIndex = true; 636 } 637 638 var _formatedDescription = desc ;//+" "+_obj._descriptionFormatedWithQuery(_list_query) 639 640 //alert(_objResult.typ) 641 642 var _bgColor="" 643 if (i%2==0) 644 { 645 _bgColor="background-color:#f3f3f3;" 646 } 647 648 _s+="<div id='search_item-"+i+"' style='padding:5px;"+_bgColor+"'>" 649 650 if (_objResult.typ==0) 651 { 652 if (_title.length==0) 653 { 654 _title = url; 655 } 656 _s+= this._buildItemResultHTML(i,_title,_formatedDescription,url,"",_objSearchResult.scoring) 657 } 658 else if ( _objResult.typ == 3 ) { 659 _htmlImage = '<img src="' +_objResult.info.image +'" width="45px" height="45px" border=0 style="margin-right:10px;">'; 660 _s += this._buildItemResultHTML( i, _title, desc, url, _htmlImage, _objSearchResult.scoring ); 661 } 662 else 663 { 664 _s+="item "+_pageInfos.info; 665 } 666 667 _s+="</div>" 668 669 } 670 671 /// 672 673 this._setResult(_s) 674 675 //// 676 677 if (_list_final_results.length==0) 678 { 679 if ((this._list_query.length==0)&&(_input.val().length>0)) 680 { 681 this._setResultTitle(Translator.tr("Type words with more characters")) 682 } 683 else 684 { 685 this._setResultTitle(Translator.tr("No results")) 686 } 687 688 689 // 690 691 } 692 else 693 { 694 this._setResultTitle(Translator.tr("Search result")+" : "+_list_final_results.length) 695 } 696 697 698 699 if (_list_final_results.length>0) 700 { 701 var _win = waJSQuery("#"+this._name_windows_result) 702 //enhance results 703 for (var i = 0;i<_list_final_results.length;i++) 704 { 705 var _objFinalResult = _list_final_results[i] 706 // .page_reference 707 var _objSearchResult = _objFinalResult._objSearchResult; 708 709 var objResult = _objSearchResult.objResult; 710 711 712 var _objInfo = objResult.info 713 714 // alert(_objInfo) 715 var _pageInfos = _globalVar.page_info[objResult.p] 716 if (objResult.typ!=0) 717 { 718 var _item = _win.find("#search_item-"+i) 719 720 var _info = _objInfo.id 721 var _nItem = -1; 722 var _n1 = typeof( _info ) == 'undefined' ? -1 : _info.lastIndexOf("-"); 723 if (_n1>-1) 724 { 725 _nItem = parseInt(_info.substring(_n1+1)) 726 _info = _info.substring(0,_n1) 727 } 728 var _extlang = Translator.m_lang_for_filename; 729 if (_extlang.length>0) 730 { 731 _extlang = "_"+_extlang 732 } 733 // alert(_extlang) 734 if (objResult.typ == 1) 735 { 736 var _urlInfo = "wa_"+_objInfo.p+"/market_"+_info+"/"; 737 738 _urlInfo += "market-definition"+_extlang+".js"; 739 740 var _idMarket = "wa_"+_objInfo.p+"/market_"+_info 741 this._loadItemMarketResult(objResult,_pageInfos,_urlInfo,_idMarket,_item,_nItem,_objSearchResult.scoring) 742 } 743 744 if (objResult.typ == 2) 745 { 746 var _urlInfo = "wa_"+_objInfo.p+"/pa_"+_info+"/"; 747 _urlInfo += "photo-album-definition"+_extlang+".js"; 748 749 //alert(_urlInfo) 750 var _idFolder = "wa_"+_objInfo.p+"/pa_"+_info 751 this._loadItemPhotoResult(objResult,_pageInfos,_urlInfo,_idFolder,_item,_nItem,_objSearchResult.scoring) 752 } 753 } 754 } 755 } 756 757 758 this._updateFilterSelect(_paramsChoices); 759 760 761 _input.focus() 762 } 763 764 _w._displaySearchWindows(_input.val()) 765 766 if (document.wa_search_index_js_loaded == true) 767 { 768 _w._onSearch() 769 } 770 else 771 { 772 _w._loading_index_in_progress=true; 773 _w._setResultTitle("Loading search index...") 774 775 _w._setResult("<div align=center style='padding:20px;'>"+htmlDynamicLoader(true,100,100)+"</div>") 776 777 WA_loadScript(_search_index_js,_WA_SearchIndexLoaded,[_w]) 778 } 779 780 waActivateDynamicLoader(waJSQuery("#"+_w._name_windows_result),true) 781 782} 783 784 785function _WA_onSearchInIndex(_list_query,_filter,_paramChoices,_prestashopResults) 786{ 787 if ( typeof( window.CONST_WA_SEARCH_INDEX2 ) == 'undefined' ) return 788 789 // this is a deep copy - aka original window.CONST_WA_SEARCH_INDEX2 will not be modified if we modify this object 790 var _globalVar = jQuery.extend(true, {}, window.CONST_WA_SEARCH_INDEX2); 791 var _hasPrestashopIndex = false;
792 793 // add shop results into the deep copy so we don't need to modifiy much the current code 794 var _hasPS = ( typeof( _prestashopResults ) != 'undefined' ) && ( _prestashopResults != null ); 795 _hasPS = _hasPS && ( typeof( _prestashopResults.data ) != 'undefined' ) && ( _prestashopResults.data != null ); 796 797 if ( _hasPS ) { 798 if ( typeof( _globalVar.result_items ) == 'undefined' ) { 799 _globalVar.result_items = new Object(); 800 } 801 802 if ( typeof( _globalVar.index ) == 'undefined' ) { 803 _globalVar.index = new Object(); 804 } 805 806 for ( var i = 0; i < _prestashopResults.data.length; i++ ) { 807 var _item = _prestashopResults.data[ i ]; 808 var _resultItem = { 809 typ: 3, 810 p: -1, 811 info: { 812 image: _item.imgURL, 813 name: _item.name, 814 link: _item.link 815 } 816 }; 817 818 _globalVar.result_items.push( _resultItem ); 819 820 for ( var j = 0; j < _list_query.length; j++ ) { 821 var _list_item = _list_query[ j ]; 822 823 if ( typeof( _globalVar.index[ _list_item ] ) == 'undefined' ) { 824 _globalVar.index[ _list_item ] = new Array(); 825 } 826 827 var _resultIndex = [ 828 _globalVar.result_items.length -1, 829 1 830 ]; 831 832 _globalVar.index[ _list_item ].unshift( _resultIndex ); 833 _hasPrestashopIndex = true; 834 } 835 } 836 } 837 838 _globalVar.has_prestashop_index = _hasPrestashopIndex; 839 840 var _hasPagesIndex = false; 841 var _hasImagesIndex = false; 842 var _hasMarketItemIndex = false; 843 844 //alert(_list_query+" "+_filter) 845 var _list_result2 = false; 846 var _list_result = new Array() 847 //alert("_filter="+_filter) 848 var nDebug = 0; 849 var _m_array_index=_globalVar.index 850 var _m_array_result_items=_globalVar.result_items 851 var _m_array_page_infos=_globalVar.page_info 852 // 853 var _list_search = _list_query 854 855 for (var i=0;i<_list_search.length;i++) 856 { 857 var w = _list_search[i]; 858 859 if (w.length>0) 860 { 861 _list_result = new Array(); 862 863 for (var index in _m_array_index) 864 { 865 var _ind_match_search = index.indexOf(w) ; 866 867 if (_ind_match_search!= -1) 868 { 869 var list_refs = _m_array_index[index]; 870 //match ! 871 872 for (var _index_result in list_refs) 873 { 874 var _refResult = list_refs[_index_result]; // _refResult == [6,1] 875 var _indexItemResult = _refResult[0] //index item result 876 var _scoring= _refResult[1] 877 //scoring ponderation 878 /* 879 _ind_match_search==0 //commence par la clé score = 1 880 _ind_match_search>0 //contient clé score = 0.5 881 index == w //cexact match score = 1.5 882 */ 883 // 884 885 var _objResult = _m_array_result_items[_indexItemResult]; 886 var _bMatch = false; 887 888 if ((_filter=="-1")||(_filter=="")) _bMatch= true; 889 if (_filter=="0") _bMatch= (_objResult.typ==0); 890 if (_filter=="1") _bMatch= (_objResult.typ==1); 891 if (_filter=="2") _bMatch= (_objResult.typ==2); 892 if (_filter=="3") _bMatch= (_objResult.typ==3); 893 894 if (_objResult.typ==0) _paramChoices.hasPagesIndex = true; 895 if (_objResult.typ==1) _paramChoices.hasMarketItemIndex = true; 896 if (_objResult.typ==2) _paramChoices.hasImagesIndex = true; 897 if (_objResult.typ==3) _paramChoices.hasPrestashopIndex = true; 898 899 //alert(_filter) 900 /* 901 if (nDebug<4) 902 { 903 alert(_filter+" "+_objResult.typ) 904 nDebug++; 905 } 906 */ 907 if (_bMatch) 908 { 909 var _objSearchResult = _list_result[_indexItemResult]; 910 911 if ( typeof( _objSearchResult ) == 'undefined' ) 912 { 913 _list_result[_indexItemResult] = new Object(); 914 _objSearchResult = _list_result[_indexItemResult]; 915 _objSearchResult.scoring = 0; 916 _objSearchResult.objResult = _objResult; 917 } 918 _objSearchResult.scoring+=_scoring; 919 } 920 921 } 922 } 923 } 924 925 if (_list_result2) 926 { 927 var _list_result3 = new Array(); 928 929 for (var index in _list_result) 930 { 931 for (var index2 in _list_result2) 932 { 933 if (index2==index) 934 { 935 _list_result3[index] = _list_result[index]; 936 break; 937 } 938 } 939 } 940 _list_result = _list_result3; 941 } 942 943 _list_result2 = _list_result; 944 } 945 946 //// 947 } 948 /////////// 949 950 var _list_final_result = new Array(); 951 952///// 953 var _nb_result=0; 954 for (var _indexSearchResult in _list_result) 955 { 956 var _objSearchResult = _list_result[_indexSearchResult] 957 //alert("result="+_infoPage) 958 var _object_final_result = new Array(); 959 // .page_reference 960 _object_final_result._objSearchResult = _objSearchResult; 961 _object_final_result.index_page=_indexSearchResult; 962 _object_final_result.scoring=0; 963 964 //_objSearchResult.objResult 965 //_ref_score + _info._getAdditionalScore(_list_search); 966 _object_final_result.test_index=_nb_result; 967 968 _list_final_result.push(_object_final_result); 969 _nb_result++; 970 971 972 } 973 //// 974 _list_final_result = _list_final_result.sort(_WA_sort_fct_scoring); 975 976// alert(_list_final_result.length) 977 978 return _list_final_result; 979} 980 981 982///////////////// 983 984 985function _WA_SearchInitialisation() 986{ 987} 988 989 990///////////////////////////////// 991/* 992function _SearchResultPageInfo() 993{ 994 this.m_ref=""; 995 this.m_img="" 996 this._filterAttributes = function (_s) 997 { 998 if ( typeof( _s ) == 'undefined' ) return"" 999 return _s 1000 } 1001 this.parseAttributes = function (_page_info) 1002 { 1003 this.m_lang = _page_info.lng; 1004 this.m_url = _page_info.url; 1005 1006 this.m_title = this._filterAttributes(_page_info.title); 1007 this.m_title2 = this._filterAttributes(_page_info.title2); 1008 1009 this.m_description = this._filterAttributes(_page_info.desc); 1010 this.m_description2 = this._filterAttributes(_page_info.desc2); 1011 1012 this.m_keywords = this._filterAttributes(_page_info.k); 1013 1014 this.m_img = this._filterAttributes(_page_info.img); 1015 var img_size = _page_info.img_size; 1016 if (!img_size)img_size="" 1017 this.m_type = parseInt(_page_info.type) 1018 if (isNaN(this.m_type)) 1019 { 1020 this.m_type = 0; 1021 } 1022 if (img_size.length>0) 1023 { 1024 var list_size = img_size.split(","); 1025 if (list_size.length==2) 1026 { 1027 this.m_img_lx=parseInt(list_size[0]) 1028 this.m_img_ly=parseInt(list_size[1]) 1029 } 1030 } 1031 } 1032 /// 1033 this._getAdditionalScore =function(_list_search) 1034 { 1035 var res = 0; 1036 for (var i=0;i<_list_search.length;i++) 1037 { 1038 var w = _list_search[i]; 1039 if (w.length>1) 1040 { 1041 res+=25 * _SearchResultPageInfo._computeScore(w,this.m_title2); 1042 res+=15 * _SearchResultPageInfo._computeScore(w,this.m_description2); 1043 res+=30 * _SearchResultPageInfo._computeScore(w,this.m_keywords); 1044 } 1045 } 1046 return res; 1047 } 1048 1049 this.url=function(lng) 1050 { 1051 if (this.m_lang=="all") 1052 { 1053 if (lng.length==0) 1054 { 1055 return this.m_url.replace(/@lng@/g,"") 1056 //return StringUtils.replace(this.m_url,"@lng@","") 1057 } 1058 else 1059 {
1060 //return StringUtils.replace(this.m_url,"@lng@","_"+lng) 1061 return this.m_url.replace(/@lng@/g,"_"+lng) 1062 } 1063 1064 } 1065 return this.m_url; 1066 } 1067 1068 1069 this.formatStringWithQuery = function(s,_list_search) 1070 { 1071 1072 var title_ref =s; 1073 var title2 = removeAccentsFromString(title_ref.toLowerCase()); 1074 1075 var result =title_ref; 1076 var result2 =title2; 1077 1078 for (var i=0;i<_list_search.length;i++) 1079 { 1080 var w = waJSQuery.trim(_list_search[i]); 1081//alert("formatStringWithQuery "+s+" "+w) 1082 var len_w = w.length; 1083 if (len_w>1) 1084 { 1085 var nb = 0; 1086 var ind0 = 0; 1087 var ind_search = 0; 1088 var ind = 0; 1089 do 1090 { 1091 ind = result2.indexOf(w,ind_search); 1092 if (ind>-1) 1093 { 1094 var index_1 = ind+len_w; 1095 1096 var s0 = result.substring(ind0,ind); 1097 var sw = result.substring(ind,ind+len_w); 1098 var s1 = result.substring(index_1); 1099 1100 var s2_0 = result2.substring(ind0,ind); 1101 var s2_1 = result2.substring(index_1); 1102 1103 result = s0+"<b>"+sw+"</b>"+s1; 1104 result2 = s2_0+"<b>"+w+"</b>"+s2_1; 1105 ind_search=index_1+7; 1106 } 1107 nb++; 1108 1109 } 1110 while (ind>0); 1111 } 1112 } 1113 //alert(result) 1114 return result; 1115 } 1116 1117 this.title=function() 1118 { 1119 var title =this.m_title; 1120 if (title.length==0) 1121 { 1122 title = "Page "+this.m_ref+" (no title !)"; 1123 } 1124 return title; 1125 } 1126 this._titleFormatedWithQuery=function(_list_search) 1127 { 1128 return this.formatStringWithQuery(this.title(),_list_search); 1129 } 1130 this._descriptionFormatedWithQuery=function (_list_search) 1131 { 1132 return this.formatStringWithQuery(this.m_description,_list_search); 1133 } 1134 1135 1136} 1137 1138 1139_SearchResultPageInfo._computeScore=function(_query_w,match_w) 1140{ 1141 var _score = 0; 1142 if (_query_w==match_w) 1143 { 1144 _score=6.2; 1145 } 1146 else 1147 { 1148 var ind = match_w.indexOf(_query_w); 1149 if (ind==0) 1150 { 1151 _score=5; 1152 } 1153 else 1154 if (ind>0) 1155 { 1156 _score=1; 1157 } 1158 } 1159// _score+=0.2 1160 return _score; 1161} 1162*/ 1163 1164 function _WA_sort_fct_string_by_length(a, b) 1165 { 1166 if (a.length < b.length) return -1; 1167 else 1168 if (a.length > b.length) return 1; 1169 return 0; 1170} 1171 1172 function _WA_sort_fct_scoring(a, b) 1173 { 1174 var _objSearch1 = a._objSearchResult 1175 var _objSearch2 = b._objSearchResult 1176 1177 if (_objSearch2.scoring < _objSearch1.scoring) return -1; 1178 else 1179 if (_objSearch2.scoring > _objSearch1.scoring) return 1; 1180 1181 if (_objSearch1.typ < _objSearch2.typ) return -1; 1182 else 1183 if (_objSearch1.typ > _objSearch2.typ) return 1; 1184 1185 1186 return 0; 1187} 1188-->
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.