From 6425f611d8cdbd02ebecb75d159f004808ca743b Mon Sep 17 00:00:00 2001 From: primalmotion Date: Wed, 4 Aug 2010 17:47:08 +0200 Subject: [PATCH] * Adding a way to set the DOM document to use. This is very usefull when you need to open a new window (with a new document) from javascript, without having to reload the script.js. (cherry picked from commit 8ded53c1de06d01e50d58543c19e73926f0fbbd4) Signed-off-by: Joel Martin --- include/canvas.js | 17 +++++++++-------- include/rfb.js | 6 ++++-- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/include/canvas.js b/include/canvas.js index 7b02b3e..e6b7b9e 100644 --- a/include/canvas.js +++ b/include/canvas.js @@ -41,6 +41,7 @@ Util.conf_default(conf, that, 'true_color', true); Util.conf_default(conf, that, 'focused', true); Util.conf_default(conf, that, 'colourMap', []); Util.conf_default(conf, that, 'scale', 1); +Util.conf_default(conf, that, 'currentDocument', document); // Override some specific getters/setters that.set_prefer_js = function(val) { @@ -386,8 +387,8 @@ that.start = function(keyPressFunc, mouseButtonFunc, mouseMoveFunc) { c_mouseButton = mouseButtonFunc || null; c_mouseMove = mouseMoveFunc || null; - Util.addEvent(document, 'keydown', onKeyDown); - Util.addEvent(document, 'keyup', onKeyUp); + Util.addEvent(conf.currentDocument, 'keydown', onKeyDown); + Util.addEvent(conf.currentDocument, 'keyup', onKeyUp); Util.addEvent(c, 'mousedown', onMouseDown); Util.addEvent(c, 'mouseup', onMouseUp); Util.addEvent(c, 'mousemove', onMouseMove); @@ -395,8 +396,8 @@ that.start = function(keyPressFunc, mouseButtonFunc, mouseMoveFunc) { onMouseWheel); /* Work around right and middle click browser behaviors */ - Util.addEvent(document, 'click', onMouseDisable); - Util.addEvent(document.body, 'contextmenu', onMouseDisable); + Util.addEvent(conf.currentDocument, 'click', onMouseDisable); + Util.addEvent(conf.currentDocument.body, 'contextmenu', onMouseDisable); Util.Debug("<< Canvas.start"); }; @@ -452,8 +453,8 @@ that.clear = function() { that.stop = function() { var c = conf.target; - Util.removeEvent(document, 'keydown', onKeyDown); - Util.removeEvent(document, 'keyup', onKeyUp); + Util.removeEvent(conf.currentDocument, 'keydown', onKeyDown); + Util.removeEvent(conf.currentDocument, 'keyup', onKeyUp); Util.removeEvent(c, 'mousedown', onMouseDown); Util.removeEvent(c, 'mouseup', onMouseUp); Util.removeEvent(c, 'mousemove', onMouseMove); @@ -461,8 +462,8 @@ that.stop = function() { onMouseWheel); /* Work around right and middle click browser behaviors */ - Util.removeEvent(document, 'click', onMouseDisable); - Util.removeEvent(document.body, 'contextmenu', onMouseDisable); + Util.removeEvent(conf.currentDocument, 'click', onMouseDisable); + Util.removeEvent(conf.currentDocument.body, 'contextmenu', onMouseDisable); // Turn off cursor rendering if (conf.cursor_uri) { diff --git a/include/rfb.js b/include/rfb.js index 5c8e2d1..ba684ee 100644 --- a/include/rfb.js +++ b/include/rfb.js @@ -132,7 +132,7 @@ var that = {}, // Public API interface // // VNC viewport rendering Canvas -Util.conf_default(conf, that, 'target', 'VNC_canvas'); +//Util.conf_default(conf, that, 'target', 'VNC_canvas'); Util.conf_default(conf, that, 'encrypt', false, true); Util.conf_default(conf, that, 'true_color', true, true); @@ -140,6 +140,8 @@ Util.conf_default(conf, that, 'true_color', true, true); Util.conf_default(conf, that, 'b64encode', true, true); Util.conf_default(conf, that, 'local_cursor', true, true); +Util.conf_default(conf, that, 'currentDocument', true, document); + // time to wait for connection Util.conf_default(conf, that, 'connectTimeout', 2000); // frequency to check for send/receive @@ -195,7 +197,7 @@ function constructor() { } // Initialize canvas try { - canvas = new Canvas({'target': conf.target}); + canvas = new Canvas({'target': conf.target, 'currentDocument': conf.currentDocument}); } catch (exc) { Util.Error("Canvas exception: " + exc); updateState('fatal', "No working Canvas");