mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2026-09-20 00:30:43 +00:00
Add a "close plugin library" button (#2072)
* provides a "close plugin library" button * starting from #1718 by @inmysocks * possibly fixes all of #1718, #1597, and #2067 * corrected code comment * add back title No idea why I overlooked this beforehand. Next time I will not suggest such changes that have little to do with the PR, but rather just comment the code. * ah, sorry, "fixed" wrong spot now ``` <$action-sendmessage $message="tm-load-plugin-from-library" url={{!!url}} title={{$(assetInfo)$!!original-title}}/> ``` ...should be back at the right spot. * mhhh... still fixing the mess load, unload, puh... let's see if I got it now * added unloadIFrame and minor syntax fixes
This commit is contained in:
committed by
Jeremy Ruston
parent
6085936475
commit
88a65f038e
@@ -29,16 +29,17 @@ function loadIFrame(url,callback) {
|
||||
callback(null,iframeInfo);
|
||||
} else {
|
||||
// Create the iframe and save it in the list
|
||||
var iframe = document.createElement("iframe"),
|
||||
iframeInfo = {
|
||||
url: url,
|
||||
status: "loading",
|
||||
domNode: iframe
|
||||
};
|
||||
var iframe = document.createElement("iframe");
|
||||
iframeInfo = {
|
||||
url: url,
|
||||
status: "loading",
|
||||
domNode: iframe
|
||||
};
|
||||
$tw.browserMessaging.iframeInfoMap[url] = iframeInfo;
|
||||
saveIFrameInfoTiddler(iframeInfo);
|
||||
// Add the iframe to the DOM and hide it
|
||||
iframe.style.display = "none";
|
||||
iframe.setAttribute("library","true");
|
||||
document.body.appendChild(iframe);
|
||||
// Set up onload
|
||||
iframe.onload = function() {
|
||||
@@ -57,6 +58,18 @@ function loadIFrame(url,callback) {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Unload library iframe for given url
|
||||
*/
|
||||
function unloadIFrame(url){
|
||||
$tw.utils.each(document.getElementsByTagName('iframe'), function(iframe) {
|
||||
if(iframe.getAttribute("library") === "true" &&
|
||||
iframe.getAttribute("src") === url) {
|
||||
iframe.parentNode.removeChild(iframe);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function saveIFrameInfoTiddler(iframeInfo) {
|
||||
$tw.wiki.addTiddler(new $tw.Tiddler($tw.wiki.getCreationFields(),{
|
||||
title: "$:/temp/ServerConnection/" + iframeInfo.url,
|
||||
@@ -93,6 +106,21 @@ exports.startup = function() {
|
||||
});
|
||||
}
|
||||
});
|
||||
// Listen for widget messages to control unloading the plugin library
|
||||
$tw.rootWidget.addEventListener("tm-unload-plugin-library",function(event) {
|
||||
var paramObject = event.paramObject || {},
|
||||
url = paramObject.url;
|
||||
$tw.browserMessaging.iframeInfoMap[url] = undefined;
|
||||
if(url) {
|
||||
unloadIFrame(url);
|
||||
$tw.utils.each(
|
||||
$tw.wiki.filterTiddlers("[[$:/temp/ServerConnection/" + url + "]] [prefix[$:/temp/RemoteAssetInfo/" + url + "/]]"),
|
||||
function(title) {
|
||||
$tw.wiki.deleteTiddler(title);
|
||||
}
|
||||
);
|
||||
}
|
||||
});
|
||||
$tw.rootWidget.addEventListener("tm-load-plugin-from-library",function(event) {
|
||||
var paramObject = event.paramObject || {},
|
||||
url = paramObject.url,
|
||||
|
||||
Reference in New Issue
Block a user