Skip to content

Commit c98dd30

Browse files
committed
Merge branch 'master' into gh-pages
2 parents f0ae363 + bf6705f commit c98dd30

16 files changed

+779
-409
lines changed

.jscsrc

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
{
2+
"esnext": true,
3+
"requireCurlyBraces": [
4+
"if",
5+
"else",
6+
"for",
7+
"while",
8+
"do",
9+
"try",
10+
"catch"
11+
],
12+
"requireSpaceAfterKeywords": [
13+
"if",
14+
"else",
15+
"for",
16+
"while",
17+
"do",
18+
"switch",
19+
"case",
20+
"return",
21+
"try",
22+
"catch",
23+
"typeof"
24+
],
25+
"requireSpaceBeforeBlockStatements": true,
26+
"requireParenthesesAroundIIFE": true,
27+
"requireSpacesInConditionalExpression": true,
28+
"disallowSpacesInNamedFunctionExpression": {
29+
"beforeOpeningRoundBrace": true
30+
},
31+
"disallowSpacesInFunctionDeclaration": {
32+
"beforeOpeningRoundBrace": true
33+
},
34+
"requireSpaceBetweenArguments": true,
35+
"requireBlocksOnNewline": true,
36+
"disallowEmptyBlocks": true,
37+
"disallowSpacesInsideArrayBrackets": true,
38+
"disallowSpacesInsideParentheses": true,
39+
"disallowDanglingUnderscores": true,
40+
"requireCommaBeforeLineBreak": true,
41+
"disallowSpacesInCallExpression": true,
42+
"disallowSpaceAfterPrefixUnaryOperators": true,
43+
"disallowSpaceBeforePostfixUnaryOperators": true,
44+
"disallowSpaceBeforeBinaryOperators": [
45+
","
46+
],
47+
"requireSpacesInForStatement": true,
48+
"requireSpaceBeforeBinaryOperators": true,
49+
"requireSpaceAfterBinaryOperators": true,
50+
"disallowKeywords": [
51+
"with"
52+
],
53+
"disallowMixedSpacesAndTabs": true,
54+
"disallowTrailingWhitespace": true,
55+
"disallowKeywordsOnNewLine": [
56+
"else"
57+
],
58+
"requireLineFeedAtFileEnd": true,
59+
"requireCapitalizedConstructors": true,
60+
"requireDotNotation": true,
61+
"disallowNewlineBeforeBlockStatements": true,
62+
"disallowMultipleLineStrings": true,
63+
"requireSpaceBeforeObjectValues": true,
64+
"validateQuoteMarks": "'",
65+
"requireSpaceAfterLineComment": true,
66+
"validateIndentation": 2,
67+
"validateLineBreaks": "LF",
68+
"disallowSpacesInFunction": {
69+
"beforeOpeningRoundBrace": true
70+
},
71+
"requireSpacesInFunction": {
72+
"beforeOpeningCurlyBrace": true
73+
},
74+
"disallowMultipleLineBreaks": true,
75+
"disallowYodaConditions": true,
76+
"disallowFunctionDeclarations": true,
77+
"disallowMultipleVarDecl": "exceptUndefined",
78+
"requirePaddingNewlinesBeforeKeywords": [
79+
"do",
80+
"for",
81+
"if",
82+
"switch",
83+
"try",
84+
"void",
85+
"while",
86+
"return"
87+
],
88+
"excludeFiles": ["**/node_modules/**", "**/min/**", "**/*.min.js"]
89+
}

Gruntfile.js

