Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eduardonunesp/50fbab3950436b68c916 to your computer and use it in GitHub Desktop.
Save eduardonunesp/50fbab3950436b68c916 to your computer and use it in GitHub Desktop.
<script type="text/javascript>
function fisherYates ( myArray ) {
var i = myArray.length, j, temp;
if ( i === 0 ) return false;
while ( --i ) {
j = Math.floor( Math.random() * ( i + 1 ) );
temp = myArray[i];
myArray[i] = myArray[j];
myArray[j] = temp;
}
}
var collection = new Array();
collection[0]="<a href='{{ collection.products.first.url | within: collection }}'><img src='{{ collection.products.first.featured_image | product_img_url: 'large' }}' alt='{{ collection.products.first.title | escape }}' />{{ product.title }}<br />{% if collection.products.first.compare_at_price_min > 0 %}<span class='strike'>{{ collection.products.first.price | money }}</span> &nbsp; <span class='red'>{{ collection.products.first.compare_at_price_min | money }}</span>{% else %}{{ collection.products.first.price | money }}{% endif %}</a>"
{% for product in collection.products offset:1 %}
collection[{{ forloop.index }}]="<a href='{{ product.url | within: collection }}'><img src='{{ product.featured_image | product_img_url: 'large' }}' alt='{{ product.title | escape }}' />{{ product.title }}<br />{% if product.compare_at_price_min > 0 %}<span class='strike'>{{ product.price | money }}</span> &nbsp; <span class='red'>{{ product.compare_at_price_min | money }}</span>{% else %}{{ product.price | money }}{% endif %}</a>";
{% endfor %}
fisherYates(collection);
for(var i=0;i<collection.length;i++) {
document.write(collection[i]);
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment