mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-05 01:26:18 +00:00
5b85786f73
* Fix popup location for tables This commit introduces the `popupAbsCoords` option to the $button widget and implements an absolut coordinate format. Coordinates for popups are stored in the format `(x,y,w,h)`. These coordinates are relative to the offset parent of the element that defines the popup. This commits adds a second format `@(x,y,w,h)`. Coordinates specified in this format a relative to the pages root element. The `popupAbsCoords` option of the $button widget enables the use of this coordinates. * Unify the declaration of the RegEx for parsing the popup-position The regular expression was declared in three locations with the same content. This commit supplies a new function `parseCoordinates` in `popup.js`. This function returns the parsed coordinates and understands the classic/absolute coordinates. This function is used in `reveal.js` and `action-popup.js` to parse the coordinates. * Add documentation for coordinate systems * Consolidate creating coordinate strings The Popup object now contains a `buildCoordinates` method that can be used to build coordinate strings. It takes an "enum" for the coordinate- system to use. This makes everything easily extensible and prevents the use of magic values. * Add tests for `parseCoordinates` and `buildCoordinates` * Add `tv-popup-abs-coords` to `collectDOMVariables` This will make the absolute coordinates available for the `DraggableWidget` and the `EventCatcherWidget`. * Add documentation for the `tv-popup-abs-coords` ... to the `DraggableWidget` and the `EventCatcherWidget`.
84 lines
1.9 KiB
JavaScript
84 lines
1.9 KiB
JavaScript
/*\
|
|
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";
|
|
};
|
|
|
|
/*
|
|
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 coordinates = $tw.popup.parseCoordinates(this.actionCoords || "");
|
|
if(coordinates) {
|
|
$tw.popup.triggerPopup({
|
|
domNode: null,
|
|
domNodeRect: {
|
|
left: coordinates.left,
|
|
top: coordinates.top,
|
|
width: coordinates.width,
|
|
height: coordinates.height
|
|
},
|
|
title: this.actionState,
|
|
wiki: this.wiki,
|
|
floating: this.floating,
|
|
absolute: coordinates.absolute
|
|
});
|
|
} else {
|
|
$tw.popup.cancel(0);
|
|
}
|
|
return true; // Action was invoked
|
|
};
|
|
|
|
exports["action-popup"] = ActionPopupWidget;
|
|
|
|
})();
|