diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..82bde88 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,17 @@ +root = true + +[*] +charset = utf-8 +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true + +[{*.js, *.json}] +indent_style = space +indent_size = 4 + +[*.css] +indent_style = tab + +[*.md] +trim_trailing_whitespace = false diff --git a/.jshintrc b/.jshintrc new file mode 100644 index 0000000..b27954b --- /dev/null +++ b/.jshintrc @@ -0,0 +1,36 @@ +{ + // strict + "bitwise": true, + "camelcase": true, + "curly": true, + "eqeqeq": true, + "es3": false, + "forin": false, + "freeze": false, + "immed": true, + "indent": 4, + "latedef": true, + "newcap": true, + "noarg": true, + "noempty": true, + "nonew": false, + "plusplus": false, + "quotmark": true, + "undef": true, + "strict": true, + "trailing": true, + "maxparams": 4, + "maxdepth": 5, + "maxstatements": 20, + "maxlen": 120, + + // environment + "browser": true, + + // globals + "globals": { + "jQuery": true, + "module": true, + "define": false + } +} diff --git a/Gruntfile.js b/Gruntfile.js index 5dc04d5..6c00f8d 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -1,48 +1,38 @@ module.exports = function(grunt) { - grunt.initConfig({ - pkg: grunt.file.readJSON('image-zoom.jquery.json'), - uglify: { - options: { - banner: [ - '/*!', - ' * @name <%= pkg.name %>', - ' * @author <%= pkg.author.name %> <<%= pkg.author.url %>>', - ' * @modified <%= grunt.template.today("dddd, mmmm dS, yyyy") %>', - ' * @version <%= pkg.version %>', - ' */' - ].join('\n') - }, - dist: { - files: [ - { - src: 'src/easyzoom.js', - dest: 'dist/easyzoom.js' - } - ] - } - }, - jshint: { - all: ['src/**/*.js'], - options: { - maxdepth: 4, - curly: true, - newcap: true, - eqeqeq: true, - browser: true, - trailing: true, - globals: { - jquery: true, - define: false, - exports: true + grunt.initConfig({ + pkg: grunt.file.readJSON('image-zoom.jquery.json'), + uglify: { + options: { + banner: [ + '/*!', + ' * @name <%= pkg.name %>', + ' * @author <%= pkg.author.name %> <<%= pkg.author.url %>>', + ' * @modified <%= grunt.template.today("dddd, mmmm dS, yyyy") %>', + ' * @version <%= pkg.version %>', + ' */' + ].join('\n') + }, + dist: { + files: [ + { + src: 'src/easyzoom.js', + dest: 'dist/easyzoom.js' + } + ] + } + }, + jshint: { + all: ['src/**/*.js'], + options: { + jshintrc: true + } } - } - } - }); + }); - grunt.loadNpmTasks('grunt-contrib-jshint'); - grunt.loadNpmTasks('grunt-contrib-uglify'); + grunt.loadNpmTasks('grunt-contrib-jshint'); + grunt.loadNpmTasks('grunt-contrib-uglify'); - grunt.registerTask('default', ['jshint', 'uglify']); + grunt.registerTask('default', ['jshint', 'uglify']); -}; \ No newline at end of file +}; diff --git a/dist/easyzoom.js b/dist/easyzoom.js index db4bc9f..5e85a93 100644 --- a/dist/easyzoom.js +++ b/dist/easyzoom.js @@ -1,6 +1,6 @@ /*! * @name image-zoom * @author Matt Hinchliffe - * @modified Wednesday, April 23rd, 2014 - * @version 2.0.5 - */!function(a){function b(b,c){return this.$target=a(b),this.opts=a.extend({},i,c),void 0===this.isOpen&&this._init(),this}var c,d,e,f,g,h,i={loadingNotice:"Loading image",errorNotice:"The image could not be loaded",preventClicks:!0,onShow:void 0,onHide:void 0};b.prototype._init=function(){var b=this;this.$link=this.$target.find("a"),this.$image=this.$target.find("img"),this.$flyout=a('
'),this.$notice=a('
'),this.$target.on("mouseenter.easyzoom touchstart.easyzoom",function(a){a.originalEvent.touches&&1!==a.originalEvent.touches.length||(a.preventDefault(),b.show(a))}).on("mousemove.easyzoom touchmove.easyzoom",function(a){b.isOpen&&(a.preventDefault(),b._move(a))}).on("mouseleave.easyzoom touchend.easyzoom",function(){b.isOpen&&b.hide()}),this.opts.preventClicks&&this.$target.on("click.easyzoom","a",function(a){a.preventDefault()})},b.prototype.show=function(a){var b,g,h,i,j=this;return this.isReady?(this.$target.append(this.$flyout),b=this.$target.width(),g=this.$target.height(),h=this.$flyout.width(),i=this.$flyout.height(),c=this.$zoom.width()-h,d=this.$zoom.height()-i,e=c/b,f=d/g,this.isOpen=!0,this.opts.onShow&&this.opts.onShow.call(this),a&&this._move(a),void 0):(this._load(this.$link.attr("href"),function(){j.show(a)}),void 0)},b.prototype._load=function(b,c){var d=this,e=new Image;this.$target.addClass("is-loading").append(this.$notice.text(this.opts.loadingNotice)),this.$zoom=a(e),e.onerror=function(){d.$notice.text(d.opts.errorNotice),d.$target.removeClass("is-loading").addClass("is-error")},e.onload=function(){0!==e.width&&(d.isReady=!0,d.$notice.detach(),d.$flyout.html(d.$zoom),d.$target.removeClass("is-loading").addClass("is-ready"),c())},e.style.position="absolute",e.src=b},b.prototype._move=function(a){if(0===a.type.indexOf("touch")){var b=a.touches||a.originalEvent.touches;g=b[0].pageX,h=b[0].pageY}else g=a.pageX||g,h=a.pageY||h;var i=this.$target.offset(),j=h-i.top,k=g-i.left,l=j*f,m=k*e;0>m||0>l||m>c||l>d?this.hide():this.$zoom.css({top:""+-1*Math.ceil(l)+"px",left:""+-1*Math.ceil(m)+"px"})},b.prototype.hide=function(){this.isOpen&&(this.$flyout.detach(),this.isOpen=!1,this.opts.onHide&&this.opts.onHide.call(this))},b.prototype.swap=function(a,b){this.hide(),this.isReady=!1,this.$target.removeClass("is-loading is-ready is-error"),this.$image.attr("src",a),this.$link.attr("href",b)},b.prototype.teardown=function(){this.hide(),this.$target.removeClass("is-loading is-ready is-error").off(".easyzoom"),delete this.$link,delete this.$zoom,delete this.$image,delete this.$notice,delete this.$flyout,delete this.isOpen,delete this.isReady},a.fn.easyZoom=function(c){return this.each(function(){var d=a.data(this,"easyZoom");d?void 0===d.isOpen&&d._init():a.data(this,"easyZoom",new b(this,c))})},"function"==typeof define&&define.amd?define(function(){return b}):"undefined"!=typeof module&&module.exports&&(module.exports=b)}(jQuery); \ No newline at end of file + * @modified Thursday, April 24th, 2014 + * @version 2.1.0 + */!function(a){"use strict";function b(b,c){return this.$target=a(b),this.opts=a.extend({},i,c),void 0===this.isOpen&&this._init(),this}var c,d,e,f,g,h,i={loadingNotice:"Loading image",errorNotice:"The image could not be loaded",preventClicks:!0,onShow:void 0,onHide:void 0};b.prototype._init=function(){var b=this;this.$link=this.$target.find("a"),this.$image=this.$target.find("img"),this.$flyout=a('
'),this.$notice=a('
'),this.$target.on("mouseenter.easyzoom touchstart.easyzoom",function(a){a.originalEvent.touches&&1!==a.originalEvent.touches.length||(a.preventDefault(),b.show(a))}).on("mousemove.easyzoom touchmove.easyzoom",function(a){b.isOpen&&(a.preventDefault(),b._move(a))}).on("mouseleave.easyzoom touchend.easyzoom",function(){b.isOpen&&b.hide()}),this.opts.preventClicks&&this.$target.on("click.easyzoom","a",function(a){a.preventDefault()})},b.prototype.show=function(a){var b,g,h,i,j=this;return this.isReady?(this.$target.append(this.$flyout),b=this.$target.width(),g=this.$target.height(),h=this.$flyout.width(),i=this.$flyout.height(),c=this.$zoom.width()-h,d=this.$zoom.height()-i,e=c/b,f=d/g,this.isOpen=!0,this.opts.onShow&&this.opts.onShow.call(this),void(a&&this._move(a))):void this._load(this.$link.attr("href"),function(){j.show(a)})},b.prototype._load=function(b,c){var d=this,e=new Image;this.$target.addClass("is-loading").append(this.$notice.text(this.opts.loadingNotice)),this.$zoom=a(e),e.onerror=function(){d.$notice.text(d.opts.errorNotice),d.$target.removeClass("is-loading").addClass("is-error")},e.onload=function(){0!==e.width&&(d.isReady=!0,d.$notice.detach(),d.$flyout.html(d.$zoom),d.$target.removeClass("is-loading").addClass("is-ready"),c())},e.style.position="absolute",e.src=b},b.prototype._move=function(a){if(0===a.type.indexOf("touch")){var b=a.touches||a.originalEvent.touches;g=b[0].pageX,h=b[0].pageY}else g=a.pageX||g,h=a.pageY||h;var i=this.$target.offset(),j=h-i.top,k=g-i.left,l=j*f,m=k*e;0>m||0>l||m>c||l>d?this.hide():this.$zoom.css({top:""+-1*Math.ceil(l)+"px",left:""+-1*Math.ceil(m)+"px"})},b.prototype.hide=function(){this.isOpen&&(this.$flyout.detach(),this.isOpen=!1,this.opts.onHide&&this.opts.onHide.call(this))},b.prototype.swap=function(a,b){this.hide(),this.isReady=!1,this.$target.removeClass("is-loading is-ready is-error"),this.$image.attr("src",a),this.$link.attr("href",b)},b.prototype.teardown=function(){this.hide(),this.$target.removeClass("is-loading is-ready is-error").off(".easyzoom"),delete this.$link,delete this.$zoom,delete this.$image,delete this.$notice,delete this.$flyout,delete this.isOpen,delete this.isReady},a.fn.easyZoom=function(c){return this.each(function(){var d=a.data(this,"easyZoom");d?void 0===d.isOpen&&d._init():a.data(this,"easyZoom",new b(this,c))})},"function"==typeof define&&define.amd?define(function(){return b}):"undefined"!=typeof module&&module.exports&&(module.exports=b)}(jQuery); \ No newline at end of file diff --git a/package.json b/package.json index a8a87dc..a8e196e 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "version": "2.1.0", "devDependencies": { "grunt": "0.4.x", - "grunt-contrib-jshint": "0.1.x", - "grunt-contrib-uglify": "0.2.x" + "grunt-contrib-jshint": "0.9.x", + "grunt-contrib-uglify": "0.4.x" } -} \ No newline at end of file +} diff --git a/src/easyzoom.js b/src/easyzoom.js index c826506..1135065 100644 --- a/src/easyzoom.js +++ b/src/easyzoom.js @@ -1,4 +1,6 @@ -(function ($) { +(function ($) { + + 'use strict'; var dw, dh, rw, rh, lx, ly;