Skip to content

Commit

Permalink
Add 'copyToClipboard' function in common.js + a few fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Micdu70 committed Jan 10, 2022
1 parent be26ce3 commit bcea8a6
Show file tree
Hide file tree
Showing 31 changed files with 423 additions and 370 deletions.
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
<script type="text/javascript" src="./js/jquery.flot.js"></script>
<script type="text/javascript" src="./js/graph.js"></script>
<script type="text/javascript" src="./js/plugins.js"></script>
<script type="text/javascript" src="./js/webui.js"></script>
<script type="text/javascript" src="./js/rtorrent.js"></script>
<script type="text/javascript" src="./js/webui.js"></script>
</head>
<body>
<div id="preload"></div>
Expand Down
37 changes: 34 additions & 3 deletions js/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -973,6 +973,38 @@ function noty(msg,status,noTime)
}
}

function fallbackCopyToClipboard(text)
{
var textarea = document.createElement("textarea");
textarea.textContent = text;
textarea.style.position = "fixed";
document.body.appendChild(textarea);
textarea.select();
try {
var success = document.execCommand("copy");
if(success)
noty( theUILang.copyToClipboardSuccess, "success" );
} catch (err) {
prompt(theUILang.copyToClipboardFailed, text);
} finally {
document.body.removeChild(textarea);
}
}

function copyToClipboard(text)
{
if (!navigator.clipboard)
{
fallbackCopyToClipboard(text);
return;
}
navigator.clipboard.writeText(text).then(function() {
noty( theUILang.copyToClipboardSuccess, "success" );
}, function(err) {
fallbackCopyToClipboard(text);
});
}

function rDirectory()
{
this.dirs = new Array();
Expand Down Expand Up @@ -1591,8 +1623,7 @@ function strip_tags(input, allowed)
// Caveat: doesn't work with Internet Explorer.
(function setBrowserTimezoneCookie()
{
try
{
try {
document.cookie = "browser_timezone="+Intl.DateTimeFormat().resolvedOptions().timeZone
} catch(e) {}
}).apply();
}).apply();
60 changes: 30 additions & 30 deletions js/plugins.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
// this function is obsolete

