jQuery Smooth Scroll - Version 1.2.3

Version Description

Download this release

Release Info

Developer BlogSynthesis
Plugin Icon 128x128 jQuery Smooth Scroll
Version 1.2.3
Comparing to
See all releases

Code changes from version 1.2.1 to 1.2.3

Files changed (6) hide show
  1. index.php +3 -0
  2. jquery-smooth-scroll.php +116 -1
  3. js/jss-script.js +120 -1
  4. js/jss-script.min.js +1 -1
  5. lang/default.po +0 -26
  6. readme.txt +85 -1
index.php ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ <?php
2
+ // Sometimes index files do not works.
3
+ ?>
jquery-smooth-scroll.php CHANGED
@@ -1 +1,116 @@
1
- <?php
2
  Copyright 2012 Anand Kumar (blogsynthesis.com)
3
  This program is free software; you can redistribute it and/or modify
4
  it under the terms of the GNU General Public License, version 2, as
5
  published by the Free Software Foundation.
6
  This program is distributed in the hope that it will be useful,
7
  but WITHOUT ANY WARRANTY; without even the implied warranty of
8
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9
  GNU General Public License for more details.
10
  You should have received a copy of the GNU General Public License
11
  along with this program; if not, write to the Free Software
12
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
13
 
14
  Kindly check README.txt for more details about the plugin.
15
 
16
  // Load JavaScript and stylesheets
17
  $this->register_scripts_and_styles();
18
 
19
 
20
 
21
 
22
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  Copyright 2012 Anand Kumar (blogsynthesis.com)
2
  This program is free software; you can redistribute it and/or modify
3
  it under the terms of the GNU General Public License, version 2, as
4
  published by the Free Software Foundation.
5
  This program is distributed in the hope that it will be useful,
6
  but WITHOUT ANY WARRANTY; without even the implied warranty of
7
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8
  GNU General Public License for more details.
9
  You should have received a copy of the GNU General Public License
10
  along with this program; if not, write to the Free Software
11
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
12
 
13
  Kindly check README.txt for more details about the plugin.
14
 
15
  // Load JavaScript and stylesheets
16
  $this->register_scripts_and_styles();
17
 
18
 
19
 
20
 
21
 
