File: /home/lgooir/.trash/rising-bamboo/dist/js/frontend/components/swatches.js
(()=>{"use strict";function t(e){return t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},t(e)}function e(e,r){for(var a=0;a<r.length;a++){var n=r[a];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,(i=n.key,o=void 0,o=function(e,r){if("object"!==t(e)||null===e)return e;var a=e[Symbol.toPrimitive];if(void 0!==a){var n=a.call(e,r||"default");if("object"!==t(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===r?String:Number)(e)}(i,"string"),"symbol"===t(o)?o:String(o)),n)}var i,o}var r=function(){function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t);var e=this;e.init(),jQuery(document).change((function(){e.init()}))}var r,a,n;return r=t,(a=[{key:"init",value:function(){this.$form=jQuery("form.rbb-swatches.variations_form"),this.register(),this.ajaxAddToCart()}},{key:"register",value:function(){var t=this,e=t.$form.find(".rbb-swatch__term"),r=t.$form.find(".rbb-swatch__term:not(.rbb-swatch__disabled)");t.$form.find("select").each((function(){t.updateLabel(this)})),e.each((function(){var e=jQuery(this),r=e.data("term"),a=e.attr("title"),n=e.parent().data("attribute"),i=t.$form.find("select#"+n),o=i.val();""!==o&&r===o&&(jQuery(this).addClass("rbb-swatch__selected"),jQuery("body").trigger("rbb-swatch__selected_event",[n,r,a,e])),jQuery(i).on("change",(function(){jQuery(this).find("option").map((function(){if(""!==this.value)return this.value})).get().includes(r)||jQuery(this).addClass("rbb-swatch__disabled")}))})),r.off("click").on("click",(function(e){var r=jQuery(this);if(r.hasClass("rbb-swatch__disabled"))return!1;var a=r.data("term"),n=r.attr("title"),i=r.parent().data("attribute");t.$form.find("select#"+i).val(a).trigger("change"),r.parent(".rbb-swatch").find(".rbb-swatch__selected").removeClass("rbb-swatch__selected"),r.addClass("rbb-swatch__selected"),jQuery("body").trigger("rbb-swatch__selected_event",[i,a,n,r]),e.preventDefault()})),t.$form.on("woocommerce_update_variation_values",(function(){t.$form.find("select").each((function(){var e=jQuery(this),r=e.parent().find(".rbb-swatch");r.find(".rbb-swatch__term").removeClass(["rbb-swatch__enabled","cursor-pointer"]).addClass(["rbb-swatch__disabled","cursor-not-allowed"]),e.find("option.enabled").each((function(){var t=jQuery(this).val();r.find('.rbb-swatch__term[data-term="'+t+'"]').removeClass(["rbb-swatch__disabled","cursor-not-allowed"]).addClass(["rbb-swatch__enabled","cursor-pointer"])})),e.on("change",(function(){t.updateLabel(this)}))}))})),t.$form.on("reset_data",(function(){jQuery("body").trigger("rbb-swatches_reset"),jQuery(this).find(".rbb-swatch__selected").removeClass("rbb-swatch__selected"),jQuery(this).find("select").each((function(){var t=jQuery(this).attr("id"),e=jQuery(this).find("option:selected").text(),r=jQuery(this).val();""!==r&&(jQuery(this).parent().find('.rbb-swatch__term[data-term="'+r+'"]').addClass("rbb-swatch__selected"),jQuery("body").trigger("rbb-swatches_reset-attr",[t,r,e]))}))})),t.$form.on("show_variation",(function(){t.$form.find("select").each((function(){var e=jQuery(this).val(),r=jQuery(this).data("attribute_name");t.$form.find(".ajax_add_to_cart").attr("data-"+r,e).data(r,e)}))}))}},{key:"updateLabel",value:function(t){var e="";jQuery(t).val()&&(e=jQuery(t).find("option:selected").text()),jQuery(t).closest(".rbb-swatch__wrap").find(".label label .label-val").html(e)}},{key:"ajaxAddToCart",value:function(){this.updateVariationData(),jQuery(document.body).on("should_send_ajax_request.adding_to_cart",(function(t,e){return!(jQuery(e).hasClass("wc-variation-selection-needed")||jQuery(e).hasClass("disabled"))}))}},{key:"updateVariationData",value:function(){jQuery("input.variation_id").on("change",(function(){var t=jQuery(this).val(),e=jQuery(this).closest("form.cart").find(".ajax_add_to_cart");if(t.length)e.attr("data-product_id",t);else{var r=jQuery(this).closest("form.cart").find('input[name="product_id"]').val();r.length&&e.attr("data-product_id",r),jQuery.each(e.data(),(function(t){t.includes("attribute_pa")&&e.removeData(t).removeAttr("data-"+t)}))}}))}}])&&e(r.prototype,a),n&&e(r,n),Object.defineProperty(r,"prototype",{writable:!1}),t}();window.RbbSwatches=new r})();