deluge/plugins/WebUi/templates/advanced/static/deluge.js

122 lines
2.8 KiB
JavaScript

/*
all javascript is optional, everything should work web 1.0
but javascript may/will enhance the experience.
i'm not a full time web-dev so don't expect beautifull patterns.
There's so much crap out there,i can't find good examples.
so i'd rather start from scratch,
Probably broken in an unexpected way , but worksforme.
*/
state = {
'row_js_continue':true
,'selected_rows': new Array()
};
function $(el_id){
return document.getElementById(el_id)
}
function get_row(id){
return $('torrent_' + id);
}
function on_click_row(e,id) {
/*filter out web 1.0 events for detail-link and pause*/
if (state.row_js_continue) {
on_click_action(e,id);
}
state.row_js_continue = true;
}
function on_click_row_js(e, id) {
/*real onClick event*/
if (!e.ctrlKey) {
deselect_rows();
}
select_row(id);
open_inner_details(id);
}
function select_row(id){
var row = get_row(id);
if (row) {
row.className = 'torrent_table_selected';
state.selected_rows[state.selected_rows.length] = id;
setCookie('selected_rows',state.selected_rows);
}
}
function deselect_rows(){
for (i in state.selected_rows) {
deselect_row(state.selected_rows[i]);
}
state.selected_rows = new Array();
}
function deselect_row(id){
var row = get_row(id);
if (row) {
row.className = 'torrent_table'
/*TODO : remove from state.selected_rows*/
}
}
function reselect_rows(){
var selected_rows = getCookie('selected_rows').split(',');
for (i in getCookie('selected_rows')) {
select_row(selected_rows[i]);
}
}
function open_details(e, id){
alert(id);
window.location.href = '/torrent/info/' + id;
}
function open_inner_details(id){
/*probably broken for IE, use FF!*/
$('torrent_info').src = '/torrent/info_inner/' + id;
}
function on_click_do_nothing(e, id){
}
on_click_action = on_click_do_nothing;
/*toobar buttons, */
function toolbar_post(url) {
/*this feels hacky, but it's the only way i know of*/
var ids = state.selected_rows.join(',');
var form = $('toolbar_form');
form.action = url +ids;
form.submit();
return false;
}
function toolbar_get(url) {
/*this feels hacky, but it's the only way i know of*/
var ids = state.selected_rows.join(',');
window.location.href = url +ids;
return false;
}
/*stuff copied from various places:*/
/*http://www.w3schools.com/js/js_cookies.asp*/
function setCookie(c_name,value,expiredays)
{
var exdate=new Date()
exdate.setDate(exdate.getDate()+expiredays)
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toGMTString())
}
function getCookie(c_name)
{
if (document.cookie.length>0)
{
c_start=document.cookie.indexOf(c_name + "=")
if (c_start!=-1)
{
c_start=c_start + c_name.length+1
c_end=document.cookie.indexOf(";",c_start)
if (c_end==-1) c_end=document.cookie.length
return unescape(document.cookie.substring(c_start,c_end))
}
}
return ""
}