kopia lustrzana https://github.com/miklobit/TiddlyWiki5
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 fixesprint-window-tiddler
rodzic
6085936475
commit
88a65f038e
|
@ -74,6 +74,7 @@ Plugins/NoInfoFound/Hint: No ''"<$text text=<<currentTab>>/>"'' found
|
||||||
Plugins/NoInformation/Hint: No information provided
|
Plugins/NoInformation/Hint: No information provided
|
||||||
Plugins/NotInstalled/Hint: This plugin is not currently installed
|
Plugins/NotInstalled/Hint: This plugin is not currently installed
|
||||||
Plugins/OpenPluginLibrary: open plugin library
|
Plugins/OpenPluginLibrary: open plugin library
|
||||||
|
Plugins/ClosePluginLibrary: close plugin library
|
||||||
Plugins/Plugins/Caption: Plugins
|
Plugins/Plugins/Caption: Plugins
|
||||||
Plugins/Plugins/Hint: Plugins
|
Plugins/Plugins/Hint: Plugins
|
||||||
Plugins/Reinstall/Caption: reinstall
|
Plugins/Reinstall/Caption: reinstall
|
||||||
|
|
|
@ -29,16 +29,17 @@ function loadIFrame(url,callback) {
|
||||||
callback(null,iframeInfo);
|
callback(null,iframeInfo);
|
||||||
} else {
|
} else {
|
||||||
// Create the iframe and save it in the list
|
// Create the iframe and save it in the list
|
||||||
var iframe = document.createElement("iframe"),
|
var iframe = document.createElement("iframe");
|
||||||
iframeInfo = {
|
iframeInfo = {
|
||||||
url: url,
|
url: url,
|
||||||
status: "loading",
|
status: "loading",
|
||||||
domNode: iframe
|
domNode: iframe
|
||||||
};
|
};
|
||||||
$tw.browserMessaging.iframeInfoMap[url] = iframeInfo;
|
$tw.browserMessaging.iframeInfoMap[url] = iframeInfo;
|
||||||
saveIFrameInfoTiddler(iframeInfo);
|
saveIFrameInfoTiddler(iframeInfo);
|
||||||
// Add the iframe to the DOM and hide it
|
// Add the iframe to the DOM and hide it
|
||||||
iframe.style.display = "none";
|
iframe.style.display = "none";
|
||||||
|
iframe.setAttribute("library","true");
|
||||||
document.body.appendChild(iframe);
|
document.body.appendChild(iframe);
|
||||||
// Set up onload
|
// Set up onload
|
||||||
iframe.onload = function() {
|
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) {
|
function saveIFrameInfoTiddler(iframeInfo) {
|
||||||
$tw.wiki.addTiddler(new $tw.Tiddler($tw.wiki.getCreationFields(),{
|
$tw.wiki.addTiddler(new $tw.Tiddler($tw.wiki.getCreationFields(),{
|
||||||
title: "$:/temp/ServerConnection/" + iframeInfo.url,
|
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) {
|
$tw.rootWidget.addEventListener("tm-load-plugin-from-library",function(event) {
|
||||||
var paramObject = event.paramObject || {},
|
var paramObject = event.paramObject || {},
|
||||||
url = paramObject.url,
|
url = paramObject.url,
|
||||||
|
|
|
@ -90,6 +90,16 @@ $:/state/add-plugin-info/$(connectionTiddler)$/$(assetInfo)$
|
||||||
</$list>
|
</$list>
|
||||||
\end
|
\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()
|
\define plugin-library-listing()
|
||||||
<$list filter="[all[tiddlers+shadows]tag[$:/tags/PluginLibrary]]">
|
<$list filter="[all[tiddlers+shadows]tag[$:/tags/PluginLibrary]]">
|
||||||
<div class="tc-plugin-library">
|
<div class="tc-plugin-library">
|
||||||
|
@ -100,6 +110,10 @@ $:/state/add-plugin-info/$(connectionTiddler)$/$(assetInfo)$
|
||||||
|
|
||||||
<$transclude/>
|
<$transclude/>
|
||||||
|
|
||||||
|
<$set name=PluginLibraryURL value={{!!url}}>
|
||||||
|
<<close-library-button>>
|
||||||
|
</$set>
|
||||||
|
|
||||||
<<display-server-connection>>
|
<<display-server-connection>>
|
||||||
</div>
|
</div>
|
||||||
</$list>
|
</$list>
|
||||||
|
|
Ładowanie…
Reference in New Issue