Skip to content

Instantly share code, notes, and snippets.

View anxiouspenguin's full-sized avatar
🐧

Michael Lorig anxiouspenguin

🐧
View GitHub Profile
@anxiouspenguin
anxiouspenguin / shopify-money.js
Last active December 6, 2023 18:11
Shopify Money Format
var Shopify = Shopify || {};
// ---------------------------------------------------------------------------
// Money format handler
// ---------------------------------------------------------------------------
Shopify.money_format = "${{amount}}";
Shopify.formatMoney = function(cents, format) {
if (typeof cents == 'string') { cents = cents.replace('.',''); }
var value = '';
var placeholderRegex = /\{\{\s*(\w+)\s*\}\}/;
var formatString = (format || this.money_format);
@anxiouspenguin
anxiouspenguin / element-exist.js
Last active December 6, 2023 18:11
if element exists (wait for element to load, even if element is a DOM element)
const element_exist = async selector => {
while ( document.querySelector(selector) === null) {
await new Promise( resolve => requestAnimationFrame(resolve) )
}
return document.querySelector(selector);
};
element_exist('#button-added-to-dom').then((selector) => {
const button = document.querySelector('#button-added-to-dom');
@anxiouspenguin
anxiouspenguin / google-places-autocomplete-multiple-inputs.js
Last active December 6, 2023 18:14
Google Places autocomplete for multiple input fields
var address_inputs = document.getElementsByClassName('address');
for(i = 0; i < address_inputs.length; i++) {
var autocomplete = new google.maps.places.Autocomplete(address_inputs[i]);
autocomplete.inputId = address_inputs[i].id;
google.maps.event.addListener(autocomplete, 'place_changed', function() {
var address_submit = document.getElementById(this.inputId.replace('address', 'submit'));
address_submit.click();