From fe3e5f299cde9da6158f41a1b765f1c5d8aa5ec1 Mon Sep 17 00:00:00 2001 From: Philip Klauzinski Date: Wed, 31 May 2017 02:42:33 -0500 Subject: [PATCH] Various updates * Added `.editorconfig` * Removed `jshint` and replaced with `eslint` * Added `.eslintrc` * Removed `uglify` and task to create minified version of jScroll source since this can be done on the user end, and it will also prevent conflicts in PRs * Removed `jquery.jscroll.min.js` --- .editorconfig | 7 +++ .eslintrc | 128 ++++++++++++++++++++++++++++++++++++++++++ .gitignore | 1 - Gruntfile.js | 47 ++-------------- jquery.jscroll.js | 14 ++--- jquery.jscroll.min.js | 12 ---- package.json | 8 +-- 7 files changed, 151 insertions(+), 66 deletions(-) create mode 100644 .editorconfig create mode 100644 .eslintrc delete mode 100644 jquery.jscroll.min.js diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..5293a9b --- /dev/null +++ b/.editorconfig @@ -0,0 +1,7 @@ +[*] +indent_style = space +indent_size = 4 +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = false \ No newline at end of file diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 0000000..52547fa --- /dev/null +++ b/.eslintrc @@ -0,0 +1,128 @@ +{ + "env": { + "browser": true + }, + "globals": { + "jQuery": true + }, + "rules": { + "curly": [ + 2, + "all" + ], + "eqeqeq": 2, + "no-eq-null": 2, + "guard-for-in": 2, + "no-unused-vars": [ + 2, + { + "args": "none" + } + ], + "strict": [ + 2, + "safe" + ], + "no-use-before-define": [ + 2, + { + "functions": false, + "variables": false + } + ], + "operator-linebreak": [ + 2, + "after" + ], + "max-len": [ + 2, + { + "code": 200, + "tabWidth": 4, + "ignoreComments": true + } + ], + "indent": [ + 2, + 4, + { + "SwitchCase": 1 + } + ], + "quotes": [ + 2, + "single" + ], + "no-multi-str": 2, + "no-mixed-spaces-and-tabs": 2, + "no-trailing-spaces": 2, + "space-unary-ops": [ + 2, + { + "nonwords": false, + "overrides": {} + } + ], + "brace-style": [ + 2, + "1tbs", + { + "allowSingleLine": true + } + ], + "comma-spacing": [ + 2, + { + "before": false, + "after": true + } + ], + "comma-dangle": [ + 2, + "never" + ], + "comma-style": [ + "error", + "last" + ], + "keyword-spacing": [ + 2, + {} + ], + "space-infix-ops": 2, + "space-before-blocks": [ + 2, + "always" + ], + "space-before-function-paren": [ + 2, + { + "anonymous": "ignore", + "named": "never" + } + ], + "array-bracket-spacing": [ + 2, + "never" + ], + "space-in-parens": [ + 2, + "never" + ], + "no-multiple-empty-lines": 2, + "no-with": 2, + "no-spaced-func": 2, + "key-spacing": [ + 2, + { + "beforeColon": false, + "afterColon": true + } + ], + "dot-notation": 2, + "semi": [ + 2, + "always" + ] + } +} \ No newline at end of file diff --git a/.gitignore b/.gitignore index 82171d1..9889ad5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ - .idea/ .project .settings/ diff --git a/Gruntfile.js b/Gruntfile.js index a04ff14..e17a3d8 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -7,52 +7,17 @@ module.exports = function(grunt) { pkg: grunt.file.readJSON('package.json'), /** - * https://github.com/gruntjs/grunt-contrib-jshint + * https://github.com/gyandeeps/gruntify-eslint */ - jshint: { + eslint: { options: { - curly: true, - eqeqeq: true, - eqnull: true, - browser: true, - newcap: false, - es3: true, - forin: true, - indent: 4, - unused: 'vars', - strict: true, - trailing: true, - quotmark: 'single', - latedef: true, - globals: { - jQuery: true - } + configFile: '.eslintrc' }, - files: { - src: ['Gruntfile.js', 'jquery.jscroll.js'] - } - }, - - /** - * https://github.com/gruntjs/grunt-contrib-uglify - */ - uglify: { - options: { - preserveComments: 'some' - }, - jscroll: { - files: { - 'jquery.jscroll.min.js': [ - 'jquery.jscroll.js' - ] - } - } + src: ['Gruntfile.js', 'jquery.jscroll.js'] } }); - grunt.loadNpmTasks('grunt-contrib-jshint'); - grunt.loadNpmTasks('grunt-contrib-uglify'); - - grunt.registerTask('default', ['jshint', 'uglify']); + grunt.loadNpmTasks('gruntify-eslint'); + grunt.registerTask('default', ['eslint']); }; \ No newline at end of file diff --git a/jquery.jscroll.js b/jquery.jscroll.js index 054c531..987ddd2 100644 --- a/jquery.jscroll.js +++ b/jquery.jscroll.js @@ -5,7 +5,7 @@ * @copyright 2011-2017, Philip Klauzinski * @license Dual licensed under the MIT and GPL Version 2 licenses. * @author Philip Klauzinski (http://webtopian.com) - * @version 2.3.7 + * @version 2.3.8 * @requires jQuery v1.4.3+ * @preserve */ @@ -121,9 +121,9 @@ } if (_options.autoTrigger && (_options.autoTriggerUntil === false || _options.autoTriggerUntil > 0)) { _nextWrap($next); - var scrollingBodyHeight = _$body.height() - $e.offset().top, - scrollingHeight = ($e.height() < scrollingBodyHeight) ? $e.height() : scrollingBodyHeight, - windowHeight = ($e.offset().top - _$window.scrollTop() > 0) ? _$window.height() - ($e.offset().top - $(window).scrollTop()) : _$window.height(); + var scrollingBodyHeight = _$body.height() - $e.offset().top, + scrollingHeight = ($e.height() < scrollingBodyHeight) ? $e.height() : scrollingBodyHeight, + windowHeight = ($e.offset().top - _$window.scrollTop() > 0) ? _$window.height() - ($e.offset().top - $(window).scrollTop()) : _$window.height(); if (scrollingHeight <= windowHeight) { _observe(); } @@ -153,7 +153,7 @@ .children('.jscroll-added').last() .html('
' + _options.loadingHtml + '
') .promise() - .done(function(){ + .done(function() { if (_options.loadingFunction) { _options.loadingFunction(); } @@ -214,13 +214,13 @@ $.fn.jscroll = function(m) { return this.each(function() { var $this = $(this), - data = $this.data('jscroll'), jscroll; + data = $this.data('jscroll'); // Instantiate jScroll on this element if it hasn't been already if (data && data.initialized) { return; } - jscroll = new jScroll($this, m); + jScroll($this, m); }); }; diff --git a/jquery.jscroll.min.js b/jquery.jscroll.min.js deleted file mode 100644 index 5071140..0000000 --- a/jquery.jscroll.min.js +++ /dev/null @@ -1,12 +0,0 @@ -/*! - * jScroll - jQuery Plugin for Infinite Scrolling / Auto-Paging - * @see @link{http://jscroll.com} - * - * @copyright 2011-2017, Philip Klauzinski - * @license Dual licensed under the MIT and GPL Version 2 licenses. - * @author Philip Klauzinski (http://webtopian.com) - * @version 2.3.6 - * @requires jQuery v1.4.3+ - * @preserve - */ -!function(a){"use strict";a.jscroll={defaults:{debug:!1,autoTrigger:!0,autoTriggerUntil:!1,loadingHtml:"Loading...",loadingFunction:!1,padding:0,nextSelector:"a:last",contentSelector:"",pagingSelector:"",callback:!1}};var b=function(b,c){var d=b.data("jscroll"),e="function"==typeof c?{callback:c}:c,f=a.extend({},a.jscroll.defaults,e,d||{}),g="visible"===b.css("overflow-y"),h=b.find(f.nextSelector).first(),i=a(window),j=a("body"),k=g?i:b,l=a.trim(h.attr("href")+" "+f.contentSelector),m=function(){var b=a(f.loadingHtml).filter("img").attr("src");if(b){var c=new Image;c.src=b}},n=function(){b.find(".jscroll-inner").length||b.contents().wrapAll('
')},o=function(a){var b;f.pagingSelector?a.closest(f.pagingSelector).hide():(b=a.parent().not(".jscroll-inner,.jscroll-added").addClass("jscroll-next-parent").hide(),b.length||a.wrap('
').parent().hide())},p=function(){return k.unbind(".jscroll").removeData("jscroll").find(".jscroll-inner").children().unwrap().filter(".jscroll-added").children().unwrap()},q=function(){if(b.is(":visible")){n();var a=b.find("div.jscroll-inner").first(),c=b.data("jscroll"),d=parseInt(b.css("borderTopWidth"),10),e=isNaN(d)?0:d,h=parseInt(b.css("paddingTop"),10)+e,i=g?k.scrollTop():b.offset().top,j=a.length?a.offset().top:0,l=Math.ceil(i-j+k.height()+h);if(!c.waiting&&l+f.padding>=a.outerHeight())return u("info","jScroll:",a.outerHeight()-l,"from bottom. Loading next request..."),t()}},r=function(a){return a=a||b.data("jscroll"),a&&a.nextHref?(s(),!0):(u("warn","jScroll: nextSelector not found - destroying"),p(),!1)},s=function(){var c=b.find(f.nextSelector).first();if(c.length)if(f.autoTrigger&&(f.autoTriggerUntil===!1||f.autoTriggerUntil>0)){o(c);var d=j.height()-b.offset().top,e=b.height()0?i.height()-(b.offset().top-a(window).scrollTop()):i.height();g>=e&&q(),k.unbind(".jscroll").bind("scroll.jscroll",function(){return q()}),f.autoTriggerUntil>0&&f.autoTriggerUntil--}else k.unbind(".jscroll"),c.bind("click.jscroll",function(){return o(c),t(),!1})},t=function(){var c=b.find("div.jscroll-inner").first(),d=b.data("jscroll");return d.waiting=!0,c.append('
').children(".jscroll-added").last().html('
'+f.loadingHtml+"
").promise().done(function(){f.loadingFunction&&f.loadingFunction()}),b.animate({scrollTop:c.outerHeight()},0,function(){var e=d.nextHref;c.find("div.jscroll-added").last().load(e,function(c,g){if("error"===g)return p();var h=a(this).find(f.nextSelector).first();d.waiting=!1,d.nextHref=h.attr("href")?a.trim(h.attr("href")+" "+f.contentSelector):!1,a(".jscroll-next-parent",b).remove(),r(),f.callback&&f.callback.call(this,e),u("dir",d)})})},u=function(a){if(f.debug&&"object"==typeof console&&("object"==typeof a||"function"==typeof console[a]))if("object"==typeof a){var b=[];for(var c in a)"function"==typeof console[c]?(b=a[c].length?a[c]:[a[c]],console[c].apply(console,b)):console.log.apply(console,b)}else console[a].apply(console,Array.prototype.slice.call(arguments,1))};return b.data("jscroll",a.extend({},d,{initialized:!0,waiting:!1,nextHref:l})),n(),m(),s(),a.extend(b.jscroll,{destroy:p}),b};a.fn.jscroll=function(c){return this.each(function(){var d,e=a(this),f=e.data("jscroll");f&&f.initialized||(d=new b(e,c))})}}(jQuery); \ No newline at end of file diff --git a/package.json b/package.json index 32203ef..0cfce64 100644 --- a/package.json +++ b/package.json @@ -1,11 +1,10 @@ { "name": "jscroll", - "version": "2.3.7", + "version": "2.3.8", "description": "jQuery plugin for infinite scrolling / auto-paging.", "main": "jquery.jscroll.js", "scripts": { - "test": "grunt jshint", - "build": "grunt uglify" + "test": "grunt eslint" }, "repository": { "type": "git", @@ -36,7 +35,6 @@ }, "devDependencies": { "grunt": "^1.0.1", - "grunt-contrib-jshint": "^0.11.3", - "grunt-contrib-uglify": "^0.9.2" + "gruntify-eslint": "^3.1.0" } }