22
+ <?php
23
+ /*
24
+ Plugin Name: jQuery Smooth Scroll
25
+ Version: 1.2.3
26
+ Plugin URI: http://www.blogsynthesis.com/wordpress-jquery-smooth-scroll-plugin/#utm_source=wpadmin&utm_medium=plugin&utm_campaign=smoothscrollplugin
27
+ 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.
28
+ Author: BlogSynthesis
29
+ Author URI: http://www.blogsynthesis.com/
30
+ License: GPL v3
31
+
32
+ jQuery Smooth Scroll Plugin
33
+ Copyright (C) 2012, Anand Kumar anand@blogsynthesis.com
34
+
35
+ This program is free software: you can redistribute it and/or modify
36
+ it under the terms of the GNU General Public License as published by
37
+ the Free Software Foundation, either version 3 of the License, or
38
+ (at your option) any later version.
39
+
40
+ This program is distributed in the hope that it will be useful,
41
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
42
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
43
+ GNU General Public License for more details.
44
+
45
+ You should have received a copy of the GNU General Public License
46
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
47
+ */
48
+
49
+ class BlogSynthesisSmoothScroll {
50
+
51
+
52
+ /*--------------------------------------------*
53
+ * Constants
54
+ *--------------------------------------------*/
55
+
56
+ const name = 'BlogSynthesis Scroll to Top';
57
+ const slug = 'blogsynthesis-scroll-to-top';
58
+
59
+
60
+ /*--------------------------------------------*
61
+ * Constructor
62
+ *--------------------------------------------*/
63
+
64
+ function __construct() {
65
+
66
+ // Define constants used throughout the plugin
67
+ $this->init_plugin_constants();
68
+
69
+ load_plugin_textdomain( 'blogsynthesis', false, dirname( plugin_basename( __FILE__ ) ) . '/lang' );
70
+
71
+ // Load JavaScript and stylesheets
72
+ $this->register_scripts_and_styles();
73
+
74
+ // Plugin Actions
75
+ add_action( 'wp_footer', array( $this, 'display_link' ) );
76
+
77
+ } // end constructor
78
+
79
+
80
+ /*--------------------------------------------*
81
+ * Core Functions
82
+ *---------------------------------------------*/
83
+
84
+ function display_link() {
85
+ ?>
86
+ <a id="scroll-to-top" href="#" title="<?php _e('Scroll to Top','blogsynthesis'); ?>"><?php _e('Top','blogsynthesis'); ?></a>
87
+ <?php
88
+ }
89
+
90
+
91
+ /*--------------------------------------------*
92
+ * Private Functions
93
+ *---------------------------------------------*/
94
+
95
+ // Initializes constants used for convenience throughout the plugin.
96
+ private function init_plugin_constants() {
97
+
98
+ if ( !defined( 'PLUGIN_NAME' ) ) {
99
+ define( 'PLUGIN_NAME', self::name );
100
+ }
101
+ if ( !defined( 'PLUGIN_SLUG' ) ) {
102
+ define( 'PLUGIN_SLUG', self::slug );
103
+ }
104
+
105
+ } // end init_plugin_constants
106
+
107
+ // Registers and enqueues stylesheets
108
+ private function register_scripts_and_styles() {
109
+ if ( is_admin() ) {
110
+ // no admin styes or scripts
111
+ } else {
112
+ $this->load_file( self::slug . '-script', '/js/jss-script.min.js', true );
113
+ $this->load_file( self::slug . '-style', '/css/jss-style.min.css' );
114
+ } // end if/else
115
+ } // end register_scripts_and_styles
116
+
117
+ // Helper function for registering and enqueueing scripts and styles.
118
+ private function load_file( $name, $file_path, $is_script = false ) {
119
+
120
+ $url = plugins_url($file_path, __FILE__);
121
+ $file = plugin_dir_path(__FILE__) . $file_path;
122
+
123
+ if( file_exists( $file ) ) {
124
+ if( $is_script ) {
125
+ wp_register_script( $name, $url, array('jquery') );
126
+ wp_enqueue_script( $name );
127
+ } else {
128
+ wp_register_style( $name, $url );
129
+ wp_enqueue_style( $name );
130
+ } // end if
131
+ } // end if
132
+
133
+ } // end load_file
134
+
135
+
136
+ } // end class
137
+ new BlogSynthesisSmoothScroll();
js/jss-script.js CHANGED
@@ -1 +1,120 @@
1
- jQuery.noConflict();
2
  function filterPath(string) {
3
  return string
4
  .replace(/^\//,'')
5
  .replace(/(index|default).[a-zA-Z]{3,4}$/,'')
6
  .replace(/\/$/,'');
7
  }
8
  var locationPath = filterPath(location.pathname);
9
  var scrollElem = scrollableElement('html', 'body');
10
 
11
  $('a[href*=#]').each(function() {
12
  var thisPath = filterPath(this.pathname) || locationPath;
13
  if ( locationPath == thisPath
14
  && (location.hostname == this.hostname || !this.hostname)
15
  && this.hash.replace(/#/,'') ) {
16
  var $target = $(this.hash), target = this.hash;
17
  if (target) {
18
  var targetOffset = $target.offset().top;
19
  $(this).click(function(event) {
20
  event.preventDefault();
21
  $(scrollElem).animate({scrollTop: targetOffset}, 400, function() {
22
  location.hash = target;
23
  });
24
  });
25
  }
26
  }
27
  });
28
 
29
  // use the first element that is "scrollable"
30
  function scrollableElement(els) {
31
  for (var i = 0, argLength = arguments.length; i <argLength; i++) {
32
  var el = arguments[i],
33
  $scrollElement = $(el);
34
  if ($scrollElement.scrollTop()> 0) {
35
  return el;
36
  } else {
37
  $scrollElement.scrollTop(1);
38
  var isScrollable = $scrollElement.scrollTop()> 0;
39
  $scrollElement.scrollTop(0);
40
  if (isScrollable) {
41
  return el;
42
  }
43
  }
44
  }
45
  return [];
46
  }
47
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  function filterPath(string) {
2
  return string
3
  .replace(/^\//,'')
4
  .replace(/(index|default).[a-zA-Z]{3,4}$/,'')
5
  .replace(/\/$/,'');
6
  }
7
  var locationPath = filterPath(location.pathname);
8
  var scrollElem = scrollableElement('html', 'body');
9
 
10
  $('a[href*=#]').each(function() {
11
  var thisPath = filterPath(this.pathname) || locationPath;
12
  if ( locationPath == thisPath
13
  && (location.hostname == this.hostname || !this.hostname)
14
  && this.hash.replace(/#/,'') ) {
15
  var $target = $(this.hash), target = this.hash;
16
  if (target) {
17
  var targetOffset = $target.offset().top;
18
  $(this).click(function(event) {
19
  event.preventDefault();
20
  $(scrollElem).animate({scrollTop: targetOffset}, 400, function() {
21
  location.hash = target;
22
  });
23
  });
24
  }
25
  }
26
  });
27
 
28
  // use the first element that is "scrollable"
29
  function scrollableElement(els) {
30
  for (var i = 0, argLength = arguments.length; i <argLength; i++) {
31
  var el = arguments[i],
32
  $scrollElement = $(el);
33
  if ($scrollElement.scrollTop()> 0) {
34
  return el;
35
  } else {
36
  $scrollElement.scrollTop(1);
37
  var isScrollable = $scrollElement.scrollTop()> 0;
38
  $scrollElement.scrollTop(0);
39
  if (isScrollable) {
40
  return el;
41
  }
42
  }
43
  }
44
  return [];
45
  }
46
 
47
+ /* Smooth Back to Top, Get This functionality from: http://wordpress.org/extend/plugins/cudazi-scroll-to-top/ */
48
+
49
+ jQuery.noConflict();
50
+ jQuery(function($) {
51
+
52
+ // When to show the scroll link
53
+ // higher number = scroll link appears further down the page
54
+ var upperLimit = 100;
55
+
56
+ // Our scroll link element
57
+ var scrollElem = $('a#scroll-to-top');
58
+
59
+ // Scroll to top speed
60
+ var scrollSpeed = 500;
61
+
62
+ // Show and hide the scroll to top link based on scroll position
63
+ scrollElem.hide();
64
+ $(window).scroll(function () {
65
+ var scrollTop = $(document).scrollTop();
66
+ if ( scrollTop > upperLimit ) {
67
+ $(scrollElem).stop().fadeTo(300, 1); // fade back in
68
+ }else{
69
+ $(scrollElem).stop().fadeTo(300, 0); // fade out
70
+ }
71
+ });
72
+
73
+ // Scroll to top animation on click
74
+ $(scrollElem).click(function(){
75
+ $('html, body').animate({scrollTop:0}, scrollSpeed); return false;
76
+ });
77
+
78
+ });
79
+
80
+
81
+ /* Smooth Scroll Links, Get This functionality from: http://wordpress.org/extend/plugins/easy-smooth-scroll-links/ */
82
+ var ss = {
83
+ fixAllLinks: function () {
84
+ var allLinks = document.getElementsByTagName('a');
85
+ for (var i = 0; i < allLinks.length; i++) {
86
+ var lnk = allLinks[i];
87
+ if ((lnk.href && lnk.href.indexOf('#') != -1) && ((lnk.pathname == location.pathname) || ('/' + lnk.pathname == location.pathname)) && (lnk.search == location.search)) {
88
+ ss.addEvent(lnk, 'click', ss.smoothScroll);
89
+ }
90
+ }
91
+ },
92
+ smoothScroll: function (e) {
93
+ if (window.event) {
94
+ target = window.event.srcElement;
95
+ } else if (e) {
96
+ target = e.target;
97
+ } else return;
98
+ if (target.nodeName.toLowerCase() != 'a') {
99
+ target = target.parentNode;
100
+ }
101
+ if (target.nodeName.toLowerCase() != 'a') return;
102
+ anchor = target.hash.substr(1);
103
+ var allLinks = document.getElementsByTagName('a');
104
+ var destinationLink = null;
105
+ for (var i = 0; i < allLinks.length; i++) {
106
+ var lnk = allLinks[i];
107
+ if (lnk.name && (lnk.name == anchor)) {
108
+ destinationLink = lnk;
109
+ break;
110
+ }
111
+ }
112
+ if (!destinationLink) destinationLink = document.getElementById(anchor);
113
+ if (!destinationLink) return true;
114
+ var destx = destinationLink.offsetLeft;
115
+ var desty = destinationLink.offsetTop;
116
+ var thisNode = destinationLink;
117
+ while (thisNode.offsetParent && (thisNode.offsetParent != document.body)) {
118
+ thisNode = thisNode.offsetParent;
119
+ destx += thisNode.offsetLeft;
120
+ desty += thisNode.offsetTop;
121
+ }
122
+ clearInterval(ss.INTERVAL);
123
+ cypos = ss.getCurrentYPos();
124
+ ss_stepsize = parseInt((desty - cypos) / ss.STEPS);
125
+ ss.INTERVAL = setInterval('ss.scrollWindow(' + ss_stepsize + ',' + desty + ',"' + anchor + '")', 10);
126
+ if (window.event) {
127
+ window.event.cancelBubble = true;
128
+ window.event.returnValue = false;
129
+ }
130
+ if (e && e.preventDefault && e.stopPropagation) {
131
+ e.preventDefault();
132
+ e.stopPropagation();
133
+ }
134
+ },
135
+ scrollWindow: function (scramount, dest, anchor) {
136
+ wascypos = ss.getCurrentYPos();
137
+ isAbove = (wascypos < dest);
138
+ window.scrollTo(0, wascypos + scramount);
139
+ iscypos = ss.getCurrentYPos();
140
+ isAboveNow = (iscypos < dest);
141
+ if ((isAbove != isAboveNow) || (wascypos == iscypos)) {
142
+ window.scrollTo(0, dest);
143
+ clearInterval(ss.INTERVAL);
144
+ location.hash = anchor;
145
+ }
146
+ },
147
+ getCurrentYPos: function () {
148
+ if (document.body && document.body.scrollTop) return document.body.scrollTop;
149
+ if (document.documentElement && document.documentElement.scrollTop) return document.documentElement.scrollTop;
150
+ if (window.pageYOffset) return window.pageYOffset;
151
+ return 0;
152
+ },
153
+ addEvent: function (elm, evType, fn, useCapture) {
154
+ if (elm.addEventListener) {
155
+ elm.addEventListener(evType, fn, useCapture);
156
+ return true;
157
+ } else if (elm.attachEvent) {
158
+ var r = elm.attachEvent("on" + evType, fn);
159
+ return r;
160
+ } else {
161
+ alert("Handler could not be removed");
162
+ }
163
+ }
164
+ }
165
+ ss.STEPS = 25;
166
+ ss.addEvent(window, "load", ss.fixAllLinks);
js/jss-script.min.js CHANGED
@@ -1 +1 @@
1
- jQuery.noConflict();jQuery(function(d){var a=100;var c=d("a#scroll-to-top");var b=500;c.hide();d(window).scroll(function(){var e=d(document).scrollTop();if(e>a){d(c).stop().fadeTo(300,1);}else{d(c).stop().fadeTo(300,0);}});d(c).click(function(){d("html, body").animate({scrollTop:0},b);return false;});});
1
+ jQuery.noConflict();jQuery(function(e){var t=100;var n=e("a#scroll-to-top");var r=500;n.hide();e(window).scroll(function(){var r=e(document).scrollTop();if(r>t){e(n).stop().fadeTo(300,1)}else{e(n).stop().fadeTo(300,0)}});e(n).click(function(){e("html, body").animate({scrollTop:0},r);return false})});
lang/default.po DELETED
@@ -1,26 +0,0 @@
1
- msgid ""
2
- msgstr ""
3
- "Project-Id-Version: Cudazi Scroll to Top\n"
4
- "Report-Msgid-Bugs-To: \n"
5
- "POT-Creation-Date: 2012-01-19 10:40-0600\n"
6
- "PO-Revision-Date: 2012-01-19 10:40-0600\n"
7
- "Last-Translator: Cudazi <info@cudazi.com>\n"
8
- "Language-Team: \n"
9
- "MIME-Version: 1.0\n"
10
- "Content-Type: text/plain; charset=UTF-8\n"
11
- "Content-Transfer-Encoding: 8bit\n"
12
- "X-Poedit-KeywordsList: _e;__\n"
13
- "X-Poedit-Basepath: .\n"
14
- "X-Poedit-Language: English\n"
15
- "X-Poedit-Country: United States\n"
16
- "X-Poedit-SearchPath-0: .\n"
17
- "X-Poedit-SearchPath-1: ..\n"
18
-
19
- #: ../plugin.php:68
20
- msgid "Scroll to Top"
21
- msgstr ""
22
-
23
- #: ../plugin.php:68
24
- msgid "Top"
25
- msgstr ""
26
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
readme.txt CHANGED
@@ -1 +1,85 @@
1
- === jQuery Smooth Scroll ===
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === jQuery Smooth Scroll ===
2
+ Contributors: BlogSynthesis
3
+ Tags: Smooth Scroll, smooth scroll anchor, scroll to top, scroll, back to top, jquery, top of page
4
+ Author: BlogSynthesis
5
+ Donate link: http://www.blogsynthesis.com/
6
+ Requires at least: 3.0.0
7
+ Tested up to: 3.5
8
+ Stable tag: 1.2.3
9
+ License: GPLv2 or later
10
+ License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
+
12
+ Smooth scrolling and smooth "back to top" by activate and forget.
13
+
14
+ == Description ==
15
+
16
+ This plugin makes your anchor text to smooth scroll adds a smooth scroll to top feature/link in the lower-right corner of long pages. Appears after a set scrolling point and hides after scrolling near the top. This plugin is based on cudazi's plugin "Scroll to Top", and you may use this plugin if you need "Scroll to top" feature.
17
+
18
+ Features include:
19
+
20
+ * Smooth Scrolling for all anchor texts.
21
+ * A back to top button on right hand side.
22
+ * No unnecessary menu item in WordPress Dashboard.
23
+ * Easy customization with some css/js code edit.
24
+ * All CSS and JS files are compressed to score high in Google Page Speed score.
25
+
26
+ Visit [BlogSynthesis Plugin Page](http://www.blogsynthesis.com/wordpress-jquery-smooth-scroll-plugin/) for more information. We will post how to add "jQuery Smooth Slider" to your blog without installing plugin.
27
+
28
+ http://www.youtube.com/watch?v=2gsdGOPfqF0
29
+
30
+ There is a major javascript change in the version 1.2.0. This version should work on your site even if WordPress Toolbar is enabled. Earlier there waere some issues.
31
+
32
+ == Installation ==
33
+
34
+ 1. Upload the plugin in 'Plugins > Add New' or FTP into the '/wp-content/plugins/' directory.
35
+ 2. Activate the plugin through the 'Plugins' menu in WordPress.
36
+ 3. Visit a long page and start scrolling down to see the link appear.
37
+
38
+ == Frequently Asked Questions ==
39
+
40
+ = Why I am not able to find any menu link in my WordPress Dashboard? =
41
+ Because there is no such link or menu item. If you need any customization feel free to ask at [WordPress.org forums](http://wordpress.org/support/plugin/jquery-smooth-scroll)
42
+
43
+ = Can I use a custom icon? =
44
+
45
+ Yes, just overwrite the arrow.png image or use the included PSD to tweak.
46
+
47
+ = Can I adjust the point when the icon/link appears? =
48
+
49
+ Yes, just edit the upperLimit value in js/jss-script.min.js.
50
+
51
+ = Why everything looks weird in js and css files? =
52
+
53
+ Because these files are compressed. I have included reader friendly files i.e. js/jss-script.min.js and css/jss-style.js
54
+
55
+ = I don't want to add a plugin. How do I add these functionality without a plugin? =
56
+ Of course you can do this. I will add a blog post about how to do this without any plugin. But remember, you can't get automatic upgrade in this condition. BTW, Follow [BlogSynthesis](http://www.blogsynthesis.com) for any update.
57
+
58
+ Note: This plugin is based on "Cudazi scroll to top" and "easy smooth scroll links" plugins.
59
+
60
+ == Screenshots ==
61
+
62
+ 1. Example usage on light background
63
+ 2. Example usage on dark background
64
+
65
+ == Changelog ==
66
+
67
+ = 1.2.0 =
68
+ * Fixed Incompatibility with Hello Bar Plugin.
69
+ * Added Easy Smooth Scroll links script.
70
+
71
+ = 1.2.0 =
72
+ * Major js change
73
+
74
+ = 1.1.0 =
75
+ * Youtube video added
76
+
77
+ = 1.0.1 =
78
+ * Improved readme.txt for WordPress.org plugin library.
79
+ * Initial release at [WordPress.org](http://wordpress.org/extend/plugins/jquery-smooth-scroll/)
80
+
81
+ = 1.0.0 =
82
+ * Initial release at [www.blogsynthesis.com](www.blogsynthesis.com/wordpress-jquery-smooth-scroll-plugin/)
83
+
84
+ == Upgrade Notice ==
85
+ The current version of jQuery Smooth Scroll requires WordPress 3.1 or higher. If you use older version of WordPress, you need to upgrade WordPress first.