1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-12-28 02:50:27 +00:00

Close subwindows when closing main window

This commit is contained in:
Jermolene 2015-05-03 16:24:02 +01:00
parent 48dcf959ff
commit 3f26492ac8
2 changed files with 21 additions and 5 deletions

View File

@ -18,7 +18,11 @@ exports.platforms = ["browser"];
exports.after = ["startup"];
exports.synchronous = true;
// Global to keep track of open windows (hashmap by title)
var windows = {};
exports.startup = function() {
// Handle open window message
$tw.rootWidget.addEventListener("tm-open-window",function(event) {
// Get the parameters
var refreshHandler,
@ -30,6 +34,7 @@ exports.startup = function() {
// Open the window
var srcWindow = window.open("","external-" + title,"width=" + width + ",height=" + height),
srcDocument = srcWindow.document;
windows[title] = srcWindow;
// Check for reopening the same window
if(srcWindow.haveInitialisedWindow) {
return;
@ -39,6 +44,7 @@ exports.startup = function() {
srcDocument.close();
srcDocument.title = title;
srcWindow.addEventListener("beforeunload",function(event) {
delete windows[title];
$tw.wiki.removeEventListener("change",refreshHandler);
},false);
// Set up the styles
@ -50,7 +56,7 @@ exports.startup = function() {
srcDocument.head.insertBefore(styleElement,srcDocument.head.firstChild);
// Render the text of the tiddler
var parser = $tw.wiki.parseTiddler(template),
widgetNode = $tw.wiki.makeWidget(parser,{document: srcDocument, variables: {currentTiddler: title}});
widgetNode = $tw.wiki.makeWidget(parser,{document: srcDocument, parentWidget: $tw.rootWidget, variables: {currentTiddler: title}});
widgetNode.render(srcDocument.body,null);
// Function to handle refreshes
refreshHandler = function(changes) {
@ -62,6 +68,13 @@ exports.startup = function() {
$tw.wiki.addEventListener("change",refreshHandler);
srcWindow.haveInitialisedWindow = true;
});
// Close open windows when unloading main window
$tw.addUnloadTask(function() {
$tw.utils.each(windows,function(win) {
win.close();
});
});
};
})();

View File

@ -66,10 +66,6 @@ body.tc-body {
<<custom-background-datauri>>
}
body.tc-body.tc-single-tiddler-window {
margin: 1em;
}
h1, h2, h3, h4, h5, h6 {
line-height: 1.2;
font-weight: 300;
@ -345,6 +341,7 @@ button svg, button img {
height: 2em;
width: 2em;
vertical-align: middle;
fill: <<colour download-foreground>>;
}
.tc-sidebar-lists input {
@ -821,6 +818,11 @@ canvas.tc-edit-bitmapeditor {
overflow: hidden; /* https://github.com/Jermolene/TiddlyWiki5/issues/282 */
}
html body.tc-body.tc-single-tiddler-window {
margin: 1em;
background-color: <<colour tiddler-background>>;
}
/*
** Toolbar buttons
*/
@ -1740,6 +1742,7 @@ body.tc-dirty span.tc-dirty-indicator, body.tc-dirty span.tc-dirty-indicator svg
opacity: 1;
min-width: 100%;
min-height: 100%;
max-width: 100%;
}
.tc-thumbnail-wrapper:hover .tc-thumbnail-image svg,