From f2ac04943fbf8343dfafcbb4a110d71fec01dd47 Mon Sep 17 00:00:00 2001 From: Jeremy Ruston Date: Wed, 23 Oct 2013 17:41:12 +0100 Subject: [PATCH] Fixed tag autocomplete popup on focus --- core/modules/new_widgets/edit-text.js | 34 ++++++++++++++++++++++++--- core/modules/utils/dom/popup.js | 2 +- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/core/modules/new_widgets/edit-text.js b/core/modules/new_widgets/edit-text.js index 4e4bb6fde..c4bd373f3 100644 --- a/core/modules/new_widgets/edit-text.js +++ b/core/modules/new_widgets/edit-text.js @@ -54,9 +54,10 @@ EditTextWidget.prototype.render = function(parent,nextSibling) { domNode.setAttribute("value",editInfo.value) } // Add an input event handler - domNode.addEventListener("input",function (event) { - return self.handleInputEvent(event); - },false); + $tw.utils.addEventListeners(domNode,[ + {name: "focus", handlerObject: this, handlerMethod: "handleFocusEvent"}, + {name: "input", handlerObject: this, handlerMethod: "handleInputEvent"} + ]); // Insert the element into the DOM parent.insertBefore(domNode,nextSibling); this.domNodes.push(domNode); @@ -108,6 +109,15 @@ EditTextWidget.prototype.execute = function() { this.editDefault = this.getAttribute("default",""); this.editClass = this.getAttribute("class"); this.editPlaceholder = this.getAttribute("placeholder"); + this.editFocusSet = this.getAttribute("focusSet"); + this.qualifyTiddlerTitles = this.getAttribute("qualifyTiddlerTitles");; + // Qualify tiddler titles if required + if(this.qualifyTiddlerTitles) { + var qualifier = this.getStateQualifier(); + if(this.editFocusSet) { + this.editFocusSet = this.editFocusSet + "-" + qualifier; + } + } // Get the editor element tag and type var tag,type; if(this.editField === "text") { @@ -186,6 +196,24 @@ EditTextWidget.prototype.handleInputEvent = function(event) { return true; }; +EditTextWidget.prototype.handleFocusEvent = function(event) { + if(this.editFocusSet) { +console.log("Focus",{ + domNode: this.domNodes[0], + title: this.editFocusSet, + wiki: this.wiki, + force: true + }) + $tw.popup.triggerPopup({ + domNode: this.domNodes[0], + title: this.editFocusSet, + wiki: this.wiki, + force: true + }); + } + return true; +}; + EditTextWidget.prototype.saveChanges = function() { var text = this.domNodes[0].value if(this.editField) { diff --git a/core/modules/utils/dom/popup.js b/core/modules/utils/dom/popup.js index 2626fff0f..f79e76120 100644 --- a/core/modules/utils/dom/popup.js +++ b/core/modules/utils/dom/popup.js @@ -30,7 +30,7 @@ Popup.prototype.show = function(options) { }; Popup.prototype.handleEvent = function(event) { - if(event.type === "click" && !$tw.utils.domContains(this.anchorDomNode,event.target)) { + if(event.type === "click" && this.anchorDomNode !== event.target && !$tw.utils.domContains(this.anchorDomNode,event.target)) { this.cancel(); } };