Last active
November 3, 2020 15:20
-
-
Save ArnoutPullen/07fe0c6c9c80307fd8dedc2b070ffd8c to your computer and use it in GitHub Desktop.
Integrate your Toolset views slider with hammer.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Register child theme assets | |
* Put this in your my-child-theme/functions.php | |
*/ | |
function my_child_theme_scripts() | |
{ | |
wp_enqueue_script('hammer', get_stylesheet_directory_uri() . '/assets/js/hammer.min.js', array(), '2.0.8', true); | |
// wp_enqueue_script('hammer-min', 'https://cdnjs.cloudflare.com/ajax/libs/hammer.js/2.0.8/hammer.min.js', array(), '2.0.8'); | |
wp_enqueue_script('webprofit-hammer', get_stylesheet_directory_uri() . '/assets/js/hammer.js', array('jquery'), '0.0.1', true); | |
} | |
add_action('wp_enqueue_scripts', 'my_child_theme_scripts'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* location: | |
* my-child-theme/assets/js/hammer.js | |
*/ | |
function register_hammer() { | |
// Get slider | |
var slider = document.getElementById('posts-slider'); | |
// Skip if no slider is found | |
if (!slider) { | |
return; | |
} | |
// Register hammer | |
var hammertime = new Hammer(slider); | |
// Get prev/next links | |
var prevSlide = document.getElementsByClassName('js-wpv-pagination-previous-link'); | |
var nextSlide = document.getElementsByClassName('js-wpv-pagination-next-link'); | |
// Register hammer events | |
hammertime.on('swipeleft', function (ev) { | |
if (prevSlide != null && prevSlide.length > 0) { | |
prevSlide[0].click(); | |
} | |
}); | |
hammertime.on('swiperight', function (ev) { | |
if (nextSlide != null && nextSlide.length > 0) { | |
nextSlide[0].click(); | |
} | |
}); | |
} | |
// Register hammer on page load | |
document.addEventListener("DOMContentLoaded", function (event) { | |
register_hammer(); | |
}); | |
// After each slide is complete, register new hammer | |
jQuery(document).on('js_event_wpv_pagination_completed', function (event, data) { | |
register_hammer(); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* location: | |
* my-child-theme/assets/js/hammer.min.js | |
* | |
* Get your hammer version here (File content) | |
* Or load hammerjs from cdn, see functions.php | |
* http://hammerjs.github.io/ | |
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- BEGIN LOOP --> | |
[wpv-layout-start] | |
[wpv-items-found] | |
<!-- wpv-loop-start --> | |
<div id="posts-slider"><wpv-loop><div class="post"> | |
<!-- Do stuff here --> | |
<!-- Hide pagination, needed for prev/next links in hammer.js --> | |
<div style="display: none;"> | |
[wpv-pager-prev-page][/wpv-pager-prev-page] | |
[wpv-pager-next-page][/wpv-pager-next-page] | |
</div> | |
</div></wpv-loop></div> | |
<!-- wpv-loop-end --> | |
[/wpv-items-found] | |
[wpv-no-items-found] | |
<strong>[wpml-string context="wpv-views"]No items found[/wpml-string]</strong> | |
[/wpv-no-items-found] | |
[wpv-layout-end] | |
<!-- END LOOP --> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment