Skip to content

Instantly share code, notes, and snippets.

View clickdees's full-sized avatar

Joey Olaopa clickdees

View GitHub Profile
@clickdees
clickdees / README.md
Created March 14, 2019 22:26 — forked from joyrexus/README.md
Vanilla JS equivalents of jQuery methods

Sans jQuery

Events

// jQuery
$(document).ready(function() {
  // code
})
/* Sample JavaScript file added with ScriptTag resource.
This sample file is meant to teach best practices.
Your app will load jQuery if it's not defined.
Your app will load jQuery if jQuery is defined but is too old, e.g. < 1.7.
Your app does not change the definition of $ or jQuery outside the app.
Example: if a Shopify theme uses jQuery 1.4.2, both of these statements run in the console will still return '1.4.2'
once the app is installed, even if the app uses jQuery 1.9.1:
jQuery.fn.jquery => "1.4.2"
$.fn.jquery -> "1.4.2"
*/
DISCOUNTS_BY_QUANTITY = {
4 => 20,
3 => 15,
2 => 10
}
discunted_count = 0
Input.cart.line_items.each do |line_item|
if line_item.variant.product.tags.include?('DiscountTag')
@clickdees
clickdees / scripts.js
Created October 9, 2018 19:55 — forked from jbutko/scripts.js
jQuery: Get index of hovered element
$(document).ready(function () {
$('.around li').hover(function () {
var index = $('.around li').index(this);
console.log(index);
}, function () { });
});
// From http://stackoverflow.com/questions/11294012/jquery-get-index-of-hovered-li
/* Sample JavaScript file added with ScriptTag resource.
This sample file is meant to teach best practices.
Your app will load jQuery if it's not defined.
Your app will load jQuery if jQuery is defined but is too old, e.g. < 1.7.
Your app does not change the definition of $ or jQuery outside the app.
Example: if a Shopify theme uses jQuery 1.4.2, both of these statements run in the console will still return '1.4.2'
once the app is installed, even if the app uses jQuery 1.9.1:
jQuery.fn.jquery => "1.4.2"
$.fn.jquery -> "1.4.2"
*/
/*
* Ensure the http protocol is always used on the myshopify.com domains.
* Uses liquid to input the correct URL.
*/
if (window.location.href.match(/https:\/\/.*.myshopify.com/) && top === self) {
window.location.href = window.location.href.replace(/https:\/\/.*.myshopify.com/, 'http://{{ shop.domain }}');
}