Skip to content

Instantly share code, notes, and snippets.

@flymke
Created November 29, 2021 11:18
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 flymke/c840f5c3a44aa2d93d4d8ed553bd343f to your computer and use it in GitHub Desktop.
Save flymke/c840f5c3a44aa2d93d4d8ed553bd343f to your computer and use it in GitHub Desktop.
Add 'opened' class to all doors that were previously clicked by the user - SantaPress
add_action( 'wp_head', function () { ?>
<script>
jQuery(document).ready(function($){
// click on door and save open status to local storage
$('.santapress-door.status-publish:not(.preview)').click(function() {
var postid = $(this).data('postid');
var opendoors = JSON.parse( window.localStorage.getItem('opendoors') );
if(!opendoors) {
var opendoors = [];
}
if(opendoors.indexOf(postid) == -1) {
// add door post id to local storage object
opendoors.push(postid);
}
// save to local storage
window.localStorage.setItem( 'opendoors', JSON.stringify(opendoors) );
// add 'opened' class to clicked door
$(this).addClass('opened');
});
// add 'opened' class to all doors that where openend by the user already (based on local storage)
if($('.santapress-container').length) {
var opendoors = JSON.parse( window.localStorage.getItem('opendoors') );
if( opendoors.length > 0 ) {
for (const postid of opendoors) {
$('.santapress-door.status-publish:not(.preview)[data-postid="'+postid+'"]').addClass('opened');
}
}
}
});
</script>
<style>
.santapress-door.opened img {
transform:perspective(1200px) translateZ(0px) translateX(0px) translateY(0px) rotateY(-45deg);
}
</style>
<?php } );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment