Skip to content

Commit

Permalink
code
Browse files Browse the repository at this point in the history
  • Loading branch information
jtangelder committed May 22, 2014
1 parent fda75a4 commit b6a8914
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/defines.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ function Hammer(element, options) {

var MOBILE_REGEX = /mobile|tablet|ip(ad|hone|od)|android|silk/i;

var SUPPORT_POINTEREVENTS = window.PointerEvent;
var SUPPORT_POINTEREVENTS = window.PointerEvent || window.MSPointerEvent;
var SUPPORT_TOUCHEVENTS = ("ontouchstart" in window);
var SUPPORT_ONLY_TOUCHEVENTS = SUPPORT_TOUCHEVENTS && MOBILE_REGEX.test(navigator.userAgent);
4 changes: 2 additions & 2 deletions src/gestures.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
function Gestures(/*inst, inputData, session*/) {
for(var key in Gestures) {
var gesture = Gestures[key];
for(var name in Gestures) {
var gesture = Gestures[name];
if(gesture.handler) {
gesture.handler.apply(gesture, arguments);
}
Expand Down
30 changes: 30 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/**
* walk objects and arrays
* @param obj
* @param iterator
* @param context
*/
function each(obj, iterator, context) {
var i, len;

Expand All @@ -18,24 +24,48 @@ function each(obj, iterator, context) {
}
}

/**
* simple function bind
* @param fn
* @param context
* @returns {Function}
*/
function bindFn(fn, context) {
return function() {
return fn.apply(context, arguments);
};
}

/**
* addEventListener with multiple events at once
* @param element
* @param types
* @param handler
*/
function addEvent(element, types, handler) {
each(types.split(' '), function(type) {
element.addEventListener(type, handler, false);
});
}

/**
* removeEventListener with multiple events at once
* @param element
* @param types
* @param handler
*/
function removeEvent(element, types, handler) {
each(types.split(' '), function(type) {
element.removeEventListener(type, handler, false);
});
}

/**
* find in string
* @param str
* @param find
* @returns {boolean}
*/
function inStr(str, find) {
return str.indexOf(find) > -1;
}

0 comments on commit b6a8914

Please sign in to comment.