1jQuery( function ( $ ) { 2 /** 3 * Check if a node is blocked for processing. 4 * 5 * @param {JQuery Object} $node 6 * @return {bool} True if the DOM Element is UI Blocked, false if not. 7 */ 8 var is_blocked = function ( $node ) { 9 return $node.is( '.processing' ) || $node.parents( '.processing' ).length; 10 }; 11 12 /** 13 * Block a node visually for processing. 14 * 15 * @param {JQuery Object} $node 16 */ 17 var block = function ( $node ) { 18 if ( !is_blocked( $node ) ) { 19 $node.addClass( 'processing' ).block( { 20 message : null, 21 overlayCSS: { 22 background: '#fff', 23 opacity : 0.6 24 } 25 } ); 26 } 27 }; 28 29 /** 30 * Unblock a node after processing is complete. 31 * 32 * @param {JQuery Object} $node 33 */ 34 var unblock = function ( $node ) { 35 $node.removeClass( 'processing' ).unblock(); 36 }; 37 38 var sooWishlist = { 39 init: function () { 40 this.data = soowData || {}; 41 42 $( document.body ) 43 .on( 'click', '.add-to-wishlist-button', this.add ) 44 .on( 'click', '.wishlist_table .remove', this.remove ) 45 .on( 'removed_from_wishlist', this.updateWishlistButtons ) 46 .on( 'removed_from_wishlist', this.updateFragments ); 47 48 this.updateFragments(); 49 }, 50 51 /** 52 * Ajax add to wishlist 53 */ 54 add: function ( event ) { 55 var $button = $( event.currentTarget ); 56 57 if ( $button.hasClass( 'added' ) ) { 58 return true; 59 } 60 61 if ( !$button.data( 'product_id' ) ) { 62 return true; 63 } 64 65 event.preventDefault(); 66 67 $button.addClass( 'loading' ); 68 69 $.post( 70 sooWishlist.data.ajaxurl, 71 { 72 action : 'soow_add_to_wishlist', 73 product_id: $button.data( 'product_id' ) 74 }, 75 function ( response ) { 76 if ( !response.success ) { 77 return; 78 } 79 80 $button.removeClass( 'loading' ).addClass( 'added' ); 81 $button.attr( 'href', sooWishlist.data.wishlisturl ); 82 83 var fragments = response.data.fragments; 84 85 if ( fragments ) { 86 $.each( fragments, function ( element, content ) { 87 $( element ).replaceWith( content ); 88 } ); 89 } 90 91 $( document.body ).trigger( 'added_to_wishlist', [$button, fragments] ); 92 } 93 ); 94 }, 95 96 /** 97 * Ajax remove product from cart 98 */ 99 remove: function ( event ) { 100 event.preventDefault(); 101 102 var $button = $( event.currentTarget ), 103 $list = $( 'div.soo-wishlist' ), 104 productId = $button.data( 'product_id' ); 105 106 $button.addClass( 'loading' ); 107 block( $list ); 108 109 $.ajax( { 110 type : 'GET', 111 url : $button.attr( 'href' ), 112 dataType: 'html', 113 success : function ( response ) { 114 var $html = $( response ), 115 $newList = $( 'div.soo-wishlist', $html ); 116 117 if ( $newList.length ) { 118 $list.replaceWith( $newList.get( 0 ) ); 119 120 $( document.body ).trigger( 'removed_from_wishlist', [productId] ); 121 } 122 } 123 } ); 124 }, 125 126 updateWishlistButtons: function( event, productId ) { 127 $( '.add-to-wishlist-button[data-product_id="' + productId + '"]' ).removeClass( 'added' ); 128 }, 129 130 updateFragments: function() { 131 $.post( 132 sooWishlist.data.ajaxurl, 133 { 134 action: 'soow_update_fragments' 135 }, 136 function ( response ) { 137 if ( !response.success ) { 138 return; 139 } 140 141 var fragments = response.data; 142 143 if ( fragments ) { 144 $.each( fragments, function ( element, content ) { 145 $( element ).replaceWith( content ); 146 } ); 147 } 148 149 $( document.body ).trigger( 'wishlist_fragments_updated', [fragments] ); 150 } 151 ); 152 } 153 }; 154
155 sooWishlist.init(); 156} );
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.