Skip to content

Instantly share code, notes, and snippets.

@sosroInSpace
Last active April 11, 2018 09:15
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 sosroInSpace/5e476ec8ff4702fdc1fdcbf5c0259be1 to your computer and use it in GitHub Desktop.
Save sosroInSpace/5e476ec8ff4702fdc1fdcbf5c0259be1 to your computer and use it in GitHub Desktop.
Code for use with local storage - display modal once and then hide after submission with different css classes applied dependent on selected options.
if ($(window).width() < 768) {
//* if local storage is supported or not -->
if (typeof Storage !== "undefined") {
/* update variable -->*/
var keyName = 'hulc_hand';
/* store local storage item into variable -->*/
var hand = localStorage.getItem(keyName);
/* if hand is not there do this function --> */
function showForm () {
$('.mobileLeftRight').removeClass('hidden');
};
/* if left button clicked function */
function makeLeft () {
localStorage.setItem(keyName, 'left');
$('.mobileLeftRight').addClass('hidden');
$('.mobileButton').addClass('mobile-button-left')
$('.hulcLogo').addClass('hulc-logo-right');
};
/* if right button clicked function */
function makeRight () {
localStorage.setItem(keyName, 'right');
$('.mobileLeftRight').addClass('hidden');
};
/* if local storage same as item left run function makeLeft */
if (hand === 'left') {
makeLeft();
} else if (hand === 'right') {/* if local storage same as item left run function makeLeft */
makeRight();
} else { /* else show form */
showForm();
}
$('#handLeftButton').click(makeLeft);
$('#handRightButton').click(makeRight);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment