Skip to content

Instantly share code, notes, and snippets.

@rileyrichter
Created February 13, 2020 21:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rileyrichter/a0c7668bc6fa1f276bb327c3850b8ed1 to your computer and use it in GitHub Desktop.
Save rileyrichter/a0c7668bc6fa1f276bb327c3850b8ed1 to your computer and use it in GitHub Desktop.
<!--
I keep a collection field with a unique identifier to control this. You could use the ITEM Id field.
Then, wherever my submit button on my form is I wrap in a div with an id of that UUID
-->
<!-- This goes in the embed in the Collection list -->
<div id="UUID-FROM-CMS-HERE">
<input type="submit" value="Vote" data-wait="..." onClick="myVote('UUID-FROM-CMS-HERE');" class="button vote-button w-button" style="cursor: pointer;">
<!-- I include my other form elements here too in the embed -->
<input type="hidden" name="Item ID" value="YOURCOLLECTIONINFOHERE">
<input type="hidden" name="Item Name" value="YOURCOLLECTIONINFOHERE">
</div>
<!-- This goes in the before body -->
<script>
function myVote(shortcode) {
$(document).on('submit', 'form', function() {
// Set product in local storage
localStorage.setItem(shortcode, "true");
// Refresh page after 3000 milliseconds
setTimeout(function() { location.reload(true); }, 3000);
});
};
</script>
<script>
for(let i=0; i<localStorage.length; i++) {
if (document.getElementById(localStorage.key(i)) === null) {
console.log("not on this page");}
else {document.getElementById(localStorage.key(i)).style.display = "none";}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment