1(function($) { 2 var Simple = function() { 3 }; 4 5 Simple.prototype.human = false; 6 7 Simple.prototype.instances = []; 8 9 Simple.prototype.resources = { 10 loading: "catalog/view/image/loading.gif", 11 loadingSmall: "catalog/view/theme/default/image/loading.gif", 12 next: "catalog/view/image/next_gray.png", 13 nextCompleted: "catalog/view/image/next_green.png" 14 }; 15 16 Simple.prototype.getValidationRules = function() { 17 var self = this; 18 19 return { 20 notEmpty: function($rule, silent) { 21 var fieldId = $rule.attr("data-for"); 22 23 if (typeof silent === "undefined") { 24 silent = false; 25 } 26 27 if (fieldId) { 28 var $field = $(self.params.mainContainer).find("#" + fieldId); 29 30 if ($field.length) { 31 if (!$rule.attr("data-required")) { 32 $rule.hide(); 33 return true; 34 } 35 36 var value = ""; 37 38 if ($field.attr("type") == "checkbox") { 39 var arr = $field.serializeArray(); 40 var values = []; 41 for (var i in arr) { 42 if (!arr.hasOwnProperty(i)) continue; 43 var realValue = arr[i].name.match(/.+\[(.+)\]\[(.+)\]/); 44 values.push(realValue[2]); 45 } 46 value = values.join(','); 47 } else if ($field.attr("type") == "radio") { 48 value = $(self.params.mainContainer).find("#" + fieldId + ":checked").val(); 49 } else { 50 value = $field.val(); 51 } 52 53 if (!value) { 54 if (!silent) { 55 if (typeof toastr !== 'undefined' && self.params.notificationToasts) { 56 toastr.error($rule.text()); 57 } 58 59 if (self.params.notificationDefault) { 60 $rule.show(); 61 } 62 } 63 return false; 64 } else { 65 $rule.hide(); 66 return true; 67 } 68 } 69 } 70 return true; 71 }, 72 equal: function($rule, silent) { 73 var fieldId = $rule.attr("data-for"); 74 var equalId = $rule.attr("data-equal"); 75 76 if (typeof silent === "undefined") { 77 silent = false; 78 } 79 80 if (fieldId && equalId) { 81 var $mainContainer = $(self.params.mainContainer); 82 83 var $field = $mainContainer.find("#" + fieldId); 84 var $equal = $mainContainer.find("#" + equalId); 85 86 if ($field.length && $equal.length) { 87 if ($equal.val() != $field.val()) { 88 if (!silent) { 89 if (typeof toastr !== 'undefined' && self.params.notificationToasts) { 90 toastr.error($rule.text()); 91 } 92 93 if (self.params.notificationDefault) { 94 $rule.show(); 95 } 96 } 97 return false; 98 } else { 99 $rule.hide(); 100 return true; 101 } 102 } 103 } 104 return true; 105 }, 106 byLength: function($rule, silent) { 107 var fieldId = $rule.attr("data-for"); 108 109 if (typeof silent === "undefined") { 110 silent = false;
111 } 112 113 if (fieldId) { 114 var $field = $(self.params.mainContainer).find("#" + fieldId); 115 116 if ($field.length) { 117 var min = 0; 118 var max = 1000; 119 120 if ($rule.attr("data-length-min")) { 121 min = ~~$rule.attr("data-length-min"); 122 } 123 124 if ($rule.attr("data-length-max")) { 125 max = ~~$rule.attr("data-length-max"); 126 } 127 128 var value = ($field.val() + '').trim(); 129 130 if (!value && !$rule.attr("data-required")) { 131 $rule.hide(); 132 return true; 133 } 134 135 if (value.length < min || value.length > max) { 136 if (!silent) { 137 if (typeof toastr !== 'undefined' && self.params.notificationToasts) { 138 toastr.error($rule.text()); 139 } 140 141 if (self.params.notificationDefault) { 142 $rule.show(); 143 } 144 } 145 return false; 146 } else { 147 $rule.hide(); 148 return true; 149 } 150 } 151 } 152 return true; 153 }, 154 regexp: function($rule, silent) { 155 var fieldId = $rule.attr("data-for"); 156 157 if (typeof silent === "undefined") { 158 silent = false; 159 } 160 161 if (fieldId) { 162 var $field = $(self.params.mainContainer).find("#" + fieldId); 163 164 if ($field.length) { 165 var regexp = $rule.attr("data-regexp"); 166 167 if (regexp) { 168 var value = ""; 169 170 if ($field.attr("type") == "checkbox") { 171 var arr = $field.serializeArray(); 172 var values = []; 173 for (var i in arr) { 174 if (!arr.hasOwnProperty(i)) continue; 175 var realValue = arr[i].name.match(/.+\[(.+)\]\[(.+)\]/); 176 values.push(realValue[2]); 177 } 178 value = values.join(','); 179 } else if ($field.attr("type") == "radio") { 180 value = $(self.params.mainContainer).find("#" + fieldId + ":checked").val(); 181 } else { 182 value = $field.val(); 183 } 184 185 if (!value && !$rule.attr("data-required")) { 186 $rule.hide(); 187 return true; 188 } 189 190 try { 191 if (!value.match(regexp)) { 192 if (!silent) { 193 if (typeof toastr !== 'undefined' && self.params.notificationToasts) { 194 toastr.error($rule.text()); 195 } 196 197 if (self.params.notificationDefault) { 198 $rule.show(); 199 } 200 } 201 return false; 202 } else { 203 $rule.hide(); 204 return true; 205 } 206 } catch (err) { 207 208 } 209 } 210 } 211 } 212 return true; 213 }, 214 api: function($rule, silent) { 215 var fieldId = $rule.attr("data-for"); 216 var $mainContainer = $(self.params.mainContainer); 217 218 if (typeof silent === "undefined") { 219 silent = false;
220 } 221 222 if (fieldId) { 223 var $field = $mainContainer.find("#" + fieldId); 224 225 if ($field.length) { 226 var filter = ""; 227 228 if ($rule.attr("data-filter")) { 229 var $filter = $mainContainer.find("#" + $rule.attr("data-filter")); 230 231 if ($filter.length) { 232 if ($filter.attr("type") == "radio") { 233 var $checked = $mainContainer.find("#" + $rule.attr("data-filter") + ":checked"); 234 if ($checked) { 235 filter = $checked.val(); 236 } else { 237 filter = ""; 238 } 239 } else if ($filter.attr("type") == "checkbox") { 240 var $checkboxes = $mainContainer.find("#" + $rule.attr("data-filter")); 241 if ($checkboxes) { 242 var tmp = []; 243 var matches = false; 244 245 for (var i = 0; i < $checkboxes.length; i++) { 246 matches = $($checkboxes[i]).attr("name").match(/\]\[(.+?)\]$/); 247 248 if (matches) { 249 if ($($checkboxes[i]).is(":checked")) { 250 tmp[tmp.length] = matches[1]; 251 } 252 } else { 253 if ($($checkboxes[i]).is(":checked")) { 254 tmp[0] = '1'; 255 } else { 256 tmp[0] = '0'; 257 } 258 } 259 } 260 filter = tmp.join(","); 261 } else { 262 filter = ""; 263 } 264 } else { 265 filter = $filter.val(); 266 } 267 } else if ($rule.attr("data-filter-value")) { 268 filter = $rule.attr("data-filter-value"); 269 } 270 } 271 272 var method = $rule.attr("data-method"); 273 274 if (method) { 275 var custom = $rule.attr("data-custom") ? true : false; 276 277 var deferred = $.Deferred(); 278 279 var value = ""; 280 281 if ($field.attr("type") == "checkbox") { 282 var arr = $field.serializeArray(); 283 var values = []; 284 for (var i in arr) { 285 if (!arr.hasOwnProperty(i)) continue; 286 var realValue = arr[i].name.match(/.+\[(.+)\]\[(.+)\]/); 287 values.push(realValue[2]); 288 } 289 value = values.join(','); 290 } else if ($field.attr("type") == "radio") { 291 value = $(self.params.mainContainer).find("#" + fieldId + ":checked").val(); 292 } else { 293 value = $field.val(); 294 } 295 296 $.get("index.php?" + self.params.additionalParams + "route=common/simple_connector/validate&method=" + method + "&filter=" + filter + "&value=" + value + (custom ? "&custom=1 " : ""), function(data) {
297 if (data == "invalid") { 298 if (!silent) { 299 if (typeof toastr !== 'undefined' && self.params.notificationToasts) { 300 toastr.error($rule.text()); 301 } 302 303 if (self.params.notificationDefault) { 304 $rule.show(); 305 } 306 } 307 deferred.resolve(false); 308 } else { 309 $rule.hide(); 310 deferred.resolve(true); 311 } 312 }); 313 314 return deferred.promise(); 315 } 316 } 317 } 318 319 return true; 320 } 321 }; 322 }; 323 324 Simple.prototype.initValidationRules = function() { 325 var self = this; 326 var $mainContainer = $(self.params.mainContainer); 327 328 $mainContainer.find(".simplecheckout-rule-group").each(function() { 329 var $ruleGroup = $(this); 330 var fieldId = $(this).attr("data-for"); 331 var promises = []; 332 333 if (fieldId) { 334 var $field = $mainContainer.find("#" + fieldId); 335 336 if ($field.length) { 337 var checker = function() { 338 var result = true; 339 340 $ruleGroup.find(".simplecheckout-rule").each(function() { 341 var $rule = $(this); 342 var type = $(this).attr("data-rule"); 343 var rules = self.getValidationRules(); 344 345 if (typeof rules[type] === "function") { 346 var promise = $.when(rules[type]($rule)).then(function(ruleResult){ 347 if (!ruleResult) { 348 result = false;
349 } 350 351 return $.when(ruleResult); 352 }); 353 354 promises.push(promise); 355 } 356 }); 357 358 $.when.apply($, promises).then(function() { 359 $field.attr("data-valid", result ? "true" : "false"); 360 361 if (!result) { 362 $field.parents(".form-group").addClass("has-error") 363 } else { 364 $field.parents(".form-group").removeClass("has-error") 365 } 366 }); 367 }; 368 369 var $pairField = false; 370 371 $ruleGroup.find(".simplecheckout-rule").each(function() { 372 if ($(this).attr("data-rule") == 'equal' && $(this).attr("data-equal")) { 373 if ($("#" + $(this).attr("data-equal")).length) { 374 $pairField = $("#" + $(this).attr("data-equal")); 375 } 376 } 377 }); 378 379 if ($field.attr('data-validate-on') && typeof $field[$field.attr('data-validate-on')] === 'function') { 380 $field[$field.attr('data-validate-on')](checker); 381 382 if ($pairField) { 383 $pairField[$field.attr('data-validate-on')](checker); 384 } 385 } else { 386 $field.change(checker); 387 388 if ($pairField) { 389 $pairField.change(checker); 390 } 391 } 392 } 393 } 394 }); 395 }; 396 397 Simple.prototype.checkRules = function(container, silent) { 398 var self = this; 399 var fields = {}; 400 var resultAll = true; 401 var allPromises = []; 402 var $mainContainer = $(self.params.mainContainer); 403 var $container = $mainContainer; 404 405 if (container) { 406 $container = $mainContainer.find(container); 407 } 408 409 if (typeof silent === "undefined") { 410 silent = false; 411 } 412 413 if ($container.length && ($container.is(":visible") || $container.find('*').is(":visible"))) { 414 $container.find(".simplecheckout-rule-group").each(function() { 415 var ruleGroupResult = true; 416 var promises = []; 417 var $ruleGroup = $(this); 418 var fieldId = $(this).attr("data-for"); 419 420 if (fieldId) { 421 var $field = $mainContainer.find("#" + fieldId); 422 423 if ($field.length) { 424 $ruleGroup.find(".simplecheckout-rule").each(function() { 425 var $rule = $(this); 426 var type = $(this).attr("data-rule"); 427 var rules = self.getValidationRules(); 428 429 if (typeof rules[type] === "function") { 430 var promise = $.when(rules[type]($rule, silent)).then(function(ruleResult){ 431 if (!ruleResult) { 432 ruleGroupResult = false;
433 } 434 435 return $.when(ruleResult); 436 }); 437 438 promises.push(promise); 439 } 440 }); 441 442 var groupPromise = $.when.apply($, promises).then(function() { 443 $field.attr("data-valid", ruleGroupResult ? "true" : "false"); 444 445 if (!ruleGroupResult) { 446 $field.parents(".form-group").addClass("has-error") 447 } else { 448 $field.parents(".form-group").removeClass("has-error") 449 } 450 451 if (!ruleGroupResult) { 452 resultAll = false; 453 } 454 }); 455 456 allPromises.push(groupPromise); 457 } 458 } 459 }); 460 } 461 462 var deferred = $.Deferred(); 463 464 $.when.apply($, allPromises).then(function() { 465 deferred.resolve(resultAll); 466 }); 467 468 return deferred.promise(); 469 }; 470 471 Simple.prototype.setAddressFields = function(block, countryId, zoneId, city, postcode, callbackAfterChanging) { 472 var self = this; 473 var $mainContainer = $(self.params.mainContainer); 474 475 var setFields = function() { 476 if (countryId) { 477 $mainContainer.find("#" + block + "_country_id").val(countryId); 478 } 479 if (zoneId) { 480 $mainContainer.find("#" + block + "_zone_id").val(zoneId); 481 } 482 if (city) { 483 $mainContainer.find("#" + block + "_city").val(city); 484 } 485 if (postcode) { 486 $mainContainer.find("#" + block + "_postcode").val(postcode); 487 } 488 489 if (typeof callbackAfterChanging === "function") { 490 callbackAfterChanging(); 491 } else if (typeof reloadAll === "function") { 492 reloadAll(); 493 } 494 }; 495 496 if ($mainContainer.find("#" + block + "_country_id").val() != countryId) { 497 $mainContainer.find("#" + block + "_zone_id").load("index.php?" + self.params.additionalParams + "route=common/simple_connector/zone&country_id=" + countryId, function() { 498 setFields(); 499 }); 500 } else { 501 setFields(); 502 } 503 }; 504 505 Simple.prototype.initFileUploader = function(beforeUploading, afterUploading) { 506 var self = this; 507 var $mainContainer = $(self.params.mainContainer); 508 509 $mainContainer.find("[data-file]").each(function() { 510 var hiddenInputId = $(this).attr("data-file"); 511 var fileNameId = hiddenInputId ? "text_" + hiddenInputId : ""; 512 513 $(this).on("click", function() { 514 $("#form-upload").remove(); 515 516 $("body").prepend("<form enctype='multipart/form-data' id='form-upload' style='display: none;'><input type='file' name='file' /></form>"); 517 518 $("#form-upload input[name='file']").trigger("click"); 519 520 if (typeof fileUploaderTimer !== "undefined") { 521 clearInterval(fileUploaderTimer); 522 } 523 524 fileUploaderTimer = setInterval(function() { 525 if ($("#form-upload input[name='file']").val() != "") { 526 clearInterval(fileUploaderTimer); 527 528 $.ajax({ 529 url: "index.php?" + self.params.additionalParams + "route=common/simple_connector/upload", 530 type: "post", 531 dataType: "json", 532 data: new FormData($("#form-upload")[0]), 533 cache: false, 534 contentType: false, 535 processData: false, 536 beforeSend: function() { 537 if (typeof beforeUploading === "function") { 538 beforeUploading(); 539 } 540 }, 541 complete: function() { 542 $("#form-upload").remove(); 543 544 if (typeof afterUploading === "function") { 545 afterUploading(); 546 } 547 }, 548 success: function(json) { 549 if (json["file"]) { 550 if (hiddenInputId) { 551 $mainContainer.find("#" + hiddenInputId).val(json["file"]).trigger('change'); 552 } 553 if (fileNameId) { 554 var fname = typeof json["filename"] !== "undefined" && json["filename"] ? json["filename"] : file; 555 $mainContainer.find("#" + fileNameId).text(fname); 556 } 557 } 558 559 if (json["error"]) { 560 if (hiddenInputId) { 561 $mainContainer.find("#" + hiddenInputId).attr("value", ""); 562 } 563 if (fileNameId) { 564 $mainContainer.find("#" + fileNameId).text(json["error"]); 565 } 566 } 567 }, 568 error: function(xhr, ajaxOptions, thrownError) { 569 alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText); 570 } 571 }); 572 } 573 }, 500); 574 }); 575 }); 576 }; 577 578 Simple.prototype.initAutocomplete = function(callbackAfterChanging) { 579 var self = this; 580 var $fields = $(self.params.mainContainer).find("#payment_address_city, #shipping_address_city, #register_city, #address_city"); 581 if (typeof($fields.autocomplete) !== "undefined") { 582 $fields.each(function() { 583 var $field = $(this) 584 var tmp = $field.attr("data-onchange"); 585 if (tmp) { 586 $field.removeAttr("data-onchange"); 587 $field.removeAttr("data-reload-payment-form"); 588 $field.attr("data-onchange-delayed", tmp); 589 } 590 591 $field.on("keydown", function(){ 592 $field.data("status", "started"); 593 }); 594 595 $field.autocomplete({ 596 source: function(request, response) { 597 $.ajax({ 598 url: "index.php?" + self.params.additionalParams + "route=common/simple_connector/geo", 599 dataType: "json", 600 data: { 601 term: typeof request.term !== "undefined" ? request.term : request 602 }, 603 success: function(data) { 604 response($.map(data, function(item) { 605 if (typeof request.term === "undefined") { 606 return { 607 id: item.id, 608 label: item.full, 609 value: item.id, 610 postcode: item.postcode, 611 zone_id: item.zone_id, 612 country_id: item.country_id, 613 city: item.city 614 }; 615 } else { 616 return { 617 id: item.id, 618 label: item.full, 619 value: item.city, 620 postcode: item.postcode, 621 zone_id: item.zone_id, 622 country_id: item.country_id, 623 city: item.city 624 }; 625 } 626 627 })); 628 } 629 }); 630 }, 631 minLength: 2, 632 delay: 300, 633 close: function( event, ui ) { 634 if ($field.data("status") == "started") { 635 //$field.val(""); 636 callbackAfterChanging($field); 637 } 638 }, 639 select: function(event, ui) { 640 $field.data("status", "selected"); 641 var name = $field.attr("name"); 642 var from = name.substr(0, name.indexOf("[")); 643 644 if (ui !== undefined) { 645 self.setAddressFields(from, ui.item.country_id, ui.item.zone_id, ui.item.city, ui.item.postcode, function() { 646 callbackAfterChanging($field); 647 }); 648 } else { 649 self.setAddressFields(from, event.country_id, event.zone_id, event.city, event.postcode, function() { 650 callbackAfterChanging($field); 651 }); 652 } 653 } 654 }); 655 }); 656 } 657 }; 658 659 Simple.prototype.initPopups = function() { 660 var self = this; 661 var $mainContainer = $(self.params.mainContainer); 662 663 if (typeof($.fancybox) == "function") { 664 $mainContainer.find(".fancybox").fancybox({ 665 width: 560, 666 height: 560, 667 autoDimensions: false 668 }); 669 } 670 671 if (typeof($.colorbox) == "function") { 672 $mainContainer.find(".colorbox").colorbox({ 673 width: 560, 674 height: 560 675 }); 676 } 677 678 if (typeof($.prettyPhoto) !== "undefined") { 679 $mainContainer.find("a[rel^='prettyPhoto']").prettyPhoto({ 680 theme: "light_square", 681 opacity: 0.5, 682 social_tools: "", 683 deeplinking: false 684 }); 685 } 686 }; 687 688 Simple.prototype.initTooltips = function(bootstrap) { 689 var self = this; 690 var $mainContainer = $(self.params.mainContainer); 691 692 $mainContainer.find("input,select,textarea").each(function() { 693 if ($(this).attr("data-file")) { 694 $mainContainer.find(".simplecheckout-tooltip[data-for='" + $(this).attr("data-file") + "']").show(); 695 } else { 696 if (bootstrap && typeof $(this).tooltip === "function") { 697 var $tooltip = $(self.params.mainContainer + " .simplecheckout-tooltip[data-for='" + $(this).attr("id") + "']"); 698 if ($tooltip.length) { 699 $(this).tooltip({ 700 html: true, 701 title: $tooltip.html(), 702 placement: 'bottom', 703 container: 'body' 704 }); 705 } 706 } else if (typeof $(this).easyTooltip === "function") { 707 $(this).easyTooltip({ 708 useElement: self.params.mainContainer + " .simplecheckout-tooltip[data-for='" + $(this).attr("id") + "']", 709 clickRemove: true 710 }); 711 } 712 } 713 }); 714 }; 715 716 Simple.prototype.initMasks = function() { 717 var self = this; 718 var $mainContainer = $(self.params.mainContainer); 719 720 if (typeof $(document).inputmask !== "undefined" && !window.localStorage.getItem('inputmaskFailed')) { 721 var masked = []; 722 $mainContainer.find("input[data-mask]").each(function(indx) { 723 var mask = $(this).attr("data-mask"); 724 var id = $(this).attr("id"); 725 if (mask && id) { 726 masked[masked.length] = [id, mask]; 727 } 728 }); 729 try { 730 for (var i = 0; i < masked.length; i++) { 731 var id = masked[i][0]; 732 var mask = masked[i][1]; 733 734 $mainContainer.find("input[id=" + id + "]") 735 .inputmask({ 736 mask: mask, 737 clearMaskOnLostFocus: true, 738 clearIncomplete: true 739 }) 740 .on('change', function() { 741 if ($(this).val().indexOf('_') > -1) { 742 window.localStorage.setItem('inputmaskFailed', true); 743 $(this).inputmask('remove'); 744 } 745 }); 746 } 747 } catch (err) {} 748 } 749 }; 750 751 Simple.prototype.initSelect2 = function() { 752 var self = this; 753 754 if (typeof $(document).select2 !== "undefined") { 755 $(self.params.mainContainer).find("select[data-type=select2]").each(function() { 756 $(this).select2({ 757 758 }); 759 }); 760 } 761 }; 762 763 Simple.prototype.initDatepickers = function(callbackAfterChanging) { 764 var self = this; 765 var days = false;
766 767 var checkWeekendAndHoliday = function(date) { 768 if (typeof $.datepicker !== "undefined") { 769 var noWeekend = $.datepicker.noWeekends(date); 770 } else { 771 var noWeekend = [(date.getDay() == 0 || date.getDay() == 6), ""]; 772 } 773 774 if (noWeekend[0]) { 775 return checkNationalDay(date); 776 } else { 777 return noWeekend; 778 } 779 }; 780 781 var checkNationalDay = function(date) { 782 var days = [ 783 [1, 1, "ru"], 784 [1, 7, "ru"], 785 [5, 9, "ru"] 786 ]; 787 788 for (i = 0; i < days.length; i++) { 789 if (date.getMonth() == days[i][0] - 1 && date.getDate() == days[i][1]) { 790 return [false, days[i][2] + "_day"]; 791 } 792 } 793 return [true, ""]; 794 }; 795 796 var addDays = function(add, onlyWeekdays) { 797 var result = add | 0; 798 var self = this; 799 if (onlyWeekdays) { 800 var i = 1; 801 while (i <= result) { 802 var d = new Date(); 803 d.setDate(d.getDate() + i); 804 var test = checkWeekendAndHoliday(d); 805 if (!test[0]) { 806 result++; 807 } 808 i++; 809 } 810 } 811 812 return result; 813 }; 814 815 var checkDays = function(date) { 816 for (var i = 0; i < days.length; i++) { 817 if (date.getDay() == days[i]) { 818 return [true, ""]; 819 } 820 } 821 822 return [false, ""]; 823 }; 824 825 $(self.params.mainContainer).find("input[type=date],input[data-type=date]").each(function() { 826 var onlyWeekdays = $(this).attr("data-weekdays-only") ? true : false, 827 min = new Date(), 828 max = new Date(); 829 830 if ($(this).attr("data-days-only")) { 831 days = $(this).attr("data-days-only").split(","); 832 onlyWeekdays = false; 833 } 834 835 if ($(this).attr("data-start-day")) { 836 min = $(this).attr("data-start-day"); 837 } else if ($(this).attr("data-start-after")) { 838 min.setDate(min.getDate() + addDays($(this).attr("data-start-after"), onlyWeekdays)); 839 } 840 841 if ($(this).attr("data-end-day")) { 842 max = $(this).attr("data-end-day"); 843 } else if ($(this).attr("data-end-after")) { 844 max.setDate(max.getDate() + addDays($(this).attr("data-end-after"), onlyWeekdays)); 845 } 846 847 if (typeof($(this).datetimepicker) !== "undefined") { 848 var disabledDays = []; 849 850 if (onlyWeekdays || typeof days.length !== "undefined") { 851 var useDays = false; 852 853 if (days.length !== "undefined" && days.length) { 854 useDays = true; 855 } 856 857 for (var i = 0; i < 7; i++) { 858 if (((i == 6 || i == 0) && onlyWeekdays) || (useDays && $.inArray(i + "", days) == -1)) { 859 disabledDays.push(i); 860 } 861 } 862 } 863 864 var $el = $(this); 865 866 $el.datetimepicker({ 867 pickDate: true, 868 pickTime: false, 869 showTimepicker: false, 870 daysOfWeekDisabled: disabledDays, 871 firstDay: 1,
872 beforeShowDay: onlyWeekdays ? checkWeekendAndHoliday : (days ? checkDays : null), 873 minDate: min ? min : null, 874 maxDate: max ? max : null, 875 useCurrent: false, 876 showButtonPanel: false, 877 language: self.params.languageCode, 878 onSelect: function() { 879 $el.datetimepicker('hide'); 880 } 881 }).on('dp.change', function(dateText, inst) { 882 if (typeof callbackAfterChanging === "function") { 883 callbackAfterChanging($el); 884 } 885 }); 886 887 $el.next().on('click', function () { 888 $el.focus(); 889 }); 890 } else if (typeof($(this).datepicker) !== "undefined") { 891 $(this).datepicker({ 892 firstDay: 1, 893 beforeShowDay: onlyWeekdays ? checkWeekendAndHoliday : (days ? checkDays : null), 894 minDate: min ? min : null, 895 maxDate: max ? max : null, 896 onSelect: function(dateText, inst) { 897 if (typeof callbackAfterChanging === "function") { 898 callbackAfterChanging($(this)); 899 } 900 } 901 }); 902 } 903 }); 904 }; 905 906 Simple.prototype.initTimepickers = function(callbackAfterChanging) { 907 var self = this; 908 var min = ""; 909 910 if ($(this).attr("data-min-time")) { 911 min = ~~ ($(this).attr("data-min-time").split(":")[0]); 912 } 913 914 var max = ""; 915 916 if ($(this).attr("data-max-time")) { 917 max = ~~ ($(this).attr("data-max-time").split(":")[0]); 918 } 919 920 var onlyHours = $(this).attr("data-hours-only") ? true : false; 921 922 $(self.params.mainContainer).find("input[type=time],input[data-type=time]").each(function() { 923 if (typeof($(this).datetimepicker) !== "undefined") { 924 var $el = $(this); 925 926 $el.datetimepicker({ 927 pickDate: false, 928 pickTime: true, 929 showMinute: !onlyHours, 930 useCurrent: false 931 }).on('dp.change', function(dateText, inst) { 932 if (typeof callbackAfterChanging === "function") { 933 callbackAfterChanging($el); 934 } 935 }); 936 937 $el.next().on('click', function () { 938 $el.focus(); 939 }); 940 } else if (typeof($(this).timepicker) !== "undefined") { 941 $(this).timepicker({ 942 hourMin: min, 943 hourMax: max, 944 showMinute: !onlyHours, 945 onSelect: function(datetimeText, datepickerInstance) { 946 if (typeof callbackAfterChanging === "function") { 947 callbackAfterChanging($(this)); 948 } 949 }, 950 onClose: function() { 951 if (typeof callbackAfterChanging === "function") { 952 callbackAfterChanging($(this)); 953 } 954 } 955 }); 956 } 957 }); 958 }; 959 960 Simple.prototype.initGoogleApi = function(callbackAfterChanging) { 961 var self = this; 962 var $mainContainer = $(self.params.mainContainer); 963 964 var $fields = $mainContainer.find("#payment_address_postcode, #shipping_address_postcode, #register_postcode, #address_postcode"); 965 966 $fields.each(function() { 967 var tmp = $(this).attr("data-onchange"); 968 if (tmp) { 969 $(this).removeAttr("data-onchange"); 970 $(this).removeAttr("data-reload-payment-form"); 971 $(this).attr("data-onchange-delayed", tmp); 972 } 973 }); 974 975 $fields.change(function() { 976 var $target = $(this); 977 var name = $(this).attr("name"); 978 var from = name.substr(0, name.indexOf("[")); 979 var geocoder = new google.maps.Geocoder(); 980 var address = $mainContainer.find("#" + from + "_postcode").val() + "," + $mainContainer.find("#" + from + "_country_id option:selected").text(); 981 var typeShort; 982 var anythingChanged = false;
983 984 if (geocoder) { 985 geocoder.geocode({ 986 "address": address, 987 "language": $mainContainer.find("#" + from + "_country_id option:selected").text() 988 }, function(results, status) { 989 if (status == google.maps.GeocoderStatus.OK) { 990 for (var result in results) { 991 for (var component in results[result].address_components) { 992 for (var type in results[result].address_components[component].types) { 993 typeShort = results[result].address_components[component].types[type]; 994 if (typeShort == "administrative_area_level_1") { 995 $mainContainer.find("#" + from + "_zone_id option").filter(function() { 996 return $(this).text().replace(/\W/g, "") == results[result].address_components[component].long_name.replace(/\W/g, ""); 997 }).attr("selected", "selected"); 998 anythingChanged = true; 999 } 1000 if (typeShort == "locality") { 1001 $mainContainer.find("#" + from + "_city").val(results[result].address_components[component].long_name); 1002 anythingChanged = true; 1003 } 1004 } 1005 } 1006 } 1007 if (anythingChanged && typeof callbackAfterChanging === "function") { 1008 callbackAfterChanging($target); 1009 } 1010 } else { 1011 //console.log("Geocoding failed: " + status); 1012 } 1013 }); 1014 } 1015 }); 1016 }; 1017 1018 Simple.prototype.checkIsHuman = function() { 1019 var self = this; 1020 var timeoutId = 0; 1021 1022 $("body").on("mousemove", function() { 1023 if (!self.human) { 1024 clearTimeout(timeoutId); 1025 1026 timeoutId = window.setTimeout(function(){ 1027 $.get("index.php?" + self.params.additionalParams + "route=common/simple_connector/human", function() { 1028 self.human = true; 1029 }); 1030 }, 300); 1031 } 1032 }); 1033 }; 1034 1035 $.ajaxSetup({ cache: false }); 1036 1037 window.Simple = Simple; 1038})(jQuery || $); 1039 1040if (typeof String.prototype.trim !== "function") { 1041 String.prototype.trim = function() { 1042 return this.replace(/^\s+|\s+$/g, ""); 1043 }; 1044} 1045 1046function includeScript(url) { 1047 document.write("<script type='text/javascript' src='" + url + "'></script>"); 1048} 1049 1050function includeStyle(url) { 1051 document.write("<link rel='stylesheet' type='text/css' href='" + url + "' media='screen' />"); 1052} 1053 1054function bind(func, context) { 1055 return function() { 1056 return func.apply(context, arguments); 1057 }; 1058} 1059 1060function inherit(proto) { 1061 function F() {} 1062 F.prototype = proto; 1063 var object = new F(); 1064 return object; 1065} 1066 1067function reloadAll() { 1068 if (typeof Simple.prototype.instances !== "undefined") { 1069 for (var i in Simple.prototype.instances) { 1070 if (!Simple.prototype.instances.hasOwnProperty(i)) continue; 1071 1072 if (typeof Simple.prototype.instances[i].reloadAll === "function") { 1073 Simple.prototype.instances[i].reloadAll(); 1074 } 1075 } 1076 } 1077} 1078 1079function reloadBlock() { 1080 if (typeof Simple.prototype.instances !== "undefined") { 1081 for (var i in Simple.prototype.instances) { 1082 if (!Simple.prototype.instances.hasOwnProperty(i)) continue; 1083 1084 if (typeof Simple.prototype.instances[i].reloadBlock === "function") { 1085 Simple.prototype.instances[i].reloadBlock.apply(Simple.prototype.instances[i], arguments); 1086 } 1087 } 1088 } 1089} 1090 1091if (!window.localStorage) { 1092 window.localStorage = { 1093 getItem: function (sKey) { 1094 if (!sKey || !this.hasOwnProperty(sKey)) { return null; } 1095 return unescape(document.cookie.replace(new RegExp("(?:^|.*;\\s*)" + escape(sKey).replace(/[\-\.\+\*]/g, "\\$&") + "\\s*\\=\\s*((?:[^;](?!;))*[^;]?).*"), "$1")); 1096 }, 1097 key: function (nKeyId) { 1098 return unescape(document.cookie.replace(/\s*\=(?:.(?!;))*$/, "").split(/\s*\=(?:[^;](?!;))*[^;]?;\s*/)[nKeyId]); 1099 }, 1100 setItem: function (sKey, sValue) {
1101 if(!sKey) { return; } 1102 document.cookie = escape(sKey) + "=" + escape(sValue) + "; expires=Tue, 19 Jan 2038 03:14:07 GMT; path=/"; 1103 this.length = document.cookie.match(/\=/g).length; 1104 }, 1105 length: 0, 1106 removeItem: function (sKey) { 1107 if (!sKey || !this.hasOwnProperty(sKey)) { return; } 1108 document.cookie = escape(sKey) + "=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/"; 1109 this.length--; 1110 }, 1111 hasOwnProperty: function (sKey) { 1112 return (new RegExp("(?:^|;\\s*)" + escape(sKey).replace(/[\-\.\+\*]/g, "\\$&") + "\\s*\\=")).test(document.cookie); 1113 } 1114 }; 1115 window.localStorage.length = (document.cookie.match(/\=/g) || window.localStorage).length; 1116}
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.