From 12270afcb2d000cc67d292f2eab38774e5cd58ad Mon Sep 17 00:00:00 2001 From: Jordan Lee Date: Mon, 30 May 2011 15:12:42 +0000 Subject: [PATCH] (trunk libT) #4004 "allow drag-and-drop links into the web client" -- implemented via a patch from Mook --- web/javascript/transmission.js | 54 ++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/web/javascript/transmission.js b/web/javascript/transmission.js index 4143b2ac6..bec2188d4 100644 --- a/web/javascript/transmission.js +++ b/web/javascript/transmission.js @@ -64,6 +64,12 @@ Transmission.prototype = $('#prefs_tab_peers_tab').click(function(e){ changeTab(this, 'prefs_tab_peers') }); $('#prefs_tab_network_tab').click(function(e){ changeTab(this, 'prefs_tab_network');}); $('#torrent_upload_form').submit(function(){ $('#upload_confirm_button').click(); return false; }); + $('#torrent_container').bind('dragover', function(e){ return tr.dragenter(e); }); + $('#torrent_container').bind('dragenter', function(e){ return tr.dragenter(e); }); + $('#torrent_container').bind('drop', function(e){ return tr.drop(e); }); + // tell jQuery to copy the dataTransfer property from events over if it exists + jQuery.event.props.push("dataTransfer"); + $('#torrent_upload_form').submit(function(){ $('#upload_confirm_button').click(); return false; }); if (iPhone) { @@ -626,6 +632,54 @@ Transmission.prototype = tr.updateButtonStates(); }, + dragenter: function( event ) { + if( event.dataTransfer && event.dataTransfer.types ) { + var types = ["text/uri-list", "text/plain"]; + for( var i = 0; i < types.length; ++i ) { + if( event.dataTransfer.types.contains(types[i]) ) { + // it would be better to actually look at the links here; + // sadly, (at least with Firefox,) trying would throw. + event.stopPropagation(); + event.preventDefault(); + event.dropEffect = "copy"; + return false; + } + } + } + else if (event.dataTransfer) { + event.dataTransfer.dropEffect = "none"; + } + return true; + }, + + drop: function( event ) { + if( !event.dataTransfer || !event.dataTransfer.types ) { + return true; + } + event.preventDefault(); + var uris = null; + var types = ["text/uri-list", "text/plain"]; + for( var i = 0; i < types.length; ++i ) { + if( event.dataTransfer.types.contains(types[i]) ) { + uris = event.dataTransfer.getData( types[i] ).split("\n"); + break; + } + } + var paused = $('#prefs_form #auto_start')[0].checked; + for( i = 0; i < uris.length; ++i ) { + var uri = uris[i]; + if( /^#/.test(uri) ) { + // lines which start with "#" are comments + continue; + } + if( /^[a-z-]+:/i.test(uri) ) { + // close enough to a url + this.remote.addTorrentByUrl( uri, paused ); + } + } + return false; + }, + hideUploadDialog: function( ) { $('body.open_showing').removeClass('open_showing'); if (!iPhone && Safari3) {