Skip to content

Commit 15bd755

Browse files
committed
New feature added and Bug Fix
Now we can easily customize easing and speed. Also the plugin is now compatible with various plugin.
1 parent 6f132ca commit 15bd755

File tree

5 files changed

+301
-110
lines changed

5 files changed

+301
-110
lines changed

images/source.psd

27.1 KB
Binary file not shown.

jquery-smooth-scroll.php

Lines changed: 118 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
<?php
22
/*
33
Plugin Name: jQuery Smooth Scroll
4-
Version: 1.2.4
4+
Version: 1.2.5
55
Plugin URI: http://www.blogsynthesis.com/wordpress-jquery-smooth-scroll-plugin/
66
Description: The plugin not only add smooth scroll to top feature/link in the lower-right corner of long pages while scrolling but also makes all jump links to scroll smoothly.
77
Author: BlogSynthesis
88
Author URI: http://www.blogsynthesis.com/
99
License: GPL v3
1010
11-
jQuery Smooth Scroll Plugin
12-
Copyright (C) 2013, Anand Kumar anand@blogsynthesis.com
11+
jQuery Smooth Scroll
12+
Copyright (C) 2013-14, Anand Kumar anand@blogsynthesis.com
1313
1414
This program is free software: you can redistribute it and/or modify
1515
it under the terms of the GNU General Public License as published by
@@ -25,92 +25,118 @@
2525
along with this program. If not, see <http://www.gnu.org/licenses/>.
2626
*/
2727

