ajaxify_rails 0.5.3 → 0.5.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +12 -1
- data/lib/ajaxify_rails/version.rb +1 -1
- data/vendor/assets/javascripts/ajaxify_rails.js.coffee +20 -5
- metadata +4 -4
data/README.md
CHANGED
@@ -77,7 +77,18 @@ You probably like to have a loader image to be displayed to the user while conte
|
|
77
77
|
This is simple. Ajaxify automatically inserts a loader div with the class `ajaxify_loader` into
|
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'
|
81
92
|
|
82
93
|
### Page Title
|
83
94
|
|
@@ -9,6 +9,8 @@ push_state_enabled = true
|
|
9
9
|
ignore_hash_change = null
|
10
10
|
load_page_from_hash = null
|
11
11
|
|
12
|
+
scroll_to_top = true
|
13
|
+
|
12
14
|
initial_history_state =
|
13
15
|
url: window.location.href
|
14
16
|
data:
|
@@ -30,7 +32,6 @@ get_content_container = ->
|
|
30
32
|
set_content_container = (new_content_container) ->
|
31
33
|
content_container = new_content_container
|
32
34
|
|
33
|
-
|
34
35
|
init = (options = {}) ->
|
35
36
|
base_paths = options.base_paths if 'base_paths' of options
|
36
37
|
flash_types = options.flash_types if 'flash_types' of options
|
@@ -38,6 +39,7 @@ init = (options = {}) ->
|
|
38
39
|
active = options.active if 'active' of options
|
39
40
|
content_container = options.content_container if 'content_container' of options
|
40
41
|
correct_url() unless $('meta[name="ajaxify:dont_correct_url"]').length > 0
|
42
|
+
scroll_to_top = options.scroll_to_top if 'scroll_to_top' of options
|
41
43
|
|
42
44
|
|
43
45
|
ajaxify = ->
|
@@ -50,12 +52,13 @@ ajaxify = ->
|
|
50
52
|
protocol_and_hostname = "#{window.location.protocol}//#{window.location.hostname}"
|
51
53
|
|
52
54
|
$('body').on 'click', "a[href^='/']:not(.no_ajaxify), a[href^='#{protocol_and_hostname}']:not(.no_ajaxify)", ->
|
53
|
-
|
54
55
|
$this = $(this)
|
56
|
+
|
55
57
|
load
|
56
58
|
url: $this.attr('href')
|
57
59
|
type: $this.data('method')
|
58
60
|
confirm: $this.data('confirm')
|
61
|
+
scroll_to_top: set_scroll_to_top($this)
|
59
62
|
|
60
63
|
false
|
61
64
|
|
@@ -65,6 +68,7 @@ ajaxify = ->
|
|
65
68
|
form[action='']#{exclude_selector}", ->
|
66
69
|
|
67
70
|
$this = $(this)
|
71
|
+
|
68
72
|
form_params = $(this).serialize()
|
69
73
|
form_params += '&ajaxified=true'
|
70
74
|
|
@@ -75,6 +79,7 @@ ajaxify = ->
|
|
75
79
|
data: form_params
|
76
80
|
type: $this.attr('method')
|
77
81
|
confirm: $this.data('confirm')
|
82
|
+
scroll_to_top: set_scroll_to_top($this)
|
78
83
|
|
79
84
|
false
|
80
85
|
|
@@ -121,9 +126,8 @@ load = (options, pop_state = false) ->
|
|
121
126
|
cache: true
|
122
127
|
beforeSend: (xhr) ->
|
123
128
|
$("##{content_container}").html( "<div class='ajaxify_loader'></div>" )
|
124
|
-
|
125
|
-
|
126
|
-
, 500
|
129
|
+
options.scroll_to_top = scroll_to_top unless 'scroll_to_top' of options
|
130
|
+
scroll_page_to_top() if options.scroll_to_top
|
127
131
|
|
128
132
|
success: (data, status, jqXHR) ->
|
129
133
|
on_ajaxify_success data, status, jqXHR, pop_state, options
|
@@ -281,6 +285,17 @@ push_state = ->
|
|
281
285
|
push_state_enabled and window.history.pushState
|
282
286
|
|
283
287
|
|
288
|
+
set_scroll_to_top = ($link_or_form) ->
|
289
|
+
scroll = $link_or_form.hasClass('scroll_to_top')
|
290
|
+
no_scroll = $link_or_form.hasClass('no_scroll_to_top')
|
291
|
+
if scroll or no_scroll then return (scroll and !no_scroll) else return scroll_to_top
|
292
|
+
|
293
|
+
|
294
|
+
scroll_page_to_top = ->
|
295
|
+
$('html, body').animate
|
296
|
+
scrollTop:0
|
297
|
+
, 500
|
298
|
+
|
284
299
|
# --------------------------------------------------------------------------------------------------------------------
|
285
300
|
# public interface
|
286
301
|
# --------------------------------------------------------------------------------------------------------------------
|
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.5.
|
4
|
+
version: 0.5.5
|
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-
|
12
|
+
date: 2013-03-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -260,7 +260,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
260
260
|
version: '0'
|
261
261
|
segments:
|
262
262
|
- 0
|
263
|
-
hash:
|
263
|
+
hash: -1886047311222868249
|
264
264
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
265
265
|
none: false
|
266
266
|
requirements:
|
@@ -269,7 +269,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
269
269
|
version: '0'
|
270
270
|
segments:
|
271
271
|
- 0
|
272
|
-
hash:
|
272
|
+
hash: -1886047311222868249
|
273
273
|
requirements: []
|
274
274
|
rubyforge_project:
|
275
275
|
rubygems_version: 1.8.25
|