{"version":3,"file":"product.view.min.js","sources":["product.view.min.js"],"sourcesContent":["! function ($) {\n \"use strict\";\n\n $(\".product_category_button_group button\").on(\"click\", function () {\n var $this = $(this);\n $this.closest(\".product_category_button_group\").find(\"button\").removeClass(\"active\");\n $this.addClass(\"active\");\n\n // Image\n var imageIndex = parseInt($this.data(\"image-index\"));\n if (!isNaN(imageIndex)) {\n $(\".slider-for\").slick(\"slickGoTo\", imageIndex, true);\n $(\".product_image_small\")\n .removeClass(\"active\")\n .eq(imageIndex)\n .addClass('active');\n }\n\n var key = $(\".product_category_button_group button.active\")\n .map(function () { return $(this).data(\"key\"); })\n .toArray()\n .join(\"-\");\n\n if (window.products.hasOwnProperty(key)) {\n var product = window.products[key];\n\n $(\".price font\").html(`市售價:${product.oldPrice}元`)\n if (product.specialPrice) {\n $(\".price\").find(\"font\").css({ color: \"#999\" })\n $(\".price span\").show().find(\"b\").html(product.specialPrice)\n } else {\n $(\".price\").find(\"font\").css({ color: \"#333\" })\n $(\".price span\").hide()\n }\n if (product.availableAmount === 0) {\n $(\".quantity_area, .product_buy_button\").addClass(\"sold_out\")\n } else {\n $(\".quantity_area, .product_buy_button\").removeClass(\"sold_out\")\n }\n $('#inputCartAmount')\n .attr(\"max\", product.availableAmount)\n .val(1);\n }\n });\n\n $(document).ready(function () {\n var $buttons = $(\".product_detail .product_category_button_group button\");\n if ($buttons.length == 1) {\n $buttons.trigger(\"click\");\n }\n });\n\n $(\".product_addon select\").on(\"change\", function () {\n var $this = $(this);\n var $checkbox = $this.parent().find(\"input[type=checkbox]\");\n if ($this.val() == 0) {\n $checkbox.prop(\"checked\", false);\n } else {\n $checkbox.prop(\"checked\", true);\n }\n });\n\n $(\".product_addon .product_h\").on(\"click\", function (e) {\n e.preventDefault();\n if ($(e.target).is(\"select\")) {\n return;\n }\n\n var $select = $(this).find(\"select\");\n if ($select.length == 0) {\n return;\n }\n if ($select.val() == 0) {\n $select.val(1).change();\n } else {\n $select.val(0).change();\n }\n });\n\n\n // 倒數\n if (window.countdownEndTime != null) {\n layoutJS.counterDate(new Date(window.countdownEndTime));\n }\n\n if (!location.pathname.toLowerCase().endsWith(\"priview\")) {\n\n $(\".product_buy_button\").on(\"click\", function () {\n var $this = $(this);\n if ($this.hasClass(\"sold_out\")) {\n return;\n }\n\n var key = $(\".product_category_button_group button.active\")\n .map(function () { return $(this).data(\"key\"); })\n .toArray()\n .join(\"-\");\n\n if (!window.products.hasOwnProperty(key)) {\n alert(\"請選擇規格\");\n return;\n }\n\n var product = window.products[key];\n var amount = $(\"#inputCartAmount\").val();\n\n if (amount == 0) {\n return;\n }\n\n var addonProductIds = {};\n $(\".product_addon .product_h select\").each(function () {\n var $this = $(this);\n if ($this.val() > 0) {\n addonProductIds[$this.data(\"product-id\")] = $this.val()\n }\n });\n\n $.ajax({\n type: \"POST\",\n url: \"/order/cart?handler=add\",\n data: {\n \"input.productId\": product.id,\n \"input.amount\": amount,\n \"input.addonProductIds\": addonProductIds\n },\n dataType: \"json\",\n beforeSend: function () {\n $(\".product_buy_button\").prop(\"disabled\", true);\n },\n complete: function () {\n $(\".product_buy_button\").prop(\"disabled\", false);\n },\n success: function (response) {\n if (response.error !== undefined) {\n var $alert = $(`