mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-01-26 00:46:52 +00:00
Improve garbage collection of external windows
Now we remove event listeners when a window is closed
This commit is contained in:
parent
7866f9b2de
commit
8708f817fa
@ -21,7 +21,8 @@ exports.synchronous = true;
|
|||||||
exports.startup = function() {
|
exports.startup = function() {
|
||||||
$tw.rootWidget.addEventListener("tm-open-window",function(event) {
|
$tw.rootWidget.addEventListener("tm-open-window",function(event) {
|
||||||
// Get the parameters
|
// Get the parameters
|
||||||
var title = event.param || event.tiddlerTitle,
|
var refreshHandler,
|
||||||
|
title = event.param || event.tiddlerTitle,
|
||||||
paramObject = event.paramObject || {},
|
paramObject = event.paramObject || {},
|
||||||
template = paramObject.template || "$:/core/ui/ViewTemplate/body",
|
template = paramObject.template || "$:/core/ui/ViewTemplate/body",
|
||||||
width = paramObject.width || "700",
|
width = paramObject.width || "700",
|
||||||
@ -29,14 +30,16 @@ exports.startup = function() {
|
|||||||
// Open the window
|
// Open the window
|
||||||
var srcWindow = window.open("","external-" + title,"width=" + width + ",height=" + height),
|
var srcWindow = window.open("","external-" + title,"width=" + width + ",height=" + height),
|
||||||
srcDocument = srcWindow.document;
|
srcDocument = srcWindow.document;
|
||||||
srcWindow.onclose = function(event) {
|
// Check for reopening the same window
|
||||||
console.log("closing popup");
|
if(srcWindow.haveInitialisedWindow) {
|
||||||
};
|
return;
|
||||||
srcWindow.addEventListener("close",function(event) {
|
}
|
||||||
console.log("closing2 popup");
|
// Initialise the document
|
||||||
},false);
|
|
||||||
srcDocument.write("<html><head></head><body class='tc-body'></body></html>");
|
srcDocument.write("<html><head></head><body class='tc-body'></body></html>");
|
||||||
srcDocument.close();
|
srcDocument.close();
|
||||||
|
srcWindow.addEventListener("beforeunload",function(event) {
|
||||||
|
$tw.wiki.removeEventListener("change",refreshHandler);
|
||||||
|
},false);
|
||||||
// Set up the styles
|
// Set up the styles
|
||||||
var styleWidgetNode = $tw.wiki.makeTranscludeWidget("$:/core/ui/PageStylesheet",{document: $tw.fakeDocument}),
|
var styleWidgetNode = $tw.wiki.makeTranscludeWidget("$:/core/ui/PageStylesheet",{document: $tw.fakeDocument}),
|
||||||
styleContainer = $tw.fakeDocument.createElement("style");
|
styleContainer = $tw.fakeDocument.createElement("style");
|
||||||
@ -44,19 +47,19 @@ exports.startup = function() {
|
|||||||
var styleElement = srcDocument.createElement("style");
|
var styleElement = srcDocument.createElement("style");
|
||||||
styleElement.innerHTML = styleContainer.textContent;
|
styleElement.innerHTML = styleContainer.textContent;
|
||||||
srcDocument.head.insertBefore(styleElement,srcDocument.head.firstChild);
|
srcDocument.head.insertBefore(styleElement,srcDocument.head.firstChild);
|
||||||
$tw.wiki.addEventListener("change",function(changes) {
|
|
||||||
if(styleWidgetNode.refresh(changes,styleContainer,null)) {
|
|
||||||
styleElement.innerHTML = styleContainer.textContent;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
// Render the text of the tiddler
|
// Render the text of the tiddler
|
||||||
var parser = $tw.wiki.parseTiddler(template),
|
var parser = $tw.wiki.parseTiddler(template),
|
||||||
widgetNode = $tw.wiki.makeWidget(parser,{document: srcDocument, variables: {currentTiddler: title}});
|
widgetNode = $tw.wiki.makeWidget(parser,{document: srcDocument, variables: {currentTiddler: title}});
|
||||||
widgetNode.render(srcDocument.body,null);
|
widgetNode.render(srcDocument.body,null);
|
||||||
$tw.wiki.addEventListener("change",function(changes) {
|
// Function to handle refreshes
|
||||||
|
refreshHandler = function(changes) {
|
||||||
|
if(styleWidgetNode.refresh(changes,styleContainer,null)) {
|
||||||
|
styleElement.innerHTML = styleContainer.textContent;
|
||||||
|
}
|
||||||
widgetNode.refresh(changes);
|
widgetNode.refresh(changes);
|
||||||
});
|
};
|
||||||
|
$tw.wiki.addEventListener("change",refreshHandler);
|
||||||
|
srcWindow.haveInitialisedWindow = true;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user