1/*Giftvoucher JS*/ 2 3function toggleTotalCode() { 4 $$('.giftvoucher-total-code').each(function(el) { 5 el.toggle(); 6 }); 7} 8 9function addGiftVoucher() { 10 var giftvoucher_code = $('giftvoucher_code').value; 11 var add_code = ''; 12 if ($('giftvoucher_existed_code')) { 13 add_code = $('giftvoucher_existed_code').value; 14 } 15 if (giftvoucher_code != '' || add_code != '') { 16 if ($('giftcard_notice_1')) 17 $('giftcard_notice_1').style.display = "none"; 18 if ($('giftcard_notice_2')) 19 $('giftcard_notice_2').style.display = "none"; 20 if ($('giftvoucher_code')) 21 $('giftvoucher_code').removeClassName("validation-failed"); 22 if ($('giftvoucher_existed_code')) 23 $('giftvoucher_existed_code').removeClassName("validation-failed"); 24 $('giftvoucher_add').hide(); 25 $('giftvoucher_wait').show(); 26 27 var url = $('giftvoucher_cache_url').innerHTML.stripTags(); 28 for (i = 0; i < url.length; i++) { 29 if (url[url.length - 1] == '/') 30 url = url.substr(0, url.length - 1); 31 } 32 if (giftvoucher_code != '') 33 url += '/code/' + giftvoucher_code; 34 if (add_code != '') 35 url += '/addcode/' + add_code; 36 new Ajax.Request(url, { 37 method: 'post', 38 postBody: '', 39 onException: function(response, e) { 40 $('giftvoucher_message').update('<ul class="error-msg col-xs-12"><li>' + e + '</li></ul>'); 41 }, 42 onComplete: function(response) { 43 location.reload(true); 44 if (response.responseText.isJSON()) { 45 var res = response.responseText.evalJSON(); 46 var needUpdate = true; 47 if (res.ajaxExpired && res.ajaxRedirect) { 48 setLocation(res.ajaxRedirect); 49 needUpdate = false; 50 } 51 if (needUpdate && res.updatepayment) { 52 var eladd = getElement(); 53 eladd.hide(); 54 $('giftvoucher_container').down('dd.giftvoucher').hide(); 55 $('giftvoucher_ajaxload').show(); 56 if (typeof shippingMethod != 'undefined') { 57 shippingMethod.save(); 58 } else if (typeof billing != 'undefined') { 59 billing.save(); 60 } else { 61 // save_address_information(save_address_url); 62 } 63 } else if (needUpdate) { 64 if (res.html) { 65 var container = $('giftvoucher_container'); 66 container.innerHTML = res.html; 67 $('payment_form_giftvoucher').show(); 68 } else { 69 $('giftvoucher_wait').hide(); 70 $('giftvoucher_add').show(); 71 } 72 var message = ''; 73 if (res.success) { 74 message = '<ul class="success-msg"><li>' + res.success + '</li></ul>'; 75 if (typeof (save_shipping_method) != 'undefined') 76 save_shipping_method(shipping_method_url, enable_update_payment, true); 77 ; 78 } 79 if (res.notice) 80 message += '<ul class="notice-msg"><li>' + res.notice + '</li></ul>'; 81 if (res.error) 82 message += '<ul class="error-msg"><li>' + res.error + '</li></ul>'; 83 if (message != '') 84 $('giftvoucher_message').update(message); 85 } 86 } else { 87 $('giftvoucher_wait').hide(); 88 $('giftvoucher_add').show(); 89 location.reload(true); 90 alert(response.responseText); 91 } 92 if (typeof (save_shipping_method) != 'undefined') 93 location.reload(true); 94 save_shipping_method(shipping_method_url, enable_update_payment, true); 95 } 96 }); 97 98 } else { 99 if (giftvoucher_code == '' && add_code == '') 100 { 101 if ($('giftcard_notice_1') && ($('giftvoucher_existed_code') == null)) 102 $('giftcard_notice_1').style.display = "block"; 103 else 104 $('giftcard_notice_2').style.display = "block"; 105 if ($('giftvoucher_code')) 106 $('giftvoucher_code').addClassName("validation-failed"); 107 if ($('giftvoucher_existed_code')) 108 $('giftvoucher_existed_code').addClassName("validation-failed"); 109 } 110 else 111 { 112 payment.save(); 113 } 114 } 115} 116 117function removeGiftVoucher(e) { 118 var el = $(e.id); 119 var url = el.children[0].value; 120 for (i = 0; i < url.length; i++) { 121 if (url[url.length - 1] == '/') 122 url = url.substr(0, url.length - 1); 123 } 124 var idPrefix = el.id; 125 var title = $(idPrefix + '_remove'); 126 var ajaxAlt = $(idPrefix + '_ajax'); 127 title.hide(); 128 el.hide(); 129 ajaxAlt.show(); 130 var request = new Ajax.Request(url, { 131 method: 'post', 132 postBody: '', 133 onException: function(response, e) { 134 $('giftvoucher_message').update('<ul class="error-msg"><li>' + e + '</li></ul>'); 135 }, 136 onComplete: function(response) { 137 location.reload(true); 138 if (response.responseText.isJSON()) { 139 var res = response.responseText.evalJSON(); 140 var needUpdate = true; 141 if (res.ajaxExpired && res.ajaxRedirect) { 142 setLocation(res.ajaxRedirect); 143 needUpdate = false; 144 } 145 if (needUpdate && res.updatepayment) { 146 var eladd = getElement(); 147 eladd.hide(); 148 $('giftvoucher_container').down('dd.giftvoucher').hide(); 149 $('giftvoucher_ajaxload').show(); 150 if (typeof shippingMethod != 'undefined') { 151 shippingMethod.save(); 152 } else if (typeof billing != 'undefined') { 153 billing.save(); 154 } else { 155 // save_address_information(save_address_url); 156 } 157 } else if (needUpdate) { 158 if (res.html) { 159 var container = $('giftvoucher_container'); 160 container.innerHTML = res.html; 161 $('payment_form_giftvoucher').show(); 162 } else { 163 ajaxAlt.hide(); 164 el.show(); 165 title.show(); 166 } 167 var message = ''; 168 if (res.success) { 169 message = '<ul class="success-msg"><li>' + res.success + '</li></ul>'; 170 if (typeof (save_shipping_method) != 'undefined') 171 save_shipping_method(shipping_method_url, enable_update_payment, true); 172 ; 173 } 174 if (res.error) 175 message += '<ul class="error-msg"><li>' + res.error + '</li></ul>'; 176 if (message != '') 177 $('giftvoucher_message').update(message); 178 } 179 } else { 180 ajaxAlt.hide(); 181 el.show(); 182 title.show(); 183 alert(response.responseText); 184 } 185 if (typeof (save_shipping_method) != 'undefined') 186 save_shipping_method(shipping_method_url, enable_update_payment, true); 187 } 188 });
189} 190 191// change or udpate gift card used to spend 192function changeUseGiftvoucher(el) { 193 194 var url = $('giftvoucher_cache_url').innerHTML.stripTags().replace('/addgift', '/giftcard'); 195 for (i = 0; i < url.length; i++) { 196 if (url[url.length - 1] == '/') 197 url = url.substr(0, url.length - 1); 198 } 199 if (el.checked) { 200 $('payment_form_giftvoucher').show(); 201 changeGiftcardVisible('giftvoucher', false); 202 url += '/giftvoucher/1'; 203 } else { 204 $('payment_form_giftvoucher').hide(); 205 changeGiftcardVisible('giftvoucher', true); 206 } 207 208 var eladd = getElement(); 209 eladd.hide(); 210 $('giftvoucher_container').down('dd.giftvoucher').hide(); 211 $('giftvoucher_ajaxload').show(); 212 new Ajax.Request(url, { 213 method: 'post', 214 postBody: '', 215 onComplete: function(response) { 216 location.reload(true); 217 if (response.responseText.isJSON()) { 218 var res = response.responseText.evalJSON(); 219 if (res.updatepayment) { 220 if (typeof shippingMethod != 'undefined') { 221 shippingMethod.save(); 222 } else if (typeof billing != 'undefined') { 223 billing.save(); 224 } else { 225 // save_address_information(save_address_url); 226 } 227 } else { 228 var eladd = getElement(); 229 eladd.show(); 230 $('giftvoucher_container').down('dd.giftvoucher').show(); 231 $('giftvoucher_ajaxload').hide(); 232 } 233 } else { 234 var eladd = getElement(); 235 eladd.show(); 236 $('giftvoucher_container').down('dd.giftvoucher').show(); 237 $('giftvoucher_ajaxload').hide(); 238 } 239 if (typeof (save_shipping_method) != 'undefined') 240 save_shipping_method(shipping_method_url, enable_update_payment, true); 241 } 242 }); 243} 244 245function onLoadGiftvoucherForm() { 246 if ($('giftvoucher')) { 247 $('giftvoucher').disabled = false; 248 if ($('giftvoucher').checked) { 249 $('payment_form_giftvoucher').show(); 250 changeGiftcardVisible('giftvoucher', false); 251 } else { 252 $('payment_form_giftvoucher').hide(); 253 changeGiftcardVisible('giftvoucher', true); 254 } 255 } 256 if ($('giftvoucher_credit')) { 257 $('giftvoucher_credit').disabled = false; 258 if ($('giftvoucher_credit').checked) { 259 $('payment_form_giftvoucher_credit').show(); 260 changeGiftcardVisible('giftvoucher_credit', false); 261 } else { 262 $('payment_form_giftvoucher_credit').hide(); 263 changeGiftcardVisible('giftvoucher_credit', true); 264 } 265 } 266} 267 268function useExistedGiftcard(el) { 269 if (el.value) { 270 $('giftvoucher-custom-code').hide(); 271 } else { 272 $('giftvoucher-custom-code').show(); 273 } 274} 275 276function changeUseExistedGiftcard(el) { 277 if (el.value) { 278 $('giftvoucher-custom-code').hide(); 279 changeGiftcardVisible('giftvoucher-custom-code', true); 280 } else { 281 $('giftvoucher-custom-code').show(); 282 changeGiftcardVisible('giftvoucher-custom-code', false); 283 } 284} 285 286function showGiftCardInput(el) { 287 var parent = Element.extend(el.parentNode); 288 el.hide(); 289 parent.down('.giftcard_input').show(); 290 parent.down('.giftcard_input input').focus(); 291} 292 293function showGiftCardAmountInput(el) { 294 var parent = Element.extend(el.parentNode); 295 el.hide(); 296 parent.down('input').show(); 297 parent.down('input').disabled = false; 298} 299 300function enterUpdateGiftCardInput(el, e) { 301 if (e.keyCode == 13) { 302 updateGiftCardInput(el); 303 } 304} 305 306function updateGiftCardInput(el) { 307 var parent = Element.extend(el.parentNode); 308 parent.down('.apply').hide(); 309 parent.down('.ajax-loader').show(); 310 311 var url = $('giftvoucher_cache_url').innerHTML.stripTags().replace('/addgift', '/updateAmount'); 312 for (i = 0; i < url.length; i++) { 313 if (url[url.length - 1] == '/') 314 url = url.substr(0, url.length - 1); 315 } 316 var code = Element.extend(el.parentNode.parentNode.parentNode.parentNode).down('button').id; 317 url += '/code/' + code; 318 url += '/amount/' + parent.down('input').value; 319 new Ajax.Request(url, { 320 method: 'post', 321 postBody: '', 322 parameters: '', 323 onException: function(response, e) { 324 $('giftvoucher_message').update('<ul class="error-msg"><li>' + e + '</li></ul>'); 325 }, 326 onComplete: function(response) { 327 location.reload(true); 328 el.show(); 329 parent.down('.ajax-loader').hide(); 330 if (response.responseText.isJSON()) { 331 var res = response.responseText.evalJSON(); 332 var needUpdate = true; 333 if (res.ajaxExpired && res.ajaxRedirect) { 334 setLocation(res.ajaxRedirect); 335 needUpdate = false; 336 } 337 if (needUpdate && res.updatepayment) { 338 var eladd = getElement(); 339 eladd.hide(); 340 $('giftvoucher_container').down('dd.giftvoucher').hide(); 341 $('giftvoucher_ajaxload').show(); 342 if (typeof shippingMethod != 'undefined') { 343 shippingMethod.save(); 344 } else if (typeof billing != 'undefined') { 345 billing.save(); 346 } else { 347 // save_address_information(save_address_url); 348 } 349 } else if (needUpdate) { 350 if (res.amount) { 351 $(code + '_remove').down('.giftcard-amount').update(res.amount); 352 parent.hide(); 353 parent = Element.extend(parent.parentNode); 354 parent.down('.giftcard_change').show(); 355 } 356 if (res.html) { 357 var container = $('giftvoucher_container'); 358 container.innerHTML = res.html; 359 $('payment_form_giftvoucher').show(); 360 } 361 var message = ''; 362 if (res.success) { 363 message = '<ul class="success-msg"><li>' + res.success + '</li></ul>'; 364 if (typeof (save_shipping_method) != 'undefined') 365 save_shipping_method(shipping_method_url, enable_update_payment, true); 366 ; 367 } 368 if (res.error) 369 message += '<ul class="error-msg"><li>' + res.error + '</li></ul>'; 370 if (message != '') 371 $('giftvoucher_message').update(message); 372 } 373 } 374 if (typeof (save_shipping_method) != 'undefined') 375 save_shipping_method(shipping_method_url, enable_update_payment, true); 376 } 377 });
378} 379 380// change or update gift card credit to spend 381function changeUseGiftCredit(el) { 382 383 var url = $('giftvoucher_cache_url').innerHTML.stripTags().replace('/addgift', '/giftcardcredit'); 384 for (i = 0; i < url.length; i++) { 385 if (url[url.length - 1] == '/') 386 url = url.substr(0, url.length - 1); 387 } 388 if (el.checked) { 389 $('payment_form_giftvoucher_credit').show(); 390 changeGiftcardVisible('giftvoucher_credit', false); 391 url += '/giftcredit/1'; 392 } else { 393 $('payment_form_giftvoucher_credit').hide(); 394 changeGiftcardVisible('giftvoucher_credit', true); 395 } 396 var eladd = getElement(); 397 eladd.hide(); 398 $('giftvoucher_container').down('dt.giftvoucher').hide(); 399 $('giftvoucher_container').down('dd.giftvoucher').hide(); 400 $('giftvoucher_container').down('dd.giftvoucher_credit').hide(); 401 $('giftvoucher_credit_ajaxload').show(); 402 new Ajax.Request(url, { 403 method: 'post', 404 postBody: '', 405 onComplete: function(response) { 406 location.reload(true); 407 if (response.responseText.isJSON()) { 408 var res = response.responseText.evalJSON(); 409 if (res.updatepayment) { 410 if (typeof shippingMethod != 'undefined') { 411 shippingMethod.save(); 412 } else if (typeof billing != 'undefined') { 413 billing.save(); 414 } else { 415 // save_address_information(save_address_url); 416 } 417 } else if (res.html) { 418 var container = $('giftvoucher_container'); 419 container.innerHTML = res.html; 420 onLoadGiftvoucherForm(); 421 var eladd = getElement(); 422 eladd.show(); 423 } else { 424 var eladd = getElement(); 425 eladd.show(); 426 $('giftvoucher_container').down('dt.giftvoucher').show(); 427 $('giftvoucher_container').down('dd.giftvoucher').show(); 428 $('giftvoucher_container').down('dd.giftvoucher_credit').show(); 429 $('giftvoucher_credit_ajaxload').hide(); 430 } 431 432 var message = ''; 433 if (res.notice) 434 message += '<ul class="notice-msg"><li>' + res.notice + '</li></ul>'; 435 if (message != '') 436 $('gift_credit_message').update(message); 437 438 } else { 439 var eladd = getElement(); 440 eladd.show(); 441 $('giftvoucher_container').down('dt.giftvoucher').show(); 442 $('giftvoucher_container').down('dd.giftvoucher').show(); 443 $('giftvoucher_container').down('dd.giftvoucher_credit').show(); 444 $('giftvoucher_credit_ajaxload').hide(); 445 } 446 if (typeof (save_shipping_method) != 'undefined') 447 save_shipping_method(shipping_method_url, enable_update_payment, true); 448 } 449 }); 450} 451 452function showCartCreditInput(el) { 453 var parent = Element.extend(el.parentNode.parentNode); 454 if (el.checked) { 455 parent.down('dd.giftvoucher_credit').show(); 456 } else { 457 parent.down('dd.giftvoucher_credit').hide(); 458 } 459} 460 461function showCartGiftCardInput(el) { 462 var parent = Element.extend(el.parentNode.parentNode); 463 if (el.checked) { 464 parent.down('dd.giftvoucher').show(); 465 } else { 466 parent.down('dd.giftvoucher').hide(); 467 } 468} 469 470function showCreditInput(el) { 471 var parent = Element.extend(el.parentNode); 472 el.hide(); 473 parent.down('.credit_input').show(); 474 parent.down('.credit_input input').focus(); 475} 476 477function enterUpdateCreditInput(el, e) { 478 if (e.keyCode == 13) { 479 updateCreditInput(el); 480 } 481} 482 483function updateCreditInput(el) { 484 var parent = Element.extend(el.parentNode); 485 486 var url = $('giftvoucher_cache_url').innerHTML.stripTags().replace('/addgift', '/creditamount'); 487 for (i = 0; i < url.length; i++) { 488 if (url[url.length - 1] == '/') 489 url = url.substr(0, url.length - 1); 490 } 491 url += '/amount/' + parent.down('input').value; 492 493 $('giftvoucher_container').down('dd.giftvoucher_credit').hide(); 494 $('giftvoucher_credit_ajaxload').show(); 495 new Ajax.Request(url, { 496 method: 'post', 497 postBody: '', 498 onComplete: function(response) { 499 location.reload(true); 500 if (response.responseText.isJSON()) { 501 var res = response.responseText.evalJSON(); 502 if (res.updatepayment) { 503 if (typeof shippingMethod != 'undefined') { 504 shippingMethod.save(); 505 } else if (typeof billing != 'undefined') { 506 billing.save(); 507 } else { 508 // save_address_information(save_address_url); 509 } 510 } else if (res.html) { 511 var container = $('giftvoucher_container'); 512 container.innerHTML = res.html; 513 onLoadGiftvoucherForm(); 514 } else { 515 $('giftvoucher_container').down('dd.giftvoucher_credit').show(); 516 $('giftvoucher_credit_ajaxload').hide(); 517 parent.hide(); 518 parent = Element.extend(parent.parentNode); 519 parent.down('.using_credit').show(); 520 } 521 522 var message = ''; 523 if (res.notice) 524 message += '<ul class="notice-msg"><li>' + res.notice + '</li></ul>'; 525 if (message != '') 526 $('gift_credit_message').update(message); 527 528 } else { 529 $('giftvoucher_container').down('dd.giftvoucher_credit').show(); 530 $('giftvoucher_credit_ajaxload').hide(); 531 } 532 if (typeof (save_shipping_method) != 'undefined') 533 save_shipping_method(shipping_method_url, enable_update_payment, true); 534 } 535 });
536} 537 538function changeGiftcardVisible(method, mode) { 539 var block = 'payment_form_' + method; 540 [block + '_before', block, block + '_after'].each(function(el) { 541 element = $(el); 542 if (element) { 543 element.style.display = (mode) ? 'none' : ''; 544 element.select('input', 'select', 'textarea', 'button').each(function(field) { 545 field.disabled = mode; 546 }); 547 } 548 }); 549} 550function checkOutLoadGiftCard(json) { 551 if (!$('giftvoucher_container')) { 552 var eladd = getElement(); 553 eladd.insert({ 554 before: json.html 555 }); 556 if ($('p_method_free')) { 557 $('p_method_free').up(1).innerHTML = $('p_method_free').up('dt').innerHTML; 558 $('p_method_free').checked = true; 559 } 560 } 561} 562 563function getElement() { 564 if ($('checkout-payment-method-load').down('#checkout-payment-method-load') == undefined) { 565 return $('checkout-payment-method-load'); 566 } else { 567 return $('checkout-payment-method-load').down('#checkout-payment-method-load'); 568 } 569}
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.