Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<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
You can’t perform that action at this time.