2008-05-17 12:44:42 +00:00
/ * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
2014-12-08 00:52:29 +03:00
ATTACH MOCHA LINK EVENTS
Notes : Here is where you define your windows and the events that open them .
If you are not using links to run Mocha methods you can remove this function .
2012-07-01 13:23:41 +03:00
2014-12-08 00:52:29 +03:00
If you need to add link events to links within windows you are creating , do
it in the onContentLoaded function of the new window .
2008-05-17 12:44:42 +00:00
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - * /
2014-11-30 01:40:26 +03:00
/* Define localStorage object for older browsers */
if ( typeof localStorage == 'undefined' ) {
window [ 'localStorage' ] = {
getItem : function ( name ) {
return Cookie . read ( name ) ;
} ,
setItem : function ( name , value ) {
2014-11-30 14:14:09 +01:00
Cookie . write ( name , value , {
duration : 365 * 10
} ) ;
2014-11-30 01:40:26 +03:00
}
}
}
2014-12-08 03:03:53 +03:00
function getLocalStorageItem ( name , defaultVal ) {
val = localStorage . getItem ( name ) ;
if ( val === null || val === undefined )
val = defaultVal ;
return val ;
}
2014-11-30 14:14:09 +01:00
initializeWindows = function ( ) {
2012-07-01 13:23:41 +03:00
2014-11-30 14:14:09 +01:00
function addClickEvent ( el , fn ) {
[ 'Link' , 'Button' ] . each ( function ( item ) {
if ( $ ( el + item ) ) {
$ ( el + item ) . addEvent ( 'click' , fn ) ;
}
} ) ;
}
2012-07-01 13:23:41 +03:00
2014-11-30 14:14:09 +01:00
addClickEvent ( 'download' , function ( e ) {
new Event ( e ) . stop ( ) ;
new MochaUI . Window ( {
id : 'downloadPage' ,
2014-12-17 14:58:32 +03:00
title : "QBT_TR(Download from urls)QBT_TR" ,
2014-11-30 14:14:09 +01:00
loadMethod : 'iframe' ,
contentURL : 'download.html' ,
scrollbars : true ,
resizable : false ,
maximizable : false ,
closable : true ,
paddingVertical : 0 ,
paddingHorizontal : 0 ,
width : 500 ,
height : 300
} ) ;
2015-01-06 23:24:54 +03:00
updateMainData ( ) ;
2014-11-30 14:14:09 +01:00
} ) ;
2012-07-01 13:23:41 +03:00
2014-11-30 14:14:09 +01:00
addClickEvent ( 'preferences' , function ( e ) {
new Event ( e ) . stop ( ) ;
new MochaUI . Window ( {
id : 'preferencesPage' ,
2014-12-17 14:58:32 +03:00
title : "QBT_TR(Options)QBT_TR" ,
2014-11-30 14:14:09 +01:00
loadMethod : 'xhr' ,
toolbar : true ,
contentURL : 'preferences_content.html' ,
require : {
css : [ 'css/Tabs.css' ]
} ,
toolbarURL : 'preferences.html' ,
resizable : true ,
maximizable : false ,
closable : true ,
paddingVertical : 0 ,
paddingHorizontal : 0 ,
width : 700 ,
height : 300
} ) ;
} ) ;
2012-07-01 13:23:41 +03:00
2014-11-30 14:14:09 +01:00
addClickEvent ( 'upload' , function ( e ) {
new Event ( e ) . stop ( ) ;
new MochaUI . Window ( {
id : 'uploadPage' ,
2014-12-17 14:58:32 +03:00
title : "QBT_TR(Download local torrent)QBT_TR" ,
2014-11-30 14:14:09 +01:00
loadMethod : 'iframe' ,
contentURL : 'upload.html' ,
scrollbars : true ,
resizable : false ,
maximizable : false ,
paddingVertical : 0 ,
paddingHorizontal : 0 ,
width : 600 ,
height : 130
} ) ;
2015-01-06 23:24:54 +03:00
updateMainData ( ) ;
2014-11-30 14:14:09 +01:00
} ) ;
2012-07-01 13:23:41 +03:00
2014-11-30 14:14:09 +01:00
globalUploadLimitFN = function ( ) {
new MochaUI . Window ( {
id : 'uploadLimitPage' ,
2014-12-17 14:58:32 +03:00
title : "QBT_TR(Global Upload Speed Limit)QBT_TR" ,
2014-11-30 14:14:09 +01:00
loadMethod : 'iframe' ,
contentURL : 'uploadlimit.html?hash=global' ,
scrollbars : false ,
resizable : false ,
maximizable : false ,
paddingVertical : 0 ,
paddingHorizontal : 0 ,
width : 424 ,
height : 80
} ) ;
}
2012-07-01 13:23:41 +03:00
2014-11-30 14:14:09 +01:00
uploadLimitFN = function ( ) {
var h = myTable . selectedIds ( ) ;
if ( h . length ) {
var hash = h [ 0 ] ;
new MochaUI . Window ( {
id : 'uploadLimitPage' ,
2014-12-17 14:58:32 +03:00
title : "QBT_TR(Torrent Upload Speed Limiting)QBT_TR" ,
2014-11-30 14:14:09 +01:00
loadMethod : 'iframe' ,
contentURL : 'uploadlimit.html?hash=' + hash ,
scrollbars : false ,
resizable : false ,
maximizable : false ,
paddingVertical : 0 ,
paddingHorizontal : 0 ,
width : 424 ,
height : 80
} ) ;
}
} ;
2012-07-01 13:23:41 +03:00
2014-12-09 19:54:35 +03:00
toggleSequentialDownloadFN = function ( ) {
var h = myTable . selectedIds ( ) ;
if ( h . length ) {
new Request ( {
url : 'command/toggleSequentialDownload' ,
method : 'post' ,
data : {
hashes : h . join ( "|" )
}
} ) . send ( ) ;
2015-01-06 23:24:54 +03:00
updateMainData ( ) ;
2014-12-09 19:54:35 +03:00
}
} ;
toggleFirstLastPiecePrioFN = function ( ) {
var h = myTable . selectedIds ( ) ;
if ( h . length ) {
new Request ( {
url : 'command/toggleFirstLastPiecePrio' ,
method : 'post' ,
data : {
hashes : h . join ( "|" )
}
} ) . send ( ) ;
2015-01-06 23:24:54 +03:00
updateMainData ( ) ;
2014-12-09 19:54:35 +03:00
}
} ;
2014-11-30 14:14:09 +01:00
globalDownloadLimitFN = function ( ) {
new MochaUI . Window ( {
id : 'downloadLimitPage' ,
2014-12-17 14:58:32 +03:00
title : "QBT_TR(Global Download Speed Limit)QBT_TR" ,
2014-11-30 14:14:09 +01:00
loadMethod : 'iframe' ,
contentURL : 'downloadlimit.html?hash=global' ,
scrollbars : false ,
resizable : false ,
maximizable : false ,
paddingVertical : 0 ,
paddingHorizontal : 0 ,
width : 424 ,
height : 80
} ) ;
}
2012-07-01 13:23:41 +03:00
2014-11-30 14:14:09 +01:00
downloadLimitFN = function ( ) {
var h = myTable . selectedIds ( ) ;
if ( h . length ) {
var hash = h [ 0 ] ;
new MochaUI . Window ( {
id : 'downloadLimitPage' ,
2014-12-17 14:58:32 +03:00
title : "QBT_TR(Torrent Download Speed Limiting)QBT_TR" ,
2014-11-30 14:14:09 +01:00
loadMethod : 'iframe' ,
contentURL : 'downloadlimit.html?hash=' + hash ,
scrollbars : false ,
resizable : false ,
maximizable : false ,
paddingVertical : 0 ,
paddingHorizontal : 0 ,
width : 424 ,
height : 80
} ) ;
}
} ;
2012-07-01 13:23:41 +03:00
2014-11-30 14:14:09 +01:00
deleteFN = function ( ) {
var h = myTable . selectedIds ( ) ;
2014-12-17 14:58:32 +03:00
/ * i f ( h . l e n g t h & & c o n f i r m ( ' Q B T _ T R ( A r e y o u s u r e y o u w a n t t o d e l e t e t h e s e l e c t e d t o r r e n t s f r o m t h e t r a n s f e r l i s t ? ) Q B T _ T R ' ) ) {
2014-12-08 00:52:29 +03:00
h . each ( function ( item , index ) {
new Request ( { url : 'command/delete' , method : 'post' , data : { hash : item } } ) . send ( ) ;
} ) ;
} * /
2014-11-30 14:14:09 +01:00
if ( h . length ) {
new MochaUI . Window ( {
id : 'confirmDeletionPage' ,
2014-12-17 14:58:32 +03:00
title : "QBT_TR(Deletion confirmation - qBittorrent)QBT_TR" ,
2014-11-30 14:14:09 +01:00
loadMethod : 'iframe' ,
contentURL : 'confirmdeletion.html?hashes=' + h . join ( ',' ) ,
scrollbars : false ,
resizable : false ,
maximizable : false ,
padding : 10 ,
width : 424 ,
height : 140
} ) ;
2015-01-06 23:24:54 +03:00
updateMainData ( ) ;
2014-11-30 14:14:09 +01:00
}
} ;
2009-11-24 19:41:31 +00:00
2014-11-30 14:14:09 +01:00
addClickEvent ( 'delete' , function ( e ) {
new Event ( e ) . stop ( ) ;
deleteFN ( ) ;
} ) ;
2012-07-01 13:23:41 +03:00
2014-11-30 14:14:09 +01:00
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 ( ) ;
} ) ;
2015-01-06 23:24:54 +03:00
updateMainData ( ) ;
2014-11-30 14:14:09 +01:00
}
} ;
2012-07-01 13:23:41 +03:00
2014-11-30 14:14:09 +01:00
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 ( ) ;
} ) ;
2015-01-06 23:24:54 +03:00
updateMainData ( ) ;
2014-11-30 14:14:09 +01:00
}
} ;
2012-07-01 13:23:41 +03:00
2014-11-30 14:14:09 +01:00
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 ( ) ;
} ) ;
}
} ;
2008-12-28 21:12:49 +00:00
2015-01-29 17:39:17 +03:00
[ 'pauseAll' , 'resumeAll' , 'pause' , 'resume' , 'recheck' ] . each ( function ( item ) {
2014-11-30 14:14:09 +01:00
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 ( ) ;
} ) ;
2015-01-06 23:24:54 +03:00
updateMainData ( ) ;
2014-11-30 14:14:09 +01:00
}
} ) ;
2012-07-01 13:23:41 +03:00
2014-11-30 14:14:09 +01:00
addClickEvent ( item + 'All' , function ( e ) {
new Event ( e ) . stop ( ) ;
new Request ( {
url : 'command/' + item + 'all'
} ) . send ( ) ;
} ) ;
} ) ;
2010-12-19 13:37:12 +00:00
2014-11-30 14:14:09 +01:00
[ 'decreasePrio' , 'increasePrio' , 'topPrio' , 'bottomPrio' ] . each ( function ( item ) {
addClickEvent ( item , function ( e ) {
new Event ( e ) . stop ( ) ;
setPriorityFN ( item ) ;
} ) ;
} ) ;
2012-07-01 13:23:41 +03:00
2014-11-30 14:14:09 +01:00
setPriorityFN = function ( cmd ) {
var h = myTable . selectedIds ( ) ;
if ( h . length ) {
new Request ( {
url : 'command/' + cmd ,
method : 'post' ,
data : {
hashes : h . join ( "|" )
}
} ) . send ( ) ;
2015-01-06 23:24:54 +03:00
updateMainData ( ) ;
2014-11-30 14:14:09 +01:00
}
}
2012-07-01 13:23:41 +03:00
2014-11-30 14:14:09 +01:00
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
} ) ;
} ) ;
2012-07-01 13:23:41 +03:00
2014-11-30 14:14:09 +01:00
addClickEvent ( 'logout' , function ( e ) {
2014-08-22 22:02:01 +04:00
new Event ( e ) . stop ( ) ;
new Request ( {
url : '/logout' ,
method : 'get' ,
onSuccess : function ( ) {
window . location . reload ( ) ;
}
} ) . send ( ) ;
} ) ;
2014-11-30 14:14:09 +01:00
addClickEvent ( 'shutdown' , function ( e ) {
new Event ( e ) . stop ( ) ;
2014-08-22 22:02:01 +04:00
new Request ( {
url : 'command/shutdown' ,
onSuccess : function ( ) {
2014-12-17 14:58:32 +03:00
document . write ( "<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\"><html xmlns=\"http://www.w3.org/1999/xhtml\"><head><title>QBT_TR(qBittorrent has been shutdown.)QBT_TR</title><style type=\"text/css\">body { text-align: center; }</style></head><body><h1>QBT_TR(qBittorrent has been shutdown.)QBT_TR</h1></body></html>" ) ;
2014-08-22 22:02:01 +04:00
stop ( ) ;
}
} ) . send ( ) ;
2014-11-30 14:14:09 +01:00
} ) ;
2012-08-19 19:25:21 +02:00
2014-11-30 14:14:09 +01:00
// Deactivate menu header links
$$ ( 'a.returnFalse' ) . each ( function ( el ) {
el . addEvent ( 'click' , function ( e ) {
new Event ( e ) . stop ( ) ;
} ) ;
} ) ;
}