ajaxify_rails 0.5.5 → 0.7.0beta

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -78,17 +78,6 @@ This is simple. Ajaxify automatically inserts a loader div with the class `ajaxi
78
78
  the content wrapper before starting an Ajax request. So just supply styles for `.ajaxify_loader` in your css, with an
79
79
  animated gif as a background.
80
80
 
81
- ### Scrolling
82
-
83
- By default, ajaxify scrolls to the top of the screen when you click on a link or submit a form.
84
- You can change this default behavior by setting 'scroll_to_top' to false on init.
85
-
86
- Ajaxify.init
87
- scroll_to_top: false
88
-
89
- You can also change the setting for individual links by adding classes:
90
- = link_to "Scroll to top", scroll_to_top_path, class: 'scroll_to_top'
91
- = link_to "Don't scroll", no_scroll_path, class: 'no_scroll_to_top'
92
81
 
93
82
  ### Page Title
94
83
 
@@ -200,6 +189,20 @@ loaded via Ajaxify.
200
189
  You can temporarily deactivate Ajaxify by calling `Ajaxify.activate(false)`. You can switch it on again with `Ajaxify.activate()`.
201
190
 
202
191
 
192
+ ### Scrolling
193
+
194
+ By default, ajaxify scrolls to the top of the screen when you click on a link or submit a form.
195
+ You can change this default behavior by setting 'scroll_to_top' to false on init.
196
+
197
+ Ajaxify.init
198
+ scroll_to_top: false
199
+
200
+ You can also change the setting for individual links by adding classes:
201
+
202
+ = link_to "Scroll to top", scroll_to_top_path, class: 'scroll_to_top'
203
+ = link_to "Don't scroll", no_scroll_path, class: 'no_scroll_to_top'
204
+
205
+
203
206
  ## Contributing
204
207
 
205
208
  1. Fork it
@@ -49,14 +49,18 @@ module ActionControllerAdditions
49
49
  data: { page_title: page_title,
50
50
  flashes: flashes.to_json } )
51
51
  response.body = response_body[0]
52
+ response.headers['Ajaxify-Assets-Digest'] = ajaxify_assets_digest
53
+
52
54
  return
53
55
  end
54
56
  super
57
+
58
+ ajaxify_add_meta_tag( ajaxify_assets_digest_meta_tag ) if !request.xhr?
59
+
55
60
  # Correcting urls for non history api browsers wont work for post requests so add a meta tag to the response body to communicate this to
56
61
  # the ajaxify javascript
57
- if request.post? and not request.xhr?
58
- response.body = response_body[0].sub('<head>', "<head>\n <meta name='ajaxify:dont_correct_url' content='true'>")
59
- end
62
+ ajaxify_add_meta_tag( view_context.tag(:meta, name: 'ajaxify:dont_correct_url', content: 'true') ) if request.post? and not request.xhr?
63
+
60
64
  return
61
65
  end
62
66
 
@@ -91,6 +95,23 @@ module ActionControllerAdditions
91
95
  sub(/(&|\?)ajaxified=true/, '').
92
96
  sub(/(&|\?)ajaxify_redirect=true/, '')
93
97
  end
98
+
99
+ # Meta tag for asset change detection - inspired by wiselinks
100
+ #
101
+ def ajaxify_assets_digest_meta_tag
102
+
103
+ view_context.tag(:meta, name: 'ajaxify:assets-digest', content: ajaxify_assets_digest)
104
+ end
105
+
106
+ def ajaxify_assets_digest
107
+ digests = Rails.application.config.assets.digests
108
+ digests ? Digest::MD5.hexdigest(digests.values.join) : ''
109
+ end
110
+
111
+ def ajaxify_add_meta_tag meta_tag
112
+ response.body = response_body[0].sub('<head>', "<head>\n #{meta_tag}")
113
+ end
114
+
94
115
  end
95
116
 
96
117
  end
@@ -1,3 +1,3 @@
1
1
  module AjaxifyRails
2
- VERSION = "0.5.5"
2
+ VERSION = "0.7.0beta"
3
3
  end
@@ -178,10 +178,14 @@ on_ajaxify_success = (data, status, jqXHR, pop_state, options) ->
178
178
 
179
179
  # Correct the url after a redirect and when it has the ajaxify param in it.
180
180
  # The latter can happen e.g. for pagination links that are auto generated.
181
+ original_request_type = options.type
181
182
  current_url = $('#ajaxify_content #ajaxify_location').html()
182
183
  if options.url != current_url
183
184
  options.url = current_url.replace(/(&|&amp;|\?)ajaxify_redirect=true/,'')
184
185
  options.type = 'GET'
186
+
187
+ unless original_request_type and original_request_type.toLowerCase() == 'post'
188
+ reload_page_if_assets_stale options.url, jqXHR
185
189
 
186
190
  update_url options, pop_state
187
191
 
@@ -296,6 +300,12 @@ scroll_page_to_top = ->
296
300
  scrollTop:0
297
301
  , 500
298
302
 
303
+
304
+ reload_page_if_assets_stale = (url, jqXHR) ->
305
+ digest_header = jqXHR.getResponseHeader('Ajaxify-Assets-Digest')
306
+ if digest_header and digest_header != $("meta[name='ajaxify:assets-digest']").attr('content')
307
+ document.location.href = url
308
+
299
309
  # --------------------------------------------------------------------------------------------------------------------
300
310
  # public interface
301
311
  # --------------------------------------------------------------------------------------------------------------------
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ajaxify_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.5
5
- prerelease:
4
+ version: 0.7.0beta
5
+ prerelease: 5
6
6
  platform: ruby
7
7
  authors:
8
8
  - Nico Ritsche
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-10 00:00:00.000000000 Z
12
+ date: 2013-03-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -260,16 +260,13 @@ required_ruby_version: !ruby/object:Gem::Requirement
260
260
  version: '0'
261
261
  segments:
262
262
  - 0
263
- hash: -1886047311222868249
263
+ hash: -96360880157980810
264
264
  required_rubygems_version: !ruby/object:Gem::Requirement
265
265
  none: false
266
266
  requirements:
267
- - - ! '>='
267
+ - - ! '>'
268
268
  - !ruby/object:Gem::Version
269
- version: '0'
270
- segments:
271
- - 0
272
- hash: -1886047311222868249
269
+ version: 1.3.1
273
270
  requirements: []
274
271
  rubyforge_project:
275
272
  rubygems_version: 1.8.25