function injectScript(fname,initFunc)
function injectScript(fname,initFunc)
{
var h = document.getElementsByTagName("head").item(0);
s = document.createElement("script");
if(initFunc)
{
{
if(browser.isIE)
s.onreadystatechange = function()
{
if((this.readyState == 'loaded') || (this.readyState == 'complete'))
if((this.readyState == 'loaded') || (this.readyState == 'complete'))
initFunc();
}
else
Expand All @@ -23,32 +23,32 @@ function injectScript(fname,initFunc)
void (h.appendChild(s));
}

function injectCSS(fname)
function injectCSS(fname)
{
var newSS=document.createElement('link');
newSS.rel='stylesheet';
newSS.href=fname;
var newSS=document.createElement('link');
newSS.rel='stylesheet';
newSS.href=fname;
var h = document.getElementsByTagName("head").item(0);
void (h.appendChild(newSS));
}

function injectCSSText(text)
function injectCSSText(text)
{
var style=document.createElement('style');
var style=document.createElement('style');
style.setAttribute("type", "text/css");
if(style.styleSheet)
style.styleSheet.cssText = text;
else
else
style.appendChild(document.createTextNode(text));
var h = document.getElementsByTagName("head").item(0);
void (h.appendChild(style));
}

var thePlugins =
var thePlugins =
{
list: {},
topMenu: [],
restictions:
restictions:
{
cantChangeToolbar: 0x0001,
cantChangeMenu: 0x0002,
Expand Down Expand Up @@ -119,52 +119,52 @@ function rPlugin( name, version, author, descr, restictions, help )
thePlugins.register(this);
}

rPlugin.prototype.markLoaded = function()
rPlugin.prototype.markLoaded = function()
{
this.allStuffLoaded = true;
}

rPlugin.prototype.enable = function()
rPlugin.prototype.enable = function()
{
this.enabled = true;
return(this);
}

rPlugin.prototype.disable = function()
rPlugin.prototype.disable = function()
{
this.enabled = false;
return(this);
}

rPlugin.prototype.launch = function()
rPlugin.prototype.launch = function()
{
this.launched = true;
return(this);
}

rPlugin.prototype.unlaunch = function()
rPlugin.prototype.unlaunch = function()
{
this.launched = false;
return(this);
}

rPlugin.prototype.remove = function()
rPlugin.prototype.remove = function()
{
if($type(this["onRemove"])=="function")
this.onRemove();
this.disable();
return(this);
}

rPlugin.prototype.showError = function(err)
rPlugin.prototype.showError = function(err)
{
if( this.allStuffLoaded )
noty( eval(err), "error" );
else
setTimeout( 'thePlugins.get("'+this.name+'").showError("' + err + '")', 1000 );
}

rPlugin.prototype.langLoaded = function()
rPlugin.prototype.langLoaded = function()
{
try {
if(($type(this["onLangLoaded"])=="function") && this.enabled)
Expand All @@ -178,15 +178,15 @@ rPlugin.prototype.loadLangPrim = function(lang,template,sendNotify)
var self = this;
$.ajax(
{
url: template.replace('{lang}',lang), // this is because plugin.path may be changed during call
url: template.replace('{lang}',lang), // this is because plugin.path may be changed during call
dataType: "script",
cache: true
}).done( function()
{
!sendNotify || self.langLoaded();
}).fail( function()
{
(lang=='en') ?
(lang=='en') ?
(!window.console || console.error( "Plugin '"+self.name+"': localization for '"+lang+"' not found." )) :
self.loadLangPrim('en',template,sendNotify);
});
Expand Down Expand Up @@ -283,7 +283,7 @@ rPlugin.prototype.attachPageToTabs = function(dlg,name,idBefore)
{
if(!dlg.className)
dlg.className = "tab";
theTabs.tabs[dlg.id] = name;
theTabs.tabs[dlg.id] = name;
var newLbl = document.createElement("li");
newLbl.id = "tab_"+dlg.id;
newLbl.innerHTML = "<a href=\"javascript://void();\" onmousedown=\"theTabs.show('"+dlg.id+"');\" onfocus=\"this.blur();\">" + name + "</a>";
Expand All @@ -309,7 +309,7 @@ rPlugin.prototype.renameTab = function(id,name)

rPlugin.prototype.removePageFromTabs = function(id)
{
delete theTabs.tabs[id];
delete theTabs.tabs[id];
$('#'+id).remove();
$('#tab_'+id).remove();
return(this);
Expand All @@ -336,9 +336,9 @@ rPlugin.prototype.addButtonToToolbar = function(id,name,onclick,idBefore)
newBtn.title=name;
newBtn.innerHTML='<div class="top-menu-item" id="'+id+'" onclick="'+onclick+';return(false);"></div>';
$(newBtn).addClass('top-menu-item').on('focus', function(e) { this.blur(); } );
var targetBtn = idBefore ? $$("mnu_"+idBefore) : null;
var targetBtn = idBefore ? $$("mnu_"+idBefore) : null;
if(targetBtn)
targetBtn.parentNode.insertBefore(newBtn,targetBtn);
targetBtn.parentNode.insertBefore(newBtn,targetBtn);
else
{
targetBtn = $$("mnu_settings");
Expand All @@ -352,16 +352,16 @@ rPlugin.prototype.removeButtonFromToolbar = function(id)
{
$("#mnu_"+id).remove();
}
rPlugin.prototype.addSeparatorToToolbar = function(idBefore)

rPlugin.prototype.addSeparatorToToolbar = function(idBefore)
{
if(this.canChangeToolbar())
{
var targetBtn = idBefore ? $$("mnu_"+idBefore) : null;
var sep = document.createElement("DIV");
sep.className = "TB_Separator";
if(targetBtn)
targetBtn.parentNode.insertBefore(sep,targetBtn);
targetBtn.parentNode.insertBefore(sep,targetBtn);
else
{
targetBtn = $$("mnu_settings");
Expand Down Expand Up @@ -410,4 +410,4 @@ rPlugin.prototype.removePaneFromCategory = function(id)
$("#"+id).remove();
$("#"+id+"_cont").remove();
return(this);
}
}
Loading

0 comments on commit bcea8a6

Please sign in to comment.