mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-23 18:17:20 +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:
parent
6085936475
commit
88a65f038e
@ -74,6 +74,7 @@ Plugins/NoInfoFound/Hint: No ''"<$text text=<<currentTab>>/>"'' found
|
||||
Plugins/NoInformation/Hint: No information provided
|
||||
Plugins/NotInstalled/Hint: This plugin is not currently installed
|
||||
Plugins/OpenPluginLibrary: open plugin library
|
||||
Plugins/ClosePluginLibrary: close plugin library
|
||||
Plugins/Plugins/Caption: Plugins
|
||||
Plugins/Plugins/Hint: Plugins
|
||||
Plugins/Reinstall/Caption: reinstall
|
||||
|
@ -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,
|
||||
|
@ -90,6 +90,16 @@ $:/state/add-plugin-info/$(connectionTiddler)$/$(assetInfo)$
|
||||
</$list>
|
||||
\end
|
||||
|
||||
\define close-library-button()
|
||||
<$reveal type='nomatch' state='$:/temp/ServerConnection/$(PluginLibraryURL)$' text=''>
|
||||
<$button class='tc-btn-big-green'>
|
||||
<$action-sendmessage $message="tm-unload-plugin-library" url={{!!url}}/>
|
||||
{{$:/core/images/chevron-left}} {{$:/language/ControlPanel/Plugins/ClosePluginLibrary}}
|
||||
<$action-deletetiddler $filter="[prefix[$:/temp/ServerConnection/$(PluginLibraryURL)$]][prefix[$:/temp/RemoteAssetInfo/$(PluginLibraryURL)$]]"/>
|
||||
</$button>
|
||||
</$reveal>
|
||||
\end
|
||||
|
||||
\define plugin-library-listing()
|
||||
<$list filter="[all[tiddlers+shadows]tag[$:/tags/PluginLibrary]]">
|
||||
<div class="tc-plugin-library">
|
||||
@ -100,6 +110,10 @@ $:/state/add-plugin-info/$(connectionTiddler)$/$(assetInfo)$
|
||||
|
||||
<$transclude/>
|
||||
|
||||
<$set name=PluginLibraryURL value={{!!url}}>
|
||||
<<close-library-button>>
|
||||
</$set>
|
||||
|
||||
<<display-server-connection>>
|
||||
</div>
|
||||
</$list>
|
||||
|
Loading…
Reference in New Issue
Block a user