Skip to content

Commit

Permalink
v0.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
gilbarbara committed Oct 7, 2016
1 parent 82d98fe commit 3a2f532
Show file tree
Hide file tree
Showing 7 changed files with 160 additions and 172 deletions.
14 changes: 1 addition & 13 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ root = true
[*]
# change these settings to your own preference
indent_style = space
indent_size = 4
indent_size = 2

# we recommend you to keep these unchanged
end_of_line = lf
Expand All @@ -17,15 +17,3 @@ insert_final_newline = true

[*.md]
trim_trailing_whitespace = false

[*.json]
indent_style = space
indent_size = 2

[{.eslintrc,.scss-lint.yml}]
indent_style = space
indent_size = 2

[*.{scss,sass}]
indent_style = space
indent_size = 2
8 changes: 1 addition & 7 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,8 @@
"env": {
"amd": true,
"browser": true,
"jquery": true,
"mocha": true,
"node": true
},
"globals": {
"$": true
},
"rules": {
"strict": 0,
// Possible Errors
Expand Down Expand Up @@ -122,6 +117,7 @@
"consistent-this": [1, "self"],
"eol-last": 1,
"key-spacing": 1,
"keyword-spacing": 1,
"lines-around-comment": [0, { "beforeBlockComment": true, "beforeLineComment": true }],
"linebreak-style": [1, "unix"],
"max-nested-callbacks": [2, 4],
Expand Down Expand Up @@ -156,11 +152,9 @@
"after": true
}
],
"space-after-keywords": 1,
"space-before-blocks": 1,
"space-before-function-paren": 1,
"space-infix-ops": 1,
"space-return-throw-case": 1,
"space-unary-ops": 1,
// Node
"callback-return": [2, ["callback", "cb", "next"]],
Expand Down
5 changes: 4 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
language: node_js
node_js:
- '0.10'
- "0.12"
- "4"
- "5"
- "6"
deploy:
provider: npm
email: [email protected]
Expand Down
143 changes: 72 additions & 71 deletions dist/disable-scroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,87 +8,88 @@
}
}(this, function() {
var disableScroll = {
// spacebar: 32, pageup: 33, pagedown: 34, end: 35, home: 36
// left: 37, up: 38, right: 39, down: 40
options: {
disableWheel: true,
disableScrollbar: true,
disableKeys: true,
scrollEventKeys: [32, 33, 34, 35, 36, 37, 38, 39, 40]
},
element: document.body,
lockToScrollPos: [0, 0],
// spacebar: 32, pageup: 33, pagedown: 34, end: 35, home: 36
// left: 37, up: 38, right: 39, down: 40
options: {
disableWheel: true,
disableScrollbar: true,
disableKeys: true,
scrollEventKeys: [32, 33, 34, 35, 36, 37, 38, 39, 40]
},
element: document.body,
lockToScrollPos: [0, 0],

/**
* Disable Page Scroll
* @external Node
*
* @param {external:Node} [element] - DOM Element, usually document.body
* @param {object} [options] - Change the initial options
*/
on: function (element, options) {
this.element = element || document.body;
this.options = this._extend(this.options, options);
/**
* Disable Page Scroll
* @external Node
*
* @param {external:Node} [element] - DOM Element, usually document.body
* @param {object} [options] - Change the initial options
*/
on: function (element, options) {
this.element = element || document.body;
this.options = this._extend(this.options, options);

if (this.options.disableWheel) {
document.addEventListener('mousewheel', this._handleWheel);
document.addEventListener('DOMMouseScroll', this._handleWheel);
document.addEventListener('touchmove', this._handleWheel);
}
if (this.options.disableWheel) {
document.addEventListener('mousewheel', this._handleWheel);
document.addEventListener('DOMMouseScroll', this._handleWheel);
document.addEventListener('touchmove', this._handleWheel);
}

if (this.options.disableScrollbar) {
this.lockToScrollPos = [
this.element.scrollLeft,
this.element.scrollTop
];
this._disableScrollbarFn = this._handleScrollbar.bind(this);
document.addEventListener('scroll', this._disableScrollbarFn);
}
if (this.options.disableScrollbar) {
this.lockToScrollPos = [
this.element.scrollLeft,
this.element.scrollTop
];
this._disableScrollbarFn = this._handleScrollbar.bind(this);
document.addEventListener('scroll', this._disableScrollbarFn);
}

if (this.options.disableKeys) {
this._disableKeysFn = this._handleKeydown.bind(this);
document.addEventListener('keydown', this._disableKeysFn);
}
},
if (this.options.disableKeys) {
this._disableKeysFn = this._handleKeydown.bind(this);
document.addEventListener('keydown', this._disableKeysFn);
}
},

/**
* Re-enable page scrolls
*/
off: function () {
document.removeEventListener('mousewheel', this._handleWheel);
document.removeEventListener('DOMMouseScroll', this._handleWheel);
document.removeEventListener('touchmove', this._handleWheel);
document.removeEventListener('scroll', this._disableScrollbarFn);
document.removeEventListener('keydown', this._disableKeysFn);
},
/**
* Re-enable page scrolls
*/
off: function () {
document.removeEventListener('mousewheel', this._handleWheel);
document.removeEventListener('DOMMouseScroll', this._handleWheel);
document.removeEventListener('touchmove', this._handleWheel);
document.removeEventListener('scroll', this._disableScrollbarFn);
document.removeEventListener('keydown', this._disableKeysFn);
},

_handleWheel: function (e) {
e.preventDefault();
},
_handleWheel: function (e) {
e.preventDefault();
},

_handleScrollbar: function () {
window.scrollTo(this.lockToScrollPos[0], this.lockToScrollPos[1]);
},
_handleScrollbar: function () {
window.scrollTo(this.lockToScrollPos[0], this.lockToScrollPos[1]);
},

_handleKeydown: function (event) {
for (var i = 0; i < this.options.scrollEventKeys.length; i++) {
if (event.keyCode === this.options.scrollEventKeys[i]) {
event.preventDefault();
return false;
}
}
},
_handleKeydown: function (event) {
for (var i = 0; i < this.options.scrollEventKeys.length; i++) {
if (event.keyCode === this.options.scrollEventKeys[i]) {
event.preventDefault();
return false;
}
}
},

_extend: function (obj) {
Object.keys(Array.prototype.slice(arguments, 1)).forEach(function (source) {
for (var prop in source) {
if (source.hasOwnProperty(prop)) {
obj[prop] = source[prop];
}
}
});
return obj;
_extend: function (original, extender) {
var destination = original;

for (var prop in extender) {
if (extender.hasOwnProperty(prop)) {
destination[prop] = extender[prop];
}
}

return destination;
}
};

return disableScroll;
Expand Down
2 changes: 1 addition & 1 deletion dist/disable-scroll.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

133 changes: 67 additions & 66 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,91 +1,92 @@
var gulp = require('gulp'),
$ = require('gulp-load-plugins')(),
del = require('del'),
exec = require('child_process').exec,
merge = require('merge-stream'),
runSequence = require('run-sequence'),
vinylPaths = require('vinyl-paths');
var gulp = require('gulp'),
$ = require('gulp-load-plugins')(),
del = require('del'),
exec = require('child_process').exec,
merge = require('merge-stream'),
runSequence = require('run-sequence'),
vinylPaths = require('vinyl-paths');

var commitMessage = '';

// Script
gulp.task('lint', function () {
return gulp.src('lib/scripts/*')
.pipe($.eslint({
useEslintrc: true,
rules: {
'no-console': 2
}
}))
.pipe($.eslint.format())
.pipe($.eslint.failOnError());
gulp.task('lint', function() {
return gulp.src('lib/scripts/*')
.pipe($.eslint({
rules: {
'no-console': 2
}
}))
.pipe($.eslint.format())
.pipe($.eslint.failOnError());
});

gulp.task('scripts', ['lint'], function () {
return gulp.src(['index.js'])
.pipe($.umd({
exports: function () {
return 'disableScroll';
},
namespace: function () {
return 'disableScroll';
}
}))
.pipe($.replace('module.exports = disableScroll;\n\n', ''))
.pipe($.rename('disable-scroll.js'))
.pipe(gulp.dest('dist'))
.pipe($.uglify())
.pipe($.rename('disable-scroll.min.js'))
.pipe(gulp.dest('dist'));
gulp.task('scripts', ['lint'], function() {
return gulp.src(['index.js'])
.pipe($.umd({
exports: function() {
return 'disableScroll';
},
namespace: function() {
return 'disableScroll';
}
}))
.pipe($.replace('module.exports = disableScroll;\n\n', ''))
.pipe($.rename('disable-scroll.js'))
.pipe(gulp.dest('dist'))
.pipe($.uglify())
.pipe($.rename('disable-scroll.min.js'))
.pipe(gulp.dest('dist'));
});

gulp.task('clean', function (cb) {
return del(['dist/*'], cb);
gulp.task('clean', function(cb) {
return del(['dist/*'], cb);
});

gulp.task('get-commit', function (cb) {
exec('git log -1 --pretty=%s && git log -1 --pretty=%b', function (err, stdout, stderr) {
var parts = stdout.replace('\n\n', '').split('\n');
gulp.task('get-commit', function(cb) {
exec('git log -1 --pretty=%s && git log -1 --pretty=%b', function(err, stdout) {
var parts = stdout.replace('\n\n', '').split('\n');

commitMessage = parts[0];
if (parts[1]) {
commitMessage += ' — ' + parts[1];
}
commitMessage = parts[0];
if (parts[1]) {
commitMessage += ' — ' + parts[1];
}

cb(err);
});
cb(err);
});
});

gulp.task('gh-pages', function () {
gulp.task('gh-pages', function() {

var clean,
push;
var clean,
push;

clean = gulp.src('.publish/.DS_Store')
.pipe(vinylPaths(del));
clean = gulp.src('.publish/.DS_Store')
.pipe(vinylPaths(del));

push = gulp.src([
'index.html',
'dist/**/*'
], { base: './' })
.pipe($.ghPages({
branch: 'gh-pages',
message: commitMessage,
force: true
}));
push = gulp.src([
'index.html',
'dist/**/*'
], { base: './' })
.pipe($.ghPages({
branch: 'gh-pages',
message: commitMessage,
force: true
}));

return merge(clean, push);
return merge(clean, push);
});

gulp.task('deploy-pages', function (cb) {
runSequence(['build', 'get-commit'], 'gh-pages', cb);
gulp.task('deploy-pages', function(cb) {
runSequence(['build', 'get-commit'], 'gh-pages', cb);
});

gulp.task('serve', function () {
gulp.watch('index.js', ['build']);
gulp.task('serve', function() {
gulp.watch('index.js', ['build']);
});

gulp.task('build', function (cb) {
process.env.NODE_ENV = 'production';
runSequence('clean', 'scripts', cb);
gulp.task('build', function(cb) {
process.env.NODE_ENV = 'production';
runSequence('clean', 'scripts', cb);
});

gulp.task('default', ['build']);
Loading

0 comments on commit 3a2f532

Please sign in to comment.