Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Use turbolinks and turboforms

  • Loading branch information...
commit c4cebfcf87f48d78666ff5de05efce3c0e063ec0 1 parent 6b61a63
@timurvafin timurvafin authored
View
5 Gemfile
@@ -13,6 +13,11 @@ group :assets do
gem 'less-rails-bootstrap'
gem 'styleguides'
+
+ gem 'turbolinks', git: 'git://github.com/fs/turbolinks.git'
+ # gem 'turbolinks', path: '../turbolinks'
+ gem 'turboforms', git: 'git://github.com/fs/turboforms.git'
+ # gem 'turboforms', path: '../turboforms'
end
gem 'jquery-rails'
View
17 Gemfile.lock
@@ -1,3 +1,18 @@
+GIT
+ remote: git://github.com/fs/turboforms.git
+ revision: 48d8cabbca5237646b131c3434dec58dbc4ee11e
+ specs:
+ turboforms (0.0.1)
+ coffee-rails
+ turbolinks
+
+GIT
+ remote: git://github.com/fs/turbolinks.git
+ revision: 551f3d6d1f9c550cbf1aba209b399624afdbbe6f
+ specs:
+ turbolinks (0.5.1)
+ coffee-rails
+
GEM
remote: http://rubygems.org/
specs:
@@ -324,6 +339,8 @@ DEPENDENCIES
styleguides
therubyracer
thin
+ turboforms!
+ turbolinks!
turnip
uglifier (>= 1.2.3)
webmock
View
1  app/assets/javascripts/application.js
@@ -8,5 +8,6 @@
//= require jquery_ujs
//= require twitter/bootstrap/alert
//= require twitter/bootstrap/dropdown
+//= require turbolinks
//= require jquery.turboforms
//= require_tree .
View
2  app/assets/javascripts/turboforms.js.coffee
@@ -1,2 +0,0 @@
-$("form").turboForms
- debug: true
View
3  app/views/devise/registrations/edit.html.slim
@@ -3,7 +3,8 @@
= simple_form_for resource,
as: resource_name,
url: registration_path(resource_name),
- html: { method: :put } do |f|
+ html: { method: :put },
+ turboform: true do |f|
legend
| New profile information
View
3  app/views/devise/registrations/new.html.slim
@@ -2,7 +2,8 @@
= simple_form_for resource,
as: resource_name,
- url: registration_path(resource_name) do |f|
+ url: registration_path(resource_name),
+ turboform: true do |f|
legend
| Create your "#{app_config.app_name}" account
View
3  app/views/devise/sessions/new.html.slim
@@ -2,7 +2,8 @@
= simple_form_for resource,
as: resource_name,
- url: session_path(resource_name) do |f|
+ url: session_path(resource_name),
+ turboform: true do |f|
legend
| Enter your "#{app_config.app_name}" account
View
2  config/initializers/devise.rb
@@ -55,7 +55,7 @@
# config.http_authenticatable = false
# If http headers should be returned for AJAX requests. True by default.
- # config.http_authenticatable_on_xhr = true
+ config.http_authenticatable_on_xhr = false
# The realm used in Http Basic Authentication. "Application" by default.
# config.http_authentication_realm = "Application"
View
12 config/navigations/user_navigation.rb
@@ -5,9 +5,15 @@
user.dom_class = 'pull-right nav '
if user_signed_in?
- user.item :account, current_user.full_name_with_email, '#',
- class: 'dropdown',
- link: { class: 'dropdown-toggle', 'data-toggle' => 'dropdown' } do |account|
+ user.item :account,
+ current_user.full_name_with_email,
+ '#',
+ class: 'dropdown',
+ 'data-no-turbolink' => true,
+ link: {
+ class: 'dropdown-toggle',
+ 'data-toggle' => 'dropdown'
+ } do |account|
account.dom_class = 'dropdown-menu'
View
60 lib/assets/javascripts/jquery.turboforms.js.coffee
@@ -1,60 +0,0 @@
-$ = jQuery
-
-$.fn.extend
- turboForms: (options) ->
- settings =
- debug: false
-
- settings = $.extend settings, options
-
- log = (msg) ->
- console?.log msg if settings.debug
-
- browserCompatibleDocumentParser = ->
- createDocumentUsingParser = (html) ->
- (new DOMParser).parseFromString html, 'text/html'
-
- createDocumentUsingWrite = (html) ->
- doc = document.implementation.createHTMLDocument ''
- doc.open 'replace'
- doc.write html
- doc.close
- doc
-
- if window.DOMParser
- testDoc = createDocumentUsingParser '<html><body><p>test'
-
- if testDoc?.body?.childNodes.length is 1
- createDocumentUsingParser
- else
- createDocumentUsingWrite
-
- createDocument = (content) ->
- browserCompatibleDocumentParser content
-
- extractUrlTitleAndBody = (doc) ->
- title = doc.querySelector 'title'
- [ title?.textContent, doc.body ]
-
- changePage = (title, body) ->
- log(title)
- log(body)
-
- document.title = title
- document.documentElement.replaceChild body, document.body
-
- setContent = (title, body) ->
- changePage title, body
-
- return @each (i, el)->
- el = $(el)
-
- el.data('remote', true)
- el.data('type', 'html')
-
- el.bind 'ajax:complete', (event, xhr, status) ->
- log("Got response with #{status} status")
- log(xhr.responseText)
-
- doc = createDocument xhr.responseText
- setContent extractUrlTitleAndBody(doc)...
Please sign in to comment.
Something went wrong with that request. Please try again.