From 20cd398e8853e1279031f4b22507ea40d95c93b6 Mon Sep 17 00:00:00 2001 From: Jeremy Ruston Date: Mon, 14 Oct 2013 23:32:01 +0100 Subject: [PATCH] Fix popup positioning in the reveal widget --- core/modules/new_widgets/reveal.js | 34 ++++++++++++++++++++++++++++++ core/modules/utils/fakedom.js | 1 + core/ui/MissingTemplate.tid | 6 +++--- 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/core/modules/new_widgets/reveal.js b/core/modules/new_widgets/reveal.js index 9f094bfd8..f57ccf7c2 100755 --- a/core/modules/new_widgets/reveal.js +++ b/core/modules/new_widgets/reveal.js @@ -33,9 +33,43 @@ RevealWidget.prototype.render = function(parent,nextSibling) { var domNode = this.document.createElement("div"); parent.insertBefore(domNode,nextSibling); this.renderChildren(domNode,null); + if(!domNode.isTiddlyWikiFakeDom && this.type === "popup" && this.isOpen) { + this.positionPopup(domNode); + } this.domNodes.push(domNode); }; +RevealWidget.prototype.positionPopup = function(domNode) { + domNode.style.position = "absolute"; + domNode.style.zIndex = "1000"; + switch(this.position) { + case "left": + domNode.style.left = (this.popup.left - domNode.offsetWidth) + "px"; + domNode.style.top = this.popup.top + "px"; + break; + case "above": + domNode.style.left = this.popup.left + "px"; + domNode.style.top = (this.popup.top - domNode.offsetHeight) + "px"; + break; + case "aboveright": + domNode.style.left = (this.popup.left + this.popup.width) + "px"; + domNode.style.top = (this.popup.top + this.popup.height - domNode.offsetHeight) + "px"; + break; + case "right": + domNode.style.left = (this.popup.left + this.popup.width) + "px"; + domNode.style.top = this.popup.top + "px"; + break; + case "belowleft": + domNode.style.left = (this.popup.left + this.popup.width - domNode.offsetWidth) + "px"; + domNode.style.top = (this.popup.top + this.popup.height) + "px"; + break; + default: // Below + domNode.style.left = this.popup.left + "px"; + domNode.style.top = (this.popup.top + this.popup.height) + "px"; + break; + } +}; + /* Compute the internal state of the widget */ diff --git a/core/modules/utils/fakedom.js b/core/modules/utils/fakedom.js index fd9be9e90..5b3502f46 100755 --- a/core/modules/utils/fakedom.js +++ b/core/modules/utils/fakedom.js @@ -28,6 +28,7 @@ var TW_TextNode = function(text) { var TW_Element = function(tag,namespace) { bumpSequenceNumber(this); + this.isTiddlyWikiFakeDom = true; this.tag = tag; this.attributes = {}; this.isRaw = false; diff --git a/core/ui/MissingTemplate.tid b/core/ui/MissingTemplate.tid index 4e7980908..c7ab0ed19 100644 --- a/core/ui/MissingTemplate.tid +++ b/core/ui/MissingTemplate.tid @@ -1,8 +1,8 @@ title: $:/core/ui/MissingTemplate -<$button popup="$:/state/missingpopup" qualifyTiddlerTitles="yes" class="btn-invisible tw-missing-tiddler-label"><$view field="title" format="text" /> -<$reveal state="$:/state/missingpopup" type="popup" position="below" qualifyTiddlerTitles="yes" >
+
<$button popup="$:/state/missingpopup" qualifyTiddlerTitles="yes" class="btn-invisible tw-missing-tiddler-label"><$view field="title" format="text" /> +<$reveal state="$:/state/missingpopup" type="popup" position="below" qualifyTiddlerTitles="yes">
<$transclude title="$:/core/ui/ListItemTemplate"/>
<$list filter="[is[current]backlinks[]sort[title]]" template="$:/core/ui/ListItemTemplate"/> -
+