1 2const commonlibCartShareSettings = { 3 uniqueId: "", 4 storageKey: "" 5} 6 7const commonlibCartShareGetLink = (cartId) => { 8 const copyButtonId = "#copy-button-"+commonlibCartShareSettings.uniqueId 9 const emailConfirmationId = "#email-confirmation-"+commonlibCartShareSettings.uniqueId 10 const resultId = "#result-"+commonlibCartShareSettings.uniqueId 11 12 $(copyButtonId).hide() 13 14 let email = $(emailConfirmationId).val() 15 16 $.post('/',{ 17 JSON: "COMMONLIB_CART_SHARE_GENERATE_LINK", 18 cart_id: cartId, 19 email: email 20 },(response) => { 21 if( response['result'] === "ok" && response['link'] ) { 22 let output = '<span>' 23 output += response['link'] 24 output += '</span>' 25 $(resultId).html(output) 26 $(copyButtonId).show() 27 } 28 }) 29} 30 31const commonlibCartShareToggle = () => { 32 const containerIdShort = "container-"+commonlibCartShareSettings.uniqueId 33 const containerId = `#${containerIdShort}` 34 35 $('.cart-submenu').each(function() { 36 let container = $(this) 37 if( $(container).attr('id') != containerIdShort ) { 38 $(container).hide() 39 let cs_key = $(container).attr('data-storage') 40 if( cs_key ) CartStorage.set(cs_key,0) 41 } 42 }) 43 44 if( $(containerId).is(':visible') ) { 45 CartStorage.set(commonlibCartShareSettings.storageKey,0); 46 $(containerId).hide(); 47 } else { 48 CartStorage.set(commonlibCartShareSettings.storageKey,1); 49 $(containerId).show(); 50 } 51} 52 53const commonlib_show_copy_message = () => { 54 const msgId = "#msg-"+commonlibCartShareSettings.uniqueId 55 56 $(msgId).show() 57 setTimeout(()=>{ 58 $(msgId).fadeOut() 59 },3000) 60} 61 62const commonlibCartShareBinds = () => { 63 const fileLocation = "/home/www/SE_sys/plugins/code/_commonLib/Cart/share.js" 64 65 // ======================================================================== 66 // toggle cart share 67 // ======================================================================== 68 register_event_hook('click_event_hook',(elem) => { 69 const action = elem.getAttribute('data-click-action') 70 71 if( action === "commonlib-cart-share-toggle" ) { 72 commonlibCartShareToggle() 73 } 74 },{ 75 type: "commonlib cart share toggle", 76 file: fileLocation, 77 uid: "commonlib_cart_share_toggle" 78 }) 79 80 // ======================================================================== 81 // get link 82 // ======================================================================== 83 register_event_hook('click_event_hook',(elem) => { 84 const action = elem.getAttribute('data-click-action') 85 86 if( action === "commonlib-cart-share-get-link" ) { 87 const cartId = elem.getAttribute('data-cartId') 88 commonlibCartShareGetLink(cartId) 89 } 90 },{ 91 type: "commonlib cart share get link", 92 file: fileLocation, 93 uid: "commonlib_cart_share_get_link" 94 }) 95 96 // ======================================================================== 97 // copy link 98 // ======================================================================== 99 register_event_hook('click_event_hook',(elem) => { 100 let action = elem.getAttribute('data-click-action') 101 if( ! action ) { 102 closest_elem = event_hook_first_action(elem,'data-click-action') 103 104 if( ! closest_elem ) return 105 106 elem = closest_elem 107 action = elem.getAttribute('data-click-action') 108 } 109 if( action === "commonlib-cart-share-copy-link" ) { 110 const id = elem.getAttribute('data-targetElement') 111 copy_to_clipboard(id) 112 commonlib_show_copy_message() 113 } 114 },{ 115 type: "commonlib cart share copy link", 116 file: fileLocation, 117 uid: "commonlib_cart_share_copy_link" 118 }) 119} 120 121const commonlibCartShareInit = (params) => { 122 commonlibCartShareSettings.uniqueId = params.uniqueId 123 commonlibCartShareSettings.storageKey = params.storageKey 124 125 commonlibCartShareBinds() 126 127 if( CartStorage.get(commonlibCartShareSettings.storageKey) == 1 ) { 128 $('#commonlib-cart-share-container').show() 129 } 130} 131 132register_hook('pre_call_row','cart',function(name,row) { 133 if( row['name'] == "upselling" ) { 134 row['func'] = function() {}; 135 } 136}); 137
138var commonlib_upselling_div_id = "cart-payment-extra1"; 139 140commonlib_upselling_div_id = "cart-payment-extra1"; 141 142 143register_hook('post_calls','cart',function(name,row) { 144 $('#'+commonlib_upselling_div_id).show(); 145 update_cart_element( $('#'+commonlib_upselling_div_id), 'rs/commonlib-cart-upselling.htm', '', function() { run_chain('update_cart_chain') } ); 146}); 147 148const commonlibQuickbuyStates = { 149 uniqueId: "", 150 selectedVariantId: 0, 151 isRunning: false, 152 storageKey: "" 153} 154 155const commonlibQuickbuyToggleInput = () => { 156 const containerIdShort = "container-"+commonlibQuickbuyStates.uniqueId 157 const containerId = "#"+containerIdShort 158 159 $('.cart-submenu').each(function() { 160 let container = $(this) 161 if( $(container).attr('id') != containerIdShort ) { 162 $(container).hide() 163 let cs_key = $(container).attr('data-+storage') 164 if( cs_key ) CartStorage.set(cs_key,0) 165 } 166 }) 167 168 if( $(containerId).is(':visible') ) { 169 CartStorage.set(commonlibQuickbuyStates.storageKey,0) 170 $(containerId).hide() 171 } else { 172 CartStorage.set(commonlibQuickbuyStates.storageKey,1) 173 $(containerId).show() 174 } 175} 176 177const commonlibQuickbuySelectItem = (variantId, textId, name) => { 178 const inputId = "#input-"+commonlibQuickbuyStates.uniqueId 179 const resultId = "#results-"+commonlibQuickbuyStates.uniqueId 180 const errorId = "#error-"+commonlibQuickbuyStates.uniqueId 181 182 commonlibQuickbuyStates.selectedVariantId = variantId 183 184 $(inputId).val(textId + " " + name) 185 $(resultId).hide() 186 $(errorId).html('') 187} 188 189const commonlibQuickbuyShowResults = (response) => { 190 const resultId = "#results-"+commonlibQuickbuyStates.uniqueId 191 192 $(resultId).html('') 193 194 if( response['results'].length == 1 ) { 195 const item = response['results'][0] 196 commonlibQuickbuySelectItem(item.variant_id, item.textid, item.text) 197 $(resultId).hide(); 198 } else { 199 for( let i=0; i < response['results'].length; i ++ ) { 200 const item = response['results'][i] 201 202 let output = $(resultId).html() 203 output += '<a href="#"' 204 output += ' data-click-action="commonlib-cart-quickbuy-select-item"' 205 output += ' data-variant_id="'+item.variant_id+'"' 206 output += ' data-textid="'+item.textid+'"' 207 output += ' data-name="'+item.text+'">' 208 output += item.textid + " " + item.text; 209 output += "</a>" 210 211 $(resultId).html(output) 212 } 213 214 $(resultId).html() 215 ? $(resultId).show() 216 : $(resultId).hide() 217 } 218} 219 220const commonlibQuickbuySearch = (inputId, key) => { 221 if( commonlibQuickbuyStates.isRunning ) return 222 223 const resultId = "#results-"+commonlibQuickbuyStates.uniqueId 224 const searchValue = $(inputId).val() 225 226 if( searchValue.length < 3 ) { 227 $(resultId).html('') 228 $(resultId).hide() 229 return 230 } 231 232 // arrow up && down 233 if( key == 38 || key == 40 ) return 234 235 // enter 236 if( key == 13 ) { 237 commonlibQuickbuyBuy() 238 return 239 } 240 241 // escape 242 if( key == 27 ) { 243 $(resultId).html('') 244 $(resultId).hide() 245 return 246 } 247 248 commonlibQuickbuyStates.isRunning = true 249 setTimeout(()=>{ 250 commonlibQuickbuyStates.isRunning = false 251 },3000) 252 253 $.ajax({ 254 type: "GET", 255 url: "/?JSON=COMMONLIB_QUICKBUY_SUGGESTIONS&search="+escape(searchValue), 256 dataType: "json", 257 cache: true, 258 success: (response) => { 259 commonlibQuickbuyStates.isRunning = false 260 if( response ) { 261 commonlibQuickbuyShowResults(response) //data, elem, url, param); 262 } 263 } 264 }); 265} 266 267const commonlibQuickbuyBuy = () => { 268 const inputId = "#input-"+commonlibQuickbuyStates.uniqueId 269 const resultId = "#results-"+commonlibQuickbuyStates.uniqueId 270 const errorId = "#error-"+commonlibQuickbuyStates.uniqueId 271 272 $(errorId).html('') 273 274 if( ! commonlibQuickbuyStates.selectedVariantId ) { 275 $(errorId).html($(errorId).attr('data-idMissing')) 276 return 277 } 278 279 $.post('/',{ 280 ADD_TO_CART: 1, 281 ID: commonlibQuickbuyStates.selectedVariantId, 282 Qty: 1 283 },() => { 284 commonlibQuickbuyStates.selectedVariantId = 0 285 run_chain('update_cart_chain') 286 }) 287} 288 289const commonlibQuickbuyInputInit = () => { 290 const inputId = "#input-"+commonlibQuickbuyStates.uniqueId 291 const elem = document.querySelector(inputId) 292 293 elem.addEventListener("keyup", (event) => { 294 commonlibQuickbuySearch(inputId,event.which) 295 }) 296} 297 298const commonlibQuickbuyBinds = () => { 299 const fileLocation = "/home/www/SE_sys/plugins/code/_commonLib/Cart/quickbuy.js" 300 301 // ======================================================================== 302 // Toggle input field 303 // ======================================================================== 304 register_event_hook('click_event_hook',(elem) => { 305 const action = elem.getAttribute('data-click-action') 306 if( action === "commonlib-cart-quickbuy-toggle" ) { 307 commonlibQuickbuyToggleInput() 308 } 309 },{ 310 type: "commonlib cart quickbuy toggle", 311 file: fileLocation, 312 uid: "commonlib_cart_quickbuy_toggle" 313 }) 314 315 // ======================================================================== 316 // Select a search suggestion 317 // ======================================================================== 318 register_event_hook('click_event_hook',(elem) => { 319 const action = elem.getAttribute('data-click-action') 320 if( action === "commonlib-cart-quickbuy-select-item" ) { 321 const variantId = elem.getAttribute('data-variant_id') 322 const textId = elem.getAttribute('data-textid') 323 const name = elem.getAttribute('data-name') 324 commonlibQuickbuySelectItem(variantId,textId,name) 325 } 326 },{ 327 type: "commonlib cart quickbuy select item", 328 file: fileLocation, 329 uid: "commonlib_cart_quickbuy_select_item" 330 }) 331 332 // ======================================================================== 333 // Select a search suggestion 334 // ======================================================================== 335 register_event_hook('click_event_hook',(elem) => { 336 const action = elem.getAttribute('data-click-action') 337 if( action === "commonlib-cart-quickbuy-buy" ) { 338 commonlibQuickbuyBuy() 339 } 340 },{ 341 type: "commonlib cart quickbuy buy", 342 file: fileLocation, 343 uid: "commonlib_cart_quickbuy_buy" 344 }) 345} 346 347const commonlibQuickbuyInit = (params) => { 348 commonlibQuickbuyStates.uniqueId = params.uniqueId 349 commonlibQuickbuyStates.storageKey = params.storageKey 350 351 commonlibQuickbuyInputInit() 352 commonlibQuickbuyBinds() 353 354 const containerId = "#container-"+commonlibQuickbuyStates.uniqueId 355 const inputId = "#input-"+commonlibQuickbuyStates.uniqueId 356 357 if( CartStorage.get(commonlibQuickbuyStates.storageKey) == 1 ) { 358 $(containerId).show() 359 $(inputId).focus() 360 } 361} 362 363 364$(document).ready(() => { 365 $('#cart-payment-extra1').load('/',{ 366 'RUN_INCLUDE':'plugin-helloretail-tracking-cart.htm' 367 }) 368}) 369 370register_hook('post_calls','htCartTracking',(name,row) => { 371 if( row.name.indexOf("update") !== -1 ) { 372 $('#cart-payment-extra1').load('/',{ 373 'RUN_INCLUDE':'plugin-helloretail-tracking-cart.htm' 374 }) 375 } 376}) 377 378if( window.pluginSettings && window.pluginSettings.is_b2b && window.pluginSettings.controlPanel.customerCategoryDefaultPayment === 1 ) { 379 register_hook('cart-v3-load-settings','setPaymentToStandard',(name,settings)=>{
380 CartStorage.set('payment_type','standard'); 381 }); 382} 383 384 385$(document).ready(() => { 386 $('#cart-payment-extra1').load('/',{ 387 'RUN_INCLUDE':'plugin-helloretail-tracking-cart.htm' 388 }) 389}) 390 391register_hook('post_calls','htCartTracking',(name,row) => { 392 if( row.name.indexOf("update") !== -1 ) { 393 $('#cart-payment-extra1').load('/',{ 394 'RUN_INCLUDE':'plugin-helloretail-tracking-cart.htm' 395 }) 396 } 397}) 398 399if( window.pluginSettings && window.pluginSettings.is_b2b && window.pluginSettings.controlPanel.customerCategoryDefaultPayment === 1 ) { 400 register_hook('cart-v3-load-settings','setPaymentToStandard',(name,settings)=>{ 401 CartStorage.set('payment_type','standard'); 402 }); 403} 404
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.