diff --git a/Gruntfile.js b/Gruntfile.js index 77a9fee..17f0396 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -87,8 +87,9 @@ module.exports = function(grunt) { version: { patch: { src: [ - '<%= pluginName %>.jquery.json', 'package.json', + '<%= pluginName %>.jquery.json', + 'bower.json', 'src/jquery.<%= pluginName %>.js', 'jquery.<%= pluginName %>.js' ], @@ -136,7 +137,7 @@ module.exports = function(grunt) { grunt.registerTask( 'deploy', ['setshell:rsync', 'shell:rsync']); grunt.registerTask( 'configs', 'Update json configs based on package.json', function() { - var pkg = grunt.config('pkg'), + var pkg = grunt.file.readJSON('package.json'), pkgBasename = grunt.config('pluginName'), bowerFile = grunt.config('bower'), bower = grunt.file.readJSON(bowerFile), diff --git a/bower.json b/bower.json index 17bcf3b..49766a5 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "jquery.smooth-scroll", - "version": "1.5.0", + "version": "1.5.2", "dependencies": { "jquery": ">=1.3" }, diff --git a/index.html b/index.html index e2d9e7f..715124b 100644 --- a/index.html +++ b/index.html @@ -73,10 +73,20 @@
Allows for easy implementation of smooth scrolling for same-page links.
+Using npm:
+1 npm
install
jquery-smooth-scroll
+
+Using bower:
+1 bower
install
jquery-smooth-scroll
+
+The old-fashioned way:
+Go to the following URL in your browser and copy/paste the code into your own file: +https://raw.githubusercontent.com/kswedberg/jquery-smooth-scroll/master/jquery.smooth-scroll.js
$('a').smoothScroll();
$('#container a').smoothScroll();
$('#container a').smoothScroll({excludeWithin: ['.container2']});
The following options, shown with their default values, are available for both $.fn.smoothScroll
and $.smoothScroll
:
12345678910111213141516171819202122232425262728293031 {
offset: 0,
// one of 'top' or 'left'
direction:
'top'
,
// only use if you want to override default behavior
scrollTarget:
null
,
// fn(opts) function to be called before scrolling occurs.
// `this` is the element(s) being scrolled
beforeScroll:
function
() {},
// fn(opts) function to be called after scrolling occurs.
// `this` is the triggering element
afterScroll:
function
() {},
easing:
'swing'
,
// speed can be a number or 'auto'
// if 'auto', the speed will be calculated based on the formula:
// (current scroll position - target scroll position) / autoCoeffic
speed: 400,
// autoCoefficent: Only used when speed set to "auto".
// The higher this number, the faster the scroll speed
autoCoefficient: 2,
// $.fn.smoothScroll only: whether to prevent the default click action
preventDefault:
true
}
+12345678910111213141516171819202122232425262728293031 {
offset: 0,
// one of 'top' or 'left'
direction:
'top'
,
// only use if you want to override default behavior
scrollTarget:
null
,
// fn(opts) function to be called before scrolling occurs.
// `this` is the element(s) being scrolled
beforeScroll:
function
() {},
// fn(opts) function to be called after scrolling occurs.
// `this` is the triggering element
afterScroll:
function
() {},
easing:
'swing'
,
// speed can be a number or 'auto'
// if 'auto', the speed will be calculated based on the formula:
// (current scroll position - target scroll position) / autoCoeffic
speed: 400,
// autoCoefficent: Only used when speed set to "auto".
// The higher this number, the faster the scroll speed
autoCoefficient: 2,
// $.fn.smoothScroll only: whether to prevent the default click action
preventDefault:
true
}
The options object for $.fn.smoothScroll
can take two additional properties:
exclude
and excludeWithin
. The value for both of these is an array of
@@ -105,7 +115,7 @@
$.smoothScroll
document.body
)
Doesn't automatically fire, so you need to bind it to some other user
interaction. For example:
-1234567 $(
'button.scrollsomething'
).on(
'click'
,
function
() {
$.smoothScroll({
scrollElement: $(
'div.scrollme'
),
scrollTarget:
'#findme'
});
return
false
;
});
+1234567 $(
'button.scrollsomething'
).on(
'click'
,
function
() {
$.smoothScroll({
scrollElement: $(
'div.scrollme'
),
scrollTarget:
'#findme'
});
return
false
;
});
The $.smoothScroll
method can take one or two arguments.
@@ -119,7 +129,7 @@ $.smoothScroll
Additional Option
The following option, in addition to those listed for $.fn.smoothScroll
above, is available
for $.smoothScroll
:
-
12345 {
// jQuery set of elements you wish to scroll.
// if null (default), $('html, body').firstScrollable() is used.
scrollElement:
null
}
+12345 {
// jQuery set of elements you wish to scroll.
// if null (default), $('html, body').firstScrollable() is used.
scrollElement:
null
}
$.fn.scrollable
diff --git a/jquery.smooth-scroll.js b/jquery.smooth-scroll.js
index e87cf95..2136509 100644
--- a/jquery.smooth-scroll.js
+++ b/jquery.smooth-scroll.js
@@ -1,12 +1,12 @@
/*!
- * jQuery Smooth Scroll - v1.5.1 - 2014-10-01
+ * jQuery Smooth Scroll - v1.5.2 - 2014-10-01
* https://github.com/kswedberg/jquery-smooth-scroll
* Copyright (c) 2014 Karl Swedberg
* Licensed MIT (https://github.com/kswedberg/jquery-smooth-scroll/blob/master/LICENSE-MIT)
*/
(function($) {
-var version = '1.5.1',
+var version = '1.5.2',
optionOverrides = {},
defaults = {
exclude: [],
diff --git a/jquery.smooth-scroll.min.js b/jquery.smooth-scroll.min.js
index 688c43d..febc6aa 100644
--- a/jquery.smooth-scroll.min.js
+++ b/jquery.smooth-scroll.min.js
@@ -1,7 +1,7 @@
/*!
- * jQuery Smooth Scroll - v1.5.1 - 2014-10-01
+ * jQuery Smooth Scroll - v1.5.2 - 2014-10-01
* https://github.com/kswedberg/jquery-smooth-scroll
* Copyright (c) 2014 Karl Swedberg
* Licensed MIT (https://github.com/kswedberg/jquery-smooth-scroll/blob/master/LICENSE-MIT)
*/
-(function(t){function e(t){return t.replace(/(:|\.)/g,"\\$1")}var l="1.5.1",o={},s={exclude:[],excludeWithin:[],offset:0,direction:"top",scrollElement:null,scrollTarget:null,beforeScroll:function(){},afterScroll:function(){},easing:"swing",speed:400,autoCoefficient:2,preventDefault:!0},n=function(e){var l=[],o=!1,s=e.dir&&"left"===e.dir?"scrollLeft":"scrollTop";return this.each(function(){if(this!==document&&this!==window){var e=t(this);e[s]()>0?l.push(this):(e[s](1),o=e[s]()>0,o&&l.push(this),e[s](0))}}),l.length||this.each(function(){"BODY"===this.nodeName&&(l=[this])}),"first"===e.el&&l.length>1&&(l=[l[0]]),l};t.fn.extend({scrollable:function(t){var e=n.call(this,{dir:t});return this.pushStack(e)},firstScrollable:function(t){var e=n.call(this,{el:"first",dir:t});return this.pushStack(e)},smoothScroll:function(l,o){if(l=l||{},"options"===l)return o?this.each(function(){var e=t(this),l=t.extend(e.data("ssOpts")||{},o);t(this).data("ssOpts",l)}):this.first().data("ssOpts");var s=t.extend({},t.fn.smoothScroll.defaults,l),n=t.smoothScroll.filterPath(location.pathname);return this.unbind("click.smoothscroll").bind("click.smoothscroll",function(l){var o=this,r=t(this),i=t.extend({},s,r.data("ssOpts")||{}),c=s.exclude,a=i.excludeWithin,f=0,h=0,u=!0,d={},p=location.hostname===o.hostname||!o.hostname,m=i.scrollTarget||t.smoothScroll.filterPath(o.pathname)===n,S=e(o.hash);if(i.scrollTarget||p&&m&&S){for(;u&&c.length>f;)r.is(e(c[f++]))&&(u=!1);for(;u&&a.length>h;)r.closest(a[h++]).length&&(u=!1)}else u=!1;u&&(i.preventDefault&&l.preventDefault(),t.extend(d,i,{scrollTarget:i.scrollTarget||S,link:o}),t.smoothScroll(d))}),this}}),t.smoothScroll=function(e,l){if("options"===e&&"object"==typeof l)return t.extend(o,l);var s,n,r,i,c,a=0,f="offset",h="scrollTop",u={},d={};"number"==typeof e?(s=t.extend({link:null},t.fn.smoothScroll.defaults,o),r=e):(s=t.extend({link:null},t.fn.smoothScroll.defaults,e||{},o),s.scrollElement&&(f="position","static"===s.scrollElement.css("position")&&s.scrollElement.css("position","relative"))),h="left"===s.direction?"scrollLeft":h,s.scrollElement?(n=s.scrollElement,/^(?:HTML|BODY)$/.test(n[0].nodeName)||(a=n[h]())):n=t("html, body").firstScrollable(s.direction),s.beforeScroll.call(n,s),r="number"==typeof e?e:l||t(s.scrollTarget)[f]()&&t(s.scrollTarget)[f]()[s.direction]||0,u[h]=r+a+s.offset,i=s.speed,"auto"===i&&(c=u[h]-n.scrollTop(),0>c&&(c*=-1),i=c/s.autoCoefficient),d={duration:i,easing:s.easing,complete:function(){s.afterScroll.call(s.link,s)}},s.step&&(d.step=s.step),n.length?n.stop().animate(u,d):s.afterScroll.call(s.link,s)},t.smoothScroll.version=l,t.smoothScroll.filterPath=function(t){return t=t||"",t.replace(/^\//,"").replace(/(?:index|default).[a-zA-Z]{3,4}$/,"").replace(/\/$/,"")},t.fn.smoothScroll.defaults=s})(jQuery);
\ No newline at end of file
+(function(t){function e(t){return t.replace(/(:|\.)/g,"\\$1")}var l="1.5.2",o={},s={exclude:[],excludeWithin:[],offset:0,direction:"top",scrollElement:null,scrollTarget:null,beforeScroll:function(){},afterScroll:function(){},easing:"swing",speed:400,autoCoefficient:2,preventDefault:!0},n=function(e){var l=[],o=!1,s=e.dir&&"left"===e.dir?"scrollLeft":"scrollTop";return this.each(function(){if(this!==document&&this!==window){var e=t(this);e[s]()>0?l.push(this):(e[s](1),o=e[s]()>0,o&&l.push(this),e[s](0))}}),l.length||this.each(function(){"BODY"===this.nodeName&&(l=[this])}),"first"===e.el&&l.length>1&&(l=[l[0]]),l};t.fn.extend({scrollable:function(t){var e=n.call(this,{dir:t});return this.pushStack(e)},firstScrollable:function(t){var e=n.call(this,{el:"first",dir:t});return this.pushStack(e)},smoothScroll:function(l,o){if(l=l||{},"options"===l)return o?this.each(function(){var e=t(this),l=t.extend(e.data("ssOpts")||{},o);t(this).data("ssOpts",l)}):this.first().data("ssOpts");var s=t.extend({},t.fn.smoothScroll.defaults,l),n=t.smoothScroll.filterPath(location.pathname);return this.unbind("click.smoothscroll").bind("click.smoothscroll",function(l){var o=this,r=t(this),i=t.extend({},s,r.data("ssOpts")||{}),c=s.exclude,a=i.excludeWithin,f=0,h=0,u=!0,d={},p=location.hostname===o.hostname||!o.hostname,m=i.scrollTarget||t.smoothScroll.filterPath(o.pathname)===n,S=e(o.hash);if(i.scrollTarget||p&&m&&S){for(;u&&c.length>f;)r.is(e(c[f++]))&&(u=!1);for(;u&&a.length>h;)r.closest(a[h++]).length&&(u=!1)}else u=!1;u&&(i.preventDefault&&l.preventDefault(),t.extend(d,i,{scrollTarget:i.scrollTarget||S,link:o}),t.smoothScroll(d))}),this}}),t.smoothScroll=function(e,l){if("options"===e&&"object"==typeof l)return t.extend(o,l);var s,n,r,i,c,a=0,f="offset",h="scrollTop",u={},d={};"number"==typeof e?(s=t.extend({link:null},t.fn.smoothScroll.defaults,o),r=e):(s=t.extend({link:null},t.fn.smoothScroll.defaults,e||{},o),s.scrollElement&&(f="position","static"===s.scrollElement.css("position")&&s.scrollElement.css("position","relative"))),h="left"===s.direction?"scrollLeft":h,s.scrollElement?(n=s.scrollElement,/^(?:HTML|BODY)$/.test(n[0].nodeName)||(a=n[h]())):n=t("html, body").firstScrollable(s.direction),s.beforeScroll.call(n,s),r="number"==typeof e?e:l||t(s.scrollTarget)[f]()&&t(s.scrollTarget)[f]()[s.direction]||0,u[h]=r+a+s.offset,i=s.speed,"auto"===i&&(c=u[h]-n.scrollTop(),0>c&&(c*=-1),i=c/s.autoCoefficient),d={duration:i,easing:s.easing,complete:function(){s.afterScroll.call(s.link,s)}},s.step&&(d.step=s.step),n.length?n.stop().animate(u,d):s.afterScroll.call(s.link,s)},t.smoothScroll.version=l,t.smoothScroll.filterPath=function(t){return t=t||"",t.replace(/^\//,"").replace(/(?:index|default).[a-zA-Z]{3,4}$/,"").replace(/\/$/,"")},t.fn.smoothScroll.defaults=s})(jQuery);
\ No newline at end of file
diff --git a/package.json b/package.json
index 9000e7a..4128189 100644
--- a/package.json
+++ b/package.json
@@ -1,7 +1,7 @@
{
"name": "jquery-smooth-scroll",
"title": "jQuery Smooth Scroll",
- "version": "1.5.1",
+ "version": "1.5.2",
"scripts": {},
"main": "jquery.smooth-scroll.js",
"author": {
diff --git a/readme.md b/readme.md
index d92c7f9..fc0b841 100644
--- a/readme.md
+++ b/readme.md
@@ -1,10 +1,30 @@
# Smooth Scroll Plugin
+Allows for easy implementation of smooth scrolling for same-page links.
+
+## Download
+
+Using npm:
+
+```bash
+npm install jquery-smooth-scroll
+```
+
+Using bower:
+
+```bash
+bower install jquery-smooth-scroll
+```
+
+The old-fashioned way:
+
+Go to the following URL in your browser and copy/paste the code into your own file:
+https://raw.githubusercontent.com/kswedberg/jquery-smooth-scroll/master/jquery.smooth-scroll.js
+
## Features
### $.fn.smoothScroll
-* Allows for easy implementation of smooth scrolling for same-page links.
* Works like this: `$('a').smoothScroll();`
* Specify a containing element if you want: `$('#container a').smoothScroll();`
* Exclude links if they are within a containing element: `$('#container a').smoothScroll({excludeWithin: ['.container2']});`
diff --git a/smooth-scroll.jquery.json b/smooth-scroll.jquery.json
index e86eb2c..1e6164b 100644
--- a/smooth-scroll.jquery.json
+++ b/smooth-scroll.jquery.json
@@ -1,6 +1,6 @@
{
"name": "smooth-scroll",
- "version": "1.5.0",
+ "version": "1.5.2",
"title": "Smooth Scroll",
"description": "Easy implementation of smooth scrolling for same-page links",
"author": {
diff --git a/src/jquery.smooth-scroll.js b/src/jquery.smooth-scroll.js
index 03c739c..a8bb32d 100644
--- a/src/jquery.smooth-scroll.js
+++ b/src/jquery.smooth-scroll.js
@@ -1,5 +1,5 @@
(function($) {
-var version = '1.5.1',
+var version = '1.5.2',
optionOverrides = {},
defaults = {
exclude: [],