1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-27 20:10:03 +00:00

Fixed tag autocomplete popup on focus

This commit is contained in:
Jeremy Ruston 2013-10-23 17:41:12 +01:00
parent dfdb34a5cc
commit f2ac04943f
2 changed files with 32 additions and 4 deletions

View File

@ -54,9 +54,10 @@ EditTextWidget.prototype.render = function(parent,nextSibling) {
domNode.setAttribute("value",editInfo.value) domNode.setAttribute("value",editInfo.value)
} }
// Add an input event handler // Add an input event handler
domNode.addEventListener("input",function (event) { $tw.utils.addEventListeners(domNode,[
return self.handleInputEvent(event); {name: "focus", handlerObject: this, handlerMethod: "handleFocusEvent"},
},false); {name: "input", handlerObject: this, handlerMethod: "handleInputEvent"}
]);
// Insert the element into the DOM // Insert the element into the DOM
parent.insertBefore(domNode,nextSibling); parent.insertBefore(domNode,nextSibling);
this.domNodes.push(domNode); this.domNodes.push(domNode);
@ -108,6 +109,15 @@ EditTextWidget.prototype.execute = function() {
this.editDefault = this.getAttribute("default",""); this.editDefault = this.getAttribute("default","");
this.editClass = this.getAttribute("class"); this.editClass = this.getAttribute("class");
this.editPlaceholder = this.getAttribute("placeholder"); 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 // Get the editor element tag and type
var tag,type; var tag,type;
if(this.editField === "text") { if(this.editField === "text") {
@ -186,6 +196,24 @@ EditTextWidget.prototype.handleInputEvent = function(event) {
return true; 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() { EditTextWidget.prototype.saveChanges = function() {
var text = this.domNodes[0].value var text = this.domNodes[0].value
if(this.editField) { if(this.editField) {

View File

@ -30,7 +30,7 @@ Popup.prototype.show = function(options) {
}; };
Popup.prototype.handleEvent = function(event) { 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(); this.cancel();
} }
}; };