1
0
mirror of https://github.com/d47081/qBittorrent.git synced 2025-03-13 05:41:17 +00:00

Follow project coding style. Issue #2192.

This commit is contained in:
Gabriele 2014-11-30 14:14:09 +01:00
parent 3672363207
commit aab2c34257
6 changed files with 798 additions and 734 deletions

View File

@ -1,171 +1,182 @@
var ContextMenu = new Class({ var ContextMenu = new Class({
//implements //implements
Implements: [Options,Events], Implements: [Options, Events],
//options //options
options: { options: {
actions: {}, actions: {},
menu: 'contextmenu', menu: 'contextmenu',
stopEvent: true, stopEvent: true,
targets: 'body', targets: 'body',
trigger: 'contextmenu', trigger: 'contextmenu',
offsets: { x:0, y:0 }, offsets: {
onShow: $empty, x: 0,
onHide: $empty, y: 0
onClick: $empty, },
fadeSpeed: 200 onShow: $empty,
}, onHide: $empty,
onClick: $empty,
//initialization fadeSpeed: 200
initialize: function(options) { },
//set options
this.setOptions(options) //initialization
initialize: function(options) {
//option diffs menu //set options
this.menu = $(this.options.menu); this.setOptions(options)
this.targets = $$(this.options.targets);
//option diffs menu
//fx this.menu = $(this.options.menu);
this.fx = new Fx.Tween(this.menu, { this.targets = $$(this.options.targets);
property: 'opacity',
duration:this.options.fadeSpeed, //fx
onComplete: function() { this.fx = new Fx.Tween(this.menu, {
if(this.getStyle('opacity')){ property: 'opacity',
this.setStyle('visibility','visible'); duration: this.options.fadeSpeed,
}else{ onComplete: function() {
this.setStyle('visibility','hidden'); if (this.getStyle('opacity')) {
} this.setStyle('visibility', 'visible');
}.bind(this.menu) }
}); else {
this.setStyle('visibility', 'hidden');
//hide and begin the listener }
this.hide().startListener(); }.bind(this.menu)
});
//hide the menu
this.menu.setStyles({ 'position':'absolute','top':'-900000px', 'display':'block' }); //hide and begin the listener
}, this.hide().startListener();
addTarget: function(t) { //hide the menu
this.targets[this.targets.length] = t; this.menu.setStyles({
t.addEvent(this.options.trigger,function(e) { 'position': 'absolute',
//enabled? 'top': '-900000px',
if(!this.options.disabled) { 'display': 'block'
//prevent default, if told to });
if(this.options.stopEvent) { e.stop(); } },
//record this as the trigger
this.options.element = $(t); addTarget: function(t) {
//position the menu this.targets[this.targets.length] = t;
this.menu.setStyles({ t.addEvent(this.options.trigger, function(e) {
top: (e.page.y + this.options.offsets.y), //enabled?
left: (e.page.x + this.options.offsets.x), if (!this.options.disabled) {
position: 'absolute', //prevent default, if told to
'z-index': '2000' if (this.options.stopEvent) {
}); e.stop();
//show the menu }
this.show(); //record this as the trigger
} this.options.element = $(t);
}.bind(this)); //position the menu
t.addEvent('click',function(e) { this.menu.setStyles({
this.hide(); top: (e.page.y + this.options.offsets.y),
}.bind(this)); left: (e.page.x + this.options.offsets.x),
}, position: 'absolute',
'z-index': '2000'
//get things started });
startListener: function() { //show the menu
/* all elements */ this.show();
this.targets.each(function(el) { }
/* show the menu */ }.bind(this));
el.addEvent(this.options.trigger,function(e) { t.addEvent('click', function(e) {
//enabled? this.hide();
if(!this.options.disabled) { }.bind(this));
//prevent default, if told to },
if(this.options.stopEvent) { e.stop(); }
//record this as the trigger //get things started
this.options.element = $(el); startListener: function() {
//position the menu /* all elements */
this.menu.setStyles({ this.targets.each(function(el) {
top: (e.page.y + this.options.offsets.y), /* show the menu */
left: (e.page.x + this.options.offsets.x), el.addEvent(this.options.trigger, function(e) {
position: 'absolute', //enabled?
'z-index': '2000' if (!this.options.disabled) {
}); //prevent default, if told to
//show the menu if (this.options.stopEvent) {
this.show(); e.stop();
} }
}.bind(this)); //record this as the trigger
el.addEvent('click',function(e) { this.options.element = $(el);
this.hide(); //position the menu
}.bind(this)); this.menu.setStyles({
},this); top: (e.page.y + this.options.offsets.y),
left: (e.page.x + this.options.offsets.x),
/* menu items */ position: 'absolute',
this.menu.getElements('a').each(function(item) { 'z-index': '2000'
item.addEvent('click',function(e) { });
if(!item.hasClass('disabled')) { //show the menu
this.execute(item.get('href').split('#')[1],$(this.options.element)); this.show();
this.fireEvent('click',[item,e]); }
} }.bind(this));
}.bind(this)); el.addEvent('click', function(e) {
},this); this.hide();
}.bind(this));
//hide on body click }, this);
$(document.body).addEvent('click', function() {
this.hide(); /* menu items */
}.bind(this)); this.menu.getElements('a').each(function(item) {
}, item.addEvent('click', function(e) {
if (!item.hasClass('disabled')) {
//show menu this.execute(item.get('href').split('#')[1], $(this.options.element));
show: function(trigger) { this.fireEvent('click', [item, e]);
//this.menu.fade('in'); }
this.fx.start(1); }.bind(this));
this.fireEvent('show'); }, this);
this.shown = true;
return this; //hide on body click
}, $(document.body).addEvent('click', function() {
this.hide();
//hide the menu }.bind(this));
hide: function(trigger) { },
if(this.shown)
{ //show menu
this.fx.start(0); show: function(trigger) {
//this.menu.fade('out'); //this.menu.fade('in');
this.fireEvent('hide'); this.fx.start(1);
this.shown = false; this.fireEvent('show');
} this.shown = true;
return this; return this;
}, },
//disable an item //hide the menu
disableItem: function(item) { hide: function(trigger) {
this.menu.getElements('a[href$=' + item + ']').addClass('disabled'); if (this.shown) {
return this; this.fx.start(0);
}, //this.menu.fade('out');
this.fireEvent('hide');
//enable an item this.shown = false;
enableItem: function(item) { }
this.menu.getElements('a[href$=' + item + ']').removeClass('disabled'); return this;
return this; },
},
//disable an item
//diable the entire menu disableItem: function(item) {
disable: function() { this.menu.getElements('a[href$=' + item + ']').addClass('disabled');
this.options.disabled = true; return this;
return this; },
},
//enable an item
//enable the entire menu enableItem: function(item) {
enable: function() { this.menu.getElements('a[href$=' + item + ']').removeClass('disabled');
this.options.disabled = false; return this;
return this; },
},
//diable the entire menu
//execute an action disable: function() {
execute: function(action,element) { this.options.disabled = true;
if(this.options.actions[action]) { return this;
this.options.actions[action](element,this); },
}
return this; //enable the entire menu
} enable: function() {
this.options.disabled = false;
}); return this;
},
//execute an action
execute: function(action, element) {
if (this.options.actions[action]) {
this.options.actions[action](element, this);
}
return this;
}
});

View File

@ -8,10 +8,10 @@
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is * copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions: * furnished to do so, subject to the following conditions:
* *
* The above copyright notice and this permission notice shall be included in * The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software. * all copies or substantial portions of the Software.
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@ -20,15 +20,19 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE. * THE SOFTWARE.
*/ */
window.addEvent('domready', function() {
window.addEvent('domready', function(){ $('urls').focus();
$('urls').focus(); $('downButton').addEvent('click', function(e) {
$('downButton').addEvent('click', function(e){ new Event(e).stop();
new Event(e).stop(); new Request({
new Request({url: 'command/download', method: 'post', data: {urls: $('urls').value}, url: 'command/download',
onComplete: function() { method: 'post',
window.parent.document.getElementById('downloadPage').parentNode.removeChild(window.parent.document.getElementById('downloadPage')); data: {
} urls: $('urls').value
}).send(); },
}); onComplete: function() {
}); window.parent.document.getElementById('downloadPage').parentNode.removeChild(window.parent.document.getElementById('downloadPage'));
}
}).send();
});
});

View File

@ -2,74 +2,74 @@
* JS counterpart of the function in src/misc.cpp * JS counterpart of the function in src/misc.cpp
*/ */
function friendlyUnit(value, isSpeed) { function friendlyUnit(value, isSpeed) {
units = [ units = [
"_(B)", "_(B)",
"_(KiB)", "_(KiB)",
"_(MiB)", "_(MiB)",
"_(GiB)", "_(GiB)",
"_(TiB)", "_(TiB)",
]; ];
if (value < 0) if (value < 0)
return "_(Unknown)"; return "_(Unknown)";
var i = 0; var i = 0;
while (value >= 1024. && i++ < 6) while (value >= 1024. && i++ < 6)
value /= 1024.; value /= 1024.;
var ret; var ret;
ret = value.toFixed(1) + " " + units[i]; ret = value.toFixed(1) + " " + units[i];
if (isSpeed) if (isSpeed)
ret += "_(/s)"; ret += "_(/s)";
return ret; return ret;
} }
/* /*
* JS counterpart of the function in src/misc.cpp * JS counterpart of the function in src/misc.cpp
*/ */
function friendlyDuration(seconds) { function friendlyDuration(seconds) {
var MAX_ETA = 8640000; var MAX_ETA = 8640000;
if (seconds < 0 || seconds >= MAX_ETA) if (seconds < 0 || seconds >= MAX_ETA)
return "∞";
if (seconds == 0)
return "0";
if (seconds < 60)
return "< " + "_(%1m)".replace("%1", "1"); //translation of "< 1m" not working
var minutes = seconds / 60;
if (minutes < 60)
return "_(%1m)".replace("%1", parseInt(minutes));
var hours = minutes / 60;
minutes = minutes - hours * 60;
if (hours < 24)
return "_(%1h %2m)".replace("%1", parseInt(hours)).replace("%2", parseInt(minutes))
var days = hours / 24;
hours = hours - days * 24;
if (days < 100)
return "_(%1d %2h)".replace("%1", parseInt(days)).replace("%2", parseInt(hours))
return "∞"; return "∞";
if (seconds == 0)
return "0";
if (seconds < 60)
return "< " + "_(%1m)".replace("%1", "1"); //translation of "< 1m" not working
var minutes = seconds / 60;
if (minutes < 60)
return "_(%1m)".replace("%1", parseInt(minutes));
var hours = minutes / 60;
minutes = minutes - hours*60;
if (hours < 24)
return "_(%1h %2m)".replace("%1", parseInt(hours)).replace("%2", parseInt(minutes))
var days = hours / 24;
hours = hours - days * 24;
if (days < 100)
return "_(%1d %2h)".replace("%1", parseInt(days)).replace("%2", parseInt(hours))
return "∞";
} }
/* /*
* From: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString * From: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString
*/ */
if (!Date.prototype.toISOString) { if (!Date.prototype.toISOString) {
(function() { (function() {
function pad(number) { function pad(number) {
if (number < 10) { if (number < 10) {
return '0' + number; return '0' + number;
} }
return number; return number;
} }
Date.prototype.toISOString = function() { Date.prototype.toISOString = function() {
return this.getUTCFullYear() + return this.getUTCFullYear() +
'-' + pad(this.getUTCMonth() + 1) + '-' + pad(this.getUTCMonth() + 1) +
'-' + pad(this.getUTCDate()) + '-' + pad(this.getUTCDate()) +
'T' + pad(this.getUTCHours()) + 'T' + pad(this.getUTCHours()) +
':' + pad(this.getUTCMinutes()) + ':' + pad(this.getUTCMinutes()) +
':' + pad(this.getUTCSeconds()) + ':' + pad(this.getUTCSeconds()) +
'.' + (this.getUTCMilliseconds() / 1000).toFixed(3).slice(2, 5) + '.' + (this.getUTCMilliseconds() / 1000).toFixed(3).slice(2, 5) +
'Z'; 'Z';
}; };
}()); }());
} }

View File

@ -8,7 +8,6 @@
it in the onContentLoaded function of the new window. it in the onContentLoaded function of the new window.
----------------------------------------------------------------- */ ----------------------------------------------------------------- */
/* Define localStorage object for older browsers */ /* Define localStorage object for older browsers */
if (typeof localStorage == 'undefined') { if (typeof localStorage == 'undefined') {
window['localStorage'] = { window['localStorage'] = {
@ -16,250 +15,284 @@ if (typeof localStorage == 'undefined') {
return Cookie.read(name); return Cookie.read(name);
}, },
setItem: function(name, value) { setItem: function(name, value) {
Cookie.write(name, value, {duration: 365 * 10}); Cookie.write(name, value, {
duration: 365 * 10
});
} }
} }
} }
initializeWindows = function(){ initializeWindows = function() {
function addClickEvent(el, fn){ function addClickEvent(el, fn) {
['Link','Button'].each(function(item) { ['Link', 'Button'].each(function(item) {
if ($(el+item)){ if ($(el + item)) {
$(el+item).addEvent('click', fn); $(el + item).addEvent('click', fn);
} }
}); });
} }
addClickEvent('download', function(e){ addClickEvent('download', function(e) {
new Event(e).stop(); new Event(e).stop();
new MochaUI.Window({ new MochaUI.Window({
id: 'downloadPage', id: 'downloadPage',
title: "_(Download from urls)", title: "_(Download from urls)",
loadMethod: 'iframe', loadMethod: 'iframe',
contentURL:'download.html', contentURL: 'download.html',
scrollbars: true, scrollbars: true,
resizable: false, resizable: false,
maximizable: false, maximizable: false,
closable: true, closable: true,
paddingVertical: 0, paddingVertical: 0,
paddingHorizontal: 0, paddingHorizontal: 0,
width: 500, width: 500,
height: 300 height: 300
}); });
}); });
addClickEvent('preferences', function(e) { addClickEvent('preferences', function(e) {
new Event(e).stop(); new Event(e).stop();
new MochaUI.Window({ new MochaUI.Window({
id: 'preferencesPage', id: 'preferencesPage',
title: "_(Options)", title: "_(Options)",
loadMethod: 'xhr', loadMethod: 'xhr',
toolbar: true, toolbar: true,
contentURL: 'preferences_content.html', contentURL: 'preferences_content.html',
require: { require: {
css: ['css/Tabs.css'] css: ['css/Tabs.css']
}, },
toolbarURL: 'preferences.html', toolbarURL: 'preferences.html',
resizable: true, resizable: true,
maximizable: false, maximizable: false,
closable: true, closable: true,
paddingVertical: 0, paddingVertical: 0,
paddingHorizontal: 0, paddingHorizontal: 0,
width: 700, width: 700,
height: 300 height: 300
}); });
}); });
addClickEvent('upload', function(e){ addClickEvent('upload', function(e) {
new Event(e).stop(); new Event(e).stop();
new MochaUI.Window({ new MochaUI.Window({
id: 'uploadPage', id: 'uploadPage',
title: "_(Download local torrent)", title: "_(Download local torrent)",
loadMethod: 'iframe', loadMethod: 'iframe',
contentURL:'upload.html', contentURL: 'upload.html',
scrollbars: true, scrollbars: true,
resizable: false, resizable: false,
maximizable: false, maximizable: false,
paddingVertical: 0, paddingVertical: 0,
paddingHorizontal: 0, paddingHorizontal: 0,
width: 600, width: 600,
height: 130 height: 130
}); });
}); });
globalUploadLimitFN = function() { globalUploadLimitFN = function() {
new MochaUI.Window({ new MochaUI.Window({
id: 'uploadLimitPage', id: 'uploadLimitPage',
title: "_(Global Upload Speed Limiting)", title: "_(Global Upload Speed Limiting)",
loadMethod: 'iframe', loadMethod: 'iframe',
contentURL:'uploadlimit.html?hash=global', contentURL: 'uploadlimit.html?hash=global',
scrollbars: false, scrollbars: false,
resizable: false, resizable: false,
maximizable: false, maximizable: false,
paddingVertical: 0, paddingVertical: 0,
paddingHorizontal: 0, paddingHorizontal: 0,
width: 424, width: 424,
height: 80 height: 80
}); });
} }
uploadLimitFN = function() { uploadLimitFN = function() {
var h = myTable.selectedIds(); var h = myTable.selectedIds();
if(h.length){ if (h.length) {
var hash = h[0]; var hash = h[0];
new MochaUI.Window({ new MochaUI.Window({
id: 'uploadLimitPage', id: 'uploadLimitPage',
title: "_(Torrent Upload Speed Limiting)", title: "_(Torrent Upload Speed Limiting)",
loadMethod: 'iframe', loadMethod: 'iframe',
contentURL:'uploadlimit.html?hash='+hash, contentURL: 'uploadlimit.html?hash=' + hash,
scrollbars: false, scrollbars: false,
resizable: false, resizable: false,
maximizable: false, maximizable: false,
paddingVertical: 0, paddingVertical: 0,
paddingHorizontal: 0, paddingHorizontal: 0,
width: 424, width: 424,
height: 80 height: 80
}); });
} }
}; };
globalDownloadLimitFN = function() { globalDownloadLimitFN = function() {
new MochaUI.Window({ new MochaUI.Window({
id: 'downloadLimitPage', id: 'downloadLimitPage',
title: "_(Global Download Speed Limiting)", title: "_(Global Download Speed Limiting)",
loadMethod: 'iframe', loadMethod: 'iframe',
contentURL:'downloadlimit.html?hash=global', contentURL: 'downloadlimit.html?hash=global',
scrollbars: false, scrollbars: false,
resizable: false, resizable: false,
maximizable: false, maximizable: false,
paddingVertical: 0, paddingVertical: 0,
paddingHorizontal: 0, paddingHorizontal: 0,
width: 424, width: 424,
height: 80 height: 80
}); });
} }
downloadLimitFN = function() { downloadLimitFN = function() {
var h = myTable.selectedIds(); var h = myTable.selectedIds();
if(h.length){ if (h.length) {
var hash = h[0]; var hash = h[0];
new MochaUI.Window({ new MochaUI.Window({
id: 'downloadLimitPage', id: 'downloadLimitPage',
title: "_(Torrent Download Speed Limiting)", title: "_(Torrent Download Speed Limiting)",
loadMethod: 'iframe', loadMethod: 'iframe',
contentURL:'downloadlimit.html?hash='+hash, contentURL: 'downloadlimit.html?hash=' + hash,
scrollbars: false, scrollbars: false,
resizable: false, resizable: false,
maximizable: false, maximizable: false,
paddingVertical: 0, paddingVertical: 0,
paddingHorizontal: 0, paddingHorizontal: 0,
width: 424, width: 424,
height: 80 height: 80
}); });
} }
}; };
deleteFN = function() { deleteFN = function() {
var h = myTable.selectedIds(); var h = myTable.selectedIds();
/*if(h.length && confirm('_(Are you sure you want to delete the selected torrents from the transfer list?)')) { /*if(h.length && confirm('_(Are you sure you want to delete the selected torrents from the transfer list?)')) {
h.each(function(item, index){ h.each(function(item, index){
new Request({url: 'command/delete', method: 'post', data: {hash: item}}).send(); new Request({url: 'command/delete', method: 'post', data: {hash: item}}).send();
}); });
}*/ }*/
if(h.length) { if (h.length) {
new MochaUI.Window({ new MochaUI.Window({
id: 'confirmDeletionPage', id: 'confirmDeletionPage',
title: "_(Deletion confirmation - qBittorrent)", title: "_(Deletion confirmation - qBittorrent)",
loadMethod: 'iframe', loadMethod: 'iframe',
contentURL:'confirmdeletion.html?hashes='+h.join(','), contentURL: 'confirmdeletion.html?hashes=' + h.join(','),
scrollbars: false, scrollbars: false,
resizable: false, resizable: false,
maximizable: false, maximizable: false,
padding: 10, padding: 10,
width: 424, width: 424,
height: 140 height: 140
}); });
}
};
addClickEvent('delete', function(e) {
new Event(e).stop();
deleteFN();
});
pauseFN = function() {
var h = myTable.selectedIds();
if (h.length) {
h.each(function(hash, index) {
new Request({
url: 'command/pause',
method: 'post',
data: {
hash: hash
}
}).send();
});
}
};
startFN = function() {
var h = myTable.selectedIds();
if (h.length) {
h.each(function(hash, index) {
new Request({
url: 'command/resume',
method: 'post',
data: {
hash: hash
}
}).send();
});
}
};
recheckFN = function() {
var h = myTable.selectedIds();
if (h.length) {
h.each(function(hash, index) {
new Request({
url: 'command/recheck',
method: 'post',
data: {
hash: hash
}
}).send();
});
}
};
['pause', 'resume', 'recheck'].each(function(item) {
addClickEvent(item, function(e) {
new Event(e).stop();
var h = myTable.selectedIds();
if (h.length) {
h.each(function(hash, index) {
new Request({
url: 'command/' + item,
method: 'post',
data: {
hash: hash
}
}).send();
});
}
});
addClickEvent(item + 'All', function(e) {
new Event(e).stop();
new Request({
url: 'command/' + item + 'all'
}).send();
});
});
['decreasePrio', 'increasePrio', 'topPrio', 'bottomPrio'].each(function(item) {
addClickEvent(item, function(e) {
new Event(e).stop();
setPriorityFN(item);
});
});
setPriorityFN = function(cmd) {
var h = myTable.selectedIds();
if (h.length) {
new Request({
url: 'command/' + cmd,
method: 'post',
data: {
hashes: h.join("|")
} }
}; }).send();
}
}
addClickEvent('delete', function(e){ addClickEvent('about', function(e) {
new Event(e).stop(); new Event(e).stop();
deleteFN(); new MochaUI.Window({
}); id: 'aboutpage',
title: 'About',
loadMethod: 'xhr',
contentURL: 'about.html',
width: 650,
height: 200,
padding: 10
});
});
pauseFN = function() { addClickEvent('logout', function(e) {
var h = myTable.selectedIds();
if(h.length){
h.each(function(hash, index){
new Request({url: 'command/pause', method: 'post', data: {hash: hash}}).send();
});
}
};
startFN = function() {
var h = myTable.selectedIds();
if(h.length){
h.each(function(hash, index){
new Request({url: 'command/resume', method: 'post', data: {hash: hash}}).send();
});
}
};
recheckFN = function() {
var h = myTable.selectedIds();
if(h.length){
h.each(function(hash, index){
new Request({url: 'command/recheck', method: 'post', data: {hash: hash}}).send();
});
}
};
['pause','resume', 'recheck'].each(function(item) {
addClickEvent(item, function(e){
new Event(e).stop();
var h = myTable.selectedIds();
if(h.length){
h.each(function(hash, index){
new Request({url: 'command/'+item, method: 'post', data: {hash: hash}}).send();
});
}
});
addClickEvent(item+'All', function(e){
new Event(e).stop();
new Request({url: 'command/'+item+'all'}).send();
});
});
['decreasePrio','increasePrio', 'topPrio', 'bottomPrio'].each(function(item) {
addClickEvent(item, function(e){
new Event(e).stop();
setPriorityFN(item);
});
});
setPriorityFN = function(cmd) {
var h = myTable.selectedIds();
if(h.length) {
new Request({url: 'command/'+cmd, method: 'post', data: {hashes: h.join("|")}}).send();
}
}
addClickEvent('about', function(e){
new Event(e).stop();
new MochaUI.Window({
id: 'aboutpage',
title: 'About',
loadMethod: 'xhr',
contentURL: 'about.html',
width: 650,
height: 200,
padding: 10
});
});
addClickEvent('logout', function(e){
new Event(e).stop(); new Event(e).stop();
new Request({ new Request({
url: '/logout', url: '/logout',
@ -270,8 +303,8 @@ initializeWindows = function(){
}).send(); }).send();
}); });
addClickEvent('shutdown', function(e){ addClickEvent('shutdown', function(e) {
new Event(e).stop(); new Event(e).stop();
new Request({ new Request({
url: 'command/shutdown', url: 'command/shutdown',
onSuccess: function() { onSuccess: function() {
@ -279,30 +312,29 @@ initializeWindows = function(){
stop(); stop();
} }
}).send(); }).send();
}); });
updateSpeedInBrowserTitleBarLinkCheckState = function() updateSpeedInBrowserTitleBarLinkCheckState = function() {
{ if (localStorage.getItem('speed_in_browser_title_bar') == 'true')
if (localStorage.getItem('speed_in_browser_title_bar') == 'true') $(speedInBrowserTitleBarLink).firstChild.style.opacity = '1';
$(speedInBrowserTitleBarLink).firstChild.style.opacity = '1'; else
else $(speedInBrowserTitleBarLink).firstChild.style.opacity = '0';
$(speedInBrowserTitleBarLink).firstChild.style.opacity = '0'; }
}
updateSpeedInBrowserTitleBarLinkCheckState(); updateSpeedInBrowserTitleBarLinkCheckState();
addClickEvent('speedInBrowserTitleBar', function(e){ addClickEvent('speedInBrowserTitleBar', function(e) {
new Event(e).stop(); new Event(e).stop();
var speed_in_browser_title_bar = localStorage.getItem('speed_in_browser_title_bar'); var speed_in_browser_title_bar = localStorage.getItem('speed_in_browser_title_bar');
speed_in_browser_title_bar = speed_in_browser_title_bar == 'true' ? 'false' : 'true'; speed_in_browser_title_bar = speed_in_browser_title_bar == 'true' ? 'false' : 'true';
localStorage.setItem('speed_in_browser_title_bar', speed_in_browser_title_bar); localStorage.setItem('speed_in_browser_title_bar', speed_in_browser_title_bar);
updateSpeedInBrowserTitleBarLinkCheckState(); updateSpeedInBrowserTitleBarLinkCheckState();
}); });
// Deactivate menu header links // Deactivate menu header links
$$('a.returnFalse').each(function(el){ $$('a.returnFalse').each(function(el) {
el.addEvent('click', function(e){ el.addEvent('click', function(e) {
new Event(e).stop(); new Event(e).stop();
}); });
}); });
} }

View File

@ -13,179 +13,194 @@ Requires:
Core.js, Window.js Core.js, Window.js
*/ */
MochaUI.extend({ MochaUI.extend({
addUpLimitSlider: function(hash){ addUpLimitSlider: function(hash) {
if ($('uplimitSliderarea')) { if ($('uplimitSliderarea')) {
var windowOptions = MochaUI.Windows.windowOptions; var windowOptions = MochaUI.Windows.windowOptions;
var sliderFirst = true; var sliderFirst = true;
// Get global upload limit // Get global upload limit
var maximum = 500; var maximum = 500;
var req = new Request({ var req = new Request({
url: 'command/getGlobalUpLimit', url: 'command/getGlobalUpLimit',
method: 'post', method: 'post',
data: {}, data: {},
onSuccess: function(data) { onSuccess: function(data) {
if(data){ if (data) {
var tmp = data.toInt(); var tmp = data.toInt();
if(tmp > 0) { if (tmp > 0) {
maximum = tmp / 1024. maximum = tmp / 1024.
} else { }
maximum = 1000 else {
} maximum = 1000
} }
// Get torrent upload limit }
// And create slider // Get torrent upload limit
if(hash == 'global') { // And create slider
var up_limit = maximum; if (hash == 'global') {
if(up_limit < 0) up_limit = 0; var up_limit = maximum;
maximum = 1000; if (up_limit < 0) up_limit = 0;
var mochaSlide = new Slider($('uplimitSliderarea'), $('uplimitSliderknob'), { maximum = 1000;
steps: maximum, var mochaSlide = new Slider($('uplimitSliderarea'), $('uplimitSliderknob'), {
offset: 0, steps: maximum,
initialStep: up_limit.round(), offset: 0,
onChange: function(pos){ initialStep: up_limit.round(),
if(pos > 0) { onChange: function(pos) {
$('uplimitUpdatevalue').set('html', pos); if (pos > 0) {
$('upLimitUnit').set('html', "_(KiB/s)"); $('uplimitUpdatevalue').set('html', pos);
} else { $('upLimitUnit').set('html', "_(KiB/s)");
$('uplimitUpdatevalue').set('html', '∞'); }
$('upLimitUnit').set('html', ""); else {
} $('uplimitUpdatevalue').set('html', '∞');
}.bind(this) $('upLimitUnit').set('html', "");
}); }
// Set default value }.bind(this)
if(up_limit == 0) { });
$('uplimitUpdatevalue').set('html', '∞'); // Set default value
$('upLimitUnit').set('html', ""); if (up_limit == 0) {
} else { $('uplimitUpdatevalue').set('html', '∞');
$('uplimitUpdatevalue').set('html', up_limit.round()); $('upLimitUnit').set('html', "");
$('upLimitUnit').set('html', "_(KiB/s)"); }
} else {
} else { $('uplimitUpdatevalue').set('html', up_limit.round());
var req = new Request({ $('upLimitUnit').set('html', "_(KiB/s)");
url: 'command/getTorrentUpLimit', }
method: 'post', }
data: {hash: hash}, else {
onSuccess: function(data) { var req = new Request({
if(data){ url: 'command/getTorrentUpLimit',
var up_limit = data.toInt(); method: 'post',
if(up_limit < 0) up_limit = 0; data: {
var mochaSlide = new Slider($('uplimitSliderarea'), $('uplimitSliderknob'), { hash: hash
steps: maximum, },
offset: 0, onSuccess: function(data) {
initialStep: (up_limit/1024.).round(), if (data) {
onChange: function(pos){ var up_limit = data.toInt();
if(pos > 0) { if (up_limit < 0) up_limit = 0;
$('uplimitUpdatevalue').set('html', pos); var mochaSlide = new Slider($('uplimitSliderarea'), $('uplimitSliderknob'), {
$('upLimitUnit').set('html', "_(KiB/s)"); steps: maximum,
} else { offset: 0,
$('uplimitUpdatevalue').set('html', '∞'); initialStep: (up_limit / 1024.).round(),
$('upLimitUnit').set('html', ""); onChange: function(pos) {
} if (pos > 0) {
}.bind(this) $('uplimitUpdatevalue').set('html', pos);
}); $('upLimitUnit').set('html', "_(KiB/s)");
// Set default value }
if(up_limit == 0) { else {
$('uplimitUpdatevalue').set('html', '∞'); $('uplimitUpdatevalue').set('html', '∞');
$('upLimitUnit').set('html', ""); $('upLimitUnit').set('html', "");
} else { }
$('uplimitUpdatevalue').set('html', (up_limit/1024.).round()); }.bind(this)
$('upLimitUnit').set('html', "_(KiB/s)"); });
} // Set default value
} if (up_limit == 0) {
} $('uplimitUpdatevalue').set('html', '∞');
}).send(); $('upLimitUnit').set('html', "");
} }
} else {
}).send(); $('uplimitUpdatevalue').set('html', (up_limit / 1024.).round());
} $('upLimitUnit').set('html', "_(KiB/s)");
}, }
}
addDlLimitSlider: function(hash){ }
if ($('dllimitSliderarea')) { }).send();
var windowOptions = MochaUI.Windows.windowOptions; }
var sliderFirst = true; }
// Get global upload limit }).send();
var maximum = 500; }
var req = new Request({ },
url: 'command/getGlobalDlLimit',
method: 'post', addDlLimitSlider: function(hash) {
data: {}, if ($('dllimitSliderarea')) {
onSuccess: function(data) { var windowOptions = MochaUI.Windows.windowOptions;
if(data){ var sliderFirst = true;
var tmp = data.toInt(); // Get global upload limit
if(tmp > 0) { var maximum = 500;
maximum = tmp / 1024. var req = new Request({
} else { url: 'command/getGlobalDlLimit',
maximum = 1000 method: 'post',
} data: {},
} onSuccess: function(data) {
// Get torrent download limit if (data) {
// And create slider var tmp = data.toInt();
if(hash == "global") { if (tmp > 0) {
var dl_limit = maximum; maximum = tmp / 1024.
if(dl_limit < 0) dl_limit = 0; }
maximum = 10000; else {
var mochaSlide = new Slider($('dllimitSliderarea'), $('dllimitSliderknob'), { maximum = 1000
steps: maximum, }
offset: 0, }
initialStep: dl_limit.round(), // Get torrent download limit
onChange: function(pos){ // And create slider
if(pos > 0) { if (hash == "global") {
$('dllimitUpdatevalue').set('html', pos); var dl_limit = maximum;
$('dlLimitUnit').set('html', "_(KiB/s)"); if (dl_limit < 0) dl_limit = 0;
} else { maximum = 10000;
$('dllimitUpdatevalue').set('html', '∞'); var mochaSlide = new Slider($('dllimitSliderarea'), $('dllimitSliderknob'), {
$('dlLimitUnit').set('html', ""); steps: maximum,
} offset: 0,
}.bind(this) initialStep: dl_limit.round(),
}); onChange: function(pos) {
// Set default value if (pos > 0) {
if(dl_limit == 0) { $('dllimitUpdatevalue').set('html', pos);
$('dllimitUpdatevalue').set('html', '∞'); $('dlLimitUnit').set('html', "_(KiB/s)");
$('dlLimitUnit').set('html', ""); }
} else { else {
$('dllimitUpdatevalue').set('html', dl_limit.round()); $('dllimitUpdatevalue').set('html', '∞');
$('dlLimitUnit').set('html', "_(KiB/s)"); $('dlLimitUnit').set('html', "");
} }
} else { }.bind(this)
var req = new Request({ });
url: 'command/getTorrentDlLimit', // Set default value
method: 'post', if (dl_limit == 0) {
data: {hash: hash}, $('dllimitUpdatevalue').set('html', '∞');
onSuccess: function(data) { $('dlLimitUnit').set('html', "");
if(data){ }
var dl_limit = data.toInt(); else {
if(dl_limit < 0) dl_limit = 0; $('dllimitUpdatevalue').set('html', dl_limit.round());
var mochaSlide = new Slider($('dllimitSliderarea'), $('dllimitSliderknob'), { $('dlLimitUnit').set('html', "_(KiB/s)");
steps: maximum, }
offset: 0, }
initialStep: (dl_limit/1024.).round(), else {
onChange: function(pos){ var req = new Request({
if(pos > 0) { url: 'command/getTorrentDlLimit',
$('dllimitUpdatevalue').set('html', pos); method: 'post',
$('dlLimitUnit').set('html', "_(KiB/s)"); data: {
} else { hash: hash
$('dllimitUpdatevalue').set('html', '∞'); },
$('dlLimitUnit').set('html', ""); onSuccess: function(data) {
} if (data) {
}.bind(this) var dl_limit = data.toInt();
}); if (dl_limit < 0) dl_limit = 0;
// Set default value var mochaSlide = new Slider($('dllimitSliderarea'), $('dllimitSliderknob'), {
if(dl_limit == 0) { steps: maximum,
$('dllimitUpdatevalue').set('html', '∞'); offset: 0,
$('dlLimitUnit').set('html', ""); initialStep: (dl_limit / 1024.).round(),
} else { onChange: function(pos) {
$('dllimitUpdatevalue').set('html', (dl_limit/1024.).round()); if (pos > 0) {
$('dlLimitUnit').set('html', "_(KiB/s)"); $('dllimitUpdatevalue').set('html', pos);
} $('dlLimitUnit').set('html', "_(KiB/s)");
} }
} else {
}).send(); $('dllimitUpdatevalue').set('html', '∞');
} $('dlLimitUnit').set('html', "");
} }
}).send(); }.bind(this)
} });
} // Set default value
}); if (dl_limit == 0) {
$('dllimitUpdatevalue').set('html', '∞');
$('dlLimitUnit').set('html', "");
}
else {
$('dllimitUpdatevalue').set('html', (dl_limit / 1024.).round());
$('dlLimitUnit').set('html', "_(KiB/s)");
}
}
}
}).send();
}
}
}).send();
}
}
});

View File

@ -1,96 +1,98 @@
var ProgressBar=new Class({ var ProgressBar = new Class({
initialize:function(value,parameters){ initialize: function(value, parameters) {
var vals={ var vals = {
'id':'progressbar_'+(ProgressBars++), 'id': 'progressbar_' + (ProgressBars++),
'value':$pick(value,0), 'value': $pick(value, 0),
'width':0, 'width': 0,
'height':0, 'height': 0,
'darkbg':'#006', 'darkbg': '#006',
'darkfg':'#fff', 'darkfg': '#fff',
'lightbg':'#fff', 'lightbg': '#fff',
'lightfg':'#000' 'lightfg': '#000'
}; };
if(parameters && $type(parameters)=='object')$extend(vals,parameters); if (parameters && $type(parameters) == 'object') $extend(vals, parameters);
if(vals.height<12)vals.height=12; if (vals.height < 12) vals.height = 12;
var obj=new Element('div',{ var obj = new Element('div', {
'id':vals.id, 'id': vals.id,
'class':'progressbar_wrapper', 'class': 'progressbar_wrapper',
'styles':{ 'styles': {
'border':'1px solid #000', 'border': '1px solid #000',
'width':vals.width, 'width': vals.width,
'height':vals.height, 'height': vals.height,
'position':'relative' 'position': 'relative'
} }
}); });
obj.vals=vals; obj.vals = vals;
obj.vals.value = $pick(value, 0); // Fix by Chris obj.vals.value = $pick(value, 0); // Fix by Chris
obj.vals.dark=new Element('div',{ obj.vals.dark = new Element('div', {
'id':vals.id+'_dark', 'id': vals.id + '_dark',
'class':'progressbar_dark', 'class': 'progressbar_dark',
'styles':{ 'styles': {
'width':vals.width, 'width': vals.width,
'height':vals.height, 'height': vals.height,
'background':vals.darkbg, 'background': vals.darkbg,
'color':vals.darkfg, 'color': vals.darkfg,
'position':'absolute', 'position': 'absolute',
'text-align':'center', 'text-align': 'center',
'left':0, 'left': 0,
'top':0, 'top': 0,
'line-height':vals.height-2 'line-height': vals.height - 2
} }
}); });
obj.vals.light=new Element('div',{ obj.vals.light = new Element('div', {
'id':vals.id+'_light', 'id': vals.id + '_light',
'class':'progressbar_light', 'class': 'progressbar_light',
'styles':{ 'styles': {
'width':vals.width, 'width': vals.width,
'height':vals.height, 'height': vals.height,
'background':vals.lightbg, 'background': vals.lightbg,
'color':vals.lightfg, 'color': vals.lightfg,
'position':'absolute', 'position': 'absolute',
'text-align':'center', 'text-align': 'center',
'left':0, 'left': 0,
'top':0, 'top': 0,
'line-height':vals.height-2 'line-height': vals.height - 2
} }
}); });
obj.appendChild(obj.vals.dark); obj.appendChild(obj.vals.dark);
obj.appendChild(obj.vals.light); obj.appendChild(obj.vals.light);
obj.getValue=ProgressBar_getValue; obj.getValue = ProgressBar_getValue;
obj.setValue=ProgressBar_setValue; obj.setValue = ProgressBar_setValue;
if(vals.width)obj.setValue(vals.value); if (vals.width) obj.setValue(vals.value);
else setTimeout('ProgressBar_checkForParent("'+obj.id+'")',1); else setTimeout('ProgressBar_checkForParent("' + obj.id + '")', 1);
return obj; return obj;
} }
}); });
function ProgressBar_getValue(){ function ProgressBar_getValue() {
return this.vals.value; return this.vals.value;
} }
function ProgressBar_setValue(value){ function ProgressBar_setValue(value) {
value=parseFloat(value); value = parseFloat(value);
if(isNaN(value))value=0; if (isNaN(value)) value = 0;
if(value>100)value=100; if (value > 100) value = 100;
if(value<0)value=0; if (value < 0) value = 0;
this.vals.value=value; this.vals.value = value;
this.vals.dark.empty(); this.vals.dark.empty();
this.vals.light.empty(); this.vals.light.empty();
this.vals.dark.appendText(value+'%'); this.vals.dark.appendText(value + '%');
this.vals.light.appendText(value+'%'); this.vals.light.appendText(value + '%');
var r=parseInt(this.vals.width*(value/100)); var r = parseInt(this.vals.width * (value / 100));
this.vals.dark.setStyle('clip','rect(0,'+r+'px,'+this.vals.height+'px,0)'); this.vals.dark.setStyle('clip', 'rect(0,' + r + 'px,' + this.vals.height + 'px,0)');
this.vals.light.setStyle('clip','rect(0,'+this.vals.width+'px,'+this.vals.height+'px,'+r+'px)'); this.vals.light.setStyle('clip', 'rect(0,' + this.vals.width + 'px,' + this.vals.height + 'px,' + r + 'px)');
} }
function ProgressBar_checkForParent(id){
var obj=$(id); function ProgressBar_checkForParent(id) {
if(!obj)return; var obj = $(id);
if(!obj.parentNode)return setTimeout('ProgressBar_checkForParent("'+id+'")',1); if (!obj) return;
obj.setStyle('width','100%'); if (!obj.parentNode) return setTimeout('ProgressBar_checkForParent("' + id + '")', 1);
var w=obj.offsetWidth; obj.setStyle('width', '100%');
obj.vals.dark.setStyle('width',w); var w = obj.offsetWidth;
obj.vals.light.setStyle('width',w); obj.vals.dark.setStyle('width', w);
obj.vals.width=w; obj.vals.light.setStyle('width', w);
obj.vals.width = w;
obj.setValue(obj.vals.value); obj.setValue(obj.vals.value);
} }
var ProgressBars=0;
var ProgressBars = 0;