Permalink
Browse files

Use Turbolinks

  • Loading branch information...
1 parent 7367246 commit 96e2c8a125ebf51ea5e9d59592c8ed2022df555a @rwdaigle committed Oct 12, 2012
View
@@ -28,9 +28,10 @@ gem 'kanshi', :require => false
gem 'jquery-rails'
gem 'haml-rails'
+gem 'turbolinks'
group :assets do
gem 'sass-rails', '~> 3.2.3'
- # gem 'coffee-rails', '~> 3.2.1'
+ gem 'coffee-rails', '~> 3.2.1'
gem 'uglifier', '>= 1.0.3'
end
View
@@ -34,6 +34,13 @@ GEM
girl_friday
arel (3.0.2)
builder (3.0.3)
+ coffee-rails (3.2.2)
+ coffee-script (>= 2.2.0)
+ railties (~> 3.2.0)
+ coffee-script (2.2.0)
+ coffee-script-source
+ execjs
+ coffee-script-source (1.3.3)
connection_pool (0.9.2)
daemons (1.1.9)
dalli (2.2.1)
@@ -166,6 +173,7 @@ GEM
treetop (1.4.10)
polyglot
polyglot (>= 0.3.1)
+ turbolinks (0.5.1)
tzinfo (0.3.33)
uglifier (1.3.0)
execjs (>= 0.3.0)
@@ -178,6 +186,7 @@ PLATFORMS
DEPENDENCIES
airbrake
+ coffee-rails (~> 3.2.1)
dalli
haml-rails
jquery-rails
@@ -198,6 +207,7 @@ DEPENDENCIES
scrolls
thin
tire
+ turbolinks
uglifier (>= 1.0.3)
will_paginate
yajl-ruby
@@ -12,4 +12,5 @@
//
//= require jquery
//= require jquery_ujs
+//= require turbolinks
//= require_tree .
@@ -1,9 +1,32 @@
+// Initial page load b/f Turbolinks kicks in
$(function() {
+ wireSearch();
+ setInitialElementStates();
+});
- var selectedClass = 'selected';
- var searchField = $("#search-form #q");
+// Subsequent loads
+$(window).bind('page:load', function() {
+ setInitialElementStates();
+});
+
+var setInitialElementStates = function() {
+ searchField().select();
+
+ // Pass form submits through Turbolinks
+ $("#search-form").submit(function() {
+ form = $(this);
+ Turbolinks.visit(form.attr('action') + '?' + form.serialize());
+ return false;
+ });
+};
- searchField.select();
+var searchField = function() {
+ return $("#search-form #q");
+};
+
+var wireSearch = function() {
+
+ var selectedClass = 'selected';
Mousetrap.bind(['down'], function(e) {
navigateList('down', $("ul.search-results li:first"));
@@ -24,7 +47,7 @@ $(function() {
Mousetrap.bind(['/', 's'], function(e) {
executeOutsideInputFields(e, function() {
- searchField.focus().select();
+ searchField().focus().select();
$("ul.search-results li.selected").removeClass(selectedClass);
haltEvent(e);
});
@@ -42,13 +65,13 @@ $(function() {
if(previouslySelectedEl.size() <= 0) {
defaultEl.addClass(selectedClass);
- searchField.blur();
+ searchField().blur();
} else {
previouslySelectedEl.removeClass(selectedClass);
newlySelectedEl = direction == 'up' ? previouslySelectedEl.prev() : previouslySelectedEl.next();
newlySelectedEl.addClass(selectedClass);
if(newlySelectedEl.size() <= 0) {
- searchField.focus();
+ searchField().focus();
}
}
}
@@ -61,9 +84,8 @@ $(function() {
};
var executeOutsideInputFields = function(event, fire) {
- console.log($(event.srcElement));
if(!$(event.srcElement).is('input')) {
fire();
}
}
-});
+};
@@ -1,4 +1,4 @@
%h4 Hi there
%p Gisted lets you quickly search and access your gists. You will need to log into GitHub via OAuth first.
-%p= link_to "Login & search my gists", search_gists_path
+%p= link_to "Login & search my gists", search_gists_path, 'data-no-turbolink' => true

0 comments on commit 96e2c8a

Please sign in to comment.