Skip to content

Commit

Permalink
another useless commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
jtangelder committed May 24, 2014
1 parent 8bf23d0 commit 6767284
Show file tree
Hide file tree
Showing 12 changed files with 72 additions and 27 deletions.
1 change: 1 addition & 0 deletions Gruntfile.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ module.exports = (grunt) ->
src: [
'src/hammer.prefix'
'src/hammer.js'
'src/utils.js'
'src/*.js'
'src/**/*.js'
'src/export.js'
Expand Down
12 changes: 10 additions & 2 deletions src/export.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
if(typeof define == "function" && define.amd) {
// expose some methods
Hammer.register = registerGesture;
Hammer.each = each;
Hammer.merge = merge;
Hammer.bindFn = bindFn;
Hammer.prefixed = prefixed;

// export to amd/module/window
if(typeof define == TYPE_FUNCTION && define.amd) {
define(function() {
return Hammer;
});
} else if(typeof module !== "undefined" && module.exports) {
} else if(typeof module != TYPE_UNDEFINED && module.exports) {
module.exports = Hammer;
} else {
window.Hammer = Hammer;
Expand Down
6 changes: 3 additions & 3 deletions src/gestures.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ Gestures.prototype.update = function(inputData) {
* @param {Object} options
* @param {Function} handler
*/
Gestures.register = function(options, handler) {
function registerGesture(options, handler) {
registeredGestures.push({
options: options,
handler: handler
});
extend(DEFAULT_OPTIONS, options);
};
merge(DEFAULT_OPTIONS, options);
}
2 changes: 1 addition & 1 deletion src/gestures/drag.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* drag gesture
*/
Gestures.register({
registerGesture({
dragThreshold: 5
},
function(inst, inputData, session) {
Expand Down
2 changes: 1 addition & 1 deletion src/gestures/gesture.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* global gesture
*/
Gestures.register({ }, function(inst, inputData) {
registerGesture({}, function(inst, inputData) {
inst.trigger("gesture", inputData);
});
2 changes: 1 addition & 1 deletion src/gestures/transform.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* transform gesture
*/
Gestures.register({
registerGesture({
scaleThreshold: 5,
rotationThreshold: 3
},
Expand Down
4 changes: 4 additions & 0 deletions src/hammer.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
var TYPE_FUNCTION = "function";
var TYPE_UNDEFINED = "undefined";

var DEFAULT_OPTIONS = {
touchAction: "pan-y"
};
Expand All @@ -19,6 +22,7 @@ function Hammer(element, options) {
this.gestures = new Gestures(this);
}

// expose
Hammer.defaults = DEFAULT_OPTIONS;

/**
Expand Down
2 changes: 1 addition & 1 deletion src/input.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var MOBILE_REGEX = /mobile|tablet|ip(ad|hone|od)|android|silk/i;

var SUPPORT_POINTER_EVENTS = window.PointerEvent || window.MSPointerEvent;
var SUPPORT_POINTER_EVENTS = prefixed("PointerEvent", window);
var SUPPORT_TOUCH = ("ontouchstart" in window);
var SUPPORT_ONLY_TOUCH = SUPPORT_TOUCH && MOBILE_REGEX.test(navigator.userAgent);

Expand Down
12 changes: 5 additions & 7 deletions src/input/pointerevent.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
var MS_POINTER = window.MSPointerEvent;

var POINTER_SRC_EVENT_MAP = {
pointerdown: SRC_EVENT_START,
pointermove: SRC_EVENT_MOVE,
Expand All @@ -11,13 +9,13 @@ var POINTER_SRC_EVENT_MAP = {
var POINTER_ELEMENT_EVENTS = "pointerdown pointermove pointerup pointercancel";
var POINTER_WINDOW_EVENTS = "pointerout";

var POINTER_TYPE_MAP = {
var IE10_POINTER_TYPE_MAP = {
2: INPUT_TYPE_TOUCH,
3: INPUT_TYPE_PEN,
4: INPUT_TYPE_MOUSE
};

if(MS_POINTER) {
if(window.MSPointerEvent) {
POINTER_ELEMENT_EVENTS = "MSPointerDown MSPointerMove MSPointerUp MSPointerCancel";
POINTER_WINDOW_EVENTS = "MSPointerOut";
}
Expand Down Expand Up @@ -55,7 +53,7 @@ Input.PointerEvent.prototype = {
if(evType == "pointerdown") {
// pointer must be down
store.push(ev);
element[(MS_POINTER ? "msSetPointerCapture" : "setPointerCapture")](ev.pointerId);
prefixed("setPointerCapture", element, [ev.pointerId]);
} else if(evType == "pointerup" || evType == "pointerout" || evType == "pointercancel") {
// we've lost the pointer
removePointer = true;
Expand All @@ -74,7 +72,7 @@ Input.PointerEvent.prototype = {
var data = {
pointers: store,
changedPointers: [ev],
pointerType: POINTER_TYPE_MAP[store[0].pointerType] || store[0].pointerType, // IE10 returns integers
pointerType: IE10_POINTER_TYPE_MAP[store[0].pointerType] || store[0].pointerType,
srcEvent: ev
};

Expand All @@ -83,7 +81,7 @@ Input.PointerEvent.prototype = {
if(removePointer) {
// remove from the store
store.splice(storeIndex, 1);
element[(MS_POINTER ? "msReleasePointerCapture" : "releasePointerCapture")](ev.pointerId);
prefixed("releasePointerCapture", element, [ev.pointerId]);
}
},

Expand Down
11 changes: 5 additions & 6 deletions src/touchaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
* set and mimic the touch-action property
*/

var BODY_STYLE = document.body.style;
var NATIVE_TOUCH_ACTION = ("touchAction" in BODY_STYLE) || ("msTouchAction" in BODY_STYLE);
var NATIVE_TOUCH_ACTION = prefixed("touchAction", document.body.style);

function TouchAction(inst, value) {
this.inst = inst;
Expand All @@ -15,9 +14,7 @@ TouchAction.prototype = {
this.value = value;

if(NATIVE_TOUCH_ACTION) {
var style = this.inst.element.style;
style.touchAction = value;
style.msTouchAction = value;
prefixed("touchAction", this.inst.element.style, value);
}
},

Expand All @@ -26,7 +23,9 @@ TouchAction.prototype = {
var touchAction = this.value;

// not needed for native and mouse input
if(!NATIVE_TOUCH_ACTION || inputData.pointerType == INPUT_TYPE_MOUSE || inputData.srcType == SRC_EVENT_START) {
if(!NATIVE_TOUCH_ACTION ||
inputData.pointerType == INPUT_TYPE_MOUSE ||
inputData.srcType == SRC_EVENT_START) {
return;
}

Expand Down
41 changes: 39 additions & 2 deletions src/utils.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
var VENDOR_PREFIXES = ["", "webkit", "moz", "MS", "ms"];

/**
* walk objects and arrays
* @param {Object} obj
Expand All @@ -24,7 +26,13 @@ function each(obj, iterator, context) {
}
}

function extend(dest, src) {
/**
* merge the values from src in the dest
* @param {Object} dest
* @param {Object} src
* @returns {Object} dest
*/
function merge(dest, src) {
for(var key in src) {
if(!src.hasOwnProperty(key)) {
continue;
Expand Down Expand Up @@ -125,6 +133,35 @@ function uniqueArray(src, key) {
}
keys.push(item[key]);
});

return results;
}

/**
* get/set (vendor prefixed) property. allows css properties, properties and functions.
* if you want to call a function by this function, you should pass an array with arguments (see .apply())
* else, a bindFn function will be returned
*
* @param {String} property
* @param {Object} obj
* @param {*} [val]
* @returns {*}
*/
function prefixed(property, obj, val) {
var prefix, prop, i;
var camelProp = property[0].toUpperCase() + property.slice(1);

for(i = 0; i < VENDOR_PREFIXES.length; i++) {
prefix = VENDOR_PREFIXES[i];
prop = (prefix) ? prefix + camelProp : property;

if(!(prop in obj)) {
continue;
} else if(typeof obj[prop] == TYPE_FUNCTION) {
return (typeof val == TYPE_UNDEFINED) ? bindFn(prop, obj) : obj[prop].apply(obj, val);
} else if(val) {
obj[prop] = val;
}
return obj[prop];
}
return null;
}
4 changes: 1 addition & 3 deletions tests/manual/log.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta name="viewport" content="width=device-width, user-scalable=no">
<title></title>
<script src="http://192.168.0.112:8081/target/target-script-min.js"></script>
<!--<script src="http://192.168.0.112:8081/target/target-script-min.js"></script>-->
</head>
<body>
<pre style="background: silver; width: 100%; height: 400px; overflow: hidden" id="hit"></pre>
Expand Down Expand Up @@ -33,8 +33,6 @@
el.textContent = ev.gesture.toDirString();
}



</script>
</body>
</html>

0 comments on commit 6767284

Please sign in to comment.