From ec63c95999027de04010b22627595de2bf7e52b7 Mon Sep 17 00:00:00 2001 From: Simon Huber Date: Mon, 19 Aug 2019 18:37:57 +0200 Subject: [PATCH 1/2] add action-popup widget ... ... that allows triggering popups via keyboard shortcuts (popups need to be positioned using css) --- core/modules/widgets/action-popup.js | 78 ++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 core/modules/widgets/action-popup.js diff --git a/core/modules/widgets/action-popup.js b/core/modules/widgets/action-popup.js new file mode 100644 index 00000000000..a5b9ab173aa --- /dev/null +++ b/core/modules/widgets/action-popup.js @@ -0,0 +1,78 @@ +/*\ +title: $:/core/modules/widgets/action-popup.js +type: application/javascript +module-type: widget + +ActionPopup widget + +\*/ +(function(){ + +/*jslint node: true, browser: true */ +/*global $tw: false */ +"use strict"; + +var Widget = require("$:/core/modules/widgets/widget.js").widget; + +var ActionPopupWidget = function(parseTreeNode,options) { + this.initialise(parseTreeNode,options); +}; + +/* +Inherit from the base widget class +*/ +ActionPopupWidget.prototype = new Widget(); + +/* +Render this widget into the DOM +*/ +ActionPopupWidget.prototype.render = function(parent,nextSibling) { + var self = this; + // Remember parent + this.parentDomNode = parent; + // Compute attributes and execute state + this.computeAttributes(); + this.execute(); + var domNode = this.document.createElement("div"); + parent.insertBefore(domNode,nextSibling); + this.domNodes.push(domNode); +}; + +ActionPopupWidget.prototype.triggerPopup = function(event) { + $tw.popup.triggerPopup({ + domNode: this.domNodes[0], + title: this.popup, + wiki: this.wiki + }); +}; + +/* +Compute the internal state of the widget +*/ +ActionPopupWidget.prototype.execute = function() { + // Get attributes + this.popup = this.getAttribute("$popup"); +}; + +ActionPopupWidget.prototype.invokeAction = function(triggeringWidget,event) { + if(this.popup) { + this.triggerPopup(); + } + return true; +}; + +/* +Selectively refreshes the widget if needed. Returns true if the widget or any of its children needed re-rendering +*/ +ActionPopupWidget.prototype.refresh = function(changedTiddlers) { + var changedAttributes = this.computeAttributes(); + if(changedAttributes["$popup"] || (this.popup && changedTiddlers[this.popup])) { + this.refreshSelf(); + return true; + } + return this.refreshChildren(changedTiddlers); +}; + +exports["action-popup"] = ActionPopupWidget; + +})(); From 9abd813b42d95c9617a4794e8519e9a5f6b9a710 Mon Sep 17 00:00:00 2001 From: Simon Huber Date: Wed, 21 Aug 2019 08:24:26 +0200 Subject: [PATCH 2/2] Update action-popup.js --- core/modules/widgets/action-popup.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/core/modules/widgets/action-popup.js b/core/modules/widgets/action-popup.js index a5b9ab173aa..e20a6db8e4b 100644 --- a/core/modules/widgets/action-popup.js +++ b/core/modules/widgets/action-popup.js @@ -39,11 +39,11 @@ ActionPopupWidget.prototype.render = function(parent,nextSibling) { }; ActionPopupWidget.prototype.triggerPopup = function(event) { - $tw.popup.triggerPopup({ - domNode: this.domNodes[0], - title: this.popup, - wiki: this.wiki - }); + $tw.popup.triggerPopup({ + domNode: this.domNodes[0], + title: this.popup, + wiki: this.wiki + }); }; /*