28-
class BlogSynthesisSmoothScroll {
29-
30-
31-
/*--------------------------------------------*
32-
* Constants
33-
*--------------------------------------------*/
34-
35-
const name = 'BlogSynthesis Scroll to Top';
36-
const slug = 'blogsynthesis-scroll-to-top';
37-
38-
39-
/*--------------------------------------------*
40-
* Constructor
41-
*--------------------------------------------*/
42-
43-
function __construct() {
44-
45-
// Define constants used throughout the plugin
46-
$this->init_plugin_constants();
47-
48-
load_plugin_textdomain( 'blogsynthesis', false, dirname( plugin_basename( __FILE__ ) ) . '/lang' );
49-
50-
// Load JavaScript and stylesheets
51-
$this->register_scripts_and_styles();
52-
53-
// Plugin Actions
54-
add_action( 'wp_footer', array( $this, 'display_link' ) );
55-
56-
} // end constructor
57-
58-
59-
/*--------------------------------------------*
60-
* Core Functions
61-
*---------------------------------------------*/
62-
63-
function display_link() {
64-
?>
65-
<a id="scroll-to-top" href="#" title="<?php _e('Scroll to Top','blogsynthesis'); ?>"><?php _e('Top','blogsynthesis'); ?></a>
66-
<?php
67-
}
68-
69-
70-
/*--------------------------------------------*
71-
* Private Functions
72-
*---------------------------------------------*/
73-
74-
// Initializes constants used for convenience throughout the plugin.
75-
private function init_plugin_constants() {
76-
77-
if ( !defined( 'PLUGIN_NAME' ) ) {
78-
define( 'PLUGIN_NAME', self::name );
79-
}
80-
if ( !defined( 'PLUGIN_SLUG' ) ) {
81-
define( 'PLUGIN_SLUG', self::slug );
82-
}
83-
84-
} // end init_plugin_constants
85-
86-
// Registers and enqueues stylesheets
87-
private function register_scripts_and_styles() {
88-
if ( is_admin() ) {
89-
// no admin styes or scripts
90-
} else {
91-
$this->load_file( self::slug . '-script', '/js/jss-script.min.js', true );
92-
$this->load_file( self::slug . '-style', '/css/jss-style.min.css' );
93-
} // end if/else
94-
} // end register_scripts_and_styles
95-
96-
// Helper function for registering and enqueueing scripts and styles.
97-
private function load_file( $name, $file_path, $is_script = false ) {
98-
99-
$url = plugins_url($file_path, __FILE__);
100-
$file = plugin_dir_path(__FILE__) . $file_path;
101-
102-
if( file_exists( $file ) ) {
103-
if( $is_script ) {
104-
wp_register_script( $name, $url, array('jquery') );
105-
wp_enqueue_script( $name );
106-
} else {
107-
wp_register_style( $name, $url );
108-
wp_enqueue_style( $name );
109-
} // end if
110-
} // end if
111-
112-
} // end load_file
113-
114-
115-
} // end class
116-
new BlogSynthesisSmoothScroll();
28+
29+
// Prevent loading this file directly - Busted!
30+
if ( ! class_exists( 'WP' ) )
31+
{
32+
header( 'Status: 403 Forbidden' );
33+
header( 'HTTP/1.1 403 Forbidden' );
34+
exit;
35+
}
36+
37+
38+
if ( !class_exists( 'jQuerySmoothScroll' ) ) {
39+
40+
class jQuerySmoothScroll {
41+
42+
function jQuerySmoothScroll() {
43+
44+
$blogsynthesis_jss_plugin_url = trailingslashit ( WP_PLUGIN_URL . '/' . dirname ( plugin_basename ( __FILE__ ) ) );
45+
$pluginname = 'jQuery Smooth Scroll';
46+
$plugin_version = '1.2.5';
47+
48+
// load plugin Scripts
49+
add_action( 'wp_head', array( &$this, 'wp_head') );
50+
51+
// add move to top button at wp_footer
52+
add_action( 'wp_footer', array( &$this, 'wp_footer') );
53+
54+
}
55+
56+
// load our css to the head
57+
function wp_head() {
58+
59+
global $blogsynthesis_jss_plugin_url;
60+
61+
// register and enqueue CSS
62+
wp_register_style( 'custom_wp_admin_css', plugin_dir_url( __FILE__ ) . 'css/jss-style.min.css', false );
63+
wp_enqueue_style( 'custom_wp_admin_css' );
64+
65+
// enqueue script
66+
wp_enqueue_script( 'script-name', plugin_dir_url( __FILE__ ) . 'js/jss-script.js', array('jquery') );
67+
68+
// You may now choose easing effect. For more information visit http://www.blogsynthesis.com/?p=860
69+
// wp_enqueue_script("jquery-effects-core");
70+
}
71+
72+
function wp_footer() {
73+
// the html button which will be added to wp_footer ?>
74+
<a id="scroll-to-top" href="#" title="<?php _e('Scroll to Top','blogsynthesis'); ?>"><?php _e('Top','blogsynthesis'); ?></a>
75+
<?php
76+
}
77+
78+
}
79+
80+
81+
//////////////////////////////////////////////////////////////////////////////
82+
83+
add_action('wp_dashboard_setup', 'blogsynthesis_jss_dashboard_widgets');
84+
85+
function blogsynthesis_jss_dashboard_widgets() {
86+
global $wp_meta_boxes;
87+
wp_add_dashboard_widget('blogsynthesisshfswidget', 'Latest from BlogSynthesis', 'blogsynthesis_jss_widget');
88+
}
89+
90+
function blogsynthesis_jss_widget() {
91+
include_once( ABSPATH . WPINC . '/feed.php' );
92+
93+
$rss = fetch_feed( 'http://feeds2.feedburner.com/blogsynthesis' );
94+
95+
if ( ! is_wp_error( $rss ) ) :
96+
97+
// Figure out how many total items there are, but limit it to 10.
98+
$maxitems = $rss->get_item_quantity( 10 );
99+
100+
// Build an array of all the items, starting with element 0 (first element).
101+
$rss_items = $rss->get_items( 0, $maxitems );
102+
103+
endif;
104+
105+
{ ?>
106+
<div class="rss-widget">
107+
<a href="http://www.blogsynthesis.com/#utm_source=wpadmin&utm_medium=dashboardwidget&utm_term=newsitemlogo&utm_campaign=shfs" title="BlogSynthesis - For Bloggers" target="_blank"><img src="http://static.blogsynthesis.com/public/blogsynthesis-100px.png" class="alignright" alt="BlogSynthesis"/></a>
108+
<ul>
109+
<?php if ( $maxitems == 0 ) : ?>
110+
<li><?php _e( 'No items', 'shfs-text-domain' ); ?></li>
111+
<?php else : ?>
112+
<?php // Loop through each feed item and display each item as a hyperlink. ?>
113+
<?php foreach ( $rss_items as $item ) : ?>
114+
<li>
115+
<a href="<?php echo esc_url( $item->get_permalink() ); ?>#utm_source=wpadmin&utm_medium=dashboardwidget&utm_term=newsitem&utm_campaign=shfs"
116+
title="<?php printf( __( 'Posted %s', 'shfs-text-domain' ), $item->get_date('j F Y | g:i a') ); ?>" target="_blank">
117+
<?php echo esc_html( $item->get_title() ); ?>
118+
</a>
119+
</li>
120+
<?php endforeach; ?>
121+
<?php endif; ?>
122+
</ul>
123+
<div style="border-top: 1px solid #ddd; padding-top: 10px; text-align:center;">
124+
<span class="addthis_toolbox addthis_default_style" style="float:left;">
125+
<a class="addthis_button_facebook_follow" addthis:userid="blogsynthesis"></a>
126+
<a class="addthis_button_twitter_follow" addthis:userid="blogsynthesis"></a>
127+
<a class="addthis_button_google_follow" addthis:userid="+BlogSynthesis"></a>
128+
<a class="addthis_button_rss_follow" addthis:userid="http://feeds2.feedburner.com/blogsynthesis"></a>
129+
</span>
130+
&nbsp; &nbsp; &nbsp;
131+
<a href="http://www.blogsynthesis.com/newsletter/"><img src="http://static.blogsynthesis.com/public/email-16px.png" alt="Subscribe via Email"/> Subscribe by email</a>
132+
&nbsp; &nbsp; &nbsp;
133+
<script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-525ab1d176544441"></script>
134+
</div>
135+
</div>
136+
<?php }
137+
138+
}
139+
140+
$jQuerySmoothScroll = new jQuerySmoothScroll();
141+
142+
}

