Skip to content

Commit

Permalink
switch to pjax for live search (uses html5 pushstate to make the back…
Browse files Browse the repository at this point in the history
…button work)
  • Loading branch information
digitaltom committed Mar 29, 2012
1 parent 4b62f60 commit f8a5d6f
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 24 deletions.
1 change: 0 additions & 1 deletion TODO
Expand Up @@ -7,7 +7,6 @@ Package Search:
- Check to replace the searchbar on http://software.opensuse.org/ with the new one, or if we don't need a package search on
the dvd download page
- Bug: Fix the statistics page
- Fix the back button after ajax search: http://diveintohtml5.info/history.html


Package Details:
Expand Down
2 changes: 1 addition & 1 deletion app/views/layouts/application.rhtml
Expand Up @@ -10,7 +10,7 @@

<%= stylesheet_link_tag "/themes/bento/css/style.css", "software" %>
<link href="http://static.opensuse.org/themes/bento/images/favicon.png" rel="shortcut icon" />
<%= javascript_include_tag "http://static.opensuse.org/themes/bento/js/jquery.js", "jquery-ui-1.8.18.custom.min", "jrails.js", "jquery.cookie", "application.js" %>
<%= javascript_include_tag "http://static.opensuse.org/themes/bento/js/jquery.js", "jquery-ui-1.8.18.custom.min", "jrails", "jquery.cookie", "application", "jquery.pjax" %>
<%= javascript_include_tag "/themes/bento/js/l10n/global-navigation-data-#{@lang}.js", "/themes/bento/js/global-navigation.js" %>
<%= yield :content_for_head %>
Expand Down
3 changes: 0 additions & 3 deletions app/views/package/show.html.erb
Expand Up @@ -92,9 +92,6 @@
<div id="search_result_container">
<div class="box box-shadow">
<h2 class="box-header">
<% unless @search_term.blank? %>
<%= link_to _("< Back to search results"), {:controller => :search, :action => :searchresult, :q => @search_term}, :class => "pkg-backlink" %>
<% end %>
<span class="alignleft"><%= @page_title -%></span>
</h2>
<div>
Expand Down
35 changes: 19 additions & 16 deletions app/views/search/_find_form.rhtml
Expand Up @@ -17,31 +17,34 @@
$('#search-messages').hide();
$('#msg').html("");
last_search = search_term;
$.ajax({ url: "<%= url_for :controller => :search, :action => :searchresult %>",
parameters = {
q: search_term,
baseproject: $("#baseproject").val(),
search_devel: $("#search_devel_checkbox").is(':checked'),
search_unsupported: $("#search_unsupported_checkbox").is(':checked')
};

$.pjax({
cache: true,
sync: false,
data: {
q: search_term,
baseproject: $("#baseproject").val(),
search_devel: $("#search_devel_checkbox").is(':checked'),
search_unsupported: $("#search_unsupported_checkbox").is(':checked')
},
url: '<%= url_for :controller => :search, :action => :searchresult %>',
data: parameters,
container: '#search_result_container',
timeout: 10000,
beforeSend: function() {
$('#search-loader-txt').html('Updating search results for: ' + search_term);
$('#search-form').addClass('search-form-busy');
},
complete: function(){
$('#search-form').removeClass('search-form-busy');
},
success: function(html){
$("#search_result_container").html(html);
$('#search-messages').hide();
},
error: function(jqXHR, textStatus, errorThrown) {
$('#msg').html("An internal error happened :-(");
$('#search-messages').show();
}
});
})

} else if (search_term.length > 0 ) {
$('#msg').html("Please enter more than 2 characters");
$('#search-result-error').hide();
Expand Down Expand Up @@ -69,14 +72,14 @@

</script>

<div class="box box-shadow pkg-header-box pkg-appstore-box">
<h1><%= link_to "openSUSE Factory<br/>App Browser", {:controller => :package, :action => :categories}, :id => "apps-headline" %></h1>
</div>
<div class="box box-shadow pkg-header-box pkg-appstore-box">
<h1><%= link_to "openSUSE Factory<br/>App Browser", {:controller => :package, :action => :categories}, :id => "apps-headline" %></h1>
</div>


<div class="box box-shadow pkg-search-box pkg-header-box">
<% form_tag( {:controller => 'search', :action => :searchresult}, :method => :get ) do %>
<h1><%= link_to "Package Search", {:controller => :search, :action => :find}, :id => "apps-headline" %></h1>
<h1><%= link_to "Package Search", {:controller => :search, :action => :find}, :id => "apps-headline" %></h1>
<%= text_field_tag 'q', @search_term, :size => 30, :id => "search-form", :autocomplete => "off" %>
<div id='search-loader' class="hidden"><span id="search-loader-txt"></span> <%= image_tag "ajax-loader.gif" %></div>
<%= submit_tag _('Search'), :name => nil, :class => "search-go-button" %>
Expand All @@ -91,7 +94,7 @@
<%= check_box_tag("search_unsupported", "true", @search_unsupported, {:id => "search_unsupported_checkbox" }) %>
<label for="search_unsupported_checkbox"><%= _("Show unsupported packages") %></label><br/>
<% @distributions ||= Array.new %>
&nbsp;Show distribution:&nbsp;
&nbsp;Show distribution:&nbsp;
<%= select_tag 'baseproject', options_for_select((@distributions.map{|d| [d[:name], d[:project]]} || ["ALL"]), (@baseproject or default_baseproject)) %>
</p>
</div>
Expand Down
4 changes: 2 additions & 2 deletions app/views/search/_find_results.rhtml
Expand Up @@ -46,10 +46,10 @@
<%= "style=\"background: url('/images/#{banner_path}') no-repeat scroll 0 0;\"" if banner_app %> >

<div class="app-screenshot-search">
<%= link_to( image_tag( screenshot_thumb_url( package ), :height => 75 ), :controller => :package, :action => :show, :package => package, :search_term => @search_term ) %>
<%= link_to( image_tag( screenshot_thumb_url( package ), :height => 75 ), :controller => :package, :action => :show, :package => package ) %>
</div>
<div class="search-result-txt">
<h3><%= link_to highlight(package_name, @search_term), :controller => :package, :action => :show, :package => package, :search_term => @search_term %>
<h3><%= link_to highlight(package_name, @search_term), :controller => :package, :action => :show, :package => package %>

<div class="search-result-rating hidden">
<%= image_tag "star_color.png" %>
Expand Down
2 changes: 1 addition & 1 deletion config/deploy.rb
Expand Up @@ -83,7 +83,7 @@
task :notify do
#diff = `#{source.local.diff(current_revision)}`
begin
diff_log = `#{source.local.log( source.next_revision(current_revision) )}`
diff_log = `#{source.local.log( source.next_revision(current_revision), branch )}`
rescue
diff_log = "No REVISION found, probably initial deployment."
end
Expand Down
9 changes: 9 additions & 0 deletions public/javascripts/jquery.pjax.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f8a5d6f

Please sign in to comment.