Advertisement
Guest User

Untitled

a guest
Jun 2nd, 2015
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.45 KB | None | 0 0
  1. function Product(form, options) {
  2. this.form = $(form);
  3. this.add2cart = this.form.find(".add2cart");
  4. this.button = this.add2cart.find("input[type=submit]");
  5. for (var k in options) {
  6. this[k] = options[k];
  7. }
  8. var self = this;
  9.  
  10.  
  11.  
  12.  
  13. this.form.find('.inline-select a').click(function () {
  14. console.log("111111111");
  15.  
  16.  
  17. });
  18.  
  19.  
  20.  
  21. this.form.find(".sku-feature").change(function () {
  22. var key = "";
  23. self.form.find(".sku-feature").each(function () {
  24. key += $(this).data('feature-id') + ':' + $(this).val() + ';';
  25. });
  26. var sku = self.features[key];
  27. console.log(sku);
  28. if (sku) {
  29. if (sku.image_id) {
  30. $("#product-image-" + sku.image_id).click();
  31. }
  32. self.updateSkuServices(sku.id);
  33. if (sku.available) {
  34. self.button.removeAttr('disabled');
  35. } else {
  36. self.form.find("div.stocks div").hide();
  37. self.form.find(".sku-no-stock").show();
  38. self.button.attr('disabled', 'disabled');
  39. }
  40. self.add2cart.find(".price").data('price', sku.price);
  41. self.updatePrice(sku.price, sku.compare_price);
  42. } else {
  43. self.form.find("div.stocks div").hide();
  44. self.form.find(".sku-no-stock").show();
  45. self.button.attr('disabled', 'disabled');
  46. self.add2cart.find(".compare-at-price").hide();
  47. self.add2cart.find(".price").empty();
  48. }
  49. self.cartButtonVisibility(true);
  50. });
  51. this.form.find(".sku-feature:first").change();
  52.  
  53.  
  54.  
  55.  
  56. }
  57.  
  58. Product.prototype.currencyFormat = function (number, no_html) {
  59.  
  60. };
  61.  
  62.  
  63. Product.prototype.serviceVariantHtml= function (id, name, price) {
  64. return $('<option data-price="' + price + '" value="' + id + '"></option>').text(name + ' (+' + this.currencyFormat(price, 1) + ')');
  65. };
  66.  
  67. Product.prototype.updateSkuServices = function (sku_id) {
  68.  
  69. };
  70. Product.prototype.updatePrice = function (price, compare_price) {
  71.  
  72. }
  73.  
  74. Product.prototype.cartButtonVisibility = function (visible) {
  75. //toggles "Add to cart" / "%s is now in your shopping cart" visibility status
  76.  
  77. }
  78.  
  79. $(function () {
  80.  
  81.  
  82. // product images
  83. $("#product-gallery a").click(function () {
  84. $('.product-gallery .image').removeClass('selected');
  85. $(this).parent().addClass('selected');
  86.  
  87. $("#product-image").addClass('blurred');
  88. $("#switching-image").show();
  89.  
  90. var img = $(this).find('img');
  91. var size = $("#product-image").attr('src').replace(/^.*\/[0-9]+\.(.*)\..*$/, '$1');
  92. var src = img.attr('src').replace(/^(.*\/[0-9]+\.)(.*)(\..*)$/, '$1' + size + '$3');
  93. $('<img>').attr('src', src).load(function () {
  94. $("#product-image").attr('src', src);
  95. $("#product-image").removeClass('blurred');
  96. $("#switching-image").hide();
  97. }).each(function() {
  98. //ensure image load is fired. Fixes opera loading bug
  99. if (this.complete) { $(this).trigger("load"); }
  100. });
  101. var size = $("#product-image").parent().attr('href').replace(/^.*\/[0-9]+\.(.*)\..*$/, '$1');
  102. var href = img.attr('src').replace(/^(.*\/[0-9]+\.)(.*)(\..*)$/, '$1' + size + '$3');
  103. $("#product-image").parent().attr('href', href);
  104. return false;
  105. });
  106.  
  107. // compare block
  108.  
  109. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement