* Common javascript
*/
-var transmission;
-var dialog;
-// Test for a Webkit build that supports box-shadow: 521+ (release Safari 3 is
-// actually 523.10.3). We need 3.1 for CSS animation (dialog sheets) but as it
-// degrades gracefully let's not worry too much.
-var Safari3 = testSafari3();
-var iPhone = RegExp("(iPhone|iPod|Android)").test(navigator.userAgent);
-if (iPhone) var scroll_timeout;
+var transmission,
+ dialog,
+ isMobileDevice = RegExp("(isMobileDevice|iPod|Android)").test(navigator.userAgent),
+ scroll_timeout;
if (!Array.indexOf){
Array.prototype.indexOf = function(obj){
}
}
-function testSafari3()
-{
- var minimum = new Array(521,0);
- var webKitFields = RegExp("(AppleWebKit/)([^ ]+)").exec(navigator.userAgent);
- if (!webKitFields || webKitFields.length < 3) return false;
- var version = webKitFields[2].split(".");
- for (var i = 0; i < minimum.length; i++) {
- var toInt = parseInt(version[i]);
- var versionField = isNaN(toInt) ? 0 : toInt;
- var minimumField = minimum[i];
-
- if (versionField > minimumField) return true;
- if (versionField < minimumField) return false;
- }
- return true;
-};
-
$(document).ready(function() {
// Initialise the dialog controller
dialog = new Dialog();
// Move search field's margin down for the styled input
$('#torrent_search').css('margin-top', 3);
}
- if (!Safari3 && !iPhone) {
- // Fix for non-Safari-3 browsers: dark borders to replace shadows.
- // Opera messes up the menu if we use a border on .trans_menu
- // div.outerbox so use ul instead
- $('.trans_menu ul, div#jqContextMenu, div.dialog_container div.dialog_window').css('border', '1px solid #777');
- // and this kills the border we used to have
- $('.trans_menu div.outerbox').css('border', 'none');
- } else if (!iPhone) {
- // Used for Safari 3.1 CSS animation. Degrades gracefully (so Safari 3
- // test is good enough) but we delay our hide/unhide to wait for the
- // scrolling - no point making other browsers wait.
- $('div#upload_container div.dialog_window').css('top', '-205px');
- $('div#prefs_container div.dialog_window').css('top', '-425px');
- $('div#dialog_container div.dialog_window').css('top', '-425px');
- $('div.dialog_container div.dialog_window').css('-webkit-transition', 'top 0.3s');
- // -webkit-appearance makes some links into buttons, but needs
- // different padding.
- $('div.dialog_container div.dialog_window a').css('padding', '2px 10px 3px');
- }
- if (iPhone){
+ if (isMobileDevice){
window.onload = function(){ setTimeout(function() { window.scrollTo(0,1); },500); };
window.onorientationchange = function(){ setTimeout(function() { window.scrollTo(0,1); },100); };
if (window.navigator.standalone)
- // Fix min height for iPhone when run in full screen mode from home screen
+ // Fix min height for isMobileDevice when run in full screen mode from home screen
// so the footer appears in the right place
$('body div#torrent_container').css('min-height', '338px');
$("label[for=torrent_upload_url]").text("URL: ");
+ } else {
+ // Fix for non-Safari-3 browsers: dark borders to replace shadows.
+ // Opera messes up the menu if we use a border on .trans_menu
+ // div.outerbox so use ul instead
+ $('.trans_menu ul, div#jqContextMenu, div.dialog_container div.dialog_window').css('border', '1px solid #777');
+ // and this kills the border we used to have
+ $('.trans_menu div.outerbox').css('border', 'none');
}
});
hideDialog: function()
{
$('body.dialog_showing').removeClass('dialog_showing');
- if (Safari3) {
- $('div#dialog_container div.dialog_window').css('top', '-150px');
- setTimeout("dialog._container.hide();",500);
- } else {
- this._container.hide();
- transmission.hideiPhoneAddressbar();
- }
+ this._container.hide();
+ transmission.hideMobileAddressbar();
transmission.updateButtonStates();
},
confirm: function(dialog_heading, dialog_message, confirm_button_label,
callback_function, callback_data, cancel_button_label)
{
- if (!iPhone && Safari3) {
- $('div#upload_container div.dialog_window').css('top', '-205px');
- $('div#prefs_container div.dialog_window').css('top', '-425px');
- setTimeout("$('#upload_container').hide();",500);
- setTimeout("$('#prefs_container').hide();",500);
- } else if (!iPhone) {
+ if (!isMobileDevice)
$('.dialog_container').hide();
- }
setInnerHTML(this._heading[0], dialog_heading);
setInnerHTML(this._message[0], dialog_message);
setInnerHTML(this._cancel_button[0], (cancel_button_label == null) ? 'Cancel' : cancel_button_label);
$('body').addClass('dialog_showing');
this._container.show();
transmission.updateButtonStates();
- if (iPhone) {
- transmission.hideiPhoneAddressbar();
- } else if (Safari3) {
- setTimeout("$('div#dialog_container div.dialog_window').css('top', '0px');",10);
- }
+ if (isMobileDevice)
+ transmission.hideMobileAddressbar();
},
/*
* Display an alert dialog
*/
alert: function(dialog_heading, dialog_message, cancel_button_label) {
- if (!iPhone && Safari3) {
- $('div#upload_container div.dialog_window').css('top', '-205px');
- $('div#prefs_container div.dialog_window').css('top', '-425px');
- setTimeout("$('#upload_container').hide();",500);
- setTimeout("$('#prefs_container').hide();",500);
- } else if (!iPhone) {
+ if (!isMobileDevice)
$('.dialog_container').hide();
- }
setInnerHTML(this._heading[0], dialog_heading);
setInnerHTML(this._message[0], dialog_message);
// jquery::hide() doesn't work here in Safari for some odd reason
this._confirm_button.css('display', 'none');
setInnerHTML(this._cancel_button[0], cancel_button_label);
// Just in case
- if (!iPhone && Safari3) {
- $('div#upload_container div.dialog_window').css('top', '-205px');
- setTimeout("$('#upload_container').hide();",500);
- } else {
- $('#upload_container').hide();
- }
+ $('#upload_container').hide();
$('body').addClass('dialog_showing');
transmission.updateButtonStates();
- if (iPhone) {
- transmission.hideiPhoneAddressbar();
- this._container.show();
- } else if (Safari3) {
- // long pause as we just hid all the dialogs on a timeout - we'll get the error
- // scrolling in and immediately disappearing if we're not careful!
- //dialogTimeout = null;
- this._container.show();
- setTimeout("$('div#dialog_container div.dialog_window').css('top', '0px');",500);
- } else {
- this._container.show();
- }
+ if (isMobileDevice)
+ transmission.hideMobileAddressbar();
+ this._container.show();
}
$('#torrent_upload_form').submit(function() { $('#upload_confirm_button').click(); return false; });
- if (iPhone) {
+ if (isMobileDevice) {
$('#inspector_close').bind('click', function() { tr.setInspectorVisible(false); });
$('#preferences_link').bind('click', function(e) { tr.releaseClutchPreferencesButton(e); });
} else {
},
preloadImages: function() {
- if (iPhone) {
+ if (isMobileDevice) {
this.loadImages(
'images/buttons/info_general.png',
'images/buttons/info_activity.png',
// iPhone conditions in the section allow us to not
// include transmenu js to save some bandwidth; if we
- // start using prefs on iPhone we need to weed
+ // start using prefs on mobile devices we need to weed
// transmenu refs out of that too.
- if (!iPhone)
+ if (!isMobileDevice)
{
$('#sort_by_' + this[Prefs._SortMethod]).selectMenuItem();
scrollToRow: function(row)
{
- if (iPhone) // FIXME: why?
+ if (isMobileDevice) // FIXME: why?
return;
var list = $('#torrent_container'),
stopAllClicked: function(ev) {
if (this.isButtonEnabled(ev)) {
this.stopAllTorrents();
- this.hideiPhoneAddressbar();
+ this.hideMobileAddressbar();
}
},
stopSelectedClicked: function(ev) {
if (this.isButtonEnabled(ev)) {
this.stopSelectedTorrents();
- this.hideiPhoneAddressbar();
+ this.hideMobileAddressbar();
}
},
startAllClicked: function(ev) {
if (this.isButtonEnabled(ev)) {
this.startAllTorrents();
- this.hideiPhoneAddressbar();
+ this.hideMobileAddressbar();
}
},
startSelectedClicked: function(ev) {
if (this.isButtonEnabled(ev)) {
this.startSelectedTorrents(false);
- this.hideiPhoneAddressbar();
+ this.hideMobileAddressbar();
}
},
hideUploadDialog: function() {
$('body.open_showing').removeClass('open_showing');
- if (!iPhone && Safari3) {
- $('div#upload_container div.dialog_window').css('top', '-205px');
- setTimeout("$('#upload_container').hide();",500);
- } else {
- $('#upload_container').hide();
- }
+ $('#upload_container').hide();
this.updateButtonStates();
},
removeClicked: function(ev) {
if (this.isButtonEnabled(ev)) {
this.removeSelectedTorrents();
- this.hideiPhoneAddressbar();
+ this.hideMobileAddressbar();
}
},
/*
- * 'Clutch Preferences' was clicked (iPhone only)
+ * 'Clutch Preferences' was clicked (isMobileDevice only)
*/
releaseClutchPreferencesButton: function() {
$('div#prefs_container div#pref_error').hide();
this.checkPort(true);
$('body').addClass('prefs_showing');
$('#prefs_container').show();
- this.hideiPhoneAddressbar();
- if (Safari3)
- setTimeout("$('div#prefs_container div.dialog_window').css('top', '0px');",10);
+ this.hideMobileAddressbar();
this.updateButtonStates();
this.togglePeriodicSessionRefresh(false);
},
hidePrefsDialog: function()
{
$('body.prefs_showing').removeClass('prefs_showing');
- if (iPhone) {
- this.hideiPhoneAddressbar();
- $('#prefs_container').hide();
- } else if (Safari3) {
- $('div#prefs_container div.dialog_window').css('top', '-425px');
- setTimeout("$('#prefs_container').hide();",500);
- } else {
- $('#prefs_container').hide();
- }
+ if (isMobileDevice)
+ this.hideMobileAddressbar();
+ $('#prefs_container').hide();
this.updateButtonStates();
this.togglePeriodicSessionRefresh(true);
},
$('#port_rand').prop('checked', p[RPC._PeerPortRandom]);
$('#port_forward').prop('checked', p[RPC._PortForwardingEnabled]);
- if (!iPhone)
+ if (!isMobileDevice)
{
setInnerHTML($('#limited_download_rate')[0], [ 'Limit (', Transmission.fmt.speed(dn_limit_k), ')' ].join(''));
var key = dn_limited ? '#limited_download_rate'
this.loadDaemonStats();
$('body').addClass('stats_showing');
$('#stats_container').show();
- this.hideiPhoneAddressbar();
- if (Safari3)
- setTimeout("$('div#stats_container div.dialog_window').css('top', '0px');",10);
+ this.hideMobileAddressbar();
this.updateButtonStates();
this.togglePeriodicStatsRefresh(true);
},
hideStatsDialog: function() {
$('body.stats_showing').removeClass('stats_showing');
- if (iPhone) {
- this.hideiPhoneAddressbar();
- $('#stats_container').hide();
- } else if (Safari3) {
- $('div#stats_container div.dialog_window').css('top', '-425px');
- setTimeout("$('#stats_container').hide();",500);
- } else {
- $('#stats_container').hide();
- }
+ if (isMobileDevice)
+ this.hideMobileAddressbar();
+ $('#stats_container').hide();
this.updateButtonStates();
this.togglePeriodicStatsRefresh(false);
},
meta_key = true;
// Shift-Click - selects a range from the last-clicked row to this one
- if (iPhone) {
+ if (isMobileDevice) {
if (row.isSelected())
this.setInspectorVisible(true);
this.setSelectedRow(row);
$('input#torrent_auto_start').attr('checked', $('#prefs_form #auto_start')[0].checked);
$('#upload_container').show();
$('#torrent_upload_url').focus();
- if (!iPhone && Safari3) {
- setTimeout("$('div#upload_container div.dialog_window').css('top', '0px');",10);
- }
// Submit the upload form
} else {
this.remote.changeFileCommand(command, rows);
},
- hideiPhoneAddressbar: function(timeInSeconds) {
- if (iPhone) {
+ hideMobileAddressbar: function(timeInSeconds) {
+ if (isMobileDevice) {
var delayLength = timeInSeconds ? timeInSeconds*1000 : 150;
- // not currently supported on iPhone
+ // not currently supported on isMobileDevice
if (/*document.body.scrollTop!=1 && */scroll_timeout==null) {
var tr = this;
scroll_timeout = setTimeout(function() {tr.doToolbarHide();}, delayLength);
inspectorTabClicked: function(ev, tab)
{
- if (iPhone) ev.stopPropagation();
+ if (isMobileDevice) ev.stopPropagation();
// select this tab and deselect the others
$(tab).addClass('selected').siblings().removeClass('selected');
// show this tab and hide the others
$('#'+tab.id+'_container').show().siblings('.inspector_container').hide();
- this.hideiPhoneAddressbar();
+ this.hideMobileAddressbar();
this.updatePeersLists();
this.updateTrackersLists();
this.updateFileList();
return;
var torrents = this.getSelectedTorrents();
- if (!torrents.length && iPhone) {
+ if (!torrents.length && isMobileDevice) {
this.setInspectorVisible(false);
return;
}
// update the ui widgetry
$('#torrent_inspector').toggle(visible);
- if (iPhone) {
+ if (isMobileDevice) {
$('body').toggleClass('inspector_showing',visible);
$('#inspector_close').toggle(visible);
- this.hideiPhoneAddressbar();
+ this.hideMobileAddressbar();
} else {
var w = visible ? $('#torrent_inspector').width() + 1 + 'px' : '0px';
$('#torrent_container')[0].style.right = w;
var popup = $('#filter-popup');
popup.dialog({
autoOpen: false,
- position: iPhone ? [0,0] : [40,80],
+ position: isMobileDevice ? [0,0] : [40,80],
show: 'blind',
hide: 'blind',
title: 'Show',
// update the ui: context menu
// (disabled in iphone mode...)
- if (!iPhone) {
+ if (!isMobileDevice) {
var e = $('#settings_menu #compact_view');
if (compact)
e.selectMenuItem();