ajax_pagination 0.5.1 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. data/.gitignore +1 -1
  2. data/.travis.yml +0 -1
  3. data/CHANGELOG.md +15 -0
  4. data/README.md +5 -5
  5. data/lib/ajax_pagination/controller_additions.rb +48 -31
  6. data/lib/ajax_pagination/helper_additions.rb +48 -24
  7. data/lib/ajax_pagination/rails.rb +0 -7
  8. data/lib/ajax_pagination/version.rb +1 -1
  9. data/lib/assets/javascripts/ajax_pagination.js.erb +11 -14
  10. data/spec/ajax_pagination/controller_additions_spec.rb +15 -3
  11. data/spec/ajax_pagination/helper_additions_spec.rb +1 -1
  12. data/spec/ajax_pagination/integration/ajaxpaginate_spec.rb +10 -9
  13. data/spec/ajax_pagination/integration/nojavascript_spec.rb +7 -7
  14. data/spec/ajax_pagination/integration/paginate_spec.rb +8 -8
  15. data/spec/ajax_pagination/integration/rails30_spec.rb +1 -1
  16. data/spec/rails30_app/app/controllers/application_controller.rb +2 -2
  17. data/spec/rails30_app/app/controllers/changelog_controller.rb +1 -1
  18. data/spec/rails30_app/app/controllers/pages_controller.rb +2 -9
  19. data/spec/rails30_app/app/views/changelog/_page.html.erb +6 -2
  20. data/spec/rails30_app/app/views/changelog/index.html.erb +1 -1
  21. data/spec/rails30_app/app/views/layouts/application.html.erb +5 -5
  22. data/spec/rails30_app/app/views/sessions/count.html.erb +1 -1
  23. data/spec/rails30_app/public/javascripts/ajax_pagination.js +12 -15
  24. data/spec/rails_app/app/controllers/application_controller.rb +2 -2
  25. data/spec/rails_app/app/controllers/changelog_controller.rb +1 -1
  26. data/spec/rails_app/app/controllers/pages_controller.rb +3 -3
  27. data/spec/rails_app/app/controllers/posts_controller.rb +3 -3
  28. data/spec/rails_app/app/views/changelog/_page.html.erb +6 -2
  29. data/spec/rails_app/app/views/changelog/index.html.erb +1 -1
  30. data/spec/rails_app/app/views/layouts/application.html.erb +5 -5
  31. data/spec/rails_app/app/views/pages/warnings.html.erb +8 -7
  32. data/spec/rails_app/app/views/posts/_page.html.erb +9 -5
  33. data/spec/rails_app/app/views/posts/_upcomingpage.html.erb +6 -2
  34. data/spec/rails_app/app/views/posts/index.html.erb +2 -2
  35. data/spec/rails_app/app/views/posts/show.html.erb +1 -1
  36. data/spec/rails_app/app/views/sessions/count.html.erb +1 -1
  37. metadata +86 -132
  38. data/spec/rails30_app/Gemfile.lock +0 -96
  39. data/spec/rails30_app/app/views/pages/warnings.html.erb +0 -43
  40. data/spec/rails_app/Gemfile.lock +0 -107
data/.gitignore CHANGED
@@ -1,6 +1,6 @@
1
1
  *.gem
2
2
  .bundle
