Plugin Directory

Changeset 3122355


Ignore:
Timestamp:
07/20/2024 05:13:13 AM (20 months ago)
Author:
wcboost
Message:

updating code for the version 1.1.1

Location:
wcboost-wishlist/trunk
Files:
1 added
10 edited

Legend:

Unmodified
Added
Removed
  • wcboost-wishlist/trunk/assets/css/wishlist.css

    r2866245 r3122355  
    1 /** Wishlist Page **/
    2 .wcboost-wishlist-header {
    3     margin-bottom: 2em;
    4 }
    5 
    6 .wcboost-wishlist-title {
    7     font-size: 1.5em;
    8 }
    9 
    10 .wcboost-wishlist__item .product-thumbnail img {
    11     max-width: 5em;
    12     height: auto;
    13 }
    14 
    15 .wcboost-wishlist__item .product-remove {
    16     vertical-align: middle;
    17 }
    18 
    19 .wcboost-wishlist__item .product-add-to-cart {
    20     text-align: right;
    21 }
    22 
    23 .wishlist-share__buttons {
    24     list-style: none;
    25     margin: 0;
    26     padding: 0;
    27 }
    28 
    29 .wishlist-share__buttons li {
    30     display: inline-block;
    31     margin: 0 0.14em 0.3em 0;
    32 }
    33 
    34 .wishlist-share__buttons a {
    35     color: inherit;
    36     text-decoration: none;
    37     display: inline-block;
    38     padding: 0.6180469716em;
    39     background-color: var(--wcboost-wishlist-color--button-background, #eee);
    40 }
    41 
    42 .entry-content .wishlist-share__buttons li a {
    43     text-decoration: none;
    44 }
    45 
    46 .wishlist-share__buttons svg {
    47     width: 1em;
    48     height: auto;
    49     margin-right: 0.25em;
    50     vertical-align: -0.125em;
    51 }
    52 
    53 .wcboost-wishlist-actions {
    54     text-align: right;
    55 }
    56 
    57 .wcboost-wishlist-edit-link-wrapper {
    58     margin: 1.5em 0;
    59 }
    60 
    61 /** Wishlist Button **/
    62 .wcboost-wishlist-button__icon {
    63     margin-right: 0.4em;
    64 }
    65 
    66 .wcboost-wishlist-button__icon img,
    67 .wcboost-wishlist-button__icon svg {
    68     vertical-align: -0.125em;
    69     width: 1em;
    70     height: auto;
    71 }
    72 
    73 .wcboost-wishlist-button__icon svg {
    74     fill: currentColor;
    75 }
    76 
    77 .wcboost-wishlist-button__icon img {
    78     display: inline;
    79 }
    80 
    81 .wcboost-wishlist-button.disabled {
    82     opacity: 0.75;
    83 }
    84 
    85 .wcboost-wishlist-button--text {
    86     display: inline-block;
    87     margin: 0.5em;
    88 }
    89 
    90 .wcboost-wishlist-button.loading .wcboost-wishlist-button__icon svg {
    91     animation: wcboost-spin .75s linear infinite;
    92 }
    93 
    94 @-webkit-keyframes wcboost-spin {
    95     0% { -webkit-transform: rotate(0deg); }
    96     100% { -webkit-transform: rotate(360deg); }
    97 }
    98 
    99 @keyframes wcboost-spin {
    100     0% { transform: rotate(0deg); }
    101     100% { transform: rotate(360deg); }
    102 }
    103 
    104 .woocommerce .wcboost-wishlist-button--custom {
    105     color: var(--wcboost-wishlist-button-color--text, #fff);
    106     border: 1px solid;
    107     border-color: var(--wcboost-wishlist-button-color--border, #333);
    108     background-color: var(--wcboost-wishlist-button-color--background, #333);
    109     transition: 0.1s ease-in;
    110 }
    111 
    112 .woocommerce .wcboost-wishlist-button--custom:hover {
    113     color: var(--wcboost-wishlist-button-hover-color--text, #fff);
    114     border-color: var(--wcboost-wishlist-button-hover-color--border, #111);
    115     background-color: var(--wcboost-wishlist-button-hover-color--background, #111);
    116 }
    117 
    118 /** Sharing notices **/
    119 .wcboost-wishlist-share-notice {
    120     color: #fff;
    121     display: none;
    122     position: fixed;
    123     bottom: 20px;
    124     left: 50%;
    125     transform: translateX(-50%);
    126     padding: 10px 40px 10px 10px;
    127     background-color: rgba(0, 0, 0, 0.7);
    128     max-width: 100%;
    129 }
    130 
    131 .wcboost-wishlist-share-notice input[type="text"] {
    132     width: 300px;
    133     max-width: 100%;
    134     padding: 5px;
    135 }
    136 
    137 .wcboost-wishlist-share-notice__close {
    138     font-size: 0;
    139     position: absolute;
    140     right: 10px;
    141     top: 50%;
    142     transform: translateY(-50%);
    143     cursor: pointer;
    144 }
    145 
    146 .wcboost-wishlist-share-notice__close::before {
    147     content: "\00d7";
    148     display: inline-block;
    149     color: #fff;
    150     font-size: 20px;
    151     padding: 5px;
    152 }
    153 
    154 /** Wishlist Form Edit **/
    155 .wcboost-wishlist-form-edit .form-row--wishlist-privacy .woocommerce-input-wrapper {
    156     display: block;
    157 }
    158 
    159 .wcboost-wishlist-form-edit .form-row--wishlist-privacy .woocommerce-input-wrapper label {
    160     display: inline;
    161     margin-left: 6px;
    162 }
    163 
    164 .wcboost-wishlist-form-edit .form-row--wishlist-privacy .woocommerce-input-wrapper label::after {
    165     content: "";
    166     display: block;
    167     white-space: pre;
    168 }
    169 
    170 /** Wishlist Form Delete **/
    171 .wcboost-wishlist-form-delete {
    172     padding: 1rem 1.5rem;
    173     margin-top: 3em;
    174     background-color: var(--wcboost-wishlist-color--delete-bg, #fcf1ef);
    175     border-left: 3px solid var(--wcboost-wishlist-color--delete, #c91c00);
    176 }
    177 
    178 .wcboost-wishlist-form-delete button {
    179     color: #fff;
    180     background-color: var(--wcboost-wishlist-color--delete, #c91c00);
    181 }
    182 
    183 /** Fixes for Storefront **/
    184 ul.products li.product .wcboost-wishlist-button img {
    185     display: inline;
    186     margin: 0;
    187 }
    188 
    189 /** Fixes for Twenty Twenty Two **/
    190 .theme-twentytwentytwo .wishlist_table th,
    191 .theme-twentytwentytwo .wishlist_table td {
    192     padding: 1rem 0 .5rem 1rem;
    193 }
    194 
    195 .theme-twentytwentytwo .wcboost-wishlist-button {
    196     line-height: normal;
    197 }
    198 
    199 .theme-twentytwentytwo .wcboost-wishlist-button--text {
    200     margin: 1rem;
    201 }
    202 
    203 /** Wishlist widget **/
    204 .wcboost-wishlist-widget-item {
    205     position: relative;
    206     margin: 1em 0;
    207 }
    208 
    209 .wcboost-wishlist-widget-item::after {
    210     content: "";
    211     display: block;
    212     clear: both;
    213 }
    214 
    215 .wcboost-wishlist-widget-item img {
    216     max-width: 60px;
    217     margin-right: 1em;
    218     float: left;
    219 }
    220 
    221 .wcboost-wishlist-widget-item__price,
    222 .wcboost-wishlist-widget-item__quantity,
    223 .wcboost-wishlist-widget-item__stock,
    224 .wcboost-wishlist-widget-item__date,
    225 .wcboost-wishlist-widget-item__add-to-cart {
    226     display: block;
    227 }
    228 
    229 .wcboost-wishlist-widget-item a.remove {
    230     line-height: 1;
    231     text-decoration: none;
    232     position: absolute;
    233     left: 0;
    234     top: 0;
    235     min-width: 1em;
    236     min-height: 1em;
    237     border-radius: 50%;
    238     transform: translate(-50%, -50%);
    239 }
     1.wcboost-wishlist-header{margin-bottom:2em}.wcboost-wishlist-title{font-size:1.5em}.wcboost-wishlist__item .product-thumbnail img{max-width:5em;height:auto}.wcboost-wishlist__item .product-remove{vertical-align:middle}.wcboost-wishlist__item .product-add-to-cart{text-align:right}.wishlist-share__buttons{list-style:none;margin:0;padding:0}.wishlist-share__buttons li{display:inline-block;margin:0 .14em .3em 0}.wishlist-share__buttons a{color:inherit;text-decoration:none;display:inline-block;padding:0.6180469716em;background-color:var(--wcboost-wishlist-color--button-background, #eee)}.wishlist-share__buttons svg{width:1em;height:auto;margin-right:.25em;vertical-align:-0.125em}.entry-content .wishlist-share__buttons li a{text-decoration:none}.wcboost-wishlist-actions{text-align:right}.wcboost-wishlist-edit-link-wrapper{margin:1.5em 0}.wcboost-wishlist-button__icon{margin-right:.4em}.wcboost-wishlist-button__icon img,.wcboost-wishlist-button__icon svg{vertical-align:-0.125em;width:1em;height:auto}.wcboost-wishlist-button__icon svg{fill:currentColor}.wcboost-wishlist-button__icon img{display:inline}.wcboost-wishlist-button.disabled{opacity:.75}.wcboost-wishlist-button--text{display:inline-block;margin:.5em}.wcboost-wishlist-button.loading .wcboost-wishlist-button__icon svg{animation:wcboost-spin .75s linear infinite}@-webkit-keyframes wcboost-spin{0%{-webkit-transform:rotate(0deg)}100%{-webkit-transform:rotate(360deg)}}@keyframes wcboost-spin{0%{transform:rotate(0deg)}100%{transform:rotate(360deg)}}.woocommerce .wcboost-wishlist-button--custom{color:var(--wcboost-wishlist-button-color--text, #fff);border:1px solid;border-color:var(--wcboost-wishlist-button-color--border, #333);background-color:var(--wcboost-wishlist-button-color--background, #333);transition:.1s ease-in}.woocommerce .wcboost-wishlist-button--custom:hover{color:var(--wcboost-wishlist-button-hover-color--text, #fff);border-color:var(--wcboost-wishlist-button-hover-color--border, #111);background-color:var(--wcboost-wishlist-button-hover-color--background, #111)}.wcboost-wishlist-share-notice{color:#fff;display:none;position:fixed;bottom:20px;left:50%;transform:translateX(-50%);padding:10px 40px 10px 10px;background-color:rgba(0,0,0,.7);max-width:100%}.wcboost-wishlist-share-notice input[type=text]{width:300px;max-width:100%;padding:5px}.wcboost-wishlist-share-notice__close{font-size:0;position:absolute;right:10px;top:50%;transform:translateY(-50%);cursor:pointer}.wcboost-wishlist-share-notice__close::before{content:"×";display:inline-block;color:#fff;font-size:20px;padding:5px}.wcboost-wishlist-form-edit .form-row--wishlist-privacy .woocommerce-input-wrapper{display:block}.wcboost-wishlist-form-edit .form-row--wishlist-privacy .woocommerce-input-wrapper label{display:inline;margin-left:6px}.wcboost-wishlist-form-edit .form-row--wishlist-privacy .woocommerce-input-wrapper label::after{content:"";display:block;white-space:pre}.wcboost-wishlist-form-delete{padding:1rem 1.5rem;margin-top:3em;background-color:var(--wcboost-wishlist-color--delete-bg, #fcf1ef);border-left:3px solid var(--wcboost-wishlist-color--delete, #c91c00)}.wcboost-wishlist-form-delete button{color:#fff;background-color:var(--wcboost-wishlist-color--delete, #c91c00)}ul.products li.product .wcboost-wishlist-button img{display:inline;margin:0}.theme-twentytwentytwo .wishlist_table th,.theme-twentytwentytwo .wishlist_table td{padding:1rem 0 .5rem 1rem}.theme-twentytwentytwo .wcboost-wishlist-button{line-height:normal}.theme-twentytwentytwo .wcboost-wishlist-button--text{margin:1rem}.wcboost-wishlist-widget-item{position:relative;margin:1em 0}.wcboost-wishlist-widget-item::after{content:"";display:block;clear:both}.wcboost-wishlist-widget-item img{max-width:60px;margin-right:1em;float:left}.wcboost-wishlist-widget-item a.remove{line-height:1;text-decoration:none;position:absolute;left:0;top:0;min-width:1em;min-height:1em;border-radius:50%;transform:translate(-50%, -50%)}.wcboost-wishlist-widget-item__price,.wcboost-wishlist-widget-item__quantity,.wcboost-wishlist-widget-item__stock,.wcboost-wishlist-widget-item__date,.wcboost-wishlist-widget-item__add-to-cart{display:block}
  • wcboost-wishlist/trunk/assets/js/wishlist-fragments.js

    r3113521 r3122355  
    2323     */
    2424    var WCBoostWishlistFragments = function() {
     25        var self = this;
     26
    2527        this.updateFragments = this.updateFragments.bind( this );
    2628        this.getProductIds   = this.getProductIds.bind( this );
     
    3436        // Refresh when storage changes in another tab.
    3537        $( window ).on( 'storage onstorage', function( e ) {
    36             if ( 'wcboost_wishlist_updated' === e.originalEvent.key ) {
    37                 // Use option `preventStorageUpdate` to prevent infinite refreshing.
    38                 $( document.body ).trigger( 'wishlist_fragments_refresh', [ false, { preventStorageUpdate: true } ] );
     38            if ( hash_key_name === e.originalEvent.key  && localStorage.getItem( hash_key_name ) !== sessionStorage.getItem( hash_key_name ) ) {
     39                $( document.body ).trigger( 'wishlist_fragments_refresh' );
    3940            }
    4041        } );
     
    5253
    5354            try {
    54                 var hash_key = sessionStorage.getItem( hash_key_name );
    55 
    56                 if ( hash_key !== null ) {
     55                var wishlist_hash = sessionStorage.getItem( hash_key_name ),
     56                    cookie_hash = Cookies.get( 'wcboost_wishlist_hash' );
     57
     58                if ( wishlist_hash !== null && wishlist_hash === cookie_hash ) {
    5759                    this.updateFragmentsFromStorage();
    5860                    this.updateButtons();
    5961                } else {
    60                     // Run for the first time.
    61                     this.refreshFragments();
     62                    throw 'No wishlist fragment';
    6263                }
    6364            } catch ( err ) {
    6465                this.refreshFragments();
    6566            }
     67        }
     68
     69        // Customiser support.
     70        var hasSelectiveRefresh = (
     71            'undefined' !== typeof wp &&
     72            wp.customize &&
     73            wp.customize.selectiveRefresh &&
     74            wp.customize.widgetsPreview &&
     75            wp.customize.widgetsPreview.WidgetPartial
     76        );
     77
     78        if ( hasSelectiveRefresh ) {
     79            wp.customize.selectiveRefresh.bind( 'partial-content-rendered', function() {
     80                self.refreshFragments();
     81            } );
    6682        }
    6783    }
     
    124140        }
    125141
    126         var hash_key = sessionStorage.getItem( hash_key_name );
    127 
    128         if ( ! hash_key ) {
    129             return;
    130         }
    131 
    132         var fragments = JSON.parse( sessionStorage.getItem( 'wcboost_wishlist_fragments_' + hash_key ) );
    133 
    134         if ( fragments !== null ) {
    135             this.updateFragments( fragments );
     142        var wishlist_hash = sessionStorage.getItem( hash_key_name );
     143
     144        if ( ! wishlist_hash ) {
     145            return;
     146        }
     147
     148        var hash_parts = wishlist_hash.split( '::' ),
     149            hash_key = hash_parts[0];
     150
     151        if ( hash_key ) {
     152            var fragments = JSON.parse( sessionStorage.getItem( 'wcboost_wishlist_fragments_' + hash_key ) );
     153
     154            if ( fragments !== null ) {
     155                this.updateFragments( fragments );
     156            }
    136157        } else {
    137158            this.refreshFragments();
     
    144165        }
    145166
    146         var hash_key = data.wishlist_hash ? data.wishlist_hash : '';
    147 
    148         sessionStorage.setItem( hash_key_name, hash_key );
    149 
    150         if ( ! options || ! options.preventStorageUpdate ) {
    151             // Update the wishlist timestamps to sync between tabs.
    152             localStorage.setItem( 'wcboost_wishlist_updated', ( new Date() ).getTime() );
    153         }
    154 
    155         if ( hash_key !== '' ) {
     167        var wishlist_hash = data.wishlist_hash ? data.wishlist_hash : '';
     168
     169        sessionStorage.setItem( hash_key_name, wishlist_hash );
     170        localStorage.setItem( hash_key_name, wishlist_hash );
     171
     172        if ( wishlist_hash ) {
     173            var hash_parts = wishlist_hash.split( '::' ),
     174                hash_key = hash_parts[0];
     175
    156176            if ( data.wishlist_items ) {
    157177                sessionStorage.setItem( 'wcboost_wishlist_' + hash_key, JSON.stringify( data.wishlist_items ) );
     
    179199        }
    180200
    181         var hash_key = sessionStorage.getItem( hash_key_name );
     201        var wishlist_hash = sessionStorage.getItem( hash_key_name );
     202
     203        if ( ! wishlist_hash ) {
     204            return;
     205        }
     206
     207        var hash_parts = wishlist_hash.split( '::' ),
     208            hash_key = hash_parts[0];
    182209
    183210        if ( ! hash_key ) {
  • wcboost-wishlist/trunk/assets/js/wishlist-fragments.min.js

    r3113521 r3122355  
    1 jQuery(function(a){if(typeof wcboost_wishlist_fragments_params==="undefined"){return false}var r=true,o=wcboost_wishlist_fragments_params.hash_name;try{r="sessionStorage"in window&&window.sessionStorage!==null;window.sessionStorage.setItem("wcboost","test");window.sessionStorage.removeItem("wcboost");window.localStorage.setItem("wcboost","test");window.localStorage.removeItem("wcboost")}catch(t){r=false}var t=function(){this.updateFragments=this.updateFragments.bind(this);this.getProductIds=this.getProductIds.bind(this);a(document.body).on("wishlist_fragments_refresh wishlist_updated",{wishlistFragmentsHandler:this},this.refreshFragments).on("wishlist_fragments_refreshed wishlist_item_added wishlist_item_removed",{wishlistFragmentsHandler:this},this.updateStorage).on("added_to_wishlist removed_from_wishlist",{wishlistFragmentsHandler:this},this.updateFragmentsOnChanges).on("wishlist_storage_updated",{wishlistFragmentsHandler:this},this.updateButtons);a(window).on("storage onstorage",function(t){if("wcboost_wishlist_updated"===t.originalEvent.key){a(document.body).trigger("wishlist_fragments_refresh",[false,{preventStorageUpdate:true}])}});if("yes"===wcboost_wishlist_fragments_params.refresh_on_load){a(document.body).trigger("wishlist_fragments_refresh")}else{a(window).on("pageshow",function(t){if(t.originalEvent.persisted){a(document.body).trigger("wishlist_fragments_refresh",[true])}});try{var t=sessionStorage.getItem(o);if(t!==null){this.updateFragmentsFromStorage();this.updateButtons()}else{this.refreshFragments()}}catch(t){this.refreshFragments()}}};t.prototype.refreshFragments=function(t,s,e){var i=t?t.data.wishlistFragmentsHandler:this;var r={time:(new Date).getTime()};if("yes"===wcboost_wishlist_fragments_params.refresh_on_load||s){r.product_ids=i.getProductIds()}a.post({url:woocommerce_params.wc_ajax_url.toString().replace("%%endpoint%%","get_wishlist_fragments"),data:r,dataType:"json",timeout:wcboost_wishlist_fragments_params.request_timeout,success:function(t){if(!t.success){a(document.body).trigger("wishlist_fragments_failed");return}i.updateFragments(t.data.fragments);a(document.body).trigger("wishlist_fragments_refreshed",[t.data,e])},error:function(){a(document.body).trigger("wishlish_fragments_ajax_error")}})};t.prototype.getProductIds=function(){var e=[];a(".wcboost-wishlist-button").each(function(t,s){e.push(s.dataset.product_id)});return e};t.prototype.updateFragmentsOnChanges=function(t,s,e){var i=t.data.wishlistFragmentsHandler;i.updateFragments(e);if(!s&&!r){i.refreshFragments(t,true)}};t.prototype.updateFragmentsFromStorage=function(){if(!r){return}var t=sessionStorage.getItem(o);if(!t){return}var s=JSON.parse(sessionStorage.getItem("wcboost_wishlist_fragments_"+t));if(s!==null){this.updateFragments(s)}else{this.refreshFragments()}};t.prototype.updateStorage=function(t,s,e){if(!r){return}var i=s.wishlist_hash?s.wishlist_hash:"";sessionStorage.setItem(o,i);if(!e||!e.preventStorageUpdate){localStorage.setItem("wcboost_wishlist_updated",(new Date).getTime())}if(i!==""){if(s.wishlist_items){sessionStorage.setItem("wcboost_wishlist_"+i,JSON.stringify(s.wishlist_items))}if(s.fragments){sessionStorage.setItem("wcboost_wishlist_fragments_"+i,JSON.stringify(s.fragments))}a(document.body).trigger("wishlist_storage_updated")}};t.prototype.updateFragments=function(t){a.each(t,function(t,s){a(t).replaceWith(s)});a(document.body).trigger("wishlist_fragments_loaded")};t.prototype.updateButtons=function(t){if(!r){return}var s=sessionStorage.getItem(o);if(!s){return}var e=JSON.parse(sessionStorage.getItem("wcboost_wishlist_"+s));if(e===null){return}var i=t?t.data.wishlistFragmentsHandler:this;a(".wcboost-wishlist-button").each(function(){var t=this.dataset.product_id,s=e[t]?e[t]:null;i.updateButtonStatus(this,s);if(this.dataset.variations){i.updateButtonVariations(this,e)}})};t.prototype.updateButtonStatus=function(t,s){var e=a(t);if(!e.length){return}if(s){if(e.hasClass("added")){return}e.removeClass("loading").addClass("added");switch(wcboost_wishlist_params.exists_item_behavior){case"view_wishlist":e.attr("href",s.wishlist_url?s.wishlist_url:wcboost_wishlist_params.wishlist_url);e.find(".wcboost-wishlist-button__text").text(wcboost_wishlist_params.i18n_view_wishlist);e.find(".wcboost-wishlist-button__icon").html(wcboost_wishlist_params.icon_filled);break;case"remove":e.attr("href",s.remove_url);e.find(".wcboost-wishlist-button__text").text(wcboost_wishlist_params.i18n_remove_from_wishlist);e.find(".wcboost-wishlist-button__icon").html(wcboost_wishlist_params.icon_filled);break;case"hide":e.hide();break}}else{if(!e.hasClass("added")&&!e.hasClass("loading")){return}e.removeClass("added loading");e.attr("href","?add-to-wishlist="+e.data("product_id"));e.find(".wcboost-wishlist-button__text").text(wcboost_wishlist_params.i18n_add_to_wishlist);e.find(".wcboost-wishlist-button__icon").html(wcboost_wishlist_params.icon_normal)}};t.prototype.updateButtonVariations=function(t,s){var e=a(t);if(!e.length||!e.data("variations")){return}var i=e.data("variations");for(var r in i){i[r]=a.extend({},i[r],{added:s[i[r].variation_id]===undefined?"no":"yes"})}e.data("variations",i)};new t});
     1jQuery(function(o){if(typeof wcboost_wishlist_fragments_params==="undefined"){return false}var n=true,d=wcboost_wishlist_fragments_params.hash_name;try{n="sessionStorage"in window&&window.sessionStorage!==null;window.sessionStorage.setItem("wcboost","test");window.sessionStorage.removeItem("wcboost");window.localStorage.setItem("wcboost","test");window.localStorage.removeItem("wcboost")}catch(t){n=false}var t=function(){var t=this;this.updateFragments=this.updateFragments.bind(this);this.getProductIds=this.getProductIds.bind(this);o(document.body).on("wishlist_fragments_refresh wishlist_updated",{wishlistFragmentsHandler:this},this.refreshFragments).on("wishlist_fragments_refreshed wishlist_item_added wishlist_item_removed",{wishlistFragmentsHandler:this},this.updateStorage).on("added_to_wishlist removed_from_wishlist",{wishlistFragmentsHandler:this},this.updateFragmentsOnChanges).on("wishlist_storage_updated",{wishlistFragmentsHandler:this},this.updateButtons);o(window).on("storage onstorage",function(t){if(d===t.originalEvent.key&&localStorage.getItem(d)!==sessionStorage.getItem(d)){o(document.body).trigger("wishlist_fragments_refresh")}});if("yes"===wcboost_wishlist_fragments_params.refresh_on_load){o(document.body).trigger("wishlist_fragments_refresh")}else{o(window).on("pageshow",function(t){if(t.originalEvent.persisted){o(document.body).trigger("wishlist_fragments_refresh",[true])}});try{var s=sessionStorage.getItem(d),e=Cookies.get("wcboost_wishlist_hash");if(s!==null&&s===e){this.updateFragmentsFromStorage();this.updateButtons()}else{throw"No wishlist fragment"}}catch(t){this.refreshFragments()}}var i="undefined"!==typeof wp&&wp.customize&&wp.customize.selectiveRefresh&&wp.customize.widgetsPreview&&wp.customize.widgetsPreview.WidgetPartial;if(i){wp.customize.selectiveRefresh.bind("partial-content-rendered",function(){t.refreshFragments()})}};t.prototype.refreshFragments=function(t,s,e){var i=t?t.data.wishlistFragmentsHandler:this;var r={time:(new Date).getTime()};if("yes"===wcboost_wishlist_fragments_params.refresh_on_load||s){r.product_ids=i.getProductIds()}o.post({url:woocommerce_params.wc_ajax_url.toString().replace("%%endpoint%%","get_wishlist_fragments"),data:r,dataType:"json",timeout:wcboost_wishlist_fragments_params.request_timeout,success:function(t){if(!t.success){o(document.body).trigger("wishlist_fragments_failed");return}i.updateFragments(t.data.fragments);o(document.body).trigger("wishlist_fragments_refreshed",[t.data,e])},error:function(){o(document.body).trigger("wishlish_fragments_ajax_error")}})};t.prototype.getProductIds=function(){var e=[];o(".wcboost-wishlist-button").each(function(t,s){e.push(s.dataset.product_id)});return e};t.prototype.updateFragmentsOnChanges=function(t,s,e){var i=t.data.wishlistFragmentsHandler;i.updateFragments(e);if(!s&&!n){i.refreshFragments(t,true)}};t.prototype.updateFragmentsFromStorage=function(){if(!n){return}var t=sessionStorage.getItem(d);if(!t){return}var s=t.split("::"),e=s[0];if(e){var i=JSON.parse(sessionStorage.getItem("wcboost_wishlist_fragments_"+e));if(i!==null){this.updateFragments(i)}}else{this.refreshFragments()}};t.prototype.updateStorage=function(t,s,e){if(!n){return}var i=s.wishlist_hash?s.wishlist_hash:"";sessionStorage.setItem(d,i);localStorage.setItem(d,i);if(i){var r=i.split("::"),a=r[0];if(s.wishlist_items){sessionStorage.setItem("wcboost_wishlist_"+a,JSON.stringify(s.wishlist_items))}if(s.fragments){sessionStorage.setItem("wcboost_wishlist_fragments_"+a,JSON.stringify(s.fragments))}o(document.body).trigger("wishlist_storage_updated")}};t.prototype.updateFragments=function(t){o.each(t,function(t,s){o(t).replaceWith(s)});o(document.body).trigger("wishlist_fragments_loaded")};t.prototype.updateButtons=function(t){if(!n){return}var s=sessionStorage.getItem(d);if(!s){return}var e=s.split("::"),i=e[0];if(!i){return}var r=JSON.parse(sessionStorage.getItem("wcboost_wishlist_"+i));if(r===null){return}var a=t?t.data.wishlistFragmentsHandler:this;o(".wcboost-wishlist-button").each(function(){var t=this.dataset.product_id,s=r[t]?r[t]:null;a.updateButtonStatus(this,s);if(this.dataset.variations){a.updateButtonVariations(this,r)}})};t.prototype.updateButtonStatus=function(t,s){var e=o(t);if(!e.length){return}if(s){if(e.hasClass("added")){return}e.removeClass("loading").addClass("added");switch(wcboost_wishlist_params.exists_item_behavior){case"view_wishlist":e.attr("href",s.wishlist_url?s.wishlist_url:wcboost_wishlist_params.wishlist_url);e.find(".wcboost-wishlist-button__text").text(wcboost_wishlist_params.i18n_view_wishlist);e.find(".wcboost-wishlist-button__icon").html(wcboost_wishlist_params.icon_filled);break;case"remove":e.attr("href",s.remove_url);e.find(".wcboost-wishlist-button__text").text(wcboost_wishlist_params.i18n_remove_from_wishlist);e.find(".wcboost-wishlist-button__icon").html(wcboost_wishlist_params.icon_filled);break;case"hide":e.hide();break}}else{if(!e.hasClass("added")&&!e.hasClass("loading")){return}e.removeClass("added loading");e.attr("href","?add-to-wishlist="+e.data("product_id"));e.find(".wcboost-wishlist-button__text").text(wcboost_wishlist_params.i18n_add_to_wishlist);e.find(".wcboost-wishlist-button__icon").html(wcboost_wishlist_params.icon_normal)}};t.prototype.updateButtonVariations=function(t,s){var e=o(t);if(!e.length||!e.data("variations")){return}var i=e.data("variations");for(var r in i){i[r]=o.extend({},i[r],{added:s[i[r].variation_id]===undefined?"no":"yes"})}e.data("variations",i)};new t});
  • wcboost-wishlist/trunk/includes/ajax-handler.php

    r3113521 r3122355  
    7272            wp_send_json_success( [
    7373                'fragments'      => self::get_refreshed_fragments(),
    74                 'wishlist_hash'  => $wishlist->get_id() ? md5( get_current_blog_id() . '_' . $wishlist->get_id() . '_' . $wishlist->get_wishlist_token() ) : '',
     74                'wishlist_hash'  => $wishlist->get_hash(),
    7575                'wishlist_url'   => $wishlist->get_public_url(),
    7676                'wishlist_items' => self::get_wishlist_items( $wishlist_id ),
     
    9797            wp_send_json_success( [
    9898                'fragments'      => self::get_refreshed_fragments(),
    99                 'wishlist_hash'  => $wishlist->get_id() ? md5( get_current_blog_id() . '_' . $wishlist->get_id() . '_' . $wishlist->get_wishlist_token() ) : '',
     99                'wishlist_hash'  => $wishlist->get_hash(),
    100100                'wishlist_url'   => $wishlist->get_public_url(),
    101101                'wishlist_items' => self::get_wishlist_items( $wishlist_id ),
     
    133133        wp_send_json_success( [
    134134            'fragments'      => $fragments,
    135             'wishlist_hash'  => $wishlist->get_id() ? md5( get_current_blog_id() . '_' . $wishlist->get_id() . '_' . $wishlist->get_wishlist_token() ) : '',
     135            'wishlist_hash'  => $wishlist->get_hash(),
    136136            'wishlist_items' => self::get_wishlist_items(),
    137137        ] );
  • wcboost-wishlist/trunk/includes/data-stores/wishlist.php

    r2999816 r3122355  
    1111
    1212    /**
     13     * Is reading data from the database.
     14     *
     15     * @var bool
     16     */
     17    private $is_reading = false;
     18
     19    /**
    1320     * Method to create a new wishlist in the database
    1421     *
     
    1724     * @global wpdb $wpdb
    1825     * @param \WCBoost\Wishlist\Wishlist $wishlist
    19      * @todo Generate slug, token
    2026     */
    2127    public function create( &$wishlist ) {
     
    205211        }
    206212
     213        $this->set_is_reading( true );
     214
    207215        if ( false === $data ) {
    208216            if ( $id ) {
     
    240248        $wishlist->set_id( $data->wishlist_id );
    241249        $wishlist->set_object_read();
     250        $this->set_is_reading( false );
    242251    }
    243252
     
    256265            throw new \Exception( __( 'Invalid wishlist.', 'wcboost-wishlist' ) );
    257266        }
     267
     268        $this->set_is_reading( true );
    258269
    259270        $items = wp_cache_get( 'wcboost-wishlist-items-' . $wishlist_id, 'wishlists' );
     
    273284                $wishlist->add_item_to_trash( $item );
    274285            } else {
    275                 $wishlist->add_item( $item );
    276             }
    277         }
     286                $wishlist->add_item( $item, [ 'silence' => true ] );
     287            }
     288        }
     289
     290        $this->set_is_reading( false );
    278291    }
    279292
     
    405418        }
    406419    }
     420
     421    /**
     422     * Set the status to determine if is reading data.
     423     * This method is called when initialization is on running.
     424     *
     425     * @since 1.1.1
     426     *
     427     * @param  bool $reading
     428     *
     429     * @return void
     430     */
     431    private function set_is_reading( $reading = false ) {
     432        $this->is_reading = wc_string_to_bool( $reading );
     433    }
     434
     435    /**
     436     * Get the reading_db status
     437     *
     438     * @since 1.1.1
     439     *
     440     * @return bool
     441     */
     442    public function is_reading() {
     443        return $this->is_reading;
     444    }
    407445}
  • wcboost-wishlist/trunk/includes/frontend.php

    r3113521 r3122355  
    1919        add_action( 'init', [ $this, 'register_scripts' ] );
    2020        add_action( 'wp_enqueue_scripts', [ $this, 'enqueue_scripts' ] );
     21
     22        // Cookie events.
     23        add_action( 'wcboost_wishlist_add_item', [ $this, 'maybe_set_cookies' ] );
     24        add_action( 'wcboost_wishlist_removed_item', [ $this, 'maybe_set_cookies' ] );
     25        add_action( 'wp', [ $this, 'maybe_set_cookies' ], 99 );
     26        add_action( 'shutdown', [ $this, 'maybe_set_cookies' ], 0 );
    2127    }
    2228
     
    645651        );
    646652    }
     653
     654    /**
     655     * Will set cookies if needed and when possible.
     656     *
     657     * @since 1.1.1
     658     *
     659     * @return void
     660     */
     661    public function maybe_set_cookies() {
     662        if ( headers_sent() || ! did_action( 'wp_loaded' ) ) {
     663            return;
     664        }
     665
     666        $wishlist = Helper::get_wishlist();
     667
     668        if ( ! $wishlist->is_empty() ) {
     669            $this->set_cookies( true );
     670        } else {
     671            $this->set_cookies( false );
     672        }
     673    }
     674
     675    /**
     676     * Set the comparison cookie
     677     *
     678     * @since 1.1.1
     679     *
     680     * @param  bool $set Should the cookie be set or unset.
     681     *
     682     * @return void
     683     */
     684    private function set_cookies( $set = true )  {
     685        $wishlist = Helper::get_wishlist();
     686
     687        if ( $set ) {
     688            wc_setcookie( 'wcboost_wishlist_hash', $wishlist->get_hash() );
     689        } else {
     690            wc_setcookie( 'wcboost_wishlist_hash', '', time() - HOUR_IN_SECONDS );
     691            unset( $_COOKIE['wcboost_wishlist_hash'] );
     692        }
     693    }
    647694}
  • wcboost-wishlist/trunk/includes/wishlist.php

    r3113521 r3122355  
    426426     *
    427427     * @param Wishlist_Item $item Item to be added
    428      * @param bool $save_to_db    Save new item to database
     428     *
    429429     * @return bool|WP_Error Returns TRUE on success, FALSE on failure. WP_Error on invalid.
    430430     */
     
    469469        }
    470470
    471         do_action( 'wcboost_wishlist_add_item', $item );
     471        if ( ! $this->data_store->is_reading() ) {
     472            do_action( 'wcboost_wishlist_add_item', $item );
     473        }
    472474
    473475        return true;
     
    726728        return apply_filters( 'wcboost_wishlist_edit_url', $url, $this );
    727729    }
     730
     731    /**
     732     * Get unique hash key for the wishlist
     733     *
     734     * @since 1.1.1
     735     *
     736     * @return string
     737     */
     738    public function get_hash_key() {
     739        $hash_key = '';
     740
     741        if ( $this->get_id() ) {
     742            $hash_key = md5( get_current_blog_id() . '_' . $this->get_id() . '_' . $this->get_wishlist_token() );
     743        }
     744
     745        return $hash_key;
     746    }
     747
     748    /**
     749     * Get hash content for the wishlist
     750     *
     751     * @since 1.1.1
     752     *
     753     * @return string
     754     */
     755    public function get_hash_content() {
     756        $hash = $this->get_id() ? md5( $this->get_id() . wp_json_encode( $this->get_items() ) . $this->count_items() ) : '';
     757
     758        return apply_filters( 'wcboost_wishlist_hash', $hash, $this );
     759    }
     760
     761    /**
     762     * Get hash for the wishlist.
     763     * Generated by combining the hash_key and hash_content.
     764     *
     765     * @since 1.1.1
     766     *
     767     * @return string Wishlist hash in format HASH_KEY::HASH_CONTENTS
     768     */
     769    public function get_hash() {
     770        return $this->get_hash_key() . '::' . $this->get_hash_content();
     771    }
    728772}
  • wcboost-wishlist/trunk/languages/wcboost-wishlist.pot

    r3113521 r3122355  
    1010"Content-Type: text/plain; charset=UTF-8\n"
    1111"Content-Transfer-Encoding: 8bit\n"
    12 "POT-Creation-Date: 2024-07-06T11:55:38+00:00\n"
     12"POT-Creation-Date: 2024-07-20T04:44:31+00:00\n"
    1313"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
    1414"X-Generator: WP-CLI 2.9.0\n"
     
    151151#: includes/customizer/customizer.php:326
    152152#: includes/form-handler.php:96
    153 #: includes/frontend.php:644
     153#: includes/frontend.php:650
    154154#: includes/helper.php:213
    155155msgid "View wishlist"
     
    246246
    247247#: includes/admin/settings.php:192
    248 #: includes/data-stores/wishlist.php:26
     248#: includes/data-stores/wishlist.php:32
    249249msgid "My Wishlist"
    250250msgstr ""
     
    361361
    362362#: includes/admin/settings.php:380
    363 #: includes/frontend.php:357
     363#: includes/frontend.php:363
    364364msgid "Edit wishlist"
    365365msgstr ""
     
    503503msgstr ""
    504504
    505 #: includes/data-stores/wishlist.php:197
    506 #: includes/data-stores/wishlist.php:215
    507 #: includes/data-stores/wishlist.php:256
     505#: includes/data-stores/wishlist.php:203
     506#: includes/data-stores/wishlist.php:223
     507#: includes/data-stores/wishlist.php:265
    508508msgid "Invalid wishlist."
    509509msgstr ""
     
    565565msgstr ""
    566566
    567 #: includes/frontend.php:137
     567#: includes/frontend.php:143
    568568msgid "The wishlist link is copied to clipboard"
    569569msgstr ""
    570570
    571 #: includes/frontend.php:138
     571#: includes/frontend.php:144
    572572msgid "Close"
    573573msgstr ""
    574574
    575 #: includes/frontend.php:335
     575#: includes/frontend.php:341
    576576msgid "Share"
    577577msgstr ""
    578578
    579 #: includes/frontend.php:393
     579#: includes/frontend.php:399
    580580msgid "You cannot delete your default wishlist. You have to set another list as default to delete this one."
    581581msgstr ""
    582582
    583 #: includes/frontend.php:395
     583#: includes/frontend.php:401
    584584msgid "This action moves the wishlist to Trash. It will be kept in Trash for 30 days."
    585585msgstr ""
    586586
    587 #: includes/frontend.php:399
     587#: includes/frontend.php:405
    588588msgid "Delete this wishlist"
    589589msgstr ""
    590590
    591591#. translators: %s product name
    592 #: includes/frontend.php:504
     592#: includes/frontend.php:510
    593593msgid "Add %s to the wishlist"
    594594msgstr ""
    595595
    596596#. translators: %s product name
    597 #: includes/frontend.php:540
     597#: includes/frontend.php:546
    598598msgid "Remove %s from the wishlist"
    599599msgstr ""
    600600
    601 #: includes/frontend.php:546
     601#: includes/frontend.php:552
    602602msgid "Open the wishlist"
    603603msgstr ""
     
    672672msgstr ""
    673673
    674 #: includes/wishlist.php:484
    675 #: includes/wishlist.php:515
     674#: includes/wishlist.php:486
     675#: includes/wishlist.php:517
    676676msgid "You are not allowed to edit the wishlist"
    677677msgstr ""
    678678
    679 #: includes/wishlist.php:488
    680 #: includes/wishlist.php:521
     679#: includes/wishlist.php:490
     680#: includes/wishlist.php:523
    681681msgid "Invalid wishlist item"
    682682msgstr ""
  • wcboost-wishlist/trunk/readme.txt

    r3120847 r3122355  
    33Tags: woocommerce wishlist, wishlist, products, e-commerce, woocommerce
    44Tested up to: 6.6
    5 Stable tag: 1.1.0
     5Stable tag: 1.1.1
    66Requires PHP: 7.0
    77Requires at least: 4.5
    88WC requires at least: 3.0.0
    9 WC tested up to: 9.0
     9WC tested up to: 9.1
    1010License: GPLv3
    1111License URI: https://www.gnu.org/licenses/gpl-3.0.html
     
    9595== Changelog ==
    9696
    97 = 1.1.0
     97= 1.1.1 =
     98- Tweak - Improve caching to dynamically update wishlist fragments.
     99- Tweak - WordPress 6.6 compatibility.
     100- Tweak – WooCommerce 9.1 compatibility.
     101
     102= 1.1.0 =
    98103- Enhancement - Improve performance with the new client caching.
    99104- Fix - Fix the installation issue.
     
    101106- Tweak – WooCommerce 9.0 compatibility.
    102107
    103 = 1.0.13
     108= 1.0.13 =
    104109- Tweak - Improve themes compatibility
    105110- Fix - Fix issues that may occur when installing the plugin.
  • wcboost-wishlist/trunk/wcboost-wishlist.php

    r3113521 r3122355  
    55 * Plugin URI: https://wcboost.com/plugin/woocommerce-wishlist/?utm_source=wp-plugins&utm_campaign=plugin-uri&utm_medium=wp-dash
    66 * Author: WCBoost
    7  * Version: 1.1.0
     7 * Version: 1.1.1
    88 * Author URI: https://wcboost.com/?utm_source=wp-plugins&utm_campaign=author-uri&utm_medium=wp-dash
    99 *
     
    1313 * Requires PHP: 7.0
    1414 * Requires at least: 4.5
    15  * Tested up to: 6.5
     15 * Tested up to: 6.6
    1616 * WC requires at least: 3.0.0
    17  * WC tested up to: 9.0
     17 * WC tested up to: 9.1
    1818 *
    1919 * @package WCBoost
Note: See TracChangeset for help on using the changeset viewer.