FIX: Display Google search form when 404 page is rendered by Ember.

This commit is contained in:
Guo Xiang Tan 2017-06-29 14:37:03 +09:00
parent 9294826f31
commit 7b35c55a1e
2 changed files with 10 additions and 15 deletions

View File

@ -1,20 +1,21 @@
class ExceptionsController < ApplicationController
skip_before_filter :check_xhr, :preload_json
before_action :hide_google
def not_found
@hide_google = true if SiteSetting.login_required
# centralize all rendering of 404 into app controller
raise Discourse::NotFound
end
# Give us an endpoint to use for 404 content in the ember app
def not_found_body
# Don't show google search if it's embedded in the Ember app
@hide_google = true
render html: build_not_found_page(200, false)
end
private
def hide_google
@hide_google = true if SiteSetting.login_required
end
end

View File

@ -30,9 +30,9 @@
<div class="span10 page-not-found-search">
<h2><%= t 'page_not_found.search_title' %></h2>
<p>
<form action='//google.com/search' id='google-search' onsubmit="return google_button_clicked()">
<input type="text" id='user-query' value="<%= @slug %>">
<input type='hidden' id='google-query' name="q">
<form action='//google.com/search' id='google-search'>
<input type="text" name="q" value="<%= @slug %>">
<input type='hidden'name="as_sitesearch" value="<%= local_domain %>">
<button class="btn btn-primary"><%= t 'page_not_found.search_google' %></button>
</form>
</p>
@ -40,12 +40,6 @@
</div>
<script language="Javascript">
function google_button_clicked(e) {
var searchValue = document.getElementById('user-query').value;
document.getElementById('google-query').value = 'site:<%= local_domain %> ' + searchValue;
return true;
}
window.onpopstate = function(event) {
if (event.state && !window.hasOwnProperty("Discourse")) { //check if Discourse object exists if not take care of back navigation
window.location = document.location;