Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 177 lines (108 sloc) 7.401 kb
ceec8c60 »
2012-09-27 version 0.0.2
1 # Ajaxify Rails
383ef458 »
2012-09-27 initial commit
2
8587390e »
2012-09-27 Update README.md
3 No more full page reloads for your Rails app! Yay!
4
5 Automatically makes your app loading content in the background via ajax.
6
312dc600 »
2012-09-28 Update README.md
7 Works by turning all internal links into ajax links that trigger an update of the page's content area.
8 Also form submission are automatically turned into ajax requests.
8587390e »
2012-09-27 Update README.md
9
10 Features:
383ef458 »
2012-09-27 initial commit
11
ceec8c60 »
2012-09-27 version 0.0.2
12 - Uses the html5 history interface for changing the url and making the browser's back and forward buttons work with ajax.
13 - Falls back to a hash based approach for browsers without the history interface (like Internet Explorer version <10)
8587390e »
2012-09-27 Update README.md
14 - Hash based and non-hash URLs are interchangeable.
15 - Transparently handles redirects and supports page titles and flash messages.
ceec8c60 »
2012-09-27 version 0.0.2
16 - Requires Ruby 1.9 and the asset pipeline.
17 - Tested with Chrome, Firefox, Safari and Internet Explorer 8+
18
19 Demo: http://ajaxify-demo.herokuapp.com/
383ef458 »
2012-09-27 initial commit
20
21 Inspired by the pjax_rails gem (https://github.com/rails/pjax_rails)
22
23 ## Installation
24
25 Add this line to your application's Gemfile:
26
27 gem 'ajaxify_rails'
28
29 And then execute:
30
31 $ bundle
32
33 In your application.js file add:
34
35 //= require ajaxify_rails
36
37 ## Usage
38
d6ab22f4 »
2012-09-28 releasing version 0.0.3
39 Call `Ajaxify.init()` in your layout's javascript.
40 Do this as early as possible to ensure Ajaxify's interchangeable url schemes (history api vs. hash based urls)
41 work most effectively.
42
43 The later you call `init()`, the later potential redirects from one scheme to another are performed,
44 which means the more unnecessary work the browser has to do.
45
46
ceec8c60 »
2012-09-27 version 0.0.2
47 ### Content Area
48
312dc600 »
2012-09-28 Update README.md
49 Ajaxify assumes that your app has a content container html tag with the id `main`.
8587390e »
2012-09-27 Update README.md
50 This tag is the container wrapping the yield statement in your layout.
51 If yield doesn't have a wrapper in your app yet, you need to supply one to get ajaxification working:
ceec8c60 »
2012-09-27 version 0.0.2
52
53 #main
54 = yield
55
312dc600 »
2012-09-28 Update README.md
56 You can change the content wrapper in your javascript by setting
ceec8c60 »
2012-09-27 version 0.0.2
57
58 Ajaxify.content_container = 'content_container_id'
8587390e »
2012-09-27 Update README.md
59
312dc600 »
2012-09-28 Update README.md
60
8587390e »
2012-09-27 Update README.md
61 ### Loader Animation
62
63 You probably like to have a loader image to be displayed to the user while content loads via ajax.
312dc600 »
2012-09-28 Update README.md
64 This is simple. Ajaxify automatically inserts a loader div with the class `ajaxify_loader` into
65 the content wrapper before starting an ajax request. So just supply styles for `.ajaxify_loader` in your css, with an
8587390e »
2012-09-27 Update README.md
66 animated gif as a background.
67
ceec8c60 »
2012-09-27 version 0.0.2
68
69 ### Page Title
70
312dc600 »
2012-09-28 Update README.md
71 If you define a method called `page_title` in your application controller, Ajaxify will automatically
8587390e »
2012-09-27 Update README.md
72 update the page's title tag after the main content has changed.
ceec8c60 »
2012-09-27 version 0.0.2
73
8587390e »
2012-09-27 Update README.md
74 ### Navigation and other Layout Updates
ceec8c60 »
2012-09-27 version 0.0.2
75
76 It's a common use case to have a navigation that needs to change its appearence and possibly functioning when the user navigates
312dc600 »
2012-09-28 Update README.md
77 to a different section of the page. Ajaxify provides a success callback that is triggered after successful
78 updates of he page's main content. Just hook into it in your javascript and make your layout changes:
ceec8c60 »
2012-09-27 version 0.0.2
79
80 Ajaxify.success ->
81 # update navigation and/or other layout elements
82
83
84 ### Flash Messages
85
8587390e »
2012-09-27 Update README.md
86 Ajaxify Rails correctly displays your flash messages after ajaxified requests. To do so it stores them in cookies.
312dc600 »
2012-09-28 Update README.md
87 By default, only `flash[:notice]` is supported. If you are using for example `flash[:warning]` as well you have to set:
ceec8c60 »
2012-09-27 version 0.0.2
88
89 Ajaxify.flash_types = ['notice', 'warning']
8587390e »
2012-09-27 Update README.md
90
91 Also make sure that you supply invisible wrapper tags in your layout with the flash type as its id, e.g.:
92
93 #notice{ style: "#{'display:none' unless flash[:notice]}" }
94 = flash[:notice]
95
96 ### Links that need to trigger full Page Reloads
97
98 We all know them. Those big requests changing the layout of the page so significantly that
312dc600 »
2012-09-28 Update README.md
99 loading ajax into a content area and doing some minor layout tweaks here and there simply doesn't cut it. Sigh.
100
101 There might also be links and forms that have already their own ajax functionality.
102
103 To turn Ajaxify off for certain links and forms, simply add the class `no_ajaxify` directly to the link or form:
8587390e »
2012-09-27 Update README.md
104
105 = link_to 'Change everything!', re_render_it_all_path, class: 'no_ajaxify'
ceec8c60 »
2012-09-27 version 0.0.2
106
107
108 ### Root Redirects
109
8587390e »
2012-09-27 Update README.md
110 Sometimes you need to redirect on the root url.
111
112 For example you might have a localized application with the locale inside the url.
312dc600 »
2012-09-28 Update README.md
113 When a user navigates to `your_domain.com` he/she gets redirected to e.g. `your_domain.com/en/`. This works fine in browsers supporting
114 the html 5 history api. However, for browsers without the history api like Internet Explorer before version 10, Ajaxify needs hints
d6ab22f4 »
2012-09-28 releasing version 0.0.3
115 about your url structure to not get confused (it creates endless redirects otherwise!). You need to explicitly supply all possible root
116 paths.
8587390e »
2012-09-27 Update README.md
117
312dc600 »
2012-09-28 Update README.md
118 Example: if your app's root url potentially redirects to `your_domain.com/en/` and `your_domain.com/de/`
ceec8c60 »
2012-09-27 version 0.0.2
119 you need to hint Ajaxyfiy like this:
120
d6ab22f4 »
2012-09-28 releasing version 0.0.3
121 Ajaxify.base_paths = ['de', 'en']
122
123 Important: `Ajaxify.base_paths` need to be set before `Ajaxify.init()` is called!
ceec8c60 »
2012-09-27 version 0.0.2
124
125
126 ### Extra Content
127
128 Sometimes you need to do non trivial modifications of the layout whenever the content in the main content area of your site changes.
312dc600 »
2012-09-28 Update README.md
129 Ajaxify allows you to attach arbitrary html to ajaxified requests. This extra html is then stripped from the main content
ceec8c60 »
2012-09-27 version 0.0.2
130 that is inserted in the content area. But before that a callback is triggered which can be used to grab the extra content and do something with it.
312dc600 »
2012-09-28 Update README.md
131 To use this feature you need to provide a method `ajaxify_extra_content` in your ApplicationController:
ceec8c60 »
2012-09-27 version 0.0.2
132
133 def ajaxify_extra_content
134 ... your extra html ...
135 end
136
137 For example you could provide url for a widget in the layout like this:
138
139 def ajaxify_extra_content
8587390e »
2012-09-27 Update README.md
140 "<div id='my_fancy_widget_html'> some html </div>"
ceec8c60 »
2012-09-27 version 0.0.2
141 end
142
312dc600 »
2012-09-28 Update README.md
143 And then, on the client side hook into Ajaxify using the `handle_extra_content` callback and select the widget html via `#ajaxify_content`:
ceec8c60 »
2012-09-27 version 0.0.2
144
145 Ajaxify.handle_extra_content = ->
8587390e »
2012-09-27 Update README.md
146 $('#my_fancy_widget').html $('#ajaxify_content #my_fancy_widget_html').html()
ceec8c60 »
2012-09-27 version 0.0.2
147
148
312dc600 »
2012-09-28 Update README.md
149 ### Reference: All Javascript Options and Callbacks
ceec8c60 »
2012-09-27 version 0.0.2
150
312dc600 »
2012-09-28 Update README.md
151 Here is a reference of all options and callbacks you can set on the client side via `Ajaxify.<i>option_or_callback</i> =` :
ceec8c60 »
2012-09-27 version 0.0.2
152
312dc600 »
2012-09-28 Update README.md
153 Option/Callback Default Description
ceec8c60 »
2012-09-27 version 0.0.2
154
312dc600 »
2012-09-28 Update README.md
155 active true Toggles link ajaxification.
156 content_container 'main' Id of the container to insert the main content into ("yield wrapper").
d6ab22f4 »
2012-09-28 releasing version 0.0.3
157 base_paths null Base path segments for applications with root url redirects.
ceec8c60 »
2012-09-27 version 0.0.2
158
312dc600 »
2012-09-28 Update README.md
159 on_before_load null Callback: Called before the ajaxify request is started.
160 on_success null Callback: Called when an ajaxify requests finished successfully.
161 on_success_once null Callback: Like on_success but only called once.
162 handle_extra_content null Callback: Called before extra content is stripped from the ajax request's response.
ceec8c60 »
2012-09-27 version 0.0.2
163
312dc600 »
2012-09-28 Update README.md
164 flash_types ['notice'] Flash types your Rails app uses. E.g. ['notice', 'warning', 'error']
165 flash_effect null Callback: Called for each flash type after flash is set.
166 clear_flash_effect null Callback: Called for each flash type whenever flash message is not present
ceec8c60 »
2012-09-27 version 0.0.2
167
168 Also check the example app source code for usage: https://github.com/ncri/ajaxify_rails_demo_app
383ef458 »
2012-09-27 initial commit
169
170
171 ## Contributing
172
173 1. Fork it
174 2. Create your feature branch (`git checkout -b my-new-feature`)
175 3. Commit your changes (`git commit -am 'Added some feature'`)
176 4. Push to the branch (`git push origin my-new-feature`)
55b358c1 »
2012-09-27 fixed readme merge conflict
177 5. Create new Pull Request
Something went wrong with that request. Please try again.