2011-09-14 05:10:51 +00:00
|
|
|
|
/**
|
|
|
|
|
* Copyright © Dave Perrett and Malcolm Jarvis
|
2008-07-10 23:57:46 +00:00
|
|
|
|
*
|
2011-09-14 05:10:51 +00:00
|
|
|
|
* This file is licensed under the GPLv2.
|
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
2008-07-10 23:57:46 +00:00
|
|
|
|
*/
|
|
|
|
|
|
2011-08-28 17:24:56 +00:00
|
|
|
|
var transmission,
|
|
|
|
|
dialog,
|
2011-08-31 00:50:28 +00:00
|
|
|
|
isMobileDevice = RegExp("(iPhone|iPod|Android)").test(navigator.userAgent),
|
2011-08-28 17:24:56 +00:00
|
|
|
|
scroll_timeout;
|
2008-07-10 23:57:46 +00:00
|
|
|
|
|
2011-08-24 02:04:35 +00:00
|
|
|
|
if (!Array.indexOf){
|
2010-10-26 00:18:41 +00:00
|
|
|
|
Array.prototype.indexOf = function(obj){
|
|
|
|
|
var i, len;
|
2011-08-24 02:04:35 +00:00
|
|
|
|
for (i=0, len=this.length; i<len; i++)
|
|
|
|
|
if (this[i]==obj)
|
2010-10-26 00:18:41 +00:00
|
|
|
|
return i;
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-14 05:10:51 +00:00
|
|
|
|
// http://forum.jquery.com/topic/combining-ui-dialog-and-tabs
|
|
|
|
|
$.fn.tabbedDialog = function (dialog_opts) {
|
|
|
|
|
this.tabs({selected: 0});
|
|
|
|
|
this.dialog(dialog_opts);
|
|
|
|
|
this.find('.ui-tab-dialog-close').append(this.parent().find('.ui-dialog-titlebar-close'));
|
|
|
|
|
this.find('.ui-tab-dialog-close').css({'position':'absolute','right':'0', 'top':'16px'});
|
|
|
|
|
this.find('.ui-tab-dialog-close > a').css({'float':'none','padding':'0'});
|
|
|
|
|
var tabul = this.find('ul:first');
|
|
|
|
|
this.parent().addClass('ui-tabs').prepend(tabul).draggable('option','handle',tabul);
|
|
|
|
|
this.siblings('.ui-dialog-titlebar').remove();
|
|
|
|
|
tabul.addClass('ui-dialog-titlebar');
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-24 02:04:35 +00:00
|
|
|
|
$(document).ready(function() {
|
2008-07-10 23:57:46 +00:00
|
|
|
|
|
2011-11-06 14:42:52 +00:00
|
|
|
|
// IE8 and below don’t support ES5 Date.now()
|
|
|
|
|
if (!Date.now) {
|
|
|
|
|
Date.now = function() {
|
|
|
|
|
return +new Date();
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2010-09-03 00:03:21 +00:00
|
|
|
|
// IE specific fixes here
|
|
|
|
|
if ($.browser.msie) {
|
|
|
|
|
try {
|
|
|
|
|
document.execCommand("BackgroundImageCache", false, true);
|
|
|
|
|
} catch(err) {}
|
|
|
|
|
$('.dialog_container').css('height',$(window).height()+'px');
|
|
|
|
|
}
|
|
|
|
|
|
2008-07-10 23:57:46 +00:00
|
|
|
|
if ($.browser.safari) {
|
2008-08-09 04:38:51 +00:00
|
|
|
|
// Move search field's margin down for the styled input
|
2010-06-21 13:14:33 +00:00
|
|
|
|
$('#torrent_search').css('margin-top', 3);
|
2008-07-10 23:57:46 +00:00
|
|
|
|
}
|
2011-08-28 17:24:56 +00:00
|
|
|
|
if (isMobileDevice){
|
2009-07-07 01:11:30 +00:00
|
|
|
|
window.onload = function(){ setTimeout(function() { window.scrollTo(0,1); },500); };
|
2011-08-24 02:04:35 +00:00
|
|
|
|
window.onorientationchange = function(){ setTimeout(function() { window.scrollTo(0,1); },100); };
|
|
|
|
|
if (window.navigator.standalone)
|
2011-08-28 17:24:56 +00:00
|
|
|
|
// Fix min height for isMobileDevice when run in full screen mode from home screen
|
2009-07-07 01:11:30 +00:00
|
|
|
|
// so the footer appears in the right place
|
|
|
|
|
$('body div#torrent_container').css('min-height', '338px');
|
|
|
|
|
$("label[for=torrent_upload_url]").text("URL: ");
|
2011-08-28 17:24:56 +00:00
|
|
|
|
} else {
|
|
|
|
|
// Fix for non-Safari-3 browsers: dark borders to replace shadows.
|
2015-04-30 05:20:48 +00:00
|
|
|
|
$('div.dialog_container div.dialog_window').css('border', '1px solid #777');
|
2009-07-07 01:11:30 +00:00
|
|
|
|
}
|
2011-11-13 20:13:25 +00:00
|
|
|
|
|
|
|
|
|
// Initialise the dialog controller
|
|
|
|
|
dialog = new Dialog();
|
|
|
|
|
|
|
|
|
|
// Initialise the main Transmission controller
|
|
|
|
|
transmission = new Transmission();
|
2008-07-10 23:57:46 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
/**
|
2012-07-20 17:37:50 +00:00
|
|
|
|
* Checks to see if the content actually changed before poking the DOM.
|
2008-07-10 23:57:46 +00:00
|
|
|
|
*/
|
2011-08-24 02:04:35 +00:00
|
|
|
|
function setInnerHTML(e, html)
|
2008-07-10 23:57:46 +00:00
|
|
|
|
{
|
2011-09-05 07:46:55 +00:00
|
|
|
|
if (!e)
|
2010-06-26 16:47:15 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2009-05-23 21:14:03 +00:00
|
|
|
|
/* innerHTML is listed as a string, but the browser seems to change it.
|
|
|
|
|
* For example, "∞" gets changed to "∞" somewhere down the line.
|
|
|
|
|
* So, let's use an arbitrary different field to test our state... */
|
2011-08-24 02:04:35 +00:00
|
|
|
|
if (e.currentHTML != html)
|
2009-05-23 21:14:03 +00:00
|
|
|
|
{
|
|
|
|
|
e.currentHTML = html;
|
2008-07-10 23:57:46 +00:00
|
|
|
|
e.innerHTML = html;
|
2009-05-23 21:14:03 +00:00
|
|
|
|
}
|
2008-07-10 23:57:46 +00:00
|
|
|
|
};
|
|
|
|
|
|
2012-07-20 17:37:50 +00:00
|
|
|
|
function sanitizeText(text)
|
|
|
|
|
{
|
|
|
|
|
return text.replace(/</g, "<").replace(/>/g, ">");
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Many of our text changes are triggered by periodic refreshes
|
|
|
|
|
* on torrents whose state hasn't changed since the last update,
|
|
|
|
|
* so see if the text actually changed before poking the DOM.
|
|
|
|
|
*/
|
|
|
|
|
function setTextContent(e, text)
|
|
|
|
|
{
|
|
|
|
|
if (e && (e.textContent != text))
|
|
|
|
|
e.textContent = text;
|
|
|
|
|
};
|
|
|
|
|
|
2008-07-10 23:57:46 +00:00
|
|
|
|
/*
|
|
|
|
|
* Given a numerator and denominator, return a ratio string
|
|
|
|
|
*/
|
2011-08-24 02:04:35 +00:00
|
|
|
|
Math.ratio = function(numerator, denominator) {
|
2009-04-24 03:21:15 +00:00
|
|
|
|
var result = Math.floor(100 * numerator / denominator) / 100;
|
2008-07-10 23:57:46 +00:00
|
|
|
|
|
|
|
|
|
// check for special cases
|
2011-08-24 02:04:35 +00:00
|
|
|
|
if (result==Number.POSITIVE_INFINITY || result==Number.NEGATIVE_INFINITY) result = -2;
|
|
|
|
|
else if (isNaN(result)) result = -1;
|
2008-07-10 23:57:46 +00:00
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
};
|
|
|
|
|
|
2011-09-14 05:10:51 +00:00
|
|
|
|
/**
|
|
|
|
|
* Round a string of a number to a specified number of decimal places
|
2010-06-22 22:30:58 +00:00
|
|
|
|
*/
|
2011-08-24 02:04:35 +00:00
|
|
|
|
Number.prototype.toTruncFixed = function(place) {
|
2011-09-14 05:10:51 +00:00
|
|
|
|
var ret = Math.floor(this * Math.pow (10, place)) / Math.pow(10, place);
|
2011-08-24 02:04:35 +00:00
|
|
|
|
return ret.toFixed(place);
|
2010-06-22 22:30:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-09-14 05:10:51 +00:00
|
|
|
|
Number.prototype.toStringWithCommas = function() {
|
|
|
|
|
return this.toString().replace(/\B(?=(?:\d{3})+(?!\d))/g, ",");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-07-10 23:57:46 +00:00
|
|
|
|
/*
|
|
|
|
|
* Trim whitespace from a string
|
|
|
|
|
*/
|
|
|
|
|
String.prototype.trim = function () {
|
|
|
|
|
return this.replace(/^\s*/, "").replace(/\s*$/, "");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
|
**** Preferences
|
|
|
|
|
***/
|
|
|
|
|
|
|
|
|
|
function Prefs() { }
|
|
|
|
|
Prefs.prototype = { };
|
|
|
|
|
|
|
|
|
|
Prefs._RefreshRate = 'refresh_rate';
|
|
|
|
|
|
|
|
|
|
Prefs._FilterMode = 'filter';
|
|
|
|
|
Prefs._FilterAll = 'all';
|
2010-06-17 04:38:03 +00:00
|
|
|
|
Prefs._FilterActive = 'active';
|
2008-07-10 23:57:46 +00:00
|
|
|
|
Prefs._FilterSeeding = 'seeding';
|
|
|
|
|
Prefs._FilterDownloading = 'downloading';
|
|
|
|
|
Prefs._FilterPaused = 'paused';
|
2010-09-03 00:20:40 +00:00
|
|
|
|
Prefs._FilterFinished = 'finished';
|
2008-07-10 23:57:46 +00:00
|
|
|
|
|
|
|
|
|
Prefs._SortDirection = 'sort_direction';
|
|
|
|
|
Prefs._SortAscending = 'ascending';
|
|
|
|
|
Prefs._SortDescending = 'descending';
|
|
|
|
|
|
|
|
|
|
Prefs._SortMethod = 'sort_method';
|
|
|
|
|
Prefs._SortByAge = 'age';
|
|
|
|
|
Prefs._SortByActivity = 'activity';
|
|
|
|
|
Prefs._SortByName = 'name';
|
2011-08-02 03:59:54 +00:00
|
|
|
|
Prefs._SortByQueue = 'queue_order';
|
2011-11-28 03:35:33 +00:00
|
|
|
|
Prefs._SortBySize = 'size';
|
2008-07-10 23:57:46 +00:00
|
|
|
|
Prefs._SortByProgress = 'percent_completed';
|
2011-06-10 14:04:32 +00:00
|
|
|
|
Prefs._SortByRatio = 'ratio';
|
2008-07-10 23:57:46 +00:00
|
|
|
|
Prefs._SortByState = 'state';
|
|
|
|
|
|
2010-06-19 16:36:00 +00:00
|
|
|
|
Prefs._CompactDisplayState= 'compact_display_state';
|
2008-07-10 23:57:46 +00:00
|
|
|
|
|
|
|
|
|
Prefs._Defaults =
|
|
|
|
|
{
|
|
|
|
|
'filter': 'all',
|
|
|
|
|
'refresh_rate' : 5,
|
|
|
|
|
'sort_direction': 'ascending',
|
2009-11-10 05:42:57 +00:00
|
|
|
|
'sort_method': 'name',
|
2010-06-19 16:36:00 +00:00
|
|
|
|
'turtle-state' : false,
|
|
|
|
|
'compact_display_state' : false
|
2008-07-10 23:57:46 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Set a preference option
|
|
|
|
|
*/
|
2011-08-24 02:04:35 +00:00
|
|
|
|
Prefs.setValue = function(key, val)
|
2008-07-10 23:57:46 +00:00
|
|
|
|
{
|
2011-09-05 07:46:55 +00:00
|
|
|
|
if (!(key in Prefs._Defaults))
|
2011-08-24 02:04:35 +00:00
|
|
|
|
console.warn("unrecognized preference key '%s'", key);
|
2008-07-10 23:57:46 +00:00
|
|
|
|
|
|
|
|
|
var date = new Date();
|
2013-01-05 03:29:22 +00:00
|
|
|
|
date.setFullYear (date.getFullYear() + 1);
|
2008-07-10 23:57:46 +00:00
|
|
|
|
document.cookie = key+"="+val+"; expires="+date.toGMTString()+"; path=/";
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get a preference option
|
|
|
|
|
*
|
|
|
|
|
* @param key the preference's key
|
|
|
|
|
* @param fallback if the option isn't set, return this instead
|
|
|
|
|
*/
|
2011-08-24 02:04:35 +00:00
|
|
|
|
Prefs.getValue = function(key, fallback)
|
2008-07-10 23:57:46 +00:00
|
|
|
|
{
|
|
|
|
|
var val;
|
|
|
|
|
|
2011-09-05 07:46:55 +00:00
|
|
|
|
if (!(key in Prefs._Defaults))
|
2011-08-24 02:04:35 +00:00
|
|
|
|
console.warn("unrecognized preference key '%s'", key);
|
2008-07-10 23:57:46 +00:00
|
|
|
|
|
2011-08-24 02:04:35 +00:00
|
|
|
|
var lines = document.cookie.split(';');
|
|
|
|
|
for (var i=0, len=lines.length; !val && i<len; ++i) {
|
|
|
|
|
var line = lines[i].trim();
|
|
|
|
|
var delim = line.indexOf('=');
|
2011-09-05 07:46:55 +00:00
|
|
|
|
if ((delim === key.length) && line.indexOf(key) === 0)
|
2011-08-24 02:04:35 +00:00
|
|
|
|
val = line.substring(delim + 1);
|
2008-07-10 23:57:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// FIXME: we support strings and booleans... add number support too?
|
2011-08-24 02:04:35 +00:00
|
|
|
|
if (!val) val = fallback;
|
2011-09-05 07:46:55 +00:00
|
|
|
|
else if (val === 'true') val = true;
|
|
|
|
|
else if (val === 'false') val = false;
|
2008-07-10 23:57:46 +00:00
|
|
|
|
return val;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get an object with all the Clutch preferences set
|
|
|
|
|
*
|
|
|
|
|
* @pararm o object to be populated (optional)
|
|
|
|
|
*/
|
2011-08-24 02:04:35 +00:00
|
|
|
|
Prefs.getClutchPrefs = function(o)
|
2008-07-10 23:57:46 +00:00
|
|
|
|
{
|
2011-08-24 02:04:35 +00:00
|
|
|
|
if (!o)
|
2008-07-10 23:57:46 +00:00
|
|
|
|
o = { };
|
2011-08-24 02:04:35 +00:00
|
|
|
|
for (var key in Prefs._Defaults)
|
|
|
|
|
o[key] = Prefs.getValue(key, Prefs._Defaults[key]);
|
2008-07-10 23:57:46 +00:00
|
|
|
|
return o;
|
|
|
|
|
};
|
2011-08-21 05:54:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// forceNumeric() plug-in implementation
|
|
|
|
|
jQuery.fn.forceNumeric = function () {
|
|
|
|
|
return this.each(function () {
|
|
|
|
|
$(this).keydown(function (e) {
|
|
|
|
|
var key = e.which || e.keyCode;
|
|
|
|
|
return !e.shiftKey && !e.altKey && !e.ctrlKey &&
|
|
|
|
|
// numbers
|
|
|
|
|
key >= 48 && key <= 57 ||
|
|
|
|
|
// Numeric keypad
|
|
|
|
|
key >= 96 && key <= 105 ||
|
|
|
|
|
// comma, period and minus, . on keypad
|
2011-09-05 07:46:55 +00:00
|
|
|
|
key === 190 || key === 188 || key === 109 || key === 110 ||
|
2011-08-21 05:54:02 +00:00
|
|
|
|
// Backspace and Tab and Enter
|
2011-09-05 07:46:55 +00:00
|
|
|
|
key === 8 || key === 9 || key === 13 ||
|
2011-08-21 05:54:02 +00:00
|
|
|
|
// Home and End
|
2011-09-05 07:46:55 +00:00
|
|
|
|
key === 35 || key === 36 ||
|
2011-08-21 05:54:02 +00:00
|
|
|
|
// left and right arrows
|
2011-09-05 07:46:55 +00:00
|
|
|
|
key === 37 || key === 39 ||
|
2011-08-21 05:54:02 +00:00
|
|
|
|
// Del and Ins
|
2011-09-05 07:46:55 +00:00
|
|
|
|
key === 46 || key === 45;
|
2011-08-21 05:54:02 +00:00
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
2011-08-24 02:04:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* http://blog.stevenlevithan.com/archives/parseuri
|
|
|
|
|
*
|
|
|
|
|
* parseUri 1.2.2
|
|
|
|
|
* (c) Steven Levithan <stevenlevithan.com>
|
|
|
|
|
* MIT License
|
|
|
|
|
*/
|
|
|
|
|
function parseUri (str) {
|
|
|
|
|
var o = parseUri.options,
|
|
|
|
|
m = o.parser[o.strictMode ? "strict" : "loose"].exec(str),
|
|
|
|
|
uri = {},
|
|
|
|
|
i = 14;
|
|
|
|
|
|
|
|
|
|
while (i--) uri[o.key[i]] = m[i] || "";
|
|
|
|
|
|
|
|
|
|
uri[o.q.name] = {};
|
|
|
|
|
uri[o.key[12]].replace(o.q.parser, function ($0, $1, $2) {
|
|
|
|
|
if ($1) uri[o.q.name][$1] = $2;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return uri;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
parseUri.options = {
|
|
|
|
|
strictMode: false,
|
|
|
|
|
key: ["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"],
|
|
|
|
|
q: {
|
|
|
|
|
name: "queryKey",
|
|
|
|
|
parser: /(?:^|&)([^&=]*)=?([^&]*)/g
|
|
|
|
|
},
|
|
|
|
|
parser: {
|
|
|
|
|
strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,
|
|
|
|
|
loose: /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/
|
|
|
|
|
}
|
|
|
|
|
};
|