mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-01-22 23:16:53 +00:00
Allow widgets to choose not to propagate actions
Allow widgets to choose not to propagate actions. This is important for widgets that themselves trigger actions. Note that this change will cause problems with any existing 5.1.8-prerelease plugins that call `invokeActions()`.
This commit is contained in:
parent
055a38ea4c
commit
758ba5edc2
@ -63,7 +63,7 @@ ButtonWidget.prototype.render = function(parent,nextSibling) {
|
|||||||
// Add a click event handler
|
// Add a click event handler
|
||||||
domNode.addEventListener("click",function (event) {
|
domNode.addEventListener("click",function (event) {
|
||||||
var handled = false;
|
var handled = false;
|
||||||
if(self.invokeActions(event)) {
|
if(self.invokeActions(this,event)) {
|
||||||
handled = true;
|
handled = true;
|
||||||
}
|
}
|
||||||
if(self.to) {
|
if(self.to) {
|
||||||
@ -94,6 +94,13 @@ ButtonWidget.prototype.render = function(parent,nextSibling) {
|
|||||||
this.domNodes.push(domNode);
|
this.domNodes.push(domNode);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
We don't allow actions to propagate because we trigger actions ourselves
|
||||||
|
*/
|
||||||
|
ButtonWidget.prototype.allowActionPropagation = function() {
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
ButtonWidget.prototype.getBoundingClientRect = function() {
|
ButtonWidget.prototype.getBoundingClientRect = function() {
|
||||||
return this.domNodes[0].getBoundingClientRect();
|
return this.domNodes[0].getBoundingClientRect();
|
||||||
}
|
}
|
||||||
|
@ -476,29 +476,30 @@ Widget.prototype.removeChildDomNodes = function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Invoke any action widgets that are descendants of this widget.
|
Invoke the action widgets that are descendents of the current widget.
|
||||||
*/
|
*/
|
||||||
Widget.prototype.invokeActions = function(event) {
|
Widget.prototype.invokeActions = function(triggeringWidget,event) {
|
||||||
return this.invokeActionCall(this,event);
|
|
||||||
};
|
|
||||||
|
|
||||||
/*
|
|
||||||
Recursively search through descendants, invoking all actions encountered.
|
|
||||||
*/
|
|
||||||
Widget.prototype.invokeActionCall = function(here,event) {
|
|
||||||
var handled = false;
|
var handled = false;
|
||||||
for(var t=0; t<here.children.length; t++) {
|
// For each child widget
|
||||||
var child = here.children[t];
|
for(var t=0; t<this.children.length; t++) {
|
||||||
if(child.invokeAction && child.invokeAction(this,event)) {
|
var child = this.children[t];
|
||||||
|
// Invoke the child if it is an action widget
|
||||||
|
if(child.invokeAction && child.invokeAction(triggeringWidget,event)) {
|
||||||
handled = true;
|
handled = true;
|
||||||
}
|
}
|
||||||
if(this.invokeActionCall(child,event)) {
|
// Propagate through through the child if it permits it
|
||||||
|
if(child.allowActionPropagation() && child.invokeActions(triggeringWidget,event)) {
|
||||||
handled = true;
|
handled = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return handled;
|
return handled;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Widget.prototype.allowActionPropagation = function() {
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
exports.widget = Widget;
|
exports.widget = Widget;
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
Loading…
Reference in New Issue
Block a user