Permalink
Browse files

Merging interaction-model work.

  • Loading branch information...
1 parent 64f6df7 commit a3cf0656208ad7eb1c3433503c5fc7afddbba427 @joseph committed Apr 23, 2012
View
@@ -0,0 +1,2 @@
+Version 3.0.0
+- panel event callback args are now (dir, x, y, panel) - was (panel, x, y)
View
@@ -21,10 +21,12 @@ window.console.compatDir = function (obj) {
for (x in o) {
parts.push(x + ": " + o[x]);
}
- return parts.join("; ");
+ return parts.join(";\n");
}
- window.console.log(stringify(obj));
+ var out = stringify(obj);
+ window.console.log(out);
+ return out;
}
View
@@ -35,6 +35,11 @@ Monocle.Controls.Panel = function () {
}
+ function setDirection(dir) {
+ p.direction = dir;
+ }
+
+
function listenTo(evtCallbacks) {
p.evtCallbacks = evtCallbacks;
}
@@ -86,7 +91,7 @@ Monocle.Controls.Panel = function () {
function invoke(evtType, evt) {
if (p.evtCallbacks[evtType]) {
- p.evtCallbacks[evtType](API, evt.m.offsetX, evt.m.offsetY);
+ p.evtCallbacks[evtType](p.direction, evt.m.offsetX, evt.m.offsetY, API);
}
evt.preventDefault();
}
@@ -115,6 +120,7 @@ Monocle.Controls.Panel = function () {
API.deafen = deafen;
API.expand = expand;
API.contract = contract;
+ API.setDirection = setDirection;
return API;
}
View
@@ -56,8 +56,10 @@ Monocle.Events.deafen = function (elem, evtType, fn, useCapture) {
// Each function is passed the event, with additional generic info about the
// cursor/touch position:
//
-// event.m.offsetX (& offsetY) -- relative to top-left of document
-// event.m.registrantX (& registrantY) -- relative to top-left of elem
+// event.m.offsetX (& offsetY) -- relative to top-left of the element
+// on which the event fired
+// event.m.registrantX (& registrantY) -- relative to top-left of element
+// on which the event is listening
//
// 'options' argument:
//
@@ -73,7 +75,11 @@ Monocle.Events.listenForContact = function (elem, fns, options) {
var cursorInfo = function (evt, ci) {
evt.m = {
pageX: ci.pageX,
- pageY: ci.pageY
+ pageY: ci.pageY,
+ clientX: ci.clientX,
+ clientY: ci.clientY,
+ screenX: ci.screenX,
+ screenY: ci.screenY
};
var target = evt.target || evt.srcElement;
@@ -88,8 +94,11 @@ Monocle.Events.listenForContact = function (elem, fns, options) {
evt.m.offsetY = offset[1];
// The position of contact from the top left of the element
- // on which the event is registered.
- if (evt.currentTarget) {
+ // on which the event is listening.
+ if (
+ evt.currentTarget &&
+ typeof evt.currentTarget.offsetLeft != 'undefined'
+ ) {
offset = offsetFor(evt, evt.currentTarget);
evt.m.registrantX = offset[0];
evt.m.registrantY = offset[1];
@@ -102,8 +111,10 @@ Monocle.Events.listenForContact = function (elem, fns, options) {
var offsetFor = function (evt, elem) {
var r;
if (elem.getBoundingClientRect) {
- var er = elem.getBoundingClientRect();
+ // Why subtract documentElement position? It's always zero, right?
+ // Nope, not on Android when zoomed in.
var dr = document.documentElement.getBoundingClientRect();
+ var er = elem.getBoundingClientRect();
r = { left: er.left - dr.left, top: er.top - dr.top };
} else {
r = { left: elem.offsetLeft, top: elem.offsetTop }
@@ -152,30 +163,30 @@ Monocle.Events.listenForContact = function (elem, fns, options) {
}
} else {
if (fns.start) {
- listeners.start = function (evt) {
+ listeners.touchstart = function (evt) {
if (evt.touches.length > 1) { return; }
fns.start(cursorInfo(evt, evt.targetTouches[0]));
}
}
if (fns.move) {
- listeners.move = function (evt) {
+ listeners.touchmove = function (evt) {
if (evt.touches.length > 1) { return; }
fns.move(cursorInfo(evt, evt.targetTouches[0]));
}
}
if (fns.end) {
- listeners.end = function (evt) {
+ listeners.touchend = function (evt) {
fns.end(cursorInfo(evt, evt.changedTouches[0]));
}
}
if (fns.cancel) {
- listeners.cancel = function (evt) {
+ listeners.touchcancel = function (evt) {
fns.cancel(cursorInfo(evt, evt.changedTouches[0]));
}
}
for (etype in listeners) {
- Monocle.Events.listen(elem, 'touch'+etype, listeners[etype], capture);
+ Monocle.Events.listen(elem, etype, listeners[etype], capture);
}
}
@@ -187,13 +198,8 @@ Monocle.Events.listenForContact = function (elem, fns, options) {
// are registered to them -- de-registers the functions from the events.
//
Monocle.Events.deafenForContact = function (elem, listeners) {
- var prefix = "";
- if (Monocle.Browser.env.touch) {
- prefix = "touch";
- }
-
for (evtType in listeners) {
- Monocle.Events.deafen(elem, prefix + evtType, listeners[evtType]);
+ Monocle.Events.deafen(elem, evtType, listeners[evtType]);
}
}
View
@@ -48,9 +48,8 @@ Monocle.Flippers.Instant = function (reader) {
}
- function turn(panel) {
+ function turn(dir) {
p.reader.selection.deselect();
- var dir = panel.properties.direction;
moveTo({ page: getPlace().pageNumber() + dir});
}
View
@@ -31,7 +31,7 @@ Monocle.Flippers.Scroller = function (reader, setPageFn) {
p.panels = new panelClass(
API,
{
- 'end': function (panel) { turn(panel.properties.direction); }
+ 'end': turn
}
);
}
View
@@ -40,21 +40,13 @@ Monocle.Flippers.Slider = function (reader) {
console.warn("Invalid panel class.")
}
}
- var q = function (action, panel, x) {
- var dir = panel.properties.direction;
- if (action == "lift") {
- lift(dir, x);
- } else if (action == "release") {
- release(dir, x);
- }
- }
p.panels = new panelClass(
API,
{
- 'start': function (panel, x) { q('lift', panel, x); },
- 'move': function (panel, x) { turning(panel.properties.direction, x); },
- 'end': function (panel, x) { q('release', panel, x); },
- 'cancel': function (panel, x) { q('release', panel, x); }
+ 'start': lift,
+ 'move': turning,
+ 'end': release,
+ 'cancel': release
}
);
}
View
@@ -19,6 +19,7 @@
//= require ./panels/imode
//= require ./panels/eink
//= require ./panels/marginal
+//= require ./panels/magic
//= require ./dimensions/columns
//= require ./flippers/slider
//= require ./flippers/scroller
View
@@ -14,9 +14,9 @@ Monocle.Panels.eInk = function (flipper, evtCallbacks) {
p.panel.listenTo({ end: function (panel, x) {
if (x < p.panel.properties.div.offsetWidth / 2) {
- p.panel.properties.direction = flipper.constants.BACKWARDS;
+ p.panel.setDirection(flipper.constants.BACKWARDS);
} else {
- p.panel.properties.direction = flipper.constants.FORWARDS;
+ p.panel.setDirection(flipper.constants.FORWARDS);
}
evtCallbacks.end(panel, x);
} });
View
@@ -25,7 +25,7 @@ Monocle.Panels.IMode = function (flipper, evtCallbacks) {
p.reader.addControl(p.panels[dir]);
p.divs[dir] = p.panels[dir].properties.div;
p.panels[dir].listenTo(evtCallbacks);
- p.panels[dir].properties.direction = flipper.constants[dir.toUpperCase()];
+ p.panels[dir].setDirection(flipper.constants[dir.toUpperCase()]);
p.divs[dir].style.width = "33%";
p.divs[dir].style[dir == "forwards" ? "right" : "left"] = 0;
}
Oops, something went wrong.

0 comments on commit a3cf065

Please sign in to comment.