diff --git a/app/assets/javascripts/uploads.js b/app/assets/javascripts/uploads.js index 2133f6bec..ae256ac0b 100644 --- a/app/assets/javascripts/uploads.js +++ b/app/assets/javascripts/uploads.js @@ -57,26 +57,41 @@ Danbooru.Upload.initialize_info = function() { $("#source-info ul").hide(); - $("#fetch-data").click(function(e) { - $.get(e.target.href).success(function(data) { - var tag_html = ""; - $.each(data.tags, function(i, v) { - tag_html += ('' + v[0] + ' '); - }); - - $("#source-artist").html('' + data.artist_name + ''); - $("#source-tags").html(tag_html); - - var new_artist_link = 'new'; - - $("#source-record").html(new_artist_link); - - $("#source-info p").hide(); - $("#source-info ul").show(); - }); + $("#fetch-data-bookmarklet").click(function(e) { + $.get(e.target.href).success(Danbooru.Upload.fill_source_info); e.preventDefault(); }); - $("#fetch-data").trigger("click"); + $("#fetch-data-bookmarklet").trigger("click"); + + $("#fetch-data-manual").click(function(e) { + var source = $("#upload_source").val(); + if (!/\S/.test(source)) { + Danbooru.error("Error: You must enter a URL into the source field to get its data"); + } else if (!/^https?:\/\//.test(source)) { + Danbooru.error("Error: Source is not a URL"); + } else { + $("#source-info span#loading-data").show(); + $.get("/source.json?url=" + encodeURIComponent(source)).success(Danbooru.Upload.fill_source_info); + } + e.preventDefault(); + }); + } + + Danbooru.Upload.fill_source_info = function(data) { + var tag_html = ""; + $.each(data.tags, function(i, v) { + tag_html += ('' + v[0] + ' '); + }); + + $("#source-artist").html('' + data.artist_name + ''); + $("#source-tags").html(tag_html); + + var new_artist_link = 'new'; + + $("#source-record").html(new_artist_link); + + $("#source-info span#loading-data").hide(); + $("#source-info ul").show(); } Danbooru.Upload.initialize_image = function() { diff --git a/app/views/sources/_info.html.erb b/app/views/sources/_info.html.erb index 1a1cbbd17..a407f1bf6 100644 --- a/app/views/sources/_info.html.erb +++ b/app/views/sources/_info.html.erb @@ -2,14 +2,18 @@ - source --> -<% if source.try(:available?) %> -
-

Loading <%= source.site_name %> data... <%= link_to "Fetch", source_path(:format => "json", :url => source.referer_url(self)), :id => "fetch-data", :style => "display: none;" %>.

+
+ <% if source.try(:available?) %> +

<%= link_to "Fetch source data", source_path(:format => "json", :url => source.referer_url(self)), :id => "fetch-data-bookmarklet", :style => "display: none;" %>

+

<%= content_tag "span", "Loading #{source.site_name} data...", :id => "loading-data" %>

+ <% else %> +

<%= link_to "Fetch source data", source_path(:format => "json"), :id => "fetch-data-manual" %>

+

<%= content_tag "span", "Loading source data...", :id => "loading-data", :style => "display: none;" %>

+ <% end %> - -
-<% end %> + +