Skip to content

Instantly share code, notes, and snippets.

@bearded-avenger
Last active December 24, 2015 08:39
Show Gist options
  • Save bearded-avenger/6772441 to your computer and use it in GitHub Desktop.
Save bearded-avenger/6772441 to your computer and use it in GitHub Desktop.
Long Form Helper - Plugin
<?php
/*
Author: Nick Haskins
Author URI: http://nickhaskins.co
Plugin Name: Long Form Helper
Plugin URI: http://nickhaskins.co
Version: 1.0
Description: A helper plugin for long posts by introducing a "scroll to" floating panel.
*/
// Check to make sure we're in DMS
add_action('pagelines_setup', 'ba_longform_helper_init' );
function ba_longform_helper_init() {
if( !function_exists('pl_has_editor') )
return;
$landing = new baLongFormHelper;
}
class baLongFormHelper {
const version = '1.0';
function __construct() {
$this->id = 'ba_longform_helper';
$this->name = 'Long Form Helper';
$this->dir = plugin_dir_path( __FILE__ );
$this->url = plugins_url( '', __FILE__ );
$this->icon = plugins_url( '/icon.png', __FILE__ );
add_action( 'template_redirect', array($this,'insert_less' ));
add_action( 'init', array( $this, 'init' ) );
}
// Add a less file
function insert_less() {
$file = sprintf( '%sstyle.less', plugin_dir_path( __FILE__ ) );
if(function_exists('pagelines_insert_core_less')) {
pagelines_insert_core_less( $file );
}
}
function init(){
add_action( 'wp_enqueue_scripts', array($this,'scripts' ));
add_action( 'wp_footer',array($this,'script_init'));
}
// Enqueue stuffs
function scripts(){
wp_register_script('ba-longform-helper',$this->url.'/jquery.scrollNav.min.js', array('jquery'), self::version, true );
if(is_single()){
wp_enqueue_script('ba-longform-helper');
}
}
function script_init(){
if(is_single()) { ?>
<!-- Long Form Helper -->
<script>
jQuery(window).load(function() {
jQuery('.entry_content').scrollNav({
sections: '.ba-longform',
titleText: 'Jump To',
fixedMargin: 0,
animated: true,
speed: 500,
showHeadline: true,
showTopLink: true,
topLinkText: 'Top',
location: 'insertBefore'
});
});
</script>
<?php }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment