Skip to content
This repository was archived by the owner on Jul 19, 2021. It is now read-only.

Use data attr selectors instead of class selectors #98

Merged
merged 3 commits into from
Feb 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions src/scripts/sections/product.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
theme.Product = (function() {

var selectors = {
addToCart: '.add-to-cart',
addToCartText: '.add-to-cart-text',
comparePrice: '.compare-price',
originalSelectorId: '.product-select',
priceWrapper: '.price-wrapper',
productFeaturedImage: '.product-image',
productJson: '.product-json',
productPrice: '.product-price',
productThumbs: '.product-single-thumbnail',
singleOptionSelector: '.single-option-selector'
addToCart: '[data-add-to-cart]',
addToCartText: '[data-add-to-cart-text]',
comparePrice: '[data-compare-price]',
originalSelectorId: '[data-product-select]',
priceWrapper: '[data-price-wrapper]',
productFeaturedImage: '[data-product-featured-image]',
productJson: '[data-product-json]',
productPrice: '[data-product-price]',
productThumbs: '[data-product-single-thumbnail]',
singleOptionSelector: '[data-single-option-selector]'
};

/**
Expand Down
20 changes: 10 additions & 10 deletions src/sections/featured-product.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<meta itemprop="description" content="{{ product.description | strip_html | escape }}">

{% if product.featured_image.src != blank %}
{{ product.featured_image.src | img_url: '480x480' | img_tag: product.featured_image.src.alt, 'product-image' }}
<img src="{{ product.featured_image.src | img_url: '480x480' }}" alt="{{ featured_image.alt | escape }}" data-product-featured-image>
{% else %}
{{ 'product-1' | placeholder_svg_tag: 'placeholder-svg placeholder-svg--small' }}
{% endif %}
Expand All @@ -21,7 +21,7 @@
<ul>
{% for image in product.images %}
<li>
<a href="{{ image.src | img_url: '480x480' }}" class="product-single-thumbnail">
<a href="{{ image.src | img_url: '480x480' }}" data-product-single-thumbnail>
<img src="{{ image.src | img_url: '160x160' }}" alt="{{ image.alt | escape }}">
</a>
</li>
Expand Down Expand Up @@ -50,8 +50,8 @@
</label>

<select
class="single-option-selector"
id="SingleOptionSelector-{{ section.id }}-{{ forloop.index0 }}"
data-single-option-selector
data-index="option{{ forloop.index }}">
{% for value in option.values %}
<option
Expand All @@ -65,7 +65,7 @@
{% endfor %}
{% endunless %}

<select class="no-js product-select" name="id">
<select name="id" class="no-js" data-product-select>
{% for variant in product.variants %}
<option
{% if variant == product.selected_or_first_available_variant %}selected="selected"{% endif %}
Expand All @@ -79,14 +79,14 @@
<label for="Quantity-{{ section.id }}">{{ 'products.product.quantity' | t }}</label>
<input type="number" id="Quantity-{{ section.id }}" name="quantity" value="1" min="1">

<div class="price-wrapper">
<span class="product-price">
<div data-price-wrapper>
<span data-product-price>
{{ product.price | default: '1999' | money }}
</span>

{% if product.compare_at_price_max > product.price %}
<span class="visually-hidden">{{ 'products.product.regular_price' | t }}</span>
<s class="compare-price">
<s data-compare-price>
{{ product.compare_at_price | money }}
</s>
{% endif %}
Expand All @@ -95,10 +95,10 @@
<button
type="submit"
name="add"
class="add-to-cart"
data-add-to-cart
{% unless product.available %}disabled="disabled"{% endunless %}
{% if section_onboarding %}disabled="disabled"{% endif %}>
<span class="add-to-cart-text">
<span data-add-to-cart-text>
{% if product.available %}
{{ 'products.product.add_to_cart' | t }}
{% else %}
Expand All @@ -119,7 +119,7 @@
{% endif %}

{% unless product.empty? %}
<script type="application/json" class="product-json">
<script type="application/json" data-product-json>
{{ product | json }}
</script>
{% endunless %}
Expand Down
20 changes: 10 additions & 10 deletions src/sections/product.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
<meta itemprop="image" content="{{ featured_image | img_url: '600x600' }}">
<meta itemprop="description" content="{{ product.description | strip_html | escape }}">

<img src="{{ featured_image | img_url: '480x480' }}" alt="{{ featured_image.alt | escape }}" class="product-image">
<img src="{{ featured_image | img_url: '480x480' }}" alt="{{ featured_image.alt | escape }}" data-product-featured-image>
{% if product.images.size > 1 %}
<ul>
{% for image in product.images %}
<li>
<a href="{{ image.src | img_url: '480x480' }}" class="product-single-thumbnail">
<a href="{{ image.src | img_url: '480x480' }}" data-product-single-thumbnail>
<img src="{{ image.src | img_url: '160x160' }}" alt="{{ image.alt | escape }}">
</a>
</li>
Expand Down Expand Up @@ -42,8 +42,8 @@
</label>

<select
class="single-option-selector"
id="SingleOptionSelector-{{ forloop.index0 }}"
data-single-option-selector
data-index="option{{ forloop.index }}">
{% for value in option.values %}
<option
Expand All @@ -57,7 +57,7 @@
{% endfor %}
{% endunless %}

<select class="no-js product-select" name="id">
<select name="id" class="no-js" data-product-select>
{% for variant in product.variants %}
<option
{% if variant == current_variant %}selected="selected"{% endif %}
Expand All @@ -71,14 +71,14 @@
<label for="Quantity">{{ 'products.product.quantity' | t }}</label>
<input type="number" id="Quantity" name="quantity" value="1" min="1">

<div class="price-wrapper">
<span class="product-price">
<div data-price-wrapper>
<span data-product-price>
{{ current_variant.price | money }}
</span>

{% if current_variant.compare_at_price_max > current_variant.price %}
<span class="visually-hidden">{{ 'products.product.regular_price' | t }}</span>
<s class="compare-price">
<s data-compare-price>
{{ current_variant.compare_at_price | money }}
</s>
{% endif %}
Expand All @@ -87,9 +87,9 @@
<button
type="submit"
name="add"
class="add-to-cart"
data-add-to-cart
{% unless current_variant.available %}disabled="disabled"{% endunless %}>
<span class="add-to-cart-text">
<span data-add-to-cart-text>
{% if current_variant.available %}
{{ 'products.product.add_to_cart' | t }}
{% else %}
Expand All @@ -110,7 +110,7 @@
{% endif %}

{% unless product.empty? %}
<script type="application/json" class="product-json">
<script type="application/json" data-product-json>
{{ product | json }}
</script>
{% endunless %}
Expand Down