Skip to content
Permalink
Browse files

Added disable on mobile option

  • Loading branch information...
seb86 committed May 12, 2019
1 parent 334cb50 commit 7bf0caa76f2a0f8cbd39fcdb72165fa160cdd085
@@ -7,6 +7,7 @@ var version = auto_load_next_post_params.alnp_version,
remove_comments = auto_load_next_post_params.alnp_remove_comments,
track_pageviews = auto_load_next_post_params.alnp_google_analytics,
is_customizer = auto_load_next_post_params.alnp_is_customizer,
is_mobile = auto_load_next_post_params.alnp_is_mobile,
event_on_load = auto_load_next_post_params.alnp_event_on_load,
event_on_entering = auto_load_next_post_params.alnp_event_on_entering,
post_title = window.document.title,
@@ -18,7 +19,8 @@ var version = auto_load_next_post_params.alnp_version,
stop_reading = false,
scroll_up = false,
article_container = 'article',
ready = auto_load_next_post_params.alnp_load_in_footer;
ready = auto_load_next_post_params.alnp_load_in_footer,
disable_mobile = auto_load_next_post_params.alnp_disable_mobile;

(function($) {

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

// Stop Auto Load Next Post from running if disabled for mobile devices.
if ( is_mobile == 'yes' && disable_mobile ) {
return false;
}

/**
* Ensure the main required selectors are set before continuing.
*
@@ -7,6 +7,7 @@ var version = auto_load_next_post_params.alnp_version,
remove_comments = auto_load_next_post_params.alnp_remove_comments,
track_pageviews = auto_load_next_post_params.alnp_google_analytics,
is_customizer = auto_load_next_post_params.alnp_is_customizer,
is_mobile = auto_load_next_post_params.alnp_is_mobile,
event_on_load = auto_load_next_post_params.alnp_event_on_load,
event_on_entering = auto_load_next_post_params.alnp_event_on_entering,
post_title = window.document.title,
@@ -18,7 +19,8 @@ var version = auto_load_next_post_params.alnp_version,
stop_reading = false,
scroll_up = false,
article_container = 'article',
ready = auto_load_next_post_params.alnp_load_in_footer;
ready = auto_load_next_post_params.alnp_load_in_footer,
disable_mobile = auto_load_next_post_params.alnp_disable_mobile;

(function($) {

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

// Stop Auto Load Next Post from running if disabled for mobile devices.
if ( is_mobile == 'yes' && disable_mobile ) {
return false;
}

/**
* Ensure the main required selectors are set before continuing.
*
@@ -237,6 +237,9 @@ public function alnp_enqueue_scripts() {
// This checks to see if the JavaScript should load in the footer or not.
$load_in_footer = alnp_load_js_in_footer();
// This checks to see if we should disable Auto Load Next Post from running on mobile devices.
$disable_mobile = alnp_disable_on_mobile();
$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 );
// Only load History.js when not in the customizer.
@@ -258,7 +261,9 @@ public function alnp_enqueue_scripts() {
'alnp_event_on_load' => get_option( 'auto_load_next_post_on_load_event' ),
'alnp_event_on_entering' => get_option( 'auto_load_next_post_on_entering_event' ),
'alnp_is_customizer' => $this->is_alnp_using_customizer(),
'alnp_load_in_footer' => $load_in_footer
'alnp_load_in_footer' => $load_in_footer,
'alnp_is_mobile' => $this->is_mobile(),
'alnp_disable_mobile' => $disable_mobile
) );
} // END if is_singular() && get_post_type()
} // END alnp_enqueue_scripts()
@@ -279,6 +284,22 @@ public static function is_alnp_using_customizer() {
return false;
} // END is_alnp_using_customizer()
/**
* Check if the site is viewed on a mobile device.
*
* @access public
* @since 1.6.0
* @static
* @return string|bool
*/
public static function is_mobile() {
if ( wp_is_mobile() ) {
return "yes";
}
return false;
} // END is_mobile()
/**
* Helper function for registering and enqueueing scripts and styles.
*
@@ -126,6 +126,14 @@ public function get_settings() {
'type' => 'checkbox'
),
'disable_on_mobile' => array(
'title' => esc_html__( 'Disable for Mobile?', 'auto-load-next-post' ),
'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' ) ),
'id' => 'auto_load_next_post_disable_on_mobile',
'default' => 'no',
'type' => 'checkbox'
),
'reset_data' => array(
'title' => esc_html__( 'Reset all data?', 'auto-load-next-post' ),
'desc' => esc_html__( 'Press the reset button to clear all settings for this plugin and re-initialize.', 'auto-load-next-post' ),
@@ -65,6 +65,25 @@ function alnp_load_js_in_footer() {
} // END alnp_load_js_in_footer()
}
if ( ! function_exists( 'alnp_disable_on_mobile' ) ) {
/**
* This helps the plugin decide to disable Auto Load Next Post
* from running on mobile devices.
*
* @since 1.6.0
* @return boolean
*/
function alnp_disable_on_mobile() {
$disable_mobile = get_option( 'auto_load_next_post_disable_on_mobile', false );
if ( isset( $disable_mobile ) && $disable_mobile == 'yes' ) {
return true;
}
return false;
} // END alnp_disable_on_mobile()
}
if ( ! function_exists( 'alnp_get_admin_screens' ) ) {
/**
* These are the only screens Auto Load Next Post will focus

0 comments on commit 7bf0caa

Please sign in to comment.
You can’t perform that action at this time.