diff --git a/.gitignore b/.gitignore index af39a3e7a..391688ff9 100644 --- a/.gitignore +++ b/.gitignore @@ -15,6 +15,7 @@ lib-cov pids logs results +tests/build.js npm-debug.log -node_modules \ No newline at end of file +node_modules diff --git a/.jscsrc b/.jscsrc index f6bc0723e..c33f0bd1b 100644 --- a/.jscsrc +++ b/.jscsrc @@ -25,7 +25,7 @@ "requireParamTypes": true }, "validateIndentation": 4, - "validateQuoteMarks": "'", + "validateQuoteMarks": "\"", "excludeFiles": [ "*.js", diff --git a/.jshintrc b/.jshintrc index 5246312b2..1d6514c87 100644 --- a/.jshintrc +++ b/.jshintrc @@ -7,7 +7,7 @@ "maxerr" : 100, "newcap" : true, "node" : true, - "quotmark" : "single", + "quotmark" : "double", "strict" : true, "sub" : false, "trailing" : true, @@ -16,4 +16,4 @@ "globals" : { "define" : false } -} \ No newline at end of file +} diff --git a/Gruntfile.coffee b/Gruntfile.coffee index 10158849e..c16d62e6b 100644 --- a/Gruntfile.coffee +++ b/Gruntfile.coffee @@ -11,11 +11,7 @@ module.exports = (grunt) -> * Licensed under the <%= _.pluck(pkg.licenses, "type").join(", ") %> license */\n\n' concat: - options: - separator: '\n\n' build: - options: - banner: '<%= meta.banner %>' src: [ 'src/hammer.prefix' 'src/hammer.js' @@ -24,13 +20,19 @@ module.exports = (grunt) -> 'src/export.js' 'src/hammer.suffix'] dest: 'hammer.js' + test: + src: [ + 'src/hammer.js' + 'src/*.js' + 'src/**/*.js'] + dest: 'tests/build.js' uglify: - options: - report: 'gzip' - sourceMap: 'hammer.min.map' - banner: '<%= meta.banner %>' - build: + min: + options: + report: 'gzip' + sourceMap: 'hammer.min.map' + banner: '<%= meta.banner %>' files: 'hammer.min.js': ['hammer.js'] @@ -68,8 +70,12 @@ module.exports = (grunt) -> hostname: "0.0.0.0" port: 8000 - mocha: - test: ['tests/unit/**/*.html'] + mocha: # disabled + test: + src: ['tests/unit/*.html'] + options: + reporter: 'List' + # Load tasks grunt.loadNpmTasks 'grunt-contrib-concat' @@ -78,11 +84,12 @@ module.exports = (grunt) -> grunt.loadNpmTasks 'grunt-contrib-jshint' grunt.loadNpmTasks 'grunt-contrib-connect' grunt.loadNpmTasks 'grunt-mocha' + grunt.loadNpmTasks 'grunt-simple-mocha' grunt.loadNpmTasks 'grunt-string-replace' grunt.loadNpmTasks 'grunt-jscs-checker' # Default task(s). grunt.registerTask 'default', ['connect','watch'] - grunt.registerTask 'build', ['concat','string-replace','uglify','yuidoc','test'] - grunt.registerTask 'test', ['jshint','jscs','qunit'] + grunt.registerTask 'build', ['concat','string-replace','uglify','test'] + grunt.registerTask 'test', ['jshint','jscs','concat:test'] grunt.registerTask 'test-travis', ['build'] diff --git a/package.json b/package.json index 26b61e18b..13769cf34 100644 --- a/package.json +++ b/package.json @@ -28,15 +28,15 @@ "dependencies": {}, "devDependencies": { "grunt": "0.4.x", - "grunt-contrib-connect": "0.7.x", "grunt-contrib-concat": "0.3.x", - "grunt-contrib-uglify": "0.4.x", + "grunt-contrib-connect": "0.7.x", "grunt-contrib-jshint": "0.9.x", + "grunt-contrib-uglify": "0.4.x", "grunt-contrib-watch": "0.6.x", - "grunt-contrib-qunit": "0.4.x", - "grunt-string-replace": "^0.2.7", "grunt-contrib-yuidoc": "^0.5.2", - "grunt-jscs-checker": "^0.4.1" + "grunt-jscs-checker": "^0.4.1", + "grunt-mocha": "^0.4.10", + "grunt-string-replace": "^0.2.7" }, "main": "hammer.js", "engines": { diff --git a/src/gestures/drag.js b/src/gestures/drag.js index 636fd40e5..3bd47a467 100644 --- a/src/gestures/drag.js +++ b/src/gestures/drag.js @@ -1,5 +1,14 @@ Gestures.Drag = { + options: { + minDistance: 10 + }, handler: function(inst, inputData) { - console.log(this, inst, inputData); + var options = inst.options; + + console.log(this, arguments); + + if(inputData.distance > options.minDistance) { + //inst.trigger("drag"); + } } }; diff --git a/src/hammer.js b/src/hammer.js index a107abe6d..a6c5caedf 100644 --- a/src/hammer.js +++ b/src/hammer.js @@ -1,5 +1,5 @@ var DEFAULT_OPTIONS = { - touchAction: 'pan-y' + touchAction: "pan-y" }; /** diff --git a/src/hammer.prefix b/src/hammer.prefix index 857a0fd9b..802443dc6 100644 --- a/src/hammer.prefix +++ b/src/hammer.prefix @@ -1,2 +1,2 @@ (function(window, undefined) { - 'use strict'; \ No newline at end of file + "use strict"; diff --git a/src/input.js b/src/input.js index 7f6a8b760..d851099b8 100644 --- a/src/input.js +++ b/src/input.js @@ -1,24 +1,24 @@ var MOBILE_REGEX = /mobile|tablet|ip(ad|hone|od)|android|silk/i; var SUPPORT_POINTEREVENT = window.PointerEvent || window.msPointerEvent; -var SUPPORT_TOUCH = ('ontouchstart' in window); +var SUPPORT_TOUCH = ("ontouchstart" in window); var SUPPORT_ONLY_TOUCH = SUPPORT_TOUCH && MOBILE_REGEX.test(navigator.userAgent); -var INPUT_TYPE_TOUCH = 'touch'; -var INPUT_TYPE_MOUSE = 'mouse'; +var INPUT_TYPE_TOUCH = "touch"; +var INPUT_TYPE_MOUSE = "mouse"; -var INPUT_EVENT_START = 'start'; -var INPUT_EVENT_MOVE = 'move'; -var INPUT_EVENT_END = 'end'; +var INPUT_EVENT_START = "start"; +var INPUT_EVENT_MOVE = "move"; +var INPUT_EVENT_END = "end"; -var DIRECTION_LEFT = 'left'; -var DIRECTION_RIGHT = 'right'; -var DIRECTION_UP = 'up'; -var DIRECTION_DOWN = 'down'; -var DIRECTION_NONE = 'none'; +var DIRECTION_LEFT = "left"; +var DIRECTION_RIGHT = "right"; +var DIRECTION_UP = "up"; +var DIRECTION_DOWN = "down"; +var DIRECTION_NONE = ""; -var PROPS_XY = ['x', 'y']; -var PROPS_CLIENTXY = ['clientX', 'clientY']; +var PROPS_XY = ["x", "y"]; +var PROPS_CLIENTXY = ["clientX", "clientY"]; /** * create new input type instance @@ -27,13 +27,13 @@ var PROPS_CLIENTXY = ['clientX', 'clientY']; * @constructor */ function Input(inst) { - var type = 'TouchMouse'; + var type = "TouchMouse"; if(SUPPORT_POINTEREVENT) { - type = 'PointerEvent'; + type = "PointerEvent"; } else if(SUPPORT_ONLY_TOUCH) { - type = 'Touch'; + type = "Touch"; } else if(!SUPPORT_TOUCH) { - type = 'Mouse'; + type = "Mouse"; } return new Input[type](inst, inputHandler); } diff --git a/src/input/mouse.js b/src/input/mouse.js index 65134a54e..2f7b97327 100644 --- a/src/input/mouse.js +++ b/src/input/mouse.js @@ -5,8 +5,8 @@ var INPUT_MOUSE_TYPE_MAP = { mouseout: INPUT_EVENT_END }; -var INPUT_MOUSE_ELEMENT_EVENTS = 'mousedown mousemove mouseup'; -var INPUT_MOUSE_WINDOW_EVENTS = 'mouseout'; +var INPUT_MOUSE_ELEMENT_EVENTS = "mousedown mousemove mouseup"; +var INPUT_MOUSE_WINDOW_EVENTS = "mouseout"; /** * Mouse events input @@ -33,7 +33,7 @@ Input.Mouse.prototype = { * @param {Object} ev */ handler: function(ev) { - if(ev.type == 'mousedown' && ev.button === 0) { + if(ev.type == "mousedown" && ev.button === 0) { this._pressed = true; } @@ -42,7 +42,7 @@ Input.Mouse.prototype = { return; } - if(ev.type == 'mouseup' || ev.type == 'mouseout') { + if(ev.type == "mouseup" || ev.type == "mouseout") { this._pressed = false; } diff --git a/src/input/touch.js b/src/input/touch.js index bc4a1acad..6479bbcdf 100644 --- a/src/input/touch.js +++ b/src/input/touch.js @@ -5,7 +5,7 @@ var INPUT_TOUCH_TYPE_MAP = { touchcancel: INPUT_EVENT_END }; -var INPUT_TOUCH_EVENTS = 'touchstart touchmove touchend touchcancel'; +var INPUT_TOUCH_EVENTS = "touchstart touchmove touchend touchcancel"; /** * Touch events input @@ -49,7 +49,7 @@ Input.Touch.prototype = { return [ // should contain all the touches, touches + changedTouches - uniqueArray(touches, 'identifier'), + uniqueArray(touches, "identifier"), // should contain only the touches that have changed changedTouches ]; diff --git a/src/input/touchmouse.js b/src/input/touchmouse.js index d3265ab9a..8c100cc99 100644 --- a/src/input/touchmouse.js +++ b/src/input/touchmouse.js @@ -27,7 +27,7 @@ Input.TouchMouse.prototype = { var isTouch = (inputData.pointerType == INPUT_TYPE_TOUCH), isMouse = (inputData.pointerType == INPUT_TYPE_MOUSE); - // when we're in a touch event, so block all upcoming mouse events + // when we"re in a touch event, so block all upcoming mouse events // most mobile browser also trigger mouseevents, right after touchstart if(isTouch) { this.mouse._allow = false; @@ -35,7 +35,7 @@ Input.TouchMouse.prototype = { return; } - // reset the allowMouse when we're done + // reset the allowMouse when we"re done if(inputEventType == INPUT_EVENT_END) { this.mouse._allow = true; } diff --git a/src/touchaction.js b/src/touchaction.js index 7399b337a..5ab75d94e 100644 --- a/src/touchaction.js +++ b/src/touchaction.js @@ -3,7 +3,7 @@ */ var BODY_STYLE = document.body.style; -var NATIVE_TOUCH_ACTION = ('touchAction' in BODY_STYLE) || ('msTouchAction' in BODY_STYLE); +var NATIVE_TOUCH_ACTION = ("touchAction" in BODY_STYLE) || ("msTouchAction" in BODY_STYLE); function TouchAction(inst, value) { this.inst = inst; @@ -36,27 +36,27 @@ TouchAction.prototype = { event.preventDefault(); } - var isPanY = inStr(touchAction, 'pan-y'); - var isPanX = inStr(touchAction, 'pan-x'); - var isNone = inStr(touchAction, 'none'); - var isManipulation = inStr(touchAction, 'manipulation'); + var isPanY = inStr(touchAction, "pan-y"); + var isPanX = inStr(touchAction, "pan-x"); + var isNone = inStr(touchAction, "none"); + var isManipulation = inStr(touchAction, "manipulation"); - // 'none' and 'pan-y pan-x' + // "none" and "pan-y pan-x" if(isNone || (isPanY && isPanX)) { this.preventDefault(event); } - // 'pan-y' or 'pan-x' + // "pan-y" or "pan-x" var direction = inputData.direction; if((isPanY && (direction == DIRECTION_LEFT || direction == DIRECTION_RIGHT)) || (isPanX && (direction == DIRECTION_UP || direction == DIRECTION_DOWN))) { this.preventDefault(event); } - // 'manipulation' + // "manipulation" // only on touchend we want to prevent the default // it should then remove the 300ms (@todo check this) - if(isManipulation && event.type == 'touchend') { + if(isManipulation && event.type == "touchend") { this.preventDefault(event); } }, diff --git a/src/utils.js b/src/utils.js index 685cb18ee..5f4212ac9 100644 --- a/src/utils.js +++ b/src/utils.js @@ -7,7 +7,7 @@ function each(obj, iterator, context) { var i, len; - if('forEach' in obj) { + if("forEach" in obj) { obj.forEach(iterator, context); } else if(obj.length !== undefined) { for(i = 0, len = obj.length; i < len; i++) { @@ -43,7 +43,7 @@ function bindFn(fn, context) { * @param {Function} handler */ function addEvent(element, types, handler) { - each(types.split(' '), function(type) { + each(types.split(" "), function(type) { element.addEventListener(type, handler, false); }); } @@ -55,7 +55,7 @@ function addEvent(element, types, handler) { * @param {Function} handler */ function removeEvent(element, types, handler) { - each(types.split(' '), function(type) { + each(types.split(" "), function(type) { element.removeEventListener(type, handler, false); }); } @@ -100,7 +100,7 @@ function toArray(obj) { } /** - * unique array based on a key (like 'id') + * unique array based on a key (like "id") * @param {Array} src * @param {String} key * @returns {Array}