1/** 2 * Savvy Search Autocomplete 3 * 4 * 5 * NOTICE OF LICENSE 6 * 7 * This source file is subject to the Academic Free License (AFL 3.0) 8 * that is bundled with this package in the file LICENSE.txt. 9 * It is also available through the world-wide-web at this URL: 10 * http://opensource.org/licenses/afl-3.0.php 11 * If you did not receive a copy of the license and are unable to 12 * obtain it through the world-wide-web, please send an email 13 * to [email protected] so we can send you a copy immediately. 14 * 15 * DISCLAIMER 16 * 17 * Do not edit or add to this file if you wish to upgrade PrestaShop to newer 18 * versions in the future. If you wish to customize PrestaShop for your 19 * needs please refer to http://www.prestashop.com for more information. 20 * 21 * @author Giant Leap Lab (http://www.giantleaplab.com) 22 * @copyright 2011-2017 Giant Leap Lab 23 * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) 24 * @version v4.0.2 (Nov 02, 2017) 25 * International Registered Trademark & Property of PrestaShop SA 26 */ 27 28!(function(){ 29 30 var instantAjaxSearchQueries = []; 31 32 function tryToCloseInstantSearch () { 33 var $oldCenterColumn = $('#old-center-column'); 34 if ( $oldCenterColumn.length > 0 ) { 35 $('#center_column').remove(); 36 $oldCenterColumn.attr('id', 'center-column').show(); 37 } 38 } 39 40 function stopInstantSearchQueries () { 41 for ( var i = 0, l = instantAjaxSearchQueries.length; i < l; i++ ) { 42 instantAjaxSearchQueries[i].abort(); 43 } 44 instantAjaxSearchQueries = []; 45 } 46 47 function bindAutocomplete ($input) { 48 var ajaxsearch = ajaxsearch || true; 49 if ( $input && !!ajaxsearch && !!ssa_autocomplete_url) { 50 $input.ssa_autocomplete({ 51 minchars : ssa_minchars, 52 url : ssa_autocomplete_url 53 }); 54 } 55 } 56 57 function bindInstantSearch ($input) { 58 if ( $input && typeof instantsearch !== 'undefined' && instantsearch ) { 59 $input.on('keyup', function () { 60 if ( $(this).val().length <= 4 ) { 61 tryToCloseInstantSearch(); 62 } 63 else { 64 stopInstantSearchQueries(); 65 instantSearchQuery = $.ajax({ 66 url : search_url + '?rand=' + new Date().getTime(), 67 data : { 68 instantSearch : 1, 69 id_lang : id_lang, 70 q : $(this).val() 71 }, 72 dataType : 'html', 73 type : 'get', 74 headers : { 75 "cache-control" : "no-cache" 76 }, 77 async : true, 78 cache : false, 79 success : function (data) { 80 if ( $input.val().length > 0 ) { 81 tryToCloseInstantSearch(); 82 $('#center_column').attr('id', 'old-center-column'); 83 $('#old-center-column').after('<div id="center-column" class="' + $('#old-center-column').attr('class') + '">' + data + '</div>').hide(); 84 // Button override 85 ajaxCart.overrideButtonsInThePage(); 86 $("#instant-search-results a.close").on('click', function () { 87 $input.val(''); 88 return tryToCloseInstantSearch(); 89 }); 90 return false; 91 } 92 else 93 tryToCloseInstantSearch(); 94 } 95 }); 96 if ( !!instantSearchQuery ) { 97 instantAjaxSearchQueries.push(instantSearchQuery); 98 } 99 } 100 }); 101 } 102 } 103 104 function initVars () { 105 $input_top = $("#ssa-search-query-top"); 106 } 107 108 function getCartObj() { 109 if ( 'ajaxCart' in window && typeof window.ajaxCart.add === 'function' ) { 110 return window.ajaxCart; 111 } 112// if ( 'parent' in window && 'ajaxCart' in window.parent && typeof window.parent.ajaxCart.add === 'function' ) { 113// return window.parent.ajaxCart; 114// } 115 return null; 116 } 117 118 function bindAddToCart ($input) { 119 window.ssa_has_addcart = false;
120 if ( $input && $input.ssa_autocomplete ) { 121 window.ssa_has_addcart = true; 122 if(typeof prestashop == 'undefined') { 123 //Prestashop 1.6 124 var cart = getCartObj(); 125 if ( !!cart ) { 126 window.ssa_has_addcart = true; 127 $(document).on('click', '.ssa-menu .ssa-add-cart', function (e) { 128 e.preventDefault(); 129 e.stopImmediatePropagation(); 130 var $el = $(this); 131 var id = $el.data('id_product'); 132 var qty = Math.max(0, $el.data('minimal_quantity')); 133 if ( !!id && !!qty ) { 134 var pContentOnly = window.contentOnly; 135 var pUpdateLayer = cart.updateLayer; 136 window.contentOnly = false; 137 cart.updateLayer = function () { 138 window.contentOnly = pContentOnly; 139 cart.updateLayer = pUpdateLayer; 140 }; 141 cart.add(id, null, false, null, qty); 142 } 143 return false; 144 }); 145 } 146 } else { 147 //Prestashop 1.7 148 window.ssa_has_addcart = true; 149 $(document).on('click', '.ssa-menu .ssa-add-cart', function (e) { 150 e.preventDefault(); 151 e.stopImmediatePropagation(); 152 var $el = $(this); 153 var id = $el.data('id_product'); 154 var qty = Math.max(0, $el.data('minimal_quantity')); 155 if ( !!id && !!qty ) { 156 var data = 'token='+prestashop.token+'&id_product='+id+'&qty='+qty+'&add=1&action=update'; 157 $.post( 158 prestashop.urls.pages.cart, 159 data, 160 function(resp){ 161 prestashop.emit('updateCart', { 162 reason: { 163 idProduct: resp.id_product, 164 idProductAttribute: resp.id_product_attribute, 165 linkAction: 'add-to-cart', 166 cart: resp.cart 167 }, 168 resp: resp 169 }); 170 }, 171 'json' 172 ); 173 } 174 return false; 175 }); 176 } 177 178 } 179 } 180 181 $(document).ready(function () { 182 $('.ssa-search-query-input').each(function () { 183 var $input_top = $(this); 184 bindAutocomplete($input_top); 185 bindInstantSearch($input_top); 186 bindAddToCart($input_top); 187 }); 188 }); 189})();
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.