1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-04 00:56:17 +00:00
TiddlyWiki5/core/modules/widgets/action-popup.js

84 lines
1.9 KiB
JavaScript
Raw Normal View History

2020-03-03 12:03:32 +00:00
/*\
title: $:/core/modules/widgets/action-popup.js
type: application/javascript
module-type: widget
Action widget to trigger a popup.
\*/
(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) {
this.computeAttributes();
this.execute();
};
/*
Compute the internal state of the widget
*/
ActionPopupWidget.prototype.execute = function() {
this.actionState = this.getAttribute("$state");
this.actionCoords = this.getAttribute("$coords");
this.floating = this.getAttribute("$floating","no") === "yes";
2020-03-03 12:03:32 +00:00
};
/*
Refresh the widget by ensuring our attributes are up to date
*/
ActionPopupWidget.prototype.refresh = function(changedTiddlers) {
var changedAttributes = this.computeAttributes();
if(changedAttributes["$state"] || changedAttributes["$coords"]) {
this.refreshSelf();
return true;
}
return this.refreshChildren(changedTiddlers);
};
/*
Invoke the action associated with this widget
*/
ActionPopupWidget.prototype.invokeAction = function(triggeringWidget,event) {
// Trigger the popup
var popupLocationRegExp = /^\((-?[0-9\.E]+),(-?[0-9\.E]+),(-?[0-9\.E]+),(-?[0-9\.E]+)\)$/,
match = popupLocationRegExp.exec(this.actionCoords || "");
2020-03-03 12:03:32 +00:00
if(match) {
$tw.popup.triggerPopup({
domNode: null,
domNodeRect: {
left: parseFloat(match[1]),
top: parseFloat(match[2]),
width: parseFloat(match[3]),
height: parseFloat(match[4])
},
title: this.actionState,
wiki: this.wiki,
floating: this.floating
2020-03-03 12:03:32 +00:00
});
} else {
$tw.popup.cancel(0);
2020-03-03 12:03:32 +00:00
}
return true; // Action was invoked
};
exports["action-popup"] = ActionPopupWidget;
})();