3
- /Gemfile.lock
3
+ Gemfile.lock
4
4
  pkg/*
5
5
  *~
6
6
  *.swp
data/.travis.yml CHANGED
@@ -1,7 +1,6 @@
1
1
  language: ruby
2
2
  rvm:
3
3
  - 1.8.7
4
- - 1.9.2
5
4
  - 1.9.3
6
5
  - rbx-18mode
7
6
  - rbx-19mode
data/CHANGELOG.md CHANGED
@@ -1,3 +1,18 @@
1
+ ## v0.6.0
2
+ The :pagination option no longer makes as much sense, now that the sections are called ajax_section. Also, this gem is as much about site navigation as pagination. This is the reason for some of the following changes.
3
+
4
+ * Further name changes made - :pagination option now called :section_id option in AJAX Pagination methods (with exception of ajax_section method), :pagination still works, but is now deprecated.
5
+
6
+ **It is suggested to grep :pagination and rename to :section_id**
7
+
8
+ * ajax_section :pagination option now called :id option, :pagination still works, but deprecated
9
+ * New :section_id, ajax_section :id options now defaults to "global" in all methods - this is backwards incompatible
10
+ * Added ajax_links helper method, to replace the magic container (a div container with class of ajaxpagination).
11
+ * div containers of class pagination are no longer magic containers
12
+ * Added ajax_section method in ActionController - which is set to the only section that should be displayed in an AJAX request. It is nil for normal requests.
13
+
14
+ **Avoid using data-pagination, or inspecting params[:pagination] directly. These will be changed in the next version. Instead, use the helper methods provided.**
15
+
1
16
  ## v0.5.1
2
17
  * Added generator for assets (so asset pipeline is no longer required).
3
18
  * Added tests for a Rails 3.0.x application.
data/README.md CHANGED
@@ -3,9 +3,9 @@
3
3
 
4
4
  [Wiki](https://github.com/ronalchn/ajax_pagination/wiki) | [RDoc](http://rdoc.info/gems/ajax_pagination/frames) | [Changelog](https://github.com/ronalchn/ajax_pagination/blob/master/CHANGELOG.md)
5
5
 
6
- Handles AJAX pagination for you, by hooking up the links you want to load content with javascript in designated page containers. Each webpage can have multiple page containers, each with a different set of pagination links. The page containers can be nested. Degrades gracefully when javascript is disabled.
6
+ Handles AJAX pagination for you, by hooking up the links you want to load content with javascript in designated page containers. Use this to ajaxify your site navigation. Degrades gracefully when javascript is disabled.
7
7
 
8
- Basically, there is a helper function to use to create a section in your webpage, where content can be changed. Links can reference the section, and thus load new content into it.
8
+ Each webpage can have multiple ajax_section containers, whether they are side by side, or even nested. Links can reference an ajax_section to load new content into the section using AJAX. Watch as the URL in the browser address bar updates, with fully working back/forward buttons.
9
9
 
10
10
  For more, see [Introduction and Background](https://github.com/ronalchn/ajax_pagination/wiki/Introduction-and-Background).
11
11
 
@@ -40,8 +40,8 @@ To use this on Rails 3.0, or without using the asset pipeline, read [Installatio
40
40
  In the ActionView, use ajax_section to declare a section, and ajax_link_to to create a link loading content into the section:
41
41
 
42
42
  ```erb
43
- <%= ajax_link_to "Link", link_url, :pagination => "section_name" %>
44
- <%= ajax_section :pagination => "section_name", :render => "mypartial" %>
43
+ <%= ajax_link_to "Link", link_url, :section_id => "section_name" %>
44
+ <%= ajax_section :id => "section_name", :render => "mypartial" %>
45
45
  ```
46
46
 
47
47
  Then, in the ActionController, use ajax_respond to render only the partial when an AJAX request is made:
@@ -52,7 +52,7 @@ Class ObjectsController < ApplicationController
52
52
  ...
53
53
  respond_to do |format|
54
54
  format.html # index.html.erb
55
- ajax_respond format, :pagination => "section_name", :render => "_mypartial"
55
+ ajax_respond format, :section_id => "section_name", :render => "_mypartial"
56
56
  end
57
57
  end
58
58
  ...
@@ -2,33 +2,34 @@ module AjaxPagination
2
2
  # This module is automatically added to all controllers
3
3
  module ControllerAdditions
4
4
  module ClassMethods
5
- # Adds default render behaviour for requests with a pagination parameter matching a certain name. By default, this name is the empty string. However, it can be changed.
5
+ # Adds default render behaviour for AJAX requests for a section with matching a certain name. By default, this name is the empty string. However, it can be changed.
6
6
  # Options:
7
+ # [:+section_id+]
8
+ # The AJAX section name which should be matched to invoke AJAX Pagination response. Defaults to "global".
9
+ #
7
10
  # [:+pagination+]
8
- # The pagination name which should be matched to invoke AJAX Pagination response. Defaults to the empty string "". This is unlike other
9
- # methods which default to "page". However, this is a better default in this case because this affects more than one controller/action.
11
+ # Deprecated. Alias for section_id.
10
12
  #
11
13
  # [:+render+]
12
- # Overrides default render behaviour for AJAX Pagination, which is to render the partial with name matching the pagination option,
14
+ # Overrides default render behaviour for AJAX Pagination, which is to render the partial with name matching the section_id option,
13
15
  # or if it does not exist, renders the default template
14
16
  #
15
17
  def ajax_respond(options = {});
16
18
  # instead of defining default render normally, we save an unbound reference to original function in case it was already defined, since we want to retain the original behaviour, and add to it (if the method is redefined after, this new behaviour is lost, but at least we don't remove others' behaviour - note that this also allows multiple invocations of this with different parameters)
17
19
  default_render = self.instance_method(:default_render) # get a reference to original method
18
- pagination = options[:pagination] || ""
20
+ section_id = options[:section_id] || options[:pagination] || "global"
19
21
  view = options[:render] || nil
20
22
  define_method(:default_render) do |*args|
21
- paramspagination = request.GET[:pagination] || params[:pagination]
22
- if paramspagination && paramspagination == pagination && request.format == "html" # override if calling AJAX Pagination
23
+ if ajax_section && ajax_section == section_id && request.format == "html" # override if calling AJAX Pagination
23
24
  unless view
24
- if lookup_context.find_all("#{params[:controller]}/_#{paramspagination}").any?
25
- view = { :partial => paramspagination } # render partial, layout is off
25
+ if lookup_context.find_all("#{params[:controller]}/_#{ajax_section}").any?
26
+ view = { :partial => ajax_section } # render partial, layout is off
26
27
  else
27
28
  view = { :layout => false } # render default view, but turn off layout
28
29
  end
29
30
  end
30
31
  respond_to do |format|
31
- ajax_respond format, :pagination => pagination, :render => view
32
+ ajax_respond format, :section_id => section_id, :render => view
32
33
  end
33
34
  else # otherwise do what would have been done
34
35
  default_render.bind(self).call(*args) # call original method of the same name
@@ -38,8 +39,24 @@ module AjaxPagination
38
39
  end
39
40
  def self.included(base)
40
41
  base.extend ClassMethods
42
+
43
+ if AjaxPagination.redirect_after_filter == true
44
+ base.after_filter :ajax_pagination_redirect
45
+ end
46
+
47
+ base.before_filter do
48
+ @_ajax_section = request.GET[:pagination] || params[:pagination]
49
+ params.delete(:pagination) if request.get?
50
+ end
41
51
  end
42
- # Registers an ajax response in html format when params [:pagination] matches options [:pagination] ( = "page" by default).
52
+
53
+ # Returns the name of the ajax section to be responded to, if present. Otherwise this is not an AJAX Pagination request
54
+ # (ie. this is otherwise a normal full page request). When no specific ajax section is requested, returns nil.
55
+ def ajax_section
56
+ @_ajax_section
57
+ end
58
+
59
+ # Registers an ajax response in html format when a request is made by AJAX Pagination (in which case ajax_section.nil? is false).
43
60
  # AJAX Pagination uses this response to render only the content which has changed. When this format is triggered,
44
61
  # a partial is passed back, and sent to AJAX Pagination as a function argument in javascript.
45
62
  #
@@ -56,31 +73,33 @@ module AjaxPagination
56
73
  # end
57
74
  #
58
75
  # Options:
76
+ # [:+section_id+]
77
+ # Changes the AJAX section name triggering this response. Triggered when ajax_section == options [:section_id].
78
+ # Defaults to "global"
79
+ #
59
80
  # [:+pagination+]
60
- # Changes the pagination name triggering this response. Triggered when params [:pagination] == options [:pagination].
61
- # Defaults to "page"
81
+ # Deprecated. Alias for section_id
62
82
  #
63
83
  # [:+render+]
64
84
  # Changes the default template/partial that is rendered by this response. The value can be any object,
65
85
  # and is rendered directly. The render behaviour is the same as the render method in controllers. If this option is not used,
66
- # then the default is a partial of the same name as :pagination, if it exists, otherwise, if it does not,
86
+ # then the default is a partial of the same name as :section_id, if it exists, otherwise, if it does not,
67
87
  # the default template is rendered (ie. the :controller/:action.:format view file). By default, no layout is used
68
88
  # to render the template/partial. It can be set by passing in a layout key.
69
89
  #
70
90
  # def welcome
71
91
  # respond_to do |format|
72
92
  # format.html
73
- # ajax_respond format, :pagination => :menu, :render => {:file => "pages/welcome"}
93
+ # ajax_respond format, :section_id => :menu, :render => {:file => "pages/welcome"}
74
94
  # end
75
95
  # end
76
96
  #
77
97
  def ajax_respond(format,options = {})
78
- paramspagination = request.GET[:pagination] || params[:pagination]
79
- if paramspagination == (options[:pagination] || 'page').to_s
98
+ if ajax_section == (options[:section_id] || options[:pagination] || 'global').to_s
80
99
  if options[:render]
81
100
  view = options[:render] # render non partial
82
- elsif lookup_context.find_all(params[:controller] + "/_" + paramspagination).any?
83
- view = {:partial => paramspagination} # render partial of the same name as pagination
101
+ elsif lookup_context.find_all(params[:controller] + "/_" + ajax_section).any?
102
+ view = {:partial => ajax_section} # render partial of the same name as pagination
84
103
  else # render usual view
85
104
  view = {}
86
105
  end
@@ -94,18 +113,18 @@ module AjaxPagination
94
113
 
95
114
  # Tests whether an AJAX Pagination partial might be displayed in the view. If the response is not directly controlled by
96
115
  # AJAX Pagination, it will return true, because the partial might be displayed. The response is handled by AJAX Pagination
97
- # if the format is html, and the params [:pagination] parameter is set. If it is set, then it will return whether
98
- # params [:pagination] == pagination (the name of the pagination set, which defaults to page).
116
+ # if the format is html, and the ajax_section parameter is set. If it is set, then it will return whether
117
+ # ajax_section == section_id (the name of the section, which defaults to page).
99
118
  #
100
119
  # This method is a convenience function so that the controller does not need to perform heavy computation which might only
101
- # be required if a certain pagination partial is displayed.
120
+ # be required if only a certain section is displayed (for an AJAX request).
102
121
  #
103
- # For example, suppose an index page contains two sets of pagination partials, one for upcoming posts, and one for published
122
+ # For example, suppose an index page contains two ajax_section containers, one for upcoming posts, and one for published
104
123
  # posts, then you might use:
105
124
  #
106
125
  # class PostsController < ApplicationController
107
126
  # def index
108
- # if ajax_section_displayed? do
127
+ # if ajax_section_displayed? :page do
109
128
  # @posts = Post.published
110
129
  # @posts.each do |post|
111
130
  # post.heavycomputation
@@ -119,16 +138,15 @@ module AjaxPagination
119
138
  # end
120
139
  # respond_to do |format|
121
140
  # format.html # index.html.erb
122
- # ajax_respond format
123
- # ajax_respond format, :pagination => 'upcomingpage'
141
+ # ajax_respond format, :section_id => 'page'
142
+ # ajax_respond format, :section_id => 'upcomingpage'
124
143
  # end
125
144
  # end
126
145
  # end
127
146
  #
128
147
  # The heavy computation will only be performed on posts which will be displayed when AJAX Pagination only wants a partial.
129
- def ajax_section_displayed?(pagination = :page)
130
- paramspagination = request.GET[:pagination] || params[:pagination]
131
- (!request.format.html?) || (paramspagination.nil?) || (paramspagination == pagination.to_s)
148
+ def ajax_section_displayed?(section_id = :global)
149
+ (ajax_section.nil?) || (ajax_section == section_id.to_s)
132
150
  end
133
151
 
134
152
  # This after_filter method is automatically included by AJAX Paginate, and does not need to be included manually. However,
@@ -144,8 +162,7 @@ module AjaxPagination
144
162
  # This filter should not affect other uses, because only AJAX calls trigger this. In addition, a ?pagination= parameter is required.
145
163
  # Therefore other AJAX libraries or usage otherwise should not be affected.
146
164
  def ajax_pagination_redirect
147
- paramspagination = request.GET[:pagination] || params[:pagination]
148
- if request.xhr? && paramspagination && response.status==302 # alter redirect response so that it can be detected by the client javascript
165
+ if request.xhr? && ajax_section && response.status==302 # alter redirect response so that it can be detected by the client javascript
149
166
  response.status = 200 # change response to OK, location header is preserved, so AJAX can get the new page manually
150
167
  end
151
168
  end
@@ -14,10 +14,10 @@ module AjaxPagination
14
14
  # <%= link_to 'New Comment', new_comment_path %>
15
15
  #
16
16
  # If you prefer to can render yourself, or call another function instead (useful for using this in the
17
- # application layout), you can pass in a block. Any content wrapped by the pagination tag will be changed
17
+ # application layout), you can pass in a block. Any content wrapped by this section will be changed
18
18
  # when paginating. A possible way to use this function by passing a block in an application layout is shown:
19
19
  #
20
- # <div class="ajaxpagination menu" data-pagination="menu">
20
+ # <%= ajax_links :section_id => "global", :class => "menu" do %>
21
21
  # <ul>
22
22
  # <li><%= link_to "Home", root_url %></li>
23
23
  # <li><%= link_to "Posts", posts_url %></li>
@@ -25,19 +25,22 @@ module AjaxPagination
25
25
  # <li><%= link_to "Readme", pages_readme_url %></li>
26
26
  # <li><%= link_to "About", pages_about_url %></li>
27
27
  # </ul>
28
- # </div>
29
- # <%= ajax_section :pagination => "" do %>
28
+ # <% end %>
29
+ # <%= ajax_section :id => "global" do %>
30
30
  # <%= yield %>
31
31
  # <% end %>
32
32
  #
33
33
  # Options:
34
- # [:+pagination+]
35
- # Changes the pagination name, which is used for requesting new content, and to uniquely identify the
34
+ # [:+id+]
35
+ # Changes the AJAX section name, which is used for requesting new content, and to uniquely identify the
36
36
  # wrapping div tag. The name passed here should be the same as the pagination name used in the controller
37
- # respond_to block. Defaults to "page".
37
+ # respond_to block. Defaults to "global".
38
+ #
39
+ # [:+pagination+]
40
+ # Deprecated. Alias for name.
38
41
  #
39
42
  # [:+render+]
40
- # Changes the partial which is rendered. Defaults to +options [:pagination]+. The partial should generally
43
+ # Changes the partial which is rendered. Defaults to +options [:name]+. The partial should generally
41
44
  # be the same as that given in the controller respond_to block, unless you are doing something strange. If a
42
45
  # block is passed to the function, this option is ignored. You can also pass options instead to render other
43
46
  # files, in which case, the behaviour is the same as the render method in views.
@@ -83,9 +86,9 @@ module AjaxPagination
83
86
  # the link simply creates a cool AJAX effect on the current page.
84
87
  #
85
88
  def ajax_section(options = {})
86
- pagination = options[:pagination] || 'page' # by default the name of the pagination is 'page'
87
- partial = options[:render] || pagination # default partial rendered is the name of the pagination
88
- divoptions = { :id => "#{pagination}_paginated_section", :class => "paginated_section" }
89
+ section_id = options[:id] || options[:pagination] || 'global' # by default the name of the section is 'global'
90
+ partial = options[:render] || section_id # default partial rendered is the name of the section
91
+ divoptions = { :id => "#{section_id}", :class => "paginated_section" }
89
92
  data = {};
90
93
  if options.has_key? :history
91
94
  data[:history] = (options[:history] != false)
@@ -116,10 +119,11 @@ module AjaxPagination
116
119
  # A loading image is also displayed above the content. Only one loading zone is allowed. The rest are ignored.
117
120
  #
118
121
  # Use this tag in your partial, wrapped around all the content you want to disable. For example, if you are
119
- # displaying pagination links which you do not want to disable, as well as content you wish to disable,
122
+ # displaying AJAX links which you do not want to disable, as well as content you wish to disable,
120
123
  # your partial might contain:
121
- #
122
- # <%= will_paginate @objects, :params => { :pagination => nil } %>
124
+ # <% ajax_links :section_id => "page" do %>
125
+ # <%= will_paginate @objects %>
126
+ # <% end %>
123
127
  # <%= ajax_loadzone do %>
124
128
  # All content here is covered by a semi-transparent rectangle.
125
129
  # A loading image is displayed on top, and any links here are unclickable
@@ -131,19 +135,39 @@ module AjaxPagination
131
135
  end
132
136
  end
133
137
 
138
+ # Used to wrap ordinary links, which will be treated as AJAX links. Only ordinary links are altered.
139
+ # If the link contains a data-remote, data-method, data-confirm attribute, it will not be ajaxified by this container.
140
+ #
141
+ # Instead of using ajax_link_to for every link, the following can be used:
142
+ #
143
+ # ajax_links :section_id => "global" do
144
+ # link_to "My link", link_url
145
+ # link_to "Back", back_url
146
+ # end
147
+ #
148
+ # This allows a :section_id option to apply to all links within the block, instead of specifying the same option
149
+ # on each link. The default :section_id is "global" if not otherwise specified.
150
+ #
151
+ def ajax_links(options = {})
152
+ section_id = options[:section_id] || 'global'
153
+ content_tag :div, "data-pagination" => section_id, :class => ((Array(options[:class]) || []) + ["ajaxpagination"]).join(" ") do
154
+ yield
155
+ end
156
+ end
157
+
134
158
  # modifies the html options, so that it calls AJAX Pagination. This method adds the appropriate parameters to make an AJAX call via
135
159
  # AJAX Pagination, using jquery-ujs.
136
160
  #
137
- # More specifically, it ensures the following attributes are defined :remote => true, "data-type" => 'html', :pagination => ?.
138
- # The pagination attribute must be defined, or else it defaults to the empty string "".
161
+ # More specifically, it ensures the following attributes are defined :remote => true, "data-type" => 'html', :section_id => ?.
162
+ # The section_id attribute must be defined, or else it defaults to the empty string "global".
139
163
  # This link always sets data-remote to true - setting to false is not allowed, since AJAX Pagination would not be triggered.
140
164
  #
141
165
  # Below is an alternative way to create an ajax link instead of ajax_link_to
142
166
  #
143
- # <%= link_to "Name", posts_url, ajax_options :pagination => "page" %>
167
+ # <%= link_to "Name", posts_url, ajax_options :section_id => "page" %>
144
168
  #
145
169
  def ajax_options(html_options = {})
146
- html_options["data-pagination".to_sym] = html_options.delete(:pagination) || html_options.delete("data-pagination") || "" # renames the option pagination to data-pagination
170
+ html_options["data-pagination".to_sym] = html_options.delete(:section_id) || html_options.delete("data-section_id") || html_options.delete(:pagination) || html_options.delete("data-pagination") || "global" # renames the option pagination to data-pagination
147
171
  html_options[:remote] = true
148
172
  html_options["data-type".to_sym] ||= html_options.delete("data-type") || 'html'
149
173
  html_options
@@ -156,7 +180,7 @@ module AjaxPagination
156
180
  # The example below creates a link "Name", which when clicked, will load posts_url into the section of the page named
157
181
  # "page" using AJAX.
158
182
  #
159
- # <%= ajax_link_to "Name", posts_url, :pagination => "page" %>
183
+ # <%= ajax_link_to "Name", posts_url, :section_id => "page" %>
160
184
  #
161
185
  def ajax_link_to(*args, &block)
162
186
  if block_given? # inject new html_options argument and call link_to
@@ -172,11 +196,11 @@ module AjaxPagination
172
196
 
173
197
  # Wrapper for form_tag, following are equivalent:
174
198
  #
175
- # <%= ajax_form_tag posts_url, :method => "post", :class => "myclass", :pagination => "page" do %>
199
+ # <%= ajax_form_tag posts_url, :method => "post", :class => "myclass", :section_id => "page" do %>
176
200
  # ...
177
201
  # <% end %>
178
202
  #
179
- # <%= form_tag posts_url, ajax_options :method => "post", :class => "myclass", :pagination => "page" do %>
203
+ # <%= form_tag posts_url, ajax_options :method => "post", :class => "myclass", :section_id => "page" do %>
180
204
  # ...
181
205
  # <% end %>
182
206
  #
@@ -191,17 +215,17 @@ module AjaxPagination
191
215
 
192
216
  # Wrapper for form_for. The following are equivalent
193
217
  #
194
- # <%= ajax_form_for @post, :method => "post", :html => {:class => "myclass", :pagination => "menu"} do %>
218
+ # <%= ajax_form_for @post, :method => "post", :html => {:class => "myclass", :section_id => "menu"} do %>
195
219
  # ...
196
220
  # <% end %>
197
221
  #
198
- # <%= form_for @post, :method => "post", :html => ajax_options({:class => "myclass", :pagination => "menu"}) do %>
222
+ # <%= form_for @post, :method => "post", :html => ajax_options({:class => "myclass", :section_id => "menu"}) do %>
199
223
  # ...
200
224
  # <% end %>
201
225
  #
202
226
  # Please be aware that in the second alternative, you should never set :remote => false manually, eg:
203
227
  #
204
- # <%= form_tag @post, :remote => false, :html => ajax_options(:pagination => "menu") do %><!-- Never Do This!!! -->
228
+ # <%= form_tag @post, :remote => false, :html => ajax_options(:section_id => "menu") do %><!-- Never Do This!!! -->
205
229
  #
206
230
  # This will prevent AJAX Pagination from being called.
207
231
  #
@@ -15,12 +15,5 @@ module AjaxPagination
15
15
  end
16
16
  end
17
17
 
18
- initializer 'ajax_pagination.redirect_filter' do
19
- if AjaxPagination.redirect_after_filter == true
20
- ActiveSupport.on_load(:action_controller) do
21
- after_filter :ajax_pagination_redirect
22
- end
23
- end
24
- end
25
18
  end
26
19
  end
@@ -1,3 +1,3 @@
1
1
  module AjaxPagination
2
- VERSION = "0.5.1"
2
+ VERSION = "0.6.0"
3
3
  end
@@ -2,7 +2,7 @@
2
2
  //= require jquery.url
3
3
 
4
4
  /*
5
- * AJAX Pagination: Ajaxifying your pagination links
5
+ * AJAX Pagination: Ajaxifying your navigation
6
6
  * https://github.com/ronalchn/ajax_pagination
7
7
  *
8
8
  * Copyright (c) 2012 Ronald Ping Man Chan
@@ -56,7 +56,7 @@ jQuery(document).ready(function () {
56
56
  swapPage(pagination_name,url,options.history);
57
57
  }
58
58
  this.exists = function() {
59
- return $('#' + pagination_name + '_paginated_section').length == 1;
59
+ return $('#' + pagination_name).length == 1;
60
60
  }
61
61
  }
62
62
  /////////////////////////////
@@ -95,15 +95,13 @@ jQuery(document).ready(function () {
95
95
  }
96
96
  }
97
97
  function getSection(pagination_name) {
98
- var id = "#" + pagination_name + "_paginated_section"; // element id we are looking for
98
+ var id = "#" + pagination_name; // element id we are looking for
99
99
  return $(id);
100
100
  }
101
101
  function getSectionName(section) {
102
102
  var id = section.attr("id");
103
103
  if (id === undefined) return undefined; // no name
104
- var pagination_name = /^(.*)_paginated_section$/.exec(id)[1];
105
- if (pagination_name == null || pagination_name === undefined) return undefined; // pagination not set up properly
106
- return pagination_name;
104
+ return id; // id = pagination_name
107
105
  }
108
106
  function getSectionNames(sections) {
109
107
  var names = new Array();
@@ -158,9 +156,9 @@ jQuery(document).ready(function () {
158
156
  // this event handler has the same arguments as for jquery and jquery-ujs, except it also takes the name of the section to put the content into as first argument
159
157
  // adapter functions will be used to reconcile the differences in arguments, this is required because jquery and jquery-ujs has different ways to get the pagination_name argument
160
158
  function beforeSendHandler(pagination_name,jqXHR,settings) {
161
- var id = "#" + pagination_name + "_paginated_section"; // element id we are looking for
159
+ var id = "#" + pagination_name; // element id we are looking for
162
160
  var requesturl = settings.url;
163
- var countid = $('[id="' + pagination_name + '_paginated_section"]').length;
161
+ var countid = $('[id="' + pagination_name + '"]').length;
164
162
  if (countid != 1) { // something wrong, cannot find unique section to load page into
165
163
  <% if AjaxPagination.warnings %>
166
164
  alert("AJAX Pagination UNIQUE_SECTION_NOT_FOUND:\nExpected one pagination section called " + pagination_name + ", found " + countid);
@@ -234,7 +232,7 @@ jQuery(document).ready(function () {
234
232
  });
235
233
  }
236
234
  function pushHistory(pagination_name,url) {
237
- var data = $("#" + pagination_name + "_paginated_section").data("pagination");
235
+ var data = $("#" + pagination_name).data("pagination");
238
236
  if (data === undefined || data.history === undefined || data.history) { // check that history is not disabled
239
237
  // construct visible url
240
238
  var data = $.deparam.querystring($.url(url).attr('query'));
@@ -252,21 +250,20 @@ jQuery(document).ready(function () {
252
250
  }
253
251
  }
254
252
  // these special containers are for convenience only, to apply the required data-remote, data-pagination attributes to all links inside
255
- $(document).on("click", ".pagination a, .ajaxpagination a, a.ajaxpagination", function(e) {
253
+ $(document).on("click", ".ajaxpagination a", function(e) {
256
254
  // ignore if already selected by jquery-ujs
257
255
  if ($(this).filter($.rails.linkClickSelector).length>0) return true; // continue with jquery-ujs - this behaviour is necessary because we do not know if the jquery-ujs handler executes before or after this handler
258
256
  // find out what data-pagination should be set to
259
- var pagination_container = $(this).closest(".pagination, .ajaxpagination"); // container of links (use to check for data-pagination first)
257
+ var pagination_container = $(this).closest(".ajaxpagination"); // container of links (use to check for data-pagination first)
260
258
  var pagination_name = pagination_container.data('pagination');
261
259
  if (pagination_name === undefined) {
262
- pagination_name = /^(.*)_paginated_section$/.exec($(this).closest(".paginated_section").attr("id")); // if data-pagination not present, search up the tree for a suitable section
260
+ pagination_name = $(this).closest(".paginated_section").attr("id"); // if data-pagination not present, search up the tree for a suitable section
263
261
  if (pagination_name == null) {
264
262
  <% if AjaxPagination.warnings %>
265
- alert("AJAX Pagination MISSING_REFERENCE:\nNo pagination section name given for link, and none could be implicitly assigned, AJAX cancelled for this request");
263
+ alert("AJAX Pagination MISSING_REFERENCE:\nNo pagination section id given for link, and none could be implicitly assigned, AJAX cancelled for this request");
266
264
  <% end %>
267
265
  return true; // pagination not set up properly
268
266
  }
269
- pagination_name = pagination_name[1];
270
267
  }
271
268
 
272
269
  // set data-remote, data-pagination