1var last_id = ''; 2var _multi_shipping = false; 3var _ms_reloaded = false; 4 5function supports_html5_storage() { 6 try { 7 $supports_html5_storage = ( 'sessionStorage' in window && window.sessionStorage !== null ); 8 9 window.sessionStorage.setItem( 'mship', 'test' ); 10 window.sessionStorage.removeItem( 'mship' ); 11 } catch (e) { 12 $supports_html5_storage = false; 13 } 14 15 return $supports_html5_storage; 16} 17 18jQuery(document).ready(function($) { 19 // store entered billing and shipping addresses 20 // so they can be imported later if the customer decides to use multishipping 21 if ( supports_html5_storage() ) { 22 var billing_fields = {}, 23 shipping_fields = {}; 24 $("form.checkout").on("blur", ".woocommerce-billing-fields :input", function() { 25 var id = $(this).attr("id"); 26 var value = $(this).val(); 27 28 billing_fields[ id ] = value; 29 localStorage.setItem( 'wcms_billing_fields', JSON.stringify( billing_fields ) ); 30 }); 31 32 $("form.checkout").on("blur", ".woocommerce-shipping-fields :input", function() { 33 var id = $(this).attr("id"); 34 var value = $(this).val(); 35 36 shipping_fields[ id ] = value; 37 localStorage.setItem( 'wcms_shipping_fields', JSON.stringify( shipping_fields ) ); 38 }); 39 40 $("form.checkout :input").trigger("blur"); 41 } 42 43 $("a.ms_delete_address").click(function(e) { 44 e.preventDefault(); 45 46 var idx = $(this).data("idx"); 47 var block = $(this).parents(".address-block"); 48 49 $(block).block({ 50 message: null, 51 overlayCSS: { 52 background: '#fff', 53 opacity: 0.6 54 } 55 }); 56 57 $.post( WCMS.ajaxurl, {action: "wc_ms_delete_address", idx: idx}, function(resp) { 58 $(block).unblock(); 59 $(block).remove(); 60 }); 61 }); 62 63 $("select.shipping_methods").on("change", function() { 64 $('body').trigger('update_checkout'); 65 }); 66 67 $("[name=shipping_method]").on("change", function() { 68 if ($(this).val() == 'local_pickup' || $(this).val() == 'local_pickup_plus') { 69 $("#wcms_message").hide(); 70 } else { 71 if ( $("#wcms_message").data("allowed") == 1 ) 72 $("#wcms_message").show(); 73 } 74 }).change(); 75 76 function disableDays(date) { 77 if ( $.inArray(date.getDay(), WCMS.datepicker_valid_days) == -1 ) { 78 return [false]; 79 } 80 81 var m = date.getMonth(), d = date.getDate(), y = date.getFullYear(); 82 var mdy = (m+1) + '-' + d +'-'+ y; 83 84 // Remove leading zeros from excluded dates 85 var excluded_dates = WCMS.datepicker_excluded_dates.map(function(excluded_date) { 86 return excluded_date.replace( /(^|-)0+/g, "$1" ); 87 }); 88 89 if ( $.inArray( mdy, excluded_dates ) != -1 ) { 90 return [false]; 91 } 92 93 return [true]; 94 } 95 96 $('body').on('updated_checkout', function() { 97 98 if ( _multi_shipping ) { 99 $("tr.shipping").remove(); 100 101 if ( !_ms_reloaded ) { 102 $('body').trigger('update_checkout'); 103 _ms_reloaded = true; 104 } 105 106 $(".ms_shipping_date").datepicker({ 107 beforeShowDay: disableDays, 108 minDate: 0 109 }); 110 111 // Don't allow user's with javascript enabled to manually edit the date 112 $(".ms_shipping_date").attr( 'readOnly', 'true' ); 113 } 114 }); 115 116 $(".user-add-address").click(function(e) { 117 e.preventDefault(); 118 var id = ''; 119 var tpl = $("#address_form_template").html(); 120 121 do { 122 id = Math.floor(Math.random()*99999999) + 1; 123 tpl = tpl.replace(/(\|sig\|)/gi, id); 124 } while ( $("#shipping_address_"+ id).length >= 1 ); 125 126 tb_show('New Address', "#TB_inline?height=520&width=400&inlineId=address_form_template&sig="+ id); 127 wcms_resize_thickbox(); 128 }); 129 130 $(".add-address").click(function(e) { 131 e.preventDefault(); 132 133 var id = ''; 134 var tpl = $("#address_form_template").html(); 135 136 do { 137 id = Math.floor(Math.random()*99999999) + 1; 138 $("#address_id").val(id); 139 //tpl = tpl.replace(/(\|sig\|)/gi, id); 140 } while ( $("#shipping_address_"+ id).length >= 1 ); 141 142 tb_show('New Address', "#TB_inline?height=520&width=400&inlineId=address_form_template&sig="+ id); 143 144 wcms_resize_thickbox(); 145 }); 146 147 $(".user-duplicate-cart").click(function(e) { 148 e.preventDefault(); 149 150 tb_show('Shipping Address', "#TB_inline?height=520&width=400&inlineId=duplicate_address_form_template"); 151 wcms_resize_thickbox() 152 }); 153 154 $("#add_address_form").submit(function() { 155 var frm = this; 156 jQuery(frm).block({ message: null, overlayCSS: { background: '#fff url
156('+ WCMS.wc_url +'/assets/images/ajax-loader.gif) no-repeat center', opacity: 0.6 } }); 157 158 $("p.woocommerce-invalid").removeClass("woocommerce-invalid"); 159 160 var data = $(this).serialize() + "&action=wc_save_to_address_book"; 161 162 $.post(WCMS.ajaxurl, data, function(resp) { 163 var data = JSON.parse(resp); 164 165 if (data.ack == "OK") { 166 // reset form 167 $('#add_address_form')[0].reset(); 168 169 window.location.href = data.next; 170 171 } else if (data.ack == "ERR") { 172 if ( data.errors && data.errors.length > 0 ) { 173 174 for ( var x = 0; x < data.errors.length; x++ ) { 175 var field_key = data.errors[x]; 176 177 $("input[name='address["+ field_key +"]']").parent("p").addClass("woocommerce-invalid"); 178 } 179 180 } 181 jQuery(frm).unblock(); 182 alert(data.message); 183 } 184 185 }); 186 187 return false; 188 }); 189 190 $("#duplicate_cart_form").submit(function() { 191 var data = $(this).serialize() + "&action=wc_duplicate_cart"; 192 193 $.post(WCMS.ajaxurl, data, function(resp) { 194 var data = JSON.parse(resp); 195 196 if (data.ack == "OK") { 197 tb_remove(); 198 var id = data.id; 199 var html = data.html; 200 201 $("#addresses_container").prepend(html); 202 $("#items_column_"+ id).droppable({ 203 activeClass: "ui-state-default", 204 hoverClass: "ui-state-hover", 205 tolerance: "pointer", 206 //accept: ":not(.ui-sortable-helper)", 207 drop: function( event, ui ) { 208 var qty = $(ui.draggable).data("quantity"); 209 var select_qty = 1; 210 211 if (qty > 1) { 212 select_qty = prompt("Enter the quantity (1-"+ qty +"):", "1"); 213 214 if (select_qty == null) { 215 return false; 216 } 217 218 if (select_qty < 1) select_qty = 1; 219 220 select_qty = Math.floor(select_qty); 221 222 if ( select_qty > qty ) select_qty = qty; 223 } 224 225 $( this ).find( ".placeholder" ).remove(); 226 227 qty -= select_qty; 228 //var qty = $(ui.draggable).data("quantity") - 1; 229 var key = $(ui.draggable).attr("id"); 230 var pid = $(ui.draggable).data("product-id"); 231 var addr_qty= $(".address-item-key-"+ key, this).length; 232 var addr_key= $(this).attr("id").split("_")[2]; 233 234 $( ui.draggable ).data("quantity", qty); 235 $( ".qty", ui.draggable ).text(qty); 236 237 if ( addr_qty == 0 ) { 238 var classes = $(ui.draggable).attr("class").replace(/(cart\-item)/gi, "address-item"); 239 240 var li = $("<li></li>") 241 .attr("class", classes) 242 .addClass("address-item-key-"+ key ) 243 .data("key", key) 244 .data("product-id", pid) 245 .html( ui.draggable.html() ).appendTo( this ); 246 247 for ( var x = 0; x < select_qty; x++ ) { 248 $(li).append('<input type="hidden" name="items_'+addr_key+'[]" value="'+ key +'" />'); 249 } 250 251 $(li) 252 .append('<a class="remove" href="#"><img style="width: 16px; height: 16px;" src="'+ WCMS.base_url +'/images/delete.png" title="Remove" /></a>') 253 .find(".qty").text(select_qty); 254 255 $(li).find("div.quantity").remove(); 256 } else { 257 var item_qty = parseInt($(".address-item-key-"+key, this).find(".qty").text()); 258 $(".address-item-key-"+key, this).find(".qty").text(item_qty+select_qty); 259 260 for ( var x = 0; x < select_qty; x++ ) { 261 $(".address-item-key-"+key, this).append('<input type="hidden" name="items_'+addr_key+'[]" value="'+ key +'" />'); 262 } 263 } 264 265 if ( qty == 0 ) { 266 $( ui.draggable ).remove(); 267 } 268 269 $('#addresses_container').masonry("reload"); 270 } 271 }); 272 273 $('#addresses_container').masonry("reload"); 274 } else if (data.ack == "ERR") { 275 alert(data.message); 276 } 277 }); 278 279 return false;
280 }); 281 282 $('.address-use').click(function() { 283 var address = JSON.parse($(this).parents('p').prev('textarea').val()); 284 $(this).prop('disabled', true); 285 286 $(".add-address").click(); 287 288 setAddress(address, last_id); 289 }); 290 291 $( "#cart_items ul li" ).draggable({ 292 appendTo: "body", 293 helper: "clone", 294 revert: false, 295 cursorAt: {left:50, top:30} 296 }); 297 298 $("li.address-item > a.remove").on("click", function(e) { 299 e.preventDefault(); 300 301 var parent = $(this).parents("li.address-item"); 302 var ul = $(parent).parents(".items-column"); 303 var qty = parseInt($(parent).find(".qty").text()); 304 var key = $(parent).data("key"); 305 var pid = $(parent).data("product-id"); 306 307 if ( $("#"+key).length > 0 ) { 308 var orig_qty = parseInt($("#"+key).find(".qty").text()); 309 var new_qty = orig_qty + qty; 310 $("#"+key) 311 .data("quantity", new_qty) 312 .find(".qty").text(new_qty); 313 } else { 314 var li = $("<li></li>") 315 .html($(parent).html()) 316 .data("quantity", qty) 317 .data("product-id", pid) 318 .attr("class", $(parent).attr("class").replace(/(address\-item)/gi, "cart-item")) 319 .attr("id", $(parent).data("key")); 320 321 $(li).find("a.remove").remove(); 322 $(li).find("input").remove(); 323 $(li).appendTo("ul.cart-items"); 324 325 $(li).draggable({ 326 appendTo: "body", 327 helper: "clone", 328 revert: false, 329 cursorAt: {left:0, top:0} 330 }); 331 } 332 333 $(parent).remove(); 334 335 if ( $(ul).children("li").length == 0 ) { 336 $(ul).append('<li class="placeholder">Drag items here</li>'); 337 } 338 339 $('#addresses_container').masonry("reload"); 340 }); 341 342 $("#address_form").submit(function() { 343 if ($(".cart-items li").length > 0) { 344 alert("Please assign a shipping address for all your cart items."); 345 return false; 346 } 347 }); 348 349 $(".items-column").droppable({ 350 activeClass: "ui-state-default", 351 hoverClass: "ui-state-hover", 352 tolerance: "pointer", 353 //accept: ":not(.ui-sortable-helper)", 354 drop: function( event, ui ) { 355 var qty = $(ui.draggable).data("quantity"); 356 var select_qty = 1; 357 358 if (qty > 1) { 359 select_qty = prompt("Enter the quantity (1-"+ qty +"):", "1"); 360 361 if (select_qty == null) { 362 return false; 363 } 364 365 if (select_qty < 1) select_qty = 1; 366 367 select_qty = Math.floor(select_qty); 368 369 if ( select_qty > qty ) select_qty = qty; 370 } 371 372 $( this ).find( ".placeholder" ).remove(); 373 374 qty -= select_qty; 375 376 //var qty = $(ui.draggable).data("quantity") - 1; 377 var key = $(ui.draggable).attr("id"); 378 var pid = $(ui.draggable).data("product-id"); 379 var addr_qty= $(".address-item-key-"+ key, this).length; 380 var addr_key= $(this).attr("id").split("_")[2]; 381 382 $( ui.draggable ).data("quantity", qty); 383 $( ".qty", ui.draggable ).text(qty); 384 385 if ( addr_qty == 0 ) { 386 var classes = $(ui.draggable).attr("class").replace(/(cart\-item)/gi, "address-item"); 387 388 var li = $("<li></li>") 389 .attr("class", classes) 390 .addClass("address-item-key-"+ key ) 391 .data("key", key) 392 .data("product-id", pid) 393 .html( ui.draggable.html() ).appendTo( this ); 394 395 for ( var x = 0; x < select_qty; x++ ) { 396 $(li).append('<input type="hidden" name="items_'+addr_key+'[]" value="'+ key +'" />'); 397 } 398 399 $(li) 400 .append('<a class="remove" href="#"><img style="width: 16px; height: 16px;" src="'+ WCMS.base_url +'/images/delete.png" title="Remove" /></a>') 401 .find(".qty").text(select_qty); 402 403 $(li).find("div.quantity").remove(); 404 } else { 405 var item_qty = parseInt($(".address-item-key-"+key, this).find(".qty").text()); 406 $(".address-item-key-"+key, this).find(".qty").text(item_qty+select_qty); 407 408 for ( var x = 0; x < select_qty; x++ ) { 409 $(".address-item-key-"+key, this).append('<input type="hidden" name="items_'+addr_key+'[]" value="'+ key +'" />'); 410 } 411 412 } 413 414 if ( qty == 0 ) { 415 $( ui.draggable ).remove(); 416 } 417 418 jQuery('#addresses_container').masonry("reload"); 419 } 420 }); 421 422 /* State/Country select boxes */ 423 var states_json = WCMS.countries.replace(/"/g, '"'); 424 var states = JSON.parse( states_json ); 425 426 jQuery('select.country_to_state').on("change", function(){ 427 428 var country = $(this).val(); 429 430 var $statebox = $(this).closest('div').find('select[id^="address[shipping_state]"], input[id^="address[shipping_state]"]'); 431 432 var $parent = $statebox.parent(); 433 434 var input_name = $statebox.attr('name'); 435 var input_id = $statebox.attr('id'); 436 var value = $statebox.val(); 437 438 if (states[country]) { 439 if (states[country].length == 0) { 440 441 // Empty array means state field is not used 442 $parent.fadeOut(200, function() { 443 $statebox.parent().find('.chzn-container').remove(); 444 $statebox.replaceWith('<input type="hidden" class="hidden" name="' + input_name + '" id="' + input_id + '" value="" />'); 445 446 $('body').trigger('country_to_state_changed', [country, $(this).closest('div')]); 447 }); 448 449 } else { 450 451 $parent.fadeOut(200, function() { 452 var options = ''; 453 var state = states[country]; 454 455 for(var index in state) { 456 options = options + '<option value="' + index + '">' + state[index] + '</option>'; 457 } 458 if ($statebox.is('input')) { 459 // Change for select 460 $statebox.replaceWith('<select name="' + input_name + '" id="' + input_id + '" class="state_select"></select>'); 461 $statebox = $(this).closest('div').find('select[id^="address[shipping_state]"], input[id^="address[shipping_state]"]'); 462 } 463 $statebox.html( '<option value="">' + WCMS.select_state_text + '</option>' + options); 464 465 $statebox.val(value); 466 467 $('body').trigger('country_to_state_changed', [country, $(this).closest('div')]); 468 469 $parent.fadeIn(500); 470 }); 471 472 } 473 } else { 474 if ($statebox.is('select')) { 475 476 $parent.fadeOut(200, function() { 477 $parent.find('.chzn-container').remove(); 478 $statebox.replaceWith('<input type="text" class="input-text" name="' + input_name + '" id="' + input_id + '" />'); 479 480 $('body').trigger('country_to_state_changed', [country, $(this).closest('div')]); 481 $parent.fadeIn(500); 482 }); 483 484 } else if ($statebox.is('.hidden')) { 485 486 $parent.find('.chzn-container').remove(); 487 $statebox.replaceWith('<input type="text" class="input-text" name="' + input_name + '" id="' + input_id + '" />'); 488 489 $('body').trigger('country_to_state_changed', [country, $(this).closest('div')]); 490 $parent.delay(200).fadeIn(500); 491 492 } 493 } 494 495 $('body').delay(200).trigger('country_to_state_changing', [country, $(this).closest('div')]); 496 497 }).change(); 498 499 $( '#ms_addresses' ).change( function() { 500 var selected = $( '#ms_addresses option:selected' ); 501 var data = selected.data(); 502 var state = ''; 503 504 if ( selected.val() == '' ) { 505 return; 506 } 507 508 for ( var prop in data ) { 509 if ( 'shipping_' == prop.substr( 0, 9 ) ) { 510 511 // Save state value for changing later. 512 if ( 'shipping_state' == prop ) { 513 state = data[ prop ]; 514 } else { 515 if ( $( '.woocommerce-shipping-fields #' + prop ).length ) { 516 $( '.woocommerce-shipping-fields #' + prop ).val( data[ prop ] ).change(); 517 } 518 519 if ( $( '.wcms-address-form .shipping_address #' + prop ).length ) { 520 $( '.wcms-address-form .shipping_address #' + prop ).val( data[ prop ] ).change(); 521 } 522 } 523 } 524 } 525 526 // Register state change after country changes. 527 $( 'body' ).one( 'country_to_state_changed', function() { 528 $( '.woocommerce-shipping-fields #shipping_state' ).val( state ).change(); 529 $( '.wcms-address-form .shipping_address #shipping_state' ).val( state ).change(); 530 } ); 531 $( '.woocommerce-shipping-fields #shipping_country, .wcms-address-form .shipping_address #shipping_country' ).change(); 532 533 } ).change(); 534 535 if ( $('#addresses_container').length ) { 536 $('#addresses_container').masonry({ 537 itemSelector: '.account-address', 538 isFitWidth: true 539 }); 540 } 541 542 if ( Modernizr && Modernizr.touch ) { 543 $("li.cart-item").on("click", function() { 544 545 if ( $(this).hasClass("cart-item-active") ) { 546 547 $(this).removeClass("cart-item-active"); 548 $("#addresses_container .account-address").removeClass("drop-ready"); 549 550 } else { 551 552 $(this).addClass("cart-item-active"); 553 $("#addresses_container .account-address").addClass("drop-ready"); 554 555 } 556 557 }); 558 559 $(".items-column").on("click", function() { 560 // get all the active items 561 var dropzone = this; 562 $("li.cart-item-active").each(function() { 563 var item = this; 564 var qty = $(item).data("quantity"); 565 var select_qty = 1; 566 567 $(dropzone).find( ".placeholder" ).remove(); 568 569 qty -= select_qty; 570 571 var key = $(item).attr("id"); 572 var pid = $(item).data("product-id");
573 var addr_qty= $(".address-item-key-"+ key, dropzone).length; 574 var addr_key= $(dropzone).attr("id").split("_")[2]; 575 576 $( item ).data("quantity", qty); 577 $( ".qty", item ).text(qty); 578 579 if ( addr_qty == 0 ) { 580 var classes = $(item).attr("class").replace(/(cart\-item)/gi, "address-item"); 581 582 var li = $("<li></li>") 583 .attr("class", classes) 584 .addClass("address-item-key-"+ key ) 585 .data("key", key) 586 .data("product-id", pid) 587 .html( $(item).html() ); 588 589 $(dropzone).append( li ); 590 591 for ( var x = 0; x < select_qty; x++ ) { 592 $(li).append('<input type="hidden" name="items_'+addr_key+'[]" value="'+ key +'" />'); 593 } 594 595 $(li) 596 .append('<a class="remove" href="#"><img style="width: 16px; height: 16px;" src="'+ WCMS.base_url +'/images/delete.png" title="Remove" /></a>') 597 .find(".qty").text(select_qty); 598 599 $(li).find("div.quantity").remove(); 600 } else { 601 var item_qty = parseInt($(".address-item-key-"+key, dropzone).find(".qty").text()); 602 $(".address-item-key-"+key, dropzone).find(".qty").text(item_qty+select_qty); 603 604 for ( var x = 0; x < select_qty; x++ ) { 605 $(".address-item-key-"+key, dropzone).append('<input type="hidden" name="items_'+addr_key+'[]" value="'+ key +'" />'); 606 } 607 608 } 609 610 if ( qty == 0 ) { 611 $( item ).remove(); 612 } 613 614 jQuery('#addresses_container').masonry("reload"); 615 }); 616 }); 617 } 618 619 $( '.delete-line-item').on('click', function() { 620 var key = $(this).data("key"); 621 var index = $(this).data("index"); 622 623 $("#delete_index").val( index ); 624 $("#delete_key").val( key ); 625 }); 626 627 $('.button.selectable').on('click', function() { 628 var container = $(this).parents(".address-duplicate-block"); 629 var idx = $(this).data("index"); 630 var input = $("#address_input_"+ idx); 631 632 input.click(); 633 634 if ( $(input).is(":checked") ) { 635 $(container).addClass("on"); 636 } else { 637 $(container).removeClass("on"); 638 } 639 640 }); 641}); 642 643jQuery(window).resize( function() { 644 wcms_resize_thickbox(); 645}); 646 647function wcms_resize_thickbox() { 648 var width = jQuery(window).width(); // 80% of the screen size, max of 400 649 650 if ( width < 400 ) { 651 width = 300; 652 var win = jQuery(document).find('#TB_window') 653 654 win.css({ 655 'width': width +'px', 656 marginLeft: '-' + parseInt((width / 2), 10) +'px' 657 }); 658 659 jQuery(document).find('#TB_ajaxContent').css('width', 'auto'); 660 } 661 662}
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.