From 5fd300083832eaca4de828191149089b544e34de Mon Sep 17 00:00:00 2001 From: Jeremy Ruston Date: Tue, 27 Nov 2012 22:27:53 +0000 Subject: [PATCH] Allowed zooming in to any element with the data-tw-zoom attribute --- core/modules/macros/zoomable.js | 36 +++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/core/modules/macros/zoomable.js b/core/modules/macros/zoomable.js index 91f988dda..105bb52f4 100644 --- a/core/modules/macros/zoomable.js +++ b/core/modules/macros/zoomable.js @@ -63,6 +63,10 @@ exports.executeMacro = function() { return this.outerFrame; }; +exports.postRenderInDom = function() { + this.zoomAll(); +}; + /* Bring a dom node into view by setting the viewport (translation and scale factors) appropriately. @@ -95,19 +99,25 @@ exports.zoomAll = function() { var node = nodes[c]; if(node.getAttribute && node.getAttribute("data-tw-zoom")) { var zoom = JSON.parse(node.getAttribute("data-tw-zoom")); - if(zoom) { - if(zoom.x < bounds.left) { - bounds.left = zoom.x; - } - if(zoom.y < bounds.top) { - bounds.top = zoom.y; - } - if((zoom.x + zoom.w) > bounds.right) { - bounds.right = zoom.x + zoom.w; - } - if((zoom.y + zoom.h) > bounds.bottom) { - bounds.bottom = zoom.y + zoom.h; - } + if(zoom === true) { + zoom = { + x: node.offsetLeft, + y: node.offsetTop, + w: node.scrollWidth, + h: node.scrollHeight + }; + } + if(zoom.x < bounds.left) { + bounds.left = zoom.x; + } + if(zoom.y < bounds.top) { + bounds.top = zoom.y; + } + if((zoom.x + zoom.w) > bounds.right) { + bounds.right = zoom.x + zoom.w; + } + if((zoom.y + zoom.h) > bounds.bottom) { + bounds.bottom = zoom.y + zoom.h; } } if(node.hasChildNodes()) {