add xhr variant detection

This commit is contained in:
r888888888
2018-06-23 12:01:44 -07:00
parent 62235e215e
commit 5aae4b649f
4 changed files with 14 additions and 7 deletions

View File

@@ -154,7 +154,7 @@
Danbooru.Post.initialize_similar = function() { Danbooru.Post.initialize_similar = function() {
$("#similar-button").click(function(e) { $("#similar-button").click(function(e) {
$.get("/iqdb_queries", {"variant": "xhr", "url": $("#post_source").val()}).done(function(html) {$("#iqdb-similar").html(html).show()}); $.get("/iqdb_queries", {"url": $("#post_source").val()}).done(function(html) {$("#iqdb-similar").html(html).show()});
e.preventDefault(); e.preventDefault();
}); });
} }

View File

@@ -61,7 +61,7 @@
Danbooru.Upload.initialize_iqdb_source = function() { Danbooru.Upload.initialize_iqdb_source = function() {
if (/^https?:\/\//.test($("#normalized_url").val())) { if (/^https?:\/\//.test($("#normalized_url").val())) {
$.get("/iqdb_queries", {"variant": "xhr", "url": $("#normalized_url").val()}).done(function(html) {$("#iqdb-similar").html(html)}); $.get("/iqdb_queries", {"url": $("#normalized_url").val()}).done(function(html) {$("#iqdb-similar").html(html)});
} }
} }
@@ -77,7 +77,7 @@
Danbooru.Upload.initialize_similar = function() { Danbooru.Upload.initialize_similar = function() {
$("#similar-button").click(function(e) { $("#similar-button").click(function(e) {
$.get("/iqdb_queries", {"variant": "xhr", "url": $("#upload_source").val()}).done(function(html) {$("#iqdb-similar").html(html).show()}); $.get("/iqdb_queries", {"url": $("#upload_source").val()}).done(function(html) {$("#iqdb-similar").html(html).show()});
e.preventDefault(); e.preventDefault();
}); });
} }

View File

@@ -1,5 +1,6 @@
class IqdbQueriesController < ApplicationController class IqdbQueriesController < ApplicationController
respond_to :html, :json respond_to :html, :json
before_action :detect_xhr
def show def show
if params[:url] if params[:url]
@@ -15,10 +16,8 @@ class IqdbQueriesController < ApplicationController
end end
respond_with(@matches) do |fmt| respond_with(@matches) do |fmt|
fmt.html fmt.html do |html|
html.xhr { render layout: false}
fmt.html.xhr do
render layout: false
end end
fmt.json do fmt.json do
@@ -26,4 +25,12 @@ class IqdbQueriesController < ApplicationController
end end
end end
end end
private
def detect_xhr
if request.xhr?
request.variant = :xhr
end
end
end end