Skip to content

Commit

Permalink
code
Browse files Browse the repository at this point in the history
  • Loading branch information
jtangelder committed May 23, 2014
1 parent 554f8c8 commit eed0902
Show file tree
Hide file tree
Showing 14 changed files with 80 additions and 63 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ lib-cov
pids
logs
results
tests/build.js

npm-debug.log
node_modules
node_modules
2 changes: 1 addition & 1 deletion .jscsrc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"requireParamTypes": true
},
"validateIndentation": 4,
"validateQuoteMarks": "'",
"validateQuoteMarks": "\"",

"excludeFiles": [
"*.js",
Expand Down
4 changes: 2 additions & 2 deletions .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"maxerr" : 100,
"newcap" : true,
"node" : true,
"quotmark" : "single",
"quotmark" : "double",
"strict" : true,
"sub" : false,
"trailing" : true,
Expand All @@ -16,4 +16,4 @@
"globals" : {
"define" : false
}
}
}
33 changes: 20 additions & 13 deletions Gruntfile.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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']

Expand Down Expand Up @@ -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'
Expand All @@ -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']
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
11 changes: 10 additions & 1 deletion src/gestures/drag.js
Original file line number Diff line number Diff line change
@@ -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");
}
}
};
2 changes: 1 addition & 1 deletion src/hammer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var DEFAULT_OPTIONS = {
touchAction: 'pan-y'
touchAction: "pan-y"
};

/**
Expand Down
2 changes: 1 addition & 1 deletion src/hammer.prefix
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
(function(window, undefined) {
'use strict';
"use strict";
34 changes: 17 additions & 17 deletions src/input.js
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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);
}
Expand Down
8 changes: 4 additions & 4 deletions src/input/mouse.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}

Expand All @@ -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;
}

Expand Down
4 changes: 2 additions & 2 deletions src/input/touch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
];
Expand Down
4 changes: 2 additions & 2 deletions src/input/touchmouse.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ 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;
} else if(isMouse && !this.mouse._allow) {
return;
}

// reset the allowMouse when we're done
// reset the allowMouse when we"re done
if(inputEventType == INPUT_EVENT_END) {
this.mouse._allow = true;
}
Expand Down
18 changes: 9 additions & 9 deletions src/touchaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
},
Expand Down
8 changes: 4 additions & 4 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down Expand Up @@ -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);
});
}
Expand All @@ -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);
});
}
Expand Down Expand Up @@ -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}
Expand Down

0 comments on commit eed0902

Please sign in to comment.