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()`.
print-window-tiddler
Jermolene 2015-03-25 22:13:22 +00:00
rodzic 055a38ea4c
commit 758ba5edc2
2 zmienionych plików z 22 dodań i 14 usunięć

Wyświetl plik

@ -63,7 +63,7 @@ ButtonWidget.prototype.render = function(parent,nextSibling) {
// Add a click event handler
domNode.addEventListener("click",function (event) {
var handled = false;
if(self.invokeActions(event)) {
if(self.invokeActions(this,event)) {
handled = true;
}
if(self.to) {
@ -94,6 +94,13 @@ ButtonWidget.prototype.render = function(parent,nextSibling) {
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() {
return this.domNodes[0].getBoundingClientRect();
}

Wyświetl plik

@ -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) {
return this.invokeActionCall(this,event);
};
/*
Recursively search through descendants, invoking all actions encountered.
*/
Widget.prototype.invokeActionCall = function(here,event) {
Widget.prototype.invokeActions = function(triggeringWidget,event) {
var handled = false;
for(var t=0; t<here.children.length; t++) {
var child = here.children[t];
if(child.invokeAction && child.invokeAction(this,event)) {
// For each child widget
for(var t=0; t<this.children.length; t++) {
var child = this.children[t];
// Invoke the child if it is an action widget
if(child.invokeAction && child.invokeAction(triggeringWidget,event)) {
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;
}
}
return handled;
};
Widget.prototype.allowActionPropagation = function() {
return true;
};
exports.widget = Widget;
})();