ajaxify_rails 0.7.5 → 0.7.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -63,7 +63,8 @@ module ActionControllerAdditions
63
63
  response_body[0] += view_context.content_tag(:div, current_url_tag + extra_content,
64
64
  id: 'ajaxify_content', style: 'display:none',
65
65
  data: { page_title: page_title,
66
- flashes: flashes.to_json } )
66
+ flashes: flashes.to_json,
67
+ container: args[:ajaxify_container] } )
67
68
  response.body = response_body[0]
68
69
  ajaxify_set_asset_digest_header
69
70
 
@@ -1,3 +1,3 @@
1
1
  module AjaxifyRails
2
- VERSION = "0.7.5"
2
+ VERSION = "0.7.6"
3
3
  end
@@ -1,4 +1,3 @@
1
-
2
1
  active = true
3
2
  content_container = 'main'
4
3
  base_paths = null
@@ -32,6 +31,7 @@ get_content_container = ->
32
31
  set_content_container = (new_content_container) ->
33
32
  content_container = new_content_container
34
33
 
34
+
35
35
  init = (options = {}) ->
36
36
  base_paths = options.base_paths if 'base_paths' of options
37
37
  flash_types = options.flash_types if 'flash_types' of options
@@ -40,6 +40,7 @@ init = (options = {}) ->
40
40
  content_container = options.content_container if 'content_container' of options
41
41
  correct_url() unless $('meta[name="ajaxify:dont_correct_url"]').length > 0
42
42
  scroll_to_top = options.scroll_to_top if 'scroll_to_top' of options
43
+ rails_ujs_fix()
43
44
 
44
45
 
45
46
  ajaxify = ->
@@ -170,7 +171,6 @@ update_url = (options, pop_state = false) ->
170
171
 
171
172
 
172
173
  on_ajaxify_success = (data, status, jqXHR, pop_state, options) ->
173
-
174
174
  $("##{content_container}").html data
175
175
 
176
176
  title = $('#ajaxify_content').data('page-title')
@@ -306,6 +306,37 @@ reload_page_if_assets_stale = (url, jqXHR) ->
306
306
  if digest_header and digest_header != $("meta[name='ajaxify:assets-digest']").attr('content')
307
307
  document.location.href = url
308
308
 
309
+
310
+
311
+ # Override rails jquery_ujs on handling links with :data-method
312
+ # Example:
313
+ # <%= link_to 'test', test_path, :method => :delete %>
314
+ rails_ujs_fix = ->
315
+ return false unless 'rails' of jQuery
316
+
317
+ jQuery.rails.handleMethod = (link) ->
318
+ href = $.rails.href(link)
319
+ method = link.data('method')
320
+ target = link.attr('target')
321
+ csrf_token = $('meta[name=csrf-token]').attr('content')
322
+ csrf_param = $('meta[name=csrf-param]').attr('content')
323
+ form = $("<form method='post' action='#{href}'></form>")
324
+ metadata_input = "<input name='_method' value='#{method}' type='hidden' />"
325
+
326
+ # Let's not use ajaxify in form submission if link
327
+ # has `no_ajaxify` class.
328
+ form.addClass('no_ajaxify') if link.hasClass('no_ajaxify')
329
+
330
+ if csrf_param != undefined && csrf_token != undefined
331
+ metadata_input += '<input name="' +
332
+ csrf_param + '" value="' +
333
+ csrf_token + '" type="hidden" />'
334
+
335
+ form.attr('target', target) if target
336
+
337
+ form.hide().append(metadata_input).appendTo('body')
338
+ form.submit()
339
+
309
340
  # --------------------------------------------------------------------------------------------------------------------
310
341
  # public interface
311
342
  # --------------------------------------------------------------------------------------------------------------------
@@ -318,4 +349,4 @@ reload_page_if_assets_stale = (url, jqXHR) ->
318
349
  # --------------------------------------------------------------------------------------------------------------------
319
350
 
320
351
  jQuery ->
321
- Ajaxify.ajaxify()
352
+ Ajaxify.ajaxify()
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.7.5
4
+ version: 0.7.6
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: 2013-03-14 00:00:00.000000000 Z
12
+ date: 2013-04-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails