-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscrollify-snap-scroll.php
70 lines (57 loc) · 2.44 KB
/
scrollify-snap-scroll.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
/**
* Plugin Name: Scrollify Snap Scroll by WinstonDev
* Description: This plugin adds Scrollify functionality for snap scroll between sections with specific classes containing the word "snap".
* Version: 1.2
* Author: Winston Porras
* Author URI: https://winstondev.site
* License: GPLv2 or later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
*/
function scrollify_snap_enqueue_scripts() {
// Enqueue Scrollify JS
wp_enqueue_script('scrollify-js', plugin_dir_url(__FILE__) . 'js/jquery.scrollify.js', array('jquery'), null, true);
// Custom script to initialize Scrollify
wp_add_inline_script('scrollify-js', '
jQuery(document).ready(function($) {
var snapSections = $("[class*=\'snap\']"); // all "snap" classes
// Filtrar solo las secciones visibles
var visibleSections = snapSections.filter(function() {
return $(this).is(":visible");
});
if (visibleSections.length > 0 && $(window).width() > 768) { // apply wide 768px
$.scrollify({
section: visibleSections,
scrollSpeed: 900, // speed
setHeights: false,
scrollbars: true,
updateHash: false, //do not update hash
touchScroll: true,
before: function(index, sections) {
var currentSection = sections[index];
if (!$(currentSection).is(":visible")) {
return false;
}
console.log("Scrolling to section:", index);
},
after: function(index, sections) {
console.log("Arrived at section:", index);
}
});
} else {
console.log("No snap sections found or on a small screen, default scrolling enabled.");
}
});
');
}
// support
function scrollify_add_plugin_links($links, $file) {
if ($file == plugin_basename(__FILE__)) {
$support_link = '<a href="mailto:winstondev01@gmail.com">Contact Support</a>';
array_push($links, $support_link);
}
return $links;
}
// Hooks
add_filter('plugin_row_meta', 'scrollify_add_plugin_links', 10, 2);
add_action('wp_enqueue_scripts', 'scrollify_snap_enqueue_scripts');