Permalink
Browse files

Improvements and simplifications to Monocle.Selection.

  • Loading branch information...
1 parent e09690b commit 62ffa2613962040a1fd28e6c47c1fdee5bb665db @joseph committed Feb 10, 2012
Showing with 32 additions and 25 deletions.
  1. +12 −2 src/core/selection.js
  2. +1 −1 src/flippers/instant.js
  3. +1 −1 src/flippers/scroller.js
  4. +1 −6 src/flippers/slider.js
  5. +1 −13 src/panels/imode.js
  6. +5 −0 test/index.html
  7. +11 −2 test/selection/index.html
View
@@ -58,7 +58,16 @@ Monocle.Selection = function (reader) {
// Given a window object, remove any user selections within. Trivial in
// most browsers, but involving major mojo on iOS.
//
- function deselect(win) {
+ function deselect() {
+ var index = 0, frame = null;
+ while (frame = reader.dom.find('component', index)) {
+ deselectOnWindow(frame.contentWindow);
+ index += 1;
+ }
+ }
+
+
+ function deselectOnWindow(win) {
win = win || window;
if (!anythingSelected(win)) { return; }
@@ -78,11 +87,12 @@ Monocle.Selection = function (reader) {
document.body.removeChild(inp);
})
});
- } else {
}
var sel = win.getSelection();
sel.removeAllRanges();
+ win.document.body.scrollLeft = 0;
+ win.document.body.scrollTop = 0;
}
View
@@ -49,7 +49,7 @@ Monocle.Flippers.Instant = function (reader) {
function turn(panel) {
- p.reader.selection.deselect(page().m.activeFrame.contentWindow);
+ p.reader.selection.deselect();
var dir = panel.properties.direction;
moveTo({ page: getPlace().pageNumber() + dir});
}
View
@@ -39,7 +39,7 @@ Monocle.Flippers.Scroller = function (reader, setPageFn) {
function turn(dir) {
if (p.turning) { return; }
- p.reader.selection.deselect(page().m.activeFrame.contentWindow);
+ p.reader.selection.deselect();
moveTo({ page: getPlace().pageNumber() + dir});
}
View
@@ -113,15 +113,10 @@ Monocle.Flippers.Slider = function (reader) {
}
- function deselect() {
- p.reader.selection.deselect(upperPage().m.activeFrame.contentWindow);
- }
-
-
function lift(dir, boxPointX) {
if (p.turnData.lifting || p.turnData.releasing) { return; }
- deselect();
+ p.reader.selection.deselect();
p.turnData.points = {
start: boxPointX,
View
@@ -99,7 +99,7 @@ Monocle.Panels.IMode = function (flipper, evtCallbacks) {
p.panels.central.contract();
- deselect();
+ p.reader.selection.deselect();
startCameo(function () {
p.divs.forwards.style.width = "33%";
@@ -172,18 +172,6 @@ Monocle.Panels.IMode = function (flipper, evtCallbacks) {
}
- function deselect() {
- for (var i = 0, cmpt; cmpt = p.reader.dom.find('component', i); ++i) {
- var sel = cmpt.contentWindow.getSelection() || cmpt.contentDocument.selection;
- //if (sel.collapse) { sel.collapse(true); }
- if (sel.removeAllRanges) { sel.removeAllRanges(); }
- if (sel.empty) { sel.empty(); }
- cmpt.contentDocument.body.scrollLeft = 0;
- cmpt.contentDocument.body.scrollTop = 0;
- }
- }
-
-
API.toggle = toggle;
API.modeOn = modeOn;
API.modeOff = modeOff;
View
@@ -89,6 +89,11 @@
— Ways that you can interact with Monocle pages.
</li>
<li>
+ <a href="selection/index.html">Selection</a>
+ &mdash; Fire events whenever the text selection changes in a Monocle
+ component.
+ </li>
+ <li>
<a href="stencil/index.html">Stencil</a>
&mdash; A Monocle feature that makes links clickable through panels.
</li>
View
@@ -66,9 +66,18 @@
<body class="narrow">
<a href="../index.html" class="backToGuide">&larr; Back to Guide</a>
- <h1>Selection events</h1>
+ <h1>Selection</h1>
<p>
- <!-- TODO -->
+ The Monocle.Selection object performs two roles. Firstly, it polls
+ components for any selected text.
+ It fires a <code>monocle:selection</code> event whenever text is
+ selected (and when that selection changes), and
+ fires a <code>monocle:deselection</code> event whenever all text is
+ deselected.
+ </p>
+ <p>
+ Secondly, it ensures that all text is deselected when a page turn
+ interaction commences.
</p>
<div id="reader"></div>

0 comments on commit 62ffa26

Please sign in to comment.