js/jss-script.js

Lines changed: 63 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
/* Smooth Back to Top, Get This functionality from: http://wordpress.org/extend/plugins/cudazi-scroll-to-top/ */
2-
31
jQuery.noConflict();
42
jQuery(function($) {
5-
3+
4+
5+
// Customize Settings: For more information visit www.blogsynthesis.com/plugins/jquery-smooth-scroll/
6+
67
// When to show the scroll link
78
// higher number = scroll link appears further down the page
89
var upperLimit = 100;
@@ -11,7 +12,16 @@ jQuery(function($) {
1112
var scrollElem = $('a#scroll-to-top');
1213

1314
// Scroll to top speed
14-
var scrollSpeed = 500;
15+
var scrollSpeed = 1500;
16+
17+
// Choose your easing effect
18+
var scrollStyle = 'swing';
19+
20+
/****************************************************
21+
* *
22+
* JUMP TO ANCHOR LINK SCRIPT START *
23+
* *
24+
****************************************************/
1525

1626
// Show and hide the scroll to top link based on scroll position
1727
scrollElem.hide();
@@ -26,13 +36,55 @@ jQuery(function($) {
2636

2737
// Scroll to top animation on click
2838
$(scrollElem).click(function(){
29-
$('html, body').animate({scrollTop:0}, scrollSpeed); return false;
39+
$('html, body').animate({scrollTop:0}, scrollSpeed, scrollStyle ); return false;
3040
});
3141

32-
});
42+
/****************************************************
43+
* *
44+
* JUMP TO ANCHOR LINK SCRIPT START *
45+
* *
46+
****************************************************/
47+
48+
$('a[href*=#]:not([href=#])').click(function()
49+
{
50+
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
51+
|| location.hostname == this.hostname)
52+
{
53+
54+
var target = $(this.hash),
55+
headerHeight = $(".primary-header").height() + 5; // Get fixed header height
56+
57+
target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
58+
59+
if (target.length)
60+
{
61+
$('html,body').animate({ scrollTop: target.offset().top }, scrollSpeed, scrollStyle );
62+
return false;
63+
}
64+
}
65+
});
66+
67+
68+
/****************************************************
69+
* *
70+
* FOLLOW BLOGSYNTHESIS.COM FOR WORDPRESS TIPS *
71+
* *
72+
****************************************************/
73+
74+
});
75+
3376

77+
/****************************************************
78+
* *
79+
* SCRIPTS ENDS HERE *
80+
* *
81+
****************************************************/
82+
3483

35-
/* Smooth Scroll Links, Get This functionality from: http://wordpress.org/extend/plugins/easy-smooth-scroll-links/ */
84+
/* DEPRECITED SCRIPT - WILL BE REMOVED IN NEXT UPDATE */
85+
86+
/* Smooth Scroll Anchor Links */
87+
/*
3688
var ss = {
3789
fixAllLinks: function () {
3890
var allLinks = document.getElementsByTagName('a');
@@ -79,7 +131,7 @@ var ss = {
79131
ss.INTERVAL = setInterval('ss.scrollWindow(' + ss_stepsize + ',' + desty + ',"' + anchor + '")', 10);
80132
if (window.event) {
81133
window.event.cancelBubble = true;
82-
window.event.returnValue = false;
134+
e.preventDefault();
83135
}
84136
if (e && e.preventDefault && e.stopPropagation) {
85137
e.preventDefault();
@@ -117,4 +169,6 @@ var ss = {
117169
}
118170
}
119171
ss.STEPS = 25;
120-
ss.addEvent(window, "load", ss.fixAllLinks);
172+
ss.addEvent(window, "load", ss.fixAllLinks);
173+
174+
*/

0 commit comments

Comments
 (0)