Permalink
Browse files

Beginnings of #75, propagate clicks across sites when a site opts-in …

…to the clicking.
  • Loading branch information...
1 parent 0e0ad32 commit 86322b424473c071c1dc9e807f3c69194c0cc9a0 @ianb ianb committed Mar 12, 2013
View
@@ -3,3 +3,4 @@ node_modules
.env*
addon/Profile
dump.rdb
+app/http/public/recorder.css
@@ -74,11 +74,14 @@ <h1>Form Example</h1>
<div>
- <label for="about">
- The Cat In The Hat, or the Cat In The Hat Comes Back: which is
- better, in essay form:
- </label>
- <textarea style="width: 100%; height: 10em" placeholder="There's no wrong answer! Except you must choose one."></textarea>
+ <button id="about-toggle" type="button">Essay (+)</button>
+ <div id="about-group" style="display: none">
+ <label for="about">
+ The Cat In The Hat, or the Cat In The Hat Comes Back: which is
+ better, in essay form:
+ </label>
+ <textarea style="width: 100%; height: 10em" placeholder="There's no wrong answer! Except you must choose one."></textarea>
+ </div>
</div>
<div>
@@ -117,7 +120,11 @@ <h1>Form Example</h1>
<!--<script src="bootstrap/js/bootstrap-carousel.js"></script>-->
<!--<script src="bootstrap/js/bootstrap-typeahead.js"></script>-->
+ <script>
+ TowTruck = {cloneClicks: "#about-toggle"};
+ </script>
<script src="/towtruck.js"></script>
<script src="startup.js"></script>
+ <script src="form.js"></script>
</body>
</html>
@@ -0,0 +1,11 @@
+$(function () {
+ $("#about-toggle").click(function () {
+ if ($("#about-group").is(":visible")) {
+ $("#about-group").hide();
+ $("#about-toggle").text("Essay (+)");
+ } else {
+ $("#about-group").show();
+ $("#about-toggle").text("Essay (-)");
+ }
+ });
+});
@@ -1,6 +1,6 @@
/* Cursor viewing support
*/
-define(["jquery", "ui", "util", "session", "element-finder", "tinycolor"], function ($, ui, util, session, elementFinder, tinycolor) {
+define(["jquery", "ui", "util", "session", "element-finder", "tinycolor", "eventMaker"], function ($, ui, util, session, elementFinder, tinycolor, eventMaker) {
var assert = util.assert;
var AssertionError = util.AssertionError;
@@ -293,12 +293,15 @@ define(["jquery", "ui", "util", "session", "element-finder", "tinycolor"], funct
}
});
-
function documentClick(event) {
// FIXME: this might just be my imagination, but somehow I just
// really don't want to do anything at this stage of the event
// handling (since I'm catching every click), and I'll just do
// something real soon:
+ if (event.towtruckInternal) {
+ // This is an artificial internal event
+ return;
+ }
setTimeout(function () {
if (elementFinder.ignoreElement(event.target)) {
return;
@@ -324,6 +327,8 @@ define(["jquery", "ui", "util", "session", "element-finder", "tinycolor"], funct
// last cursor update was calculated, so we force the cursor to
// the last location during a click:
if (! pos.sameUrl) {
+ // FIXME: if we *could have* done a local click, but we follow along
+ // later, we'll be in different states if that click was important.
return;
}
Cursor.getClient(pos.clientId).updatePosition(pos);
@@ -333,6 +338,9 @@ define(["jquery", "ui", "util", "session", "element-finder", "tinycolor"], funct
var top = offset.top + pos.offsetY;
var left = offset.left + pos.offsetX;
displayClick({top: top, left: left});
+ if (TowTruck.cloneClicks && target.is(TowTruck.cloneClicks)) {
+ eventMaker.performClick(target);
+ }
});
function displayClick(pos) {
@@ -0,0 +1,47 @@
+define(["jquery", "util"], function ($, util) {
+ var eventMaker = util.Module("eventMaker");
+ var assert = util.assert;
+
+ eventMaker.performClick = function (target) {
+ // FIXME: should accept other parameters, like Ctrl/Alt/etc
+ var event = document.createEvent("MouseEvents");
+ event.initMouseEvent(
+ "click", // type
+ true, // canBubble
+ true, // cancelable
+ window, // view
+ 0, // detail
+ 0, // screenX
+ 0, // screenY
+ 0, // clientX
+ 0, // clientY
+ false, // ctrlKey
+ false, // altKey
+ false, // shiftKey
+ false, // metaKey
+ 0, // button
+ null // relatedTarget
+ );
+ // FIXME: I'm not sure this custom attribute always propagates?
+ // seems okay in Firefox/Chrome, but I've had problems with
+ // setting attributes on keyboard events in the past.
+ event.towtruckInternal = true;
+ target = $(target)[0];
+ var cancelled = target.dispatchEvent(event);
+ if (cancelled) {
+ return;
+ }
+ if (target.tagName == "A") {
+ var href = target.href;
+ if (href) {
+ location.href = href;
+ return;
+ }
+ }
+ // FIXME: should do button clicks
+ };
+
+ eventMaker.inEvent = false;
+
+ return eventMaker;
+});

0 comments on commit 86322b4

Please sign in to comment.