mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-11-20 17:24:52 +00:00
Medium-sized refactoring of macro architecture
Now event handlers are attached to element nodes, not to macro nodes.
This commit is contained in:
@@ -40,12 +40,6 @@ exports.executeMacro = function() {
|
||||
return child;
|
||||
};
|
||||
|
||||
exports.addEventHandlers = function() {
|
||||
if(this.editor.addEventHandlers) {
|
||||
this.editor.addEventHandlers();
|
||||
}
|
||||
};
|
||||
|
||||
exports.postRenderInDom = function() {
|
||||
if(this.editor.postRenderInDom) {
|
||||
this.editor.postRenderInDom();
|
||||
@@ -66,8 +60,6 @@ exports.refreshInDom = function(changes) {
|
||||
this.execute(this.parents,this.tiddlerTitle);
|
||||
// Render to the DOM
|
||||
this.child.renderInDom(parent,nextSibling);
|
||||
this.domNode = this.child.domNode;
|
||||
this.addEventHandlers();
|
||||
}
|
||||
} else {
|
||||
// Refresh any children
|
||||
|
||||
@@ -19,7 +19,10 @@ function BitmapEditor(macroNode) {
|
||||
BitmapEditor.prototype.getChild = function() {
|
||||
return $tw.Tree.Element("canvas",{
|
||||
"class": ["tw-edit-field"]
|
||||
},[]);
|
||||
},[],{
|
||||
events: ["touchstart","touchmove","touchend","mousedown","mousemove","mouseup"],
|
||||
eventHandler: this
|
||||
});
|
||||
};
|
||||
|
||||
BitmapEditor.prototype.postRenderInDom = function() {
|
||||
@@ -43,57 +46,54 @@ BitmapEditor.prototype.postRenderInDom = function() {
|
||||
ctx.drawImage(currImage,0,0);
|
||||
};
|
||||
|
||||
BitmapEditor.prototype.addEventHandlers = function() {
|
||||
var self = this;
|
||||
this.macroNode.child.domNode.addEventListener("touchstart",function(event) {
|
||||
self.brushDown = true;
|
||||
self.strokeStart(event.touches[0].clientX,event.touches[0].clientY);
|
||||
BitmapEditor.prototype.handleEvent = function(event) {
|
||||
switch(event.type) {
|
||||
case "touchstart":
|
||||
this.brushDown = true;
|
||||
this.strokeStart(event.touches[0].clientX,event.touches[0].clientY);
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
return false;
|
||||
},false);
|
||||
this.macroNode.child.domNode.addEventListener("touchmove",function(event) {
|
||||
if(self.brushDown) {
|
||||
self.strokeMove(event.touches[0].clientX,event.touches[0].clientY);
|
||||
case "touchmove":
|
||||
if(this.brushDown) {
|
||||
this.strokeMove(event.touches[0].clientX,event.touches[0].clientY);
|
||||
}
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
return false;
|
||||
},false);
|
||||
this.macroNode.child.domNode.addEventListener("touchend",function(event) {
|
||||
if(self.brushDown) {
|
||||
self.brushDown = false;
|
||||
self.strokeEnd();
|
||||
case "touchend":
|
||||
if(this.brushDown) {
|
||||
this.brushDown = false;
|
||||
this.strokeEnd();
|
||||
}
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
return false;
|
||||
},false);
|
||||
this.macroNode.child.domNode.addEventListener("mousedown",function(event) {
|
||||
self.strokeStart(event.clientX,event.clientY);
|
||||
self.brushDown = true;
|
||||
case "mousedown":
|
||||
this.strokeStart(event.clientX,event.clientY);
|
||||
this.brushDown = true;
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
return false;
|
||||
},false);
|
||||
this.macroNode.child.domNode.addEventListener("mousemove",function(event) {
|
||||
if(self.brushDown) {
|
||||
self.strokeMove(event.clientX,event.clientY);
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
return false;
|
||||
}
|
||||
},false);
|
||||
this.macroNode.child.domNode.addEventListener("mouseup",function(event) {
|
||||
if(self.brushDown) {
|
||||
self.brushDown = false;
|
||||
self.strokeEnd();
|
||||
case "mousemove":
|
||||
if(this.brushDown) {
|
||||
this.strokeMove(event.clientX,event.clientY);
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
},false);
|
||||
case "mouseup":
|
||||
if(this.brushDown) {
|
||||
this.brushDown = false;
|
||||
this.strokeEnd();
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
BitmapEditor.prototype.adjustCoordinates = function(x,y) {
|
||||
|
||||
@@ -55,12 +55,10 @@ TextEditor.prototype.getChild = function() {
|
||||
attributes.value = value;
|
||||
}
|
||||
// Wrap the editor control in a div
|
||||
return $tw.Tree.Element("div",{},[$tw.Tree.Element(tagName,attributes,content)]);
|
||||
};
|
||||
|
||||
TextEditor.prototype.addEventHandlers = function() {
|
||||
this.macroNode.child.domNode.addEventListener("focus",this,false);
|
||||
this.macroNode.child.domNode.addEventListener("keyup",this,false);
|
||||
return $tw.Tree.Element("div",{},[$tw.Tree.Element(tagName,attributes,content)],{
|
||||
events: ["focus","keyup"],
|
||||
eventHandler: this
|
||||
});
|
||||
};
|
||||
|
||||
TextEditor.prototype.handleEvent = function(event) {
|
||||
|
||||
Reference in New Issue
Block a user