Lines changed: 29 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ module.exports = function(grunt) {
1818
// Project configuration.
1919
grunt.initConfig({
2020
pluginName: 'smooth-scroll',
21-
bower: './bower.json',
2221
pkg: grunt.file.readJSON('package.json'),
2322
meta: {
2423
banner: '/*!<%= "\\n" %>' +
@@ -27,12 +26,11 @@ module.exports = function(grunt) {
2726
'<%= pkg.homepage ? " * " + pkg.homepage + "\\n" : "" %>' +
2827
' * Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author.name %>' +
2928
'<%= "\\n" %>' +
30-
' * Licensed <%= _.pluck(pkg.licenses, "type").join(", ") %>' +
31-
' (<%= _.pluck(pkg.licenses, "url").join(", ") %>)' +
29+
' * Licensed <%= pkg.license %>' +
3230
'<%= "\\n" %>' + ' */' +
3331
'<%= "\\n\\n" %>'
3432
},
35-
concat: {
33+
concat: {
3634
all: {
3735
src: ['src/jquery.<%= pluginName %>.js'],
3836
dest: 'jquery.<%= pluginName %>.js'
@@ -41,8 +39,8 @@ module.exports = function(grunt) {
4139
stripBanners: true,
4240
banner: '<%= meta.banner %>',
4341
process: function(src) {
44-
var umdHead = grunt.file.read('lib/tmpl/umdhead.tpl'),
45-
umdFoot = grunt.file.read('lib/tmpl/umdfoot.tpl');
42+
var umdHead = grunt.file.read('lib/tmpl/umdhead.tpl');
43+
var umdFoot = grunt.file.read('lib/tmpl/umdfoot.tpl');
4644

4745
src = src
4846
.replace('(function($) {', umdHead)
@@ -58,7 +56,8 @@ module.exports = function(grunt) {
5856
'jquery.<%= pluginName %>.min.js': ['<%= concat.all.dest %>']
5957
},
6058
options: {
61-
preserveComments: 'some'
59+
banner: '<%= meta.banner %>',
60+
// preserveComments: /\/\*[\s\S]*/
6261
}
6362
}
6463
},
@@ -77,6 +76,7 @@ module.exports = function(grunt) {
7776
all: ['Gruntfile.js', 'src/**/*.js'],
7877
options: {
7978
curly: true,
79+
devel: true,
8080
eqeqeq: true,
8181
unused: true,
8282
immed: true,
@@ -94,78 +94,48 @@ module.exports = function(grunt) {
9494
}
9595
}
9696
},
97+
jscs: {
98+
src: 'src/**/*.js',
99+
options: {
100+
config: '.jscsrc',
101+
fix: true,
102+
verbose: true
103+
}
104+
},
97105
version: {
98-
patch: {
106+
107+
files: {
99108
src: [
100109
'package.json',
101-
'<%= pluginName %>.jquery.json',
102-
'bower.json',
103110
'src/jquery.<%= pluginName %>.js',
104111
'jquery.<%= pluginName %>.js'
105-
],
106-
options: {
107-
release: 'patch'
108-
}
109-
},
110-
same: {
111-
src: ['package.json', 'src/jquery.<%= pluginName %>.js', 'jquery.<%= pluginName %>.js']
112+
]
112113
},
113-
bannerPatch: {
114+
banner: {
114115
src: ['jquery.<%= pluginName %>.js'],
115116
options: {
116-
prefix: '- v',
117-
release: 'patch'
117+
prefix: '- v'
118118
}
119-
}
120-
}
121-
});
122-
123-
grunt.registerTask( 'configs', 'Update json configs based on package.json', function() {
124-
var pkg = grunt.file.readJSON('package.json'),
125-
pkgBasename = grunt.config('pluginName'),
126-
bowerFile = grunt.config('bower'),
127-
bower = grunt.file.readJSON(bowerFile),
128-
jqConfigFile = pkgBasename + '.jquery.json',
129-
jqConfig = grunt.file.readJSON(jqConfigFile);
130-
131-
['main', 'version', 'dependencies', 'keywords'].forEach(function(el) {
132-
bower[el] = pkg[el];
133-
jqConfig[el] = pkg[el];
134-
});
135-
136-
['author', 'repository', 'homepage', 'docs', 'bugs', 'demo', 'licenses'].forEach(function(el) {
137-
jqConfig[el] = pkg[el];
138-
});
139-
140-
jqConfig.keywords.shift();
141-
142-
jqConfig.name = pkgBasename;
143-
bower.name = 'jquery-' + pkgBasename;
144-
145-
grunt.file.write( bowerFile, JSON.stringify(bower, null, 2) + '\n');
146-
grunt.log.writeln( 'File "' + bowerFile + '" updated."' );
119+
},
147120

148-
while ( /jquery/i.test(jqConfig.keywords[0]) ) {
149-
jqConfig.keywords.shift();
150121
}
151-
152-
grunt.file.write( jqConfigFile, JSON.stringify(jqConfig, null, 2) + '\n');
153-
grunt.log.writeln( 'File "' + jqConfigFile + '" updated."' );
154122
});
155123

156124
grunt.registerTask('docs', 'Convert readme.md to html and concat with header and footer for index.html', function() {
157-
var readme = grunt.file.read('readme.md'),
158-
head = grunt.template.process( grunt.file.read('lib/tmpl/header.tpl') ),
159-
foot = grunt.file.read('lib/tmpl/footer.tpl'),
160-
doc = marked(readme);
125+
var readme = grunt.file.read('readme.md');
126+
var head = grunt.template.process(grunt.file.read('lib/tmpl/header.tpl'));
127+
var foot = grunt.file.read('lib/tmpl/footer.tpl');
128+
var doc = marked(readme);
161129

162130
grunt.file.write('index.html', head + doc + foot);
163131
});
164132

165-
grunt.registerTask('build', ['jshint', 'concat', 'version:same', 'configs', 'uglify', 'docs']);
166-
grunt.registerTask('patch', ['jshint', 'concat', 'version:bannerPatch', 'version:patch', 'configs', 'uglify']);
133+
grunt.registerTask('lint', ['jshint', 'jscs']);
134+
grunt.registerTask('build', ['lint', 'concat', 'version', 'uglify', 'docs']);
135+
grunt.registerTask('patch', ['lint', 'concat', 'version::patch', 'uglify']);
167136
grunt.registerTask('default', ['build']);
168137

138+
grunt.loadNpmTasks('grunt-jscs');
169139
grunt.loadNpmTasks('grunt-contrib-jshint');
170140
grunt.loadNpmTasks('grunt-contrib-uglify');
171141
grunt.loadNpmTasks('grunt-contrib-concat');

bower.json

Lines changed: 0 additions & 21 deletions
This file was deleted.

demo/hashchange.html

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<title>Smooth Scroll jQuery Plugin Demo</title>
6+
<style type="text/css">
7+
body {
8+
font-family: "Helvetica Neue", Helvetica, sans-serif;
9+
}
10+
.container {
11+
margin: 40px auto;
12+
width: 200px;
13+
}
14+
h2 {
15+
text-align: center;
16+
}
17+
</style>
18+
</head>
19+
<body>
20+
<h2>Smooth Scroll jQuery Plugin with Back Button Support</h2>
21+
<div class="container">
22+
<ul id="nav">
23+
<li><a href="#p1">p1</a></li>
24+
<li><a href="#p2">p2</a></li>
25+
<li><a href="#p3">p3</a></li>
26+
<li><a href="#p4">p4</a></li>
27+
<li><a href="#p5">p5</a></li>
28+
<li><a href="index.html#p5">index.html#p5</a> (goes to new page)</li>
29+
<li><a href="#">#</a></li>
30+
31+
<li><a href="#not-here">not-here</a></li>
32+
</ul>
33+
<p id="p1">p1 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
34+
<p id="p2">p2 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
35+
<a href="#nav">back to nav</a>
36+
<p id="p3">p3 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
37+
<a href="#nav">back to nav</a>
38+
<p id="p4">p4 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
39+
<a href="#nav">back to nav</a>
40+
<p id="p5">p5 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
41+
<a href="#nav">back to nav</a>
42+
<p id="p6">p6 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
43+
<a href="#nav">back to nav</a>
44+
45+
</div>
46+
<script src="../lib/jquery/jquery.js"></script>
47+
<script src="../src/jquery.smooth-scroll.js"></script>
48+
<script>
49+
$('a[href*="#"]')
50+
.bind('click', function(event) {
51+
var hash = this.hash.replace(/[#<>]/g, '')
52+
53+
if (this.pathname === location.pathname) {
54+
event.preventDefault();
55+
}
56+
57+
if (hash) {
58+
location.hash = '#/' + hash;
59+
}
60+
})
61+
62+
$(window).bind('hashchange', function(event) {
63+
$.smoothScroll({
64+
scrollTarget: '#' + location.hash.replace(/^\#\/?/, '')
65+
});
66+
});
67+
</script>
68+
69+
</body>
70+
</html>

0 commit comments

Comments
 (0)