Skip to content

Commit 7bf0caa

Browse files
committed
Added disable on mobile option
1 parent 334cb50 commit 7bf0caa

File tree

5 files changed

+65
-3
lines changed

5 files changed

+65
-3
lines changed

assets/js/frontend/auto-load-next-post.dev.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ var version = auto_load_next_post_params.alnp_version,
77
remove_comments = auto_load_next_post_params.alnp_remove_comments,
88
track_pageviews = auto_load_next_post_params.alnp_google_analytics,
99
is_customizer = auto_load_next_post_params.alnp_is_customizer,
10+
is_mobile = auto_load_next_post_params.alnp_is_mobile,
1011
event_on_load = auto_load_next_post_params.alnp_event_on_load,
1112
event_on_entering = auto_load_next_post_params.alnp_event_on_entering,
1213
post_title = window.document.title,
@@ -18,7 +19,8 @@ var version = auto_load_next_post_params.alnp_version,
1819
stop_reading = false,
1920
scroll_up = false,
2021
article_container = 'article',
21-
ready = auto_load_next_post_params.alnp_load_in_footer;
22+
ready = auto_load_next_post_params.alnp_load_in_footer,
23+
disable_mobile = auto_load_next_post_params.alnp_disable_mobile;
2224

2325
(function($) {
2426

@@ -27,6 +29,11 @@ var version = auto_load_next_post_params.alnp_version,
2729
return false;
2830
}
2931

32+
// Stop Auto Load Next Post from running if disabled for mobile devices.
33+
if ( is_mobile == 'yes' && disable_mobile ) {
34+
return false;
35+
}
36+
3037
/**
3138
* Ensure the main required selectors are set before continuing.
3239
*

assets/js/frontend/auto-load-next-post.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ var version = auto_load_next_post_params.alnp_version,
77
remove_comments = auto_load_next_post_params.alnp_remove_comments,
88
track_pageviews = auto_load_next_post_params.alnp_google_analytics,
99
is_customizer = auto_load_next_post_params.alnp_is_customizer,
10+
is_mobile = auto_load_next_post_params.alnp_is_mobile,
1011
event_on_load = auto_load_next_post_params.alnp_event_on_load,
1112
event_on_entering = auto_load_next_post_params.alnp_event_on_entering,
1213
post_title = window.document.title,
@@ -18,7 +19,8 @@ var version = auto_load_next_post_params.alnp_version,
1819
stop_reading = false,
1920
scroll_up = false,
2021
article_container = 'article',
21-
ready = auto_load_next_post_params.alnp_load_in_footer;
22+
ready = auto_load_next_post_params.alnp_load_in_footer,
23+
disable_mobile = auto_load_next_post_params.alnp_disable_mobile;
2224

2325
(function($) {
2426

@@ -27,6 +29,11 @@ var version = auto_load_next_post_params.alnp_version,
2729
return false;
2830
}
2931

32+
// Stop Auto Load Next Post from running if disabled for mobile devices.
33+
if ( is_mobile == 'yes' && disable_mobile ) {
34+
return false;
35+
}
36+
3037
/**
3138
* Ensure the main required selectors are set before continuing.
3239
*

auto-load-next-post.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,9 @@ public function alnp_enqueue_scripts() {
237237
// This checks to see if the JavaScript should load in the footer or not.
238238
$load_in_footer = alnp_load_js_in_footer();
239239

240+
// This checks to see if we should disable Auto Load Next Post from running on mobile devices.
241+
$disable_mobile = alnp_disable_on_mobile();
242+
240243
$this->load_file( 'auto-load-next-post-scrollspy', '/assets/js/libs/scrollspy.min.js', true, array('jquery'), AUTO_LOAD_NEXT_POST_VERSION, $load_in_footer );
241244

242245
// Only load History.js when not in the customizer.
@@ -258,7 +261,9 @@ public function alnp_enqueue_scripts() {
258261
'alnp_event_on_load' => get_option( 'auto_load_next_post_on_load_event' ),
259262
'alnp_event_on_entering' => get_option( 'auto_load_next_post_on_entering_event' ),
260263
'alnp_is_customizer' => $this->is_alnp_using_customizer(),
261-
'alnp_load_in_footer' => $load_in_footer
264+
'alnp_load_in_footer' => $load_in_footer,
265+
'alnp_is_mobile' => $this->is_mobile(),
266+
'alnp_disable_mobile' => $disable_mobile
262267
) );
263268
} // END if is_singular() && get_post_type()
264269
} // END alnp_enqueue_scripts()
@@ -279,6 +284,22 @@ public static function is_alnp_using_customizer() {
279284
return false;
280285
} // END is_alnp_using_customizer()
281286

287+
/**
288+
* Check if the site is viewed on a mobile device.
289+
*
290+
* @access public
291+
* @since 1.6.0
292+
* @static
293+
* @return string|bool
294+
*/
295+
public static function is_mobile() {
296+
if ( wp_is_mobile() ) {
297+
return "yes";
298+
}
299+
300+
return false;
301+
} // END is_mobile()
302+
282303
/**
283304
* Helper function for registering and enqueueing scripts and styles.
284305
*

includes/admin/settings/class-alnp-settings-misc.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,14 @@ public function get_settings() {
126126
'type' => 'checkbox'
127127
),
128128

129+
'disable_on_mobile' => array(
130+
'title' => esc_html__( 'Disable for Mobile?', 'auto-load-next-post' ),
131+
'desc' => sprintf( esc_html__( 'Enable to disable %s from running on mobile devices.', 'auto-load-next-post' ), esc_html__( 'Auto Load Next Post', 'auto-load-next-post' ) ),
132+
'id' => 'auto_load_next_post_disable_on_mobile',
133+
'default' => 'no',
134+
'type' => 'checkbox'
135+
),
136+
129137
'reset_data' => array(
130138
'title' => esc_html__( 'Reset all data?', 'auto-load-next-post' ),
131139
'desc' => esc_html__( 'Press the reset button to clear all settings for this plugin and re-initialize.', 'auto-load-next-post' ),

includes/auto-load-next-post-core-functions.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,25 @@ function alnp_load_js_in_footer() {
6565
} // END alnp_load_js_in_footer()
6666
}
6767

68+
if ( ! function_exists( 'alnp_disable_on_mobile' ) ) {
69+
/**
70+
* This helps the plugin decide to disable Auto Load Next Post
71+
* from running on mobile devices.
72+
*
73+
* @since 1.6.0
74+
* @return boolean
75+
*/
76+
function alnp_disable_on_mobile() {
77+
$disable_mobile = get_option( 'auto_load_next_post_disable_on_mobile', false );
78+
79+
if ( isset( $disable_mobile ) && $disable_mobile == 'yes' ) {
80+
return true;
81+
}
82+
83+
return false;
84+
} // END alnp_disable_on_mobile()
85+
}
86+
6887
if ( ! function_exists( 'alnp_get_admin_screens' ) ) {
6988
/**
7089
* These are the only screens Auto Load Next Post will focus

0 commit comments

Comments
 (0)