ajaxify_rails 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +32 -25
- data/lib/ajaxify_rails/version.rb +1 -1
- data/vendor/assets/javascripts/ajaxify_rails.js.coffee +198 -213
- metadata +4 -4
data/README.md
CHANGED
@@ -17,6 +17,8 @@ Features:
|
|
17
17
|
|
18
18
|
Demo: http://ajaxify-demo.herokuapp.com/ (the first page load might take a while, as heroku needs to spin up a dyno)
|
19
19
|
|
20
|
+
Demo source: https://github.com/ncri/ajaxify_rails_demo_app
|
21
|
+
|
20
22
|
Blog Post: http://rubyandrails.posterous.com/introducing-the-ajaxify-rails-gem
|
21
23
|
|
22
24
|
Inspired by the pjax_rails gem (https://github.com/rails/pjax_rails).
|
@@ -49,7 +51,6 @@ work most effectively.
|
|
49
51
|
The later you call `init()`, the later potential redirects from one scheme to another are performed,
|
50
52
|
which means the more unnecessary work the browser has to do.
|
51
53
|
|
52
|
-
|
53
54
|
### Content Area
|
54
55
|
|
55
56
|
Ajaxify assumes that your app has a content container html tag with the id `main`.
|
@@ -59,9 +60,14 @@ If yield doesn't have a wrapper in your app yet, you need to supply one to get a
|
|
59
60
|
#main
|
60
61
|
= yield
|
61
62
|
|
62
|
-
You can
|
63
|
+
You can set the content container of your app when initializing Ajaxify:
|
64
|
+
|
65
|
+
Ajaxify.init
|
66
|
+
content_container: 'content_container_id'
|
63
67
|
|
64
|
-
|
68
|
+
or later using `set_content_container`:
|
69
|
+
|
70
|
+
Ajaxify.set_content_container('content_container_id')
|
65
71
|
|
66
72
|
|
67
73
|
### Loader Animation
|
@@ -81,18 +87,20 @@ use it to automatically update the title tag after the main content has changed.
|
|
81
87
|
|
82
88
|
It's a common use case to have a navigation that needs to change its appearence and possibly functioning when the user navigates
|
83
89
|
to a different section of the page. Ajaxify provides a success callback that is triggered after successful
|
84
|
-
updates of the page's main content. Just
|
90
|
+
updates of the page's main content. Just bind to the `ajaxify:content_loaded' event and make your layout changes:
|
85
91
|
|
86
|
-
|
92
|
+
$('body').on 'ajaxify:content_loaded', ->
|
87
93
|
# update navigation and/or other layout elements
|
88
94
|
|
89
95
|
|
90
96
|
### Flash Messages
|
91
97
|
|
92
98
|
Ajaxify correctly displays your flash messages after ajaxified requests.
|
93
|
-
By default, only `flash[:notice]` is supported. If you are using for example `flash[:warning]` as well you have to
|
99
|
+
By default, only `flash[:notice]` is supported. If you are using for example `flash[:warning]` as well you have to add the flash_types
|
100
|
+
option to the `Ajaxify.init()` call:
|
94
101
|
|
95
|
-
Ajaxify.
|
102
|
+
Ajaxify.init
|
103
|
+
flash_types: ['notice', 'warning']
|
96
104
|
|
97
105
|
Also make sure that you supply invisible wrapper tags in your layout for each flash type you use, with the id set to the type, e.g.:
|
98
106
|
|
@@ -124,7 +132,8 @@ paths.
|
|
124
132
|
Example: if your app's root url potentially redirects to `your_domain.com/en/` and `your_domain.com/de/`
|
125
133
|
you need to hint Ajaxyfiy like this:
|
126
134
|
|
127
|
-
Ajaxify.
|
135
|
+
Ajaxify.init
|
136
|
+
base_paths = ['de', 'en']
|
128
137
|
|
129
138
|
Important: `Ajaxify.base_paths` need to be set before `Ajaxify.init()` is called!
|
130
139
|
|
@@ -146,9 +155,9 @@ For example you could provide url for a widget in the layout like this:
|
|
146
155
|
"<div id='my_fancy_widget_html'> some html </div>"
|
147
156
|
end
|
148
157
|
|
149
|
-
And then, on the client side
|
158
|
+
And then, on the client side bind to the `ajaxify:content_inserted` event and select the widget html via `#ajaxify_content`:
|
150
159
|
|
151
|
-
|
160
|
+
$('body').on 'ajaxify:content_inserted', ->
|
152
161
|
$('#my_fancy_widget').html $('#ajaxify_content #my_fancy_widget_html').html()
|
153
162
|
|
154
163
|
Tip: you can call view helpers to render extra content from within your controller using the view_context:
|
@@ -157,27 +166,25 @@ Tip: you can call view helpers to render extra content from within your controll
|
|
157
166
|
view_context.my_fancy_widget
|
158
167
|
end
|
159
168
|
|
160
|
-
###
|
169
|
+
### Ajaxify Events
|
170
|
+
|
171
|
+
Ajaxify provides a few jQuery events you can bind to:
|
172
|
+
|
173
|
+
* `ajaxify:before_load` => Triggered before the ajaxify request is started. Params: `url`.
|
174
|
+
* `ajaxify:content_loaded` => Triggered after an ajaxify request finished successfully. Params: `data, status, jqXHR, url`.
|
175
|
+
* `ajaxify:content_inserted` => Triggered after an ajaxify request finished but before extra content is stripped from the response.
|
176
|
+
* `ajaxify:flash_displayed` => Triggered after a flash message is displayed. Parameters: `flash_type`.
|
161
177
|
|
162
|
-
Here is a reference of all options and callbacks you can set on the client side via Ajaxify.<i>option_or_callback</i> = :
|
163
178
|
|
164
|
-
|
179
|
+
### Javascript
|
165
180
|
|
166
|
-
|
167
|
-
|
168
|
-
base_paths null Base path segments for applications with root url redirects.
|
169
|
-
Needs to be set before Ajaxify.init().
|
181
|
+
Put your javascript into an `ajaxify:content_loaded` event handler, to make sure it is executed after content has
|
182
|
+
loaded via Ajaxify. You can't use dom ready for example as that only gets triggered for full page relaods.
|
170
183
|
|
171
|
-
on_before_load null Callback: Called before the ajaxify request is started.
|
172
|
-
on_success null Callback: Called when an ajaxify requests finished successfully.
|
173
|
-
on_success_once null Callback: Like on_success but only called once.
|
174
|
-
handle_extra_content null Callback: Called before extra content is stripped from the Ajax request's response.
|
175
184
|
|
176
|
-
|
177
|
-
flash_effect null Callback: Called for each flash type after flash is set.
|
178
|
-
clear_flash_effect null Callback: Called for each flash type whenever flash message is not present
|
185
|
+
### Toggle Ajaxify
|
179
186
|
|
180
|
-
|
187
|
+
You can temporarily deactivate Ajaxify by calling `Ajaxify.activate(false)`. You can switch it on again with `Ajaxify.activate()`.
|
181
188
|
|
182
189
|
|
183
190
|
## Contributing
|
@@ -1,291 +1,276 @@
|
|
1
|
-
@Ajaxify =
|
2
1
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
handle_extra_content: null
|
8
|
-
base_paths: null
|
2
|
+
active = true
|
3
|
+
content_container = 'main'
|
4
|
+
base_paths = null
|
5
|
+
flash_types = ['notice']
|
9
6
|
|
10
|
-
|
11
|
-
|
12
|
-
on_before_load: null
|
13
|
-
on_success: null
|
14
|
-
on_success_once: null
|
7
|
+
ignore_hash_change = null
|
8
|
+
load_page_from_hash = null
|
15
9
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
clear_flash_effect: null
|
10
|
+
initial_history_state =
|
11
|
+
url: window.location.href
|
12
|
+
data:
|
13
|
+
ajaxified: true
|
21
14
|
|
22
|
-
# internal use only
|
23
|
-
#
|
24
|
-
ignore_hash_change: null
|
25
|
-
load_page_from_hash: null
|
26
15
|
|
27
|
-
|
28
|
-
|
29
|
-
data:
|
30
|
-
ajaxified: true
|
16
|
+
activate = (new_active = true) ->
|
17
|
+
active = new_active
|
31
18
|
|
19
|
+
get_content_container = ->
|
20
|
+
content_container
|
32
21
|
|
33
|
-
|
22
|
+
set_content_container = (new_content_container) ->
|
23
|
+
content_container = new_content_container
|
34
24
|
|
35
|
-
if this.active
|
36
25
|
|
37
|
-
|
38
|
-
this.load_page_from_hash = false
|
39
|
-
this.on_hash_change()
|
26
|
+
ajaxify = ->
|
40
27
|
|
41
|
-
|
28
|
+
if active
|
42
29
|
|
43
|
-
|
30
|
+
if load_page_from_hash
|
31
|
+
load_page_from_hash = false
|
32
|
+
on_hash_change()
|
44
33
|
|
45
|
-
|
34
|
+
protocol_and_hostname = "#{window.location.protocol}//#{window.location.hostname}"
|
46
35
|
|
47
|
-
|
48
|
-
self.load
|
49
|
-
url: $this.attr('href')
|
50
|
-
type: $this.data('method')
|
51
|
-
confirm: $this.data('confirm')
|
36
|
+
$('body').on 'click', "a[href^='/']:not(.no_ajaxify), a[href^='#{protocol_and_hostname}']:not(.no_ajaxify)", ->
|
52
37
|
|
53
|
-
|
38
|
+
$this = $(this)
|
39
|
+
load
|
40
|
+
url: $this.attr('href')
|
41
|
+
type: $this.data('method')
|
42
|
+
confirm: $this.data('confirm')
|
54
43
|
|
55
|
-
|
56
|
-
$('body').on 'submit', "form[action^='/']#{exclude_selector},
|
57
|
-
form[action^='#{protocol_and_hostname}']#{exclude_selector},
|
58
|
-
form[action='']#{exclude_selector}", ->
|
44
|
+
false
|
59
45
|
|
60
|
-
|
61
|
-
|
62
|
-
|
46
|
+
exclude_selector = ":not(.no_ajaxify):not([enctype='multipart/form-data'])"
|
47
|
+
$('body').on 'submit', "form[action^='/']#{exclude_selector},
|
48
|
+
form[action^='#{protocol_and_hostname}']#{exclude_selector},
|
49
|
+
form[action='']#{exclude_selector}", ->
|
63
50
|
|
64
|
-
|
51
|
+
$this = $(this)
|
52
|
+
form_params = $(this).serialize()
|
53
|
+
form_params += '&ajaxified=true'
|
65
54
|
|
66
|
-
|
67
|
-
url: if action != '' then action else '/'
|
68
|
-
data: form_params
|
69
|
-
type: $this.attr('method')
|
70
|
-
confirm: $this.data('confirm')
|
55
|
+
action = $this.attr('action')
|
71
56
|
|
72
|
-
|
57
|
+
load
|
58
|
+
url: if action != '' then action else '/'
|
59
|
+
data: form_params
|
60
|
+
type: $this.attr('method')
|
61
|
+
confirm: $this.data('confirm')
|
73
62
|
|
63
|
+
false
|
74
64
|
|
75
|
-
# (history interface browsers only)
|
76
|
-
window.onpopstate = (e) ->
|
77
|
-
if e.state
|
78
|
-
e.state.cache = false
|
79
|
-
self.load e.state, true
|
80
65
|
|
66
|
+
# (history interface browsers only)
|
67
|
+
window.onpopstate = (e) ->
|
68
|
+
if e.state
|
69
|
+
e.state.cache = false
|
70
|
+
load e.state, true
|
81
71
|
|
82
|
-
# (non history interface browsers only)
|
83
|
-
window.onhashchange = ->
|
84
|
-
unless self.ignore_hash_change
|
85
|
-
self.on_hash_change()
|
86
|
-
else
|
87
|
-
self.ignore_hash_change = false
|
88
72
|
|
73
|
+
# (non history interface browsers only)
|
74
|
+
window.onhashchange = ->
|
75
|
+
unless ignore_hash_change
|
76
|
+
on_hash_change()
|
77
|
+
else
|
78
|
+
ignore_hash_change = false
|
89
79
|
|
90
|
-
# load content from url hash (non history interface browsers)
|
91
|
-
on_hash_change: ->
|
92
|
-
url = window.location.hash.replace(/#/, "")
|
93
80
|
|
94
|
-
|
95
|
-
|
96
|
-
|
81
|
+
# load content from url hash (non history interface browsers)
|
82
|
+
on_hash_change = ->
|
83
|
+
url = window.location.hash.replace(/#/, "")
|
97
84
|
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
url: url
|
102
|
-
, true
|
85
|
+
base_path_regexp = base_path_regexp()
|
86
|
+
if match = window.location.pathname.match(base_path_regexp)
|
87
|
+
url = match[0] + url
|
103
88
|
|
89
|
+
url = '/' if url == ''
|
90
|
+
hash_changed = true
|
104
91
|
|
105
|
-
load
|
92
|
+
load
|
93
|
+
url: url
|
94
|
+
, true
|
106
95
|
|
107
|
-
unless this.load_page_from_hash
|
108
|
-
self = this
|
109
96
|
|
110
|
-
|
97
|
+
load = (options, pop_state = false) ->
|
111
98
|
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
99
|
+
unless load_page_from_hash
|
100
|
+
|
101
|
+
data = options.data || { ajaxified: true }
|
102
|
+
|
103
|
+
if options.type and options.type == 'delete'
|
104
|
+
type = 'post'
|
105
|
+
if is_string(data)
|
106
|
+
data += '&_method=delete'
|
118
107
|
else
|
119
|
-
|
108
|
+
data._method = 'delete'
|
109
|
+
else
|
110
|
+
type = options.type or 'get'
|
120
111
|
|
121
|
-
|
122
|
-
|
112
|
+
if options.confirm
|
113
|
+
return false unless confirm options.confirm
|
123
114
|
|
124
|
-
|
125
|
-
self.on_before_load options.url
|
115
|
+
$('body').trigger 'ajaxify:before_load', [options.url]
|
126
116
|
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
success: (data, status, jqXHR) ->
|
140
|
-
self.on_ajaxify_success data, status, jqXHR, pop_state, options
|
141
|
-
|
142
|
-
|
143
|
-
show_flashes: (flashes) ->
|
144
|
-
self = this
|
145
|
-
$.each this.flash_types, ->
|
146
|
-
if flashes and flashes[this]
|
147
|
-
$("##{this}").html flashes[this]
|
148
|
-
$("##{this}").show()
|
149
|
-
if self.flash_effect
|
150
|
-
if self.clear_flash_effect
|
151
|
-
self.clear_flash_effect this
|
152
|
-
self.flash_effect this
|
153
|
-
else
|
154
|
-
$("##{this}").hide()
|
117
|
+
$.ajax
|
118
|
+
url: options.url
|
119
|
+
dataType: 'html'
|
120
|
+
data: data
|
121
|
+
type: type
|
122
|
+
cache: true
|
123
|
+
beforeSend: (xhr) ->
|
124
|
+
$("##{content_container}").html( "<div class='ajaxify_loader'></div>" )
|
125
|
+
$('html, body').animate
|
126
|
+
scrollTop:0
|
127
|
+
, 500
|
155
128
|
|
129
|
+
success: (data, status, jqXHR) ->
|
130
|
+
on_ajaxify_success data, status, jqXHR, pop_state, options
|
156
131
|
|
157
|
-
on_ajaxify_success: (data, status, jqXHR, pop_state, options) ->
|
158
132
|
|
159
|
-
|
133
|
+
show_flashes = (flashes) ->
|
134
|
+
$.each flash_types, ->
|
135
|
+
if flashes and flashes[this]
|
136
|
+
$("##{this}").html flashes[this]
|
137
|
+
$("##{this}").show()
|
138
|
+
$('body').trigger 'ajaxify:flash_displayed', [this]
|
160
139
|
|
161
|
-
|
162
|
-
|
140
|
+
else
|
141
|
+
$("##{this}").hide()
|
163
142
|
|
164
|
-
# Correct the url after a redirect and when it has the ajaxify param in it.
|
165
|
-
# The latter can happen e.g. for pagination links that are auto generated.
|
166
|
-
current_url = $('#ajaxify_content #ajaxify_location').html()
|
167
|
-
if options.url != current_url
|
168
|
-
options.url = current_url.replace(/(&|&|\?)ajaxify_redirect=true/,'')
|
169
|
-
options.type = 'GET'
|
170
143
|
|
171
|
-
|
144
|
+
on_ajaxify_success = (data, status, jqXHR, pop_state, options) ->
|
172
145
|
|
173
|
-
|
174
|
-
this.handle_extra_content()
|
146
|
+
$("##{content_container}").html data
|
175
147
|
|
176
|
-
|
148
|
+
title = $('#ajaxify_content').data('page-title')
|
149
|
+
flashes = $('#ajaxify_content').data('flashes')
|
177
150
|
|
178
|
-
|
179
|
-
|
151
|
+
# Correct the url after a redirect and when it has the ajaxify param in it.
|
152
|
+
# The latter can happen e.g. for pagination links that are auto generated.
|
153
|
+
current_url = $('#ajaxify_content #ajaxify_location').html()
|
154
|
+
if options.url != current_url
|
155
|
+
options.url = current_url.replace(/(&|&|\?)ajaxify_redirect=true/,'')
|
156
|
+
options.type = 'GET'
|
180
157
|
|
181
|
-
|
158
|
+
update_url options, pop_state
|
182
159
|
|
183
|
-
|
184
|
-
this.on_success( data, status, jqXHR, options.url )
|
160
|
+
$('body').trigger 'ajaxify:content_inserted'
|
185
161
|
|
186
|
-
|
187
|
-
this.on_success_once( data, status, jqXHR )
|
188
|
-
this.on_success_once = null
|
162
|
+
$("##{content_container} #ajaxify_content").remove()
|
189
163
|
|
164
|
+
if title
|
165
|
+
document.title = title.replace /&/, '&' # Todo: need to figure out what else needs to be unescaped
|
190
166
|
|
191
|
-
|
167
|
+
show_flashes(flashes)
|
192
168
|
|
193
|
-
|
169
|
+
$('body').trigger('ajaxify:content_loaded', [data, status, jqXHR, options.url])
|
194
170
|
|
195
|
-
# unless back/forward arrowing or request method is not 'get'
|
196
|
-
if !pop_state and get_request
|
197
171
|
|
198
|
-
|
172
|
+
update_url = (options, pop_state = false) ->
|
199
173
|
|
200
|
-
|
201
|
-
window.history.replaceState this.initial_history_state, ''
|
202
|
-
this.initial_history_state = ''
|
174
|
+
get_request = (!options.type or options.type.toLowerCase() == 'get')
|
203
175
|
|
204
|
-
|
205
|
-
|
206
|
-
data: options.data
|
207
|
-
type: options.type
|
208
|
-
,'', options.url
|
176
|
+
# unless back/forward arrowing or request method is not 'get'
|
177
|
+
if !pop_state and get_request
|
209
178
|
|
210
|
-
|
211
|
-
this.ignore_hash_change = true # for non histroy interface browsers: avoids loading the page for hash changes caused by link clicks
|
212
|
-
hash = "#{options.url.replace(new RegExp(this.protocol_with_host()), '')}"
|
179
|
+
if window.history.pushState
|
213
180
|
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
hash = "/#{hash}" unless hash == '' or hash.indexOf('/') == 0
|
181
|
+
if initial_history_state != ''
|
182
|
+
window.history.replaceState initial_history_state, ''
|
183
|
+
initial_history_state = ''
|
218
184
|
|
219
|
-
|
185
|
+
window.history.pushState
|
186
|
+
url: options.url
|
187
|
+
data: options.data
|
188
|
+
type: options.type
|
189
|
+
,'', options.url
|
220
190
|
|
191
|
+
else
|
192
|
+
ignore_hash_change = true # for non histroy interface browsers: avoids loading the page for hash changes caused by link clicks
|
193
|
+
hash = "#{options.url.replace(new RegExp(protocol_with_host()), '')}"
|
221
194
|
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
# starting with base path and continuing with '?', e.g. "^\/en\?" (i.e. we are at the base path root and have query params)
|
227
|
-
self = this
|
228
|
-
new RegExp("^\/(#{ $.map(this.base_paths, (el) ->
|
229
|
-
el = self.regexp_escape el
|
230
|
-
"##{el}($|\/|\\?)"
|
231
|
-
).join('|')})", 'i')
|
195
|
+
base_path_regexp = base_path_regexp()
|
196
|
+
if base_path_regexp
|
197
|
+
hash = hash.replace(base_path_regexp, '')
|
198
|
+
hash = "/#{hash}" unless hash == '' or hash.indexOf('/') == 0
|
232
199
|
|
200
|
+
window.location.hash = hash
|
233
201
|
|
234
|
-
correct_url: ->
|
235
|
-
if this.active
|
236
202
|
|
237
|
-
|
203
|
+
base_path_regexp = ->
|
204
|
+
return null unless base_paths
|
205
|
+
# match starting and ending with base path, e.g. "^\/en$" (i.e. we are at the base path root) or
|
206
|
+
# starting with base path and continuing with '/', e.g. "^\/en\/" (i.e. we are NOT at the base path root) or
|
207
|
+
# starting with base path and continuing with '?', e.g. "^\/en\?" (i.e. we are at the base path root and have query params)
|
208
|
+
new RegExp("^\/(#{ $.map(base_paths, (el) ->
|
209
|
+
el = regexp_escape el
|
210
|
+
"##{el}($|\/|\\?)"
|
211
|
+
).join('|')})", 'i')
|
238
212
|
|
239
|
-
return unless window.location.hash.match(/^#(\/|\?)/) # check hash format
|
240
213
|
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
else
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
214
|
+
correct_url = ->
|
215
|
+
if active
|
216
|
+
|
217
|
+
if window.location.hash.indexOf('#') == 0 # if url has a '#' in it treat it as a non history interface hash based scheme url
|
218
|
+
|
219
|
+
return unless window.location.hash.match(/^#(\/|\?)/) # check hash format
|
220
|
+
|
221
|
+
if !window.history.pushState
|
222
|
+
Ajaxify.load_page_from_hash = true # notify Ajaxify that a hash will be loaded and ignore all other calls to load until hash url is loaded
|
223
|
+
else
|
224
|
+
# load proper url in case browser supports history api
|
225
|
+
path = window.location.pathname
|
226
|
+
path = '' if path == '/'
|
227
|
+
path = path + window.location.hash.replace(/#/, "")
|
228
|
+
window.location.href = "#{protocol_with_host()}#{path}"
|
229
|
+
|
230
|
+
else if !window.history.pushState # move path behind '#' for browsers without history api
|
231
|
+
|
232
|
+
if window.location.pathname == '/'
|
233
|
+
if window.location.search != ''
|
234
|
+
window.location.href = "#{protocol_with_host()}/#/#{window.location.search}" # move search behind #
|
235
|
+
return
|
236
|
+
|
237
|
+
base_path_regexp = base_path_regexp()
|
238
|
+
if base_path_regexp and (match = window.location.pathname.match(base_path_regexp))
|
239
|
+
if match[0] == window.location.pathname
|
240
|
+
if window.location.search == ''
|
241
|
+
return # we are on a base path here already, so don't do anything
|
264
242
|
else
|
265
|
-
path =
|
243
|
+
path = match[0].replace(/\?/,'') + '#'
|
266
244
|
else
|
267
|
-
path = "
|
245
|
+
path = "#{match[0].replace(/\/$/,'')}#/#{window.location.pathname.replace(match[0],'')}"
|
246
|
+
else
|
247
|
+
path = "/##{window.location.pathname}"
|
268
248
|
|
269
|
-
|
249
|
+
window.location.href = "#{protocol_with_host()}#{path}#{window.location.search}"
|
270
250
|
|
251
|
+
init = (options = {}) ->
|
252
|
+
base_paths = options.base_paths if 'base_paths' of options
|
253
|
+
flash_types = options.flash_types if 'flash_types' of options
|
254
|
+
active = options.active if 'active' of options
|
255
|
+
content_container = options.content_container if 'content_container' of options
|
256
|
+
correct_url()
|
271
257
|
|
272
|
-
|
273
|
-
|
258
|
+
#
|
259
|
+
# utility functions
|
260
|
+
#
|
274
261
|
|
262
|
+
is_string = (variable) ->
|
263
|
+
Object.prototype.toString.call(variable) == '[object String]'
|
275
264
|
|
276
|
-
|
277
|
-
|
278
|
-
#
|
265
|
+
regexp_escape = (str) ->
|
266
|
+
str.replace new RegExp('[.\\\\+*?\\[\\^\\]$(){}=!<>|:\\-]', 'g'), '\\$&'
|
279
267
|
|
280
|
-
|
281
|
-
|
268
|
+
protocol_with_host = ->
|
269
|
+
loc = window.location
|
270
|
+
"#{loc.protocol}//#{loc.host}"
|
282
271
|
|
283
|
-
regexp_escape: (str) ->
|
284
|
-
str.replace new RegExp('[.\\\\+*?\\[\\^\\]$(){}=!<>|:\\-]', 'g'), '\\$&'
|
285
272
|
|
286
|
-
|
287
|
-
loc = window.location
|
288
|
-
"#{loc.protocol}//#{loc.host}"
|
273
|
+
@Ajaxify = { init, ajaxify, load, activate, set_content_container, get_content_container }
|
289
274
|
|
290
275
|
|
291
276
|
jQuery ->
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ajaxify_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-10-
|
12
|
+
date: 2012-10-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -66,7 +66,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
66
66
|
version: '0'
|
67
67
|
segments:
|
68
68
|
- 0
|
69
|
-
hash:
|
69
|
+
hash: 2019060543339106194
|
70
70
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
71
|
none: false
|
72
72
|
requirements:
|
@@ -75,7 +75,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
75
75
|
version: '0'
|
76
76
|
segments:
|
77
77
|
- 0
|
78
|
-
hash:
|
78
|
+
hash: 2019060543339106194
|
79
79
|
requirements: []
|
80
80
|
rubyforge_project:
|
81
81
|
rubygems_version: 1.8.24
|