diff --git a/core/modules/editor/engines/framed.js b/core/modules/editor/engines/framed.js index 6e7da24da..5eee8255b 100644 --- a/core/modules/editor/engines/framed.js +++ b/core/modules/editor/engines/framed.js @@ -79,6 +79,7 @@ function FramedEngine(options) { // Add event listeners $tw.utils.addEventListeners(this.domNode,[ {name: "click",handlerObject: this,handlerMethod: "handleClickEvent"}, + {name: "focus",handlerObject: this.widget,handlerMethod: "handleFocusEvent"}, {name: "input",handlerObject: this,handlerMethod: "handleInputEvent"}, {name: "keydown",handlerObject: this.widget,handlerMethod: "handleKeydownEvent"} ]); @@ -152,6 +153,13 @@ FramedEngine.prototype.focus = function() { this.domNode.select(); } }; + +/* +Handle the focus event +*/ +FramedEngine.prototype.handleFocusEvent = function() { + this.widget.cancelPopups(); +}; /* Handle a click diff --git a/core/modules/editor/engines/simple.js b/core/modules/editor/engines/simple.js index bb77893d7..acd4bc3d2 100644 --- a/core/modules/editor/engines/simple.js +++ b/core/modules/editor/engines/simple.js @@ -122,6 +122,7 @@ SimpleEngine.prototype.handleInputEvent = function(event) { Handle a dom "focus" event */ SimpleEngine.prototype.handleFocusEvent = function(event) { + this.widget.cancelPopups(); if(this.widget.editFocusPopup) { $tw.popup.triggerPopup({ domNode: this.domNode, diff --git a/core/modules/editor/factory.js b/core/modules/editor/factory.js index 0e44bd459..c2e56f150 100644 --- a/core/modules/editor/factory.js +++ b/core/modules/editor/factory.js @@ -248,6 +248,13 @@ function editTextWidgetFactory(toolbarEngine,nonToolbarEngine) { } }; + /* + Cancel Popups + */ + EditTextWidget.prototype.cancelPopups = function() { + $tw.popup.cancel(0,this.engine.domNode); + }; + /* Handle a dom "keydown" event, which we'll bubble up to our container for the keyboard widgets benefit */ diff --git a/core/modules/utils/dom/popup.js b/core/modules/utils/dom/popup.js index d44da6779..ce148af95 100644 --- a/core/modules/utils/dom/popup.js +++ b/core/modules/utils/dom/popup.js @@ -148,20 +148,44 @@ Popup.prototype.show = function(options) { } }; +/* +Detect if a Popup contains an input field that has focus +Returns true or false +*/ +Popup.prototype.detectInputWithinPopup = function(node) { + var withinPopup = false; + for(var i=0; i