mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2026-09-04 09:08:54 +00:00
Added reveal macro
This commit is contained in:
@@ -14,64 +14,55 @@ Module that creates a $tw.utils.Popup object prototype that manages popups in th
|
||||
|
||||
/*
|
||||
Creates a Popup object with these options:
|
||||
wiki: the wiki to use for resolving tiddler titles
|
||||
rootElement: the DOM element to which the popup zapper should be attached
|
||||
*/
|
||||
var Popup = function(options) {
|
||||
options = options || {};
|
||||
this.wiki = options.wiki;
|
||||
this.rootElement = options.rootElement || document.body;
|
||||
this.popupTextRef = null;
|
||||
};
|
||||
|
||||
Popup.prototype.popup = function(stateTextRef) {
|
||||
Popup.prototype.show = function(options) {
|
||||
this.cancel();
|
||||
this.popupTextRef = stateTextRef;
|
||||
this.rootElement.addEventListener("click",this,true);
|
||||
this.title = options.title;
|
||||
this.wiki = options.wiki;
|
||||
// this.rootElement.addEventListener("click",this,true);
|
||||
};
|
||||
|
||||
Popup.prototype.handleEvent = function(event) {
|
||||
if(event.type === "click") {
|
||||
this.rootElement.removeEventListener("click",this,true);
|
||||
this.cancel();
|
||||
}
|
||||
};
|
||||
|
||||
Popup.prototype.cancel = function() {
|
||||
if(this.popupTextRef) {
|
||||
this.wiki.deleteTextReference(this.popupTextRef);
|
||||
this.popupTextRef = null;
|
||||
// this.rootElement.removeEventListener("click",this,true);
|
||||
if(this.title) {
|
||||
this.wiki.deleteTiddler(this.title);
|
||||
this.title = null;
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
Trigger a popup open or closed. Parameters are in a hashmap:
|
||||
textRef: text reference where the popup details are stored
|
||||
title: title of the tiddler where the popup details are stored
|
||||
domNode: dom node to which the popup will be positioned
|
||||
qualifyTiddlerTitles: "yes" if state tiddler titles are to be qualified
|
||||
contextTiddlerTitle: title of tiddler providing context for text references
|
||||
contextParents: parent stack
|
||||
wiki: wiki
|
||||
*/
|
||||
Popup.prototype.triggerPopup = function(options) {
|
||||
// Get the textref of the popup state tiddler
|
||||
var textRef = options.textRef;
|
||||
if(options.qualifyTiddlerTitles === "yes") {
|
||||
textRef = textRef + "(" + options.contextParents.join(",") + "," + options.contextTiddlerTitle + ")";
|
||||
}
|
||||
// Get the current popup state tiddler
|
||||
var value = options.wiki.getTextReference(textRef,"",options.contextTiddlerTitle);
|
||||
var value = options.wiki.getTextReference(options.title,"");
|
||||
console.log("Value is",value)
|
||||
// Check if the popup is open by checking whether it matches "(<x>,<y>)"
|
||||
var popupLocationRegExp = /^\((-?[0-9\.E]+),(-?[0-9\.E]+),(-?[0-9\.E]+),(-?[0-9\.E]+)\)$/;
|
||||
if(popupLocationRegExp.test(value)) {
|
||||
this.cancel();
|
||||
} else {
|
||||
// Set the position if we're opening it
|
||||
options.wiki.setTextReference(textRef,
|
||||
this.cancel();
|
||||
options.wiki.setTextReference(options.title,
|
||||
"(" + options.domNode.offsetLeft + "," + options.domNode.offsetTop + "," +
|
||||
options.domNode.offsetWidth + "," + options.domNode.offsetHeight + ")",
|
||||
options.contextTiddlerTitle,true);
|
||||
this.popup(textRef);
|
||||
options.domNode.offsetWidth + "," + options.domNode.offsetHeight + ")");
|
||||
this.show(options);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -24,6 +24,17 @@ exports.trim = function(str) {
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
Convert a string to base64 encoding
|
||||
*/
|
||||
exports.toBase64 = function(str) {
|
||||
if($tw.browser) {
|
||||
return window.btoa(str);
|
||||
} else {
|
||||
new Buffer(str).toString("base64");
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
Return the number of keys in an object
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user