From 581d165822239aaf2827e4e49b189855bd976143 Mon Sep 17 00:00:00 2001 From: Jeremy Ruston Date: Tue, 13 Mar 2012 15:12:23 +0000 Subject: [PATCH] Catch navigation events that fall through to the document And broadcast them back to the first story macro that accepts them --- js/App.js | 4 ++++ js/Renderer.js | 39 +++++++++++++++++++++++++++++++++++---- 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/js/App.js b/js/App.js index 63aae7e7f..4bf2be69b 100644 --- a/js/App.js +++ b/js/App.js @@ -120,6 +120,10 @@ var App = function() { text: "The time was recently " + (new Date()).toString() })); },3000); + // Listen for navigate events that weren't caught + document.addEventListener("tw-navigate",function (event) { + renderer.broadcastEvent(event); + },false); } }; diff --git a/js/Renderer.js b/js/Renderer.js index 04bd0d03e..9262b33b5 100644 --- a/js/Renderer.js +++ b/js/Renderer.js @@ -34,6 +34,10 @@ Node.prototype.clone = function() { return this; }; +Node.prototype.broadcastEvent = function(event) { + return true; +} + Node.prototype.execute = Node.prototype.render = Node.prototype.renderInDom = @@ -220,10 +224,6 @@ MacroNode.prototype.renderInDom = function(parentDomNode,insertBefore) { } }; -MacroNode.prototype.handleEvent = function(event) { - return this.macro.events[event.type].call(this,event); -}; - MacroNode.prototype.refresh = function(changes) { var t, self = this; @@ -267,6 +267,26 @@ MacroNode.prototype.refreshInDom = function(changes) { } }; +MacroNode.prototype.handleEvent = function(event) { + return this.macro.events[event.type].call(this,event); +}; + +MacroNode.prototype.broadcastEvent = function(event) { + if(this.macro.events && this.macro.events.hasOwnProperty(event.type)) { + if(!this.handleEvent(event)) { + return false; + } + } + if(this.content) { + for(var t=0; t