Skip to content

Instantly share code, notes, and snippets.

@Kadreev
Created March 25, 2022 22:42
Show Gist options
  • Select an option

  • Save Kadreev/e56fc9013fcba0c7ce9beb7dee3029a3 to your computer and use it in GitHub Desktop.

Select an option

Save Kadreev/e56fc9013fcba0c7ce9beb7dee3029a3 to your computer and use it in GitHub Desktop.
GLOBAL BINDING
/*
* Shopify Common JS
*
*/
if ((typeof window.Shopify) == 'undefined') {
window.Shopify = {};
}
Shopify.bind = function(fn, scope) {
return function() {
return fn.apply(scope, arguments);
}
};
Shopify.setSelectorByValue = function(selector, value) {
for (var i = 0, count = selector.options.length; i < count; i++) {
var option = selector.options[i];
if (value == option.value || value == option.innerHTML) {
selector.selectedIndex = i;
return i;
}
}
};
Shopify.addListener = function(target, eventName, callback) {
target.addEventListener ? target.addEventListener(eventName, callback, false) : target.attachEvent('on'+eventName, callback);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment