Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/jpdery/moobile-core
Browse files Browse the repository at this point in the history
  • Loading branch information
jpdery committed May 29, 2012
2 parents a6f1560 + e092a6b commit 8389340
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Source/Control/NavigationBarItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ Moobile.NavigationBarItem = new Class({
if (this._title) {
this._title.replaceWithComponent(title, true);
} else {
this.addChildComponentInside(title, null, '.bar-title');
this.addChildComponent(title);
}

this._title = title;
Expand Down
94 changes: 94 additions & 0 deletions Source/Event/Event.Touch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
---
name: Event.Touch
description: Provides several touch events.
license: MIT-style license.
author:
- Jean-Philippe Dery (jeanphilippe.dery@gmail.com)
requires:
- Mobile/Browser.Features.Touch
- Event.Mouse
provides:
- Event.Touch
...
*/

(function() {

var touchOverTargets = [];
var touchOutTargets = [];

Element.defineCustomEvent('touchover', {

base: 'touchmove',

condition: function() {
return false;
},

onSetup: function() {
touchOverTargets.include(this);
},

onTeardown: function() {
touchOverTargets.erase(this);
}

});

Element.defineCustomEvent('touchleave', {

base: 'touchmove',

condition: function() {
return false;
},

onSetup: function() {
touchOutTargets.include(this);
},

onTeardown: function() {
touchOutTargets.erase(this);
}
});

var onDocumentTouchMove = function(e) {

if (touchOverTargets.length === 0 &&
touchOutTargets.length === 0)
return;

var touches = e.targetTouches;
for (var i = 0; i < touches.length; i++) {
var touch = touches[i];
var element = document.elementFromPoint(touch.pageX, touch.pageY);
if (element) {
for (var j = 0; j < touchOverTargets.length; j++) {
var target = touchOverTargets[j];
if (target === element || target.contains(element)) {
target.fireEvent('touchover', e);
}
}
for (var j = 0; j < touchOutTargets.length; j++) {
var target = touchOutTargets[j];
if (target !== element && target.contains(element) === false) {
target.fireEvent('touchout', e);
}
}
}
}
};

window.addEvent('ready', function() {
document.addEvent('touchmove', onDocumentTouchMove);
});

})();
1 change: 1 addition & 0 deletions package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ sources:
- "Source/Event/Event.Rotate.js"
- "Source/Event/Event.Mouse.js"
- "Source/Event/Event.Tap.js"
- "Source/Event/Event.Touch.js"
- "Source/Request/Request.js"
- "Source/Scroller/Scroller.js"
- "Source/Scroller/Scroller.Engine.js"
Expand Down

0 comments on commit 8389340

Please sign in to comment.