ajax_pagination 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,15 @@
1
+ ## v0.4.0
2
+ * Reload logic rewritten, we now have world-class support for browser history. This is the biggest change. It is almost unnecessary to use the :reload option now, because the history support engine is much more intelligent. The original reason for the :reload option is to expose good history behaviour. This is now unnecessary, because the glitches which would otherwise occur are now solved in a better way. There is one remaining use for it. When browsers visit the same url, they do not add a new history item (therefore it is the same as clicking refresh). And when jumping to another history item with the same url, Firefox does not reload the page (although Chrome does). AJAX Pagination behaves like Firefox. However, sometimes different urls refer to the same content, when considering just a single section of the page. The :reload option is now used for this purpose. If present, it should specify all the important parts of the url which should be the same, for two different urls to be considered to same for the page section. The syntax for this reload specification is identical to before. Only the use of it has changed. Although this does change behaviour quite a bit, existing code should still work fine. This was changed because this behaviour more successfully mimics browser behaviour automatically - so less configuration.
3
+ * Moving css from javascript to stylesheet - this should make it easier to customize aspects of it.
4
+ * Expose a $.ajax_pagination API with a well-defined, and useful interface.
5
+ * Javascript enabled when AJAX loads full page. Only scripts inside of <div> section inserted will be executed.
6
+ * Fix bug: When javascript active but AJAX Pagination disabled, ajax_link_to, ajax_form_tag, ajax_form_for tags stop working because of data-remote. Now data-remote is tidied up so that jquery-ujs not activated (which is the cause of the bug).
7
+ * Make javascript more robust - rare bugs which occur for webpages with poor structuring of divs with class paginated_section.
8
+ * Added warnings page to example application to demonstrate possible warnings.
9
+ * Added events ajaxp:before, ajaxp:beforeSend, ajaxp:done, ajaxp:fail, ajaxp:loading, ajaxp:focus, ajaxp:loaded - these emit from section where page is loading (wheres ajax:? events emit from link clicked). New events also fire due to browser back/forward (while ajax:? only do not fire on browser back - these come from jquery-ujs)
10
+ * Visual cues overridable (by returning false from events).
11
+ * When jumping history, section no longer gets reloaded if parent already being reloaded.
12
+
1
13
  ## v0.3.0
2
14
  * Class method ajax_pagination :reload option - a string in json form no longer accepted, pass it in as a hash or array of hashes instead
3
15
  * image option added to ajax_pagination view helper, to specify a loading image other than the default
data/README.md CHANGED
@@ -5,8 +5,20 @@
5
5
 
6
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.
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.
9
+
8
10
  For more, see [Introduction and Background](https://github.com/ronalchn/ajax_pagination/wiki/Introduction-and-Background).
9
11
 
12
+ ## Features
13
+
14
+ * So easy to use, you don't need to touch a single line of javascript
15
+ * Supports multiple and nested sections
16
+ * Supports browser history, for more see [Robust Support for Browser History in AJAX Pagination](https://github.com/ronalchn/ajax_pagination/wiki/Robust-Support-for-Browser-History-in-AJAX-Pagination)
17
+ * Supports links, but also POST, DELETE, PUT links and forms. Then all can be used to change the content in a section
18
+ * Supports redirects - a necessary feature when used with forms
19
+ * Custom javascript events
20
+ * Built in visual cues when loading new content - can be altered with css.
21
+
10
22
  ## Installation
11
23
  Add to your Gemfile:
12
24
 
@@ -14,268 +26,31 @@ Add to your Gemfile:
14
26
 
15
27
  and run the bundle install command.
16
28
 
17
- Then add to your assets/javascripts/application.js,
18
-
19
- ```javascript
20
- //= require ajax_pagination
21
- ```
29
+ Then add to your asset manifests,
22
30
 
23
- AJAX Pagination depends on jquery-rails and jquery-historyjs, so if their javascript files are not already included, also include to following in your assets/javascripts/application.js file:
24
-
25
- ```javascript
31
+ ```js
32
+ // app/assets/javascripts/application.js
26
33
  //= require jquery
27
34
  //= require jquery_ujs
28
35
  //= require history
36
+ //= require ajax_pagination
37
+ ```
38
+
39
+ ```css
40
+ /* app/assets/stylesheets/application.css
41
+ * require ajax_pagination
42
+ */
29
43
  ```
30
44
 
31
45
  ## Getting Started
32
- The next section presents the usage of the functions in detail. However, it also presents the different options that can be chosen. For a simpler overview of how you can easily use this gem, please read one of the more specific guides below (found in the wiki):
46
+ To learn how to use this gem, read one of the usage guides below (found in the wiki):
33
47
 
34
48
  * [Adding AJAX to will_paginate](https://github.com/ronalchn/ajax_pagination/wiki/Adding-AJAX-to-will_paginate)
35
49
  * [Adding AJAX to site navigation](https://github.com/ronalchn/ajax_pagination/wiki/Adding-AJAX-to-site-navigation)
36
50
 
37
- and much [more](https://github.com/ronalchn/ajax_pagination/wiki/Home).
38
-
39
- ## Usage
40
-
41
- The pagination needs a name (in case you have multiple sets of AJAX pagination on the same webpage). By default, the name is "page". If you only intend to use a single set of pagination links, then leave it as "page". The name is used to distinguish different sets of pagination links, and is also used as a default for other functionaility.
42
-
43
- ### Ajaxifying the content
44
-
45
- Move the content to be paginated into a partial. If you are using the will_paginate gem (or similar), there is only one set of content to put into a partial. If you are using this to paginate between distinct views or even different controllers, you will need to move each set of content into a different partial.
46
-
47
- By default, AJAX Pagination looks for the pagination content in the partial with filename matching the name of the pagination (by default "page"), so it is a good idea to use this name. If multiple views have pagination content in the same controller (especially if for the same pagination set), you will need to use different filenames for them.
48
-
49
- Then, instead of the paginated content, put the following in your view:
50
-
51
- ```erb
52
- <%= ajax_pagination %>
53
- ```
54
-
55
- If the pagination name is not "page", pass the new pagination name in.
56
-
57
- ```erb
58
- <%= ajax_pagination :pagination => "page" %>
59
- ```
60
-
61
- If the partial is not named the same, pass it the new name as an option:
62
-
63
- ```erb
64
- <%= ajax_pagination :render => "mypartial" %>
65
- ```
66
-
67
- This will cause it to display content in the _mypartial.* view.
68
-
69
- If you are using will_paginate, and the links are wrapped in a div with class="pagination", the links will be ajaxified automatically.
70
-
71
- Otherwise, you can wrap a set of links with a container. We recommend that the class given is "ajaxpagination". You can put the links inside the partial, for example:
72
-
73
- ```html
74
- <div class="ajaxpagination"><a href="#">My ajaxified link</a></div>
75
- ```
76
-
77
- If you want to ajaxify individual links, check out the ajax_link_to helper (shown later), which is more flexible (can handle non-GET requests). Wrapping links in a container is actually just a convenience feature, which internally does the same things ajax_link_to does.
78
-
79
- If you are using will_paginate, you can simply put the links inside the partial (so that the new links get reloaded when the page changes):
80
-
81
- ```erb
82
- <%= will_paginate @objects, :params => { :pagination => nil } %>
83
- ```
84
-
85
- Note: It is recommended to set the pagination parameter to nil. When AJAX pagination calls the controller with a request for the partial, it appends ?pagination=NAMEOFPAGINATION. If the parameter is not set, AJAX Pagination will not respond to the AJAX call. will_paginate by default keeps any parameters in the query string. However, because this parameter is for internal use only, setting it to nil will keep the parameter from showing up in the url, making it look nicer (also better for caching).
86
-
87
- Now, AJAX Pagination will automatically call the controller for new content when an ajaxified link is clicked.
88
-
89
- If the links are outside the partial, you will need to also let AJAX Pagination know what content container should be reloaded when the links are followed. In this case, the div with ajaxpagination class should define the data-pagination attribute, the value corresponding to the name of the pagination content, for example you can do the following (which ajaxifies the menu navigation links):
90
-
91
- ```erb
92
- <div class="ajaxpagination menu" data-pagination="menu">
93
- <ul>
94
- <li><%= link_to "Home", root_url %></li>
95
- <li><%= link_to "Posts", posts_url %></li>
96
- <li><%= link_to "Changelog", changelog_url %></li>
97
- <li><%= link_to "Readme", pages_readme_url %></li>
98
- <li><%= link_to "About", pages_about_url %></li>
99
- </ul>
100
- </div>
101
- <%= ajax_pagination :pagination => "menu", :reload => {:urlpart => "path", :urlregex => "^.*$"} do %>
102
- <%= yield %>
103
- <% end %>
104
- ```
105
-
106
- Incidentally, this example also presents an alternative to passing in a :render option to <tt>ajax_pagination</tt>. Instead, you can pass it a block, in which case you can call the render helper yourself, or any other function (in this case, yield). If a block is passed, any :render option is ignored.
107
-
108
- ### Controller responder
109
-
110
- However, the controller needs to be told how to respond. If we do not indicate the response, it will render the whole html page as usual. This will still work (and only display the new content required), but it will send all the page content. By default, when this happens in development, an alert will pop up warning that this is not the best solution. AJAX Pagination works around this by detecting that you want to load new content into a section called "page" for example, but the new content actually contains a section called "page". Therefore, it replaces the old content with only the content of the response inside the section "page".
111
-
112
- This behaviour makes it easy to get AJAX Pagination working. And if you are not worried about efficiency (sending all the page content all the time), or if you are doing this for page caching purposes, you can leave it as is. To turn off the warning in development mode, simply generate an initializer, and set ```ruby
113
- config.warnings = false
114
- ```.
115
-
116
- To only send the data that is required (not including the page layout etc.), add a call to <tt>ajax_pagination(format)</tt> in the controller action.
117
-
118
- ```ruby
119
- respond_to do |format|
120
- format.html # index.html.erb
121
- ajax_pagination(format)
122
- end
123
- ```
124
-
125
- If either the pagination name or the partial filename is not the default (a partial named whatever :pagination is, "_page" in this case), you will need to pass these in as options.
126
-
127
- ```ruby
128
- ajax_pagination format, :pagination => "page", :render => "mytemplate"
129
- ```
130
-
131
- This will render controller/mytemplate. If you want a partial to be rendered, use:
132
-
133
- ```ruby
134
- ajax_pagination format, :pagination => "page", :render => {:partial => "mytemplate"}
135
- ```
136
-
137
- In both cases, the layout is off by default. You can pass in a layout to use in the render by the usual means.
138
-
139
- The pagination should now be more efficient.
140
-
141
- ### Default controller responder
142
-
143
- Although it is fine if used for a single action, eg. with will_paginate, individually adding a respond_to line for every controller and action might take a while, if used for site navigation, or navigating between the different actions of a single controller.
144
-
145
- There is also a class method defined for ActionController, also named ajax_pagination. If we are using it for site navigation, and the pagination name is "menu", then we can simply call:
146
-
147
- ```ruby
148
- class ApplicationController < ActionController:Base
149
- ajax_pagination :pagination => "menu"
150
- end
151
- ```
51
+ For more, including how specific features work, look in the [wiki](https://github.com/ronalchn/ajax_pagination/wiki/Home).
152
52
 
153
- We can, as with the instance method, also pass in a ```ruby
154
- :render => { :template => "myview", :layout => "mylayout" }
155
- ``` option. However, in this case, it is actually designed to be used without specifying the view template displayed. The reason is that when it is not defined, the default behaviour is normally what you want. Suppose you accessed a page at the url /controller/action?pagination=menu. The pagination=menu query argument indicates that this is a special AJAX request. If pagination is not defined exactly as "menu" in this example, the rendering does not trigger.
156
-
157
- AJAX Pagination first tries to render "controller/_menu", :layout => false, if it exists. If it does not, then it will render "controller/action", :layout => false.
158
-
159
- Therefore, when used for site navigation, it will by default, render the same page it would otherwise have rendered, only without the layout. Sometimes, we have parts of the page we want to render again (and is wrapped by the ajax_pagination container which identifies the section of the page which is reloaded), but exists in the layout. To deal with this case, we can set the layout to a special layout. This is used if, for example, we have flash notices or alerts we want to be removed, or displayed as appropriate for each AJAX call.
160
-
161
- In this case, we create a layout in layouts/flash_layout.html.erb for example, which renders the flash notices. Then, we can pass the layout in as follows:
162
-
163
- ```ruby
164
- class ApplicationController < ActionController:Base
165
- ajax_pagination :pagination => "menu", :render => { :layout => "flash_layout" }
166
- end
167
- ```
168
-
169
- Notice that no template file is specified. By not specifying the view template file, the controller/action view will be rendered.
170
-
171
- If we want to navigate within a controller, we can use this in the specific controller instead of the ApplicationController.
172
-
173
- Please note that the class method only specifies the default behaviour, by defining default_render (but it only triggers on the AJAX calls, otherwise it calls the original default_render function to handle the rendering). This default can be overrided by calling the instance method within an action, allowing you to use this for special cases (controllers or actions).
174
-
175
- Because the default_render method is used, if you subsequently define default_render, you may clobber the behaviour defined by AJAX Pagination. To deal with this, make sure that the call to the ajax_pagination class method is after any other definition. AJAX Pagination will not clobber any default_render method already defined. Requests which are not AJAX calls will be passed on to the original default_render method.
176
-
177
- ### Loading visualization
178
-
179
- AJAX Pagination can also add a loading image and partially blanking out of the paginated content. To do this, you can wrap all the content you want to cover with <tt>ajax_pagination_loadzone</tt>. For example, in the partial, you might have:
180
-
181
- ```erb
182
- <%= will_paginate @objects, :params => { :pagination => nil } %>
183
- <%= ajax_pagination_loadzone do %>
184
- While this partial is being loaded with other content,
185
- all content here has opacity reduced, and is covered by a transparent rectangle,
186
- a loading image is displayed on top, and any links here are unclickable
187
- <% end %>
188
- ```
189
-
190
- Links outside are still clickable (such as the will_paginate links).
191
-
192
- The loading image is currently an image asset at "ajax-loader.gif", so put your loading image there. You can specify a new default filename in your initializer. If you want a different loading image (other than configuring a site-wide default), you can pass an option :image => "newimageinassetpipeline.gif" to the ajax_pagination view helper method.
193
-
194
- If you want all the content in the partial (or otherwise wrapped by the ajax_pagination helper method) to be included as a loading zone (with the visual loading cues), you can instead, set the :loadzone option to true, eg:
195
-
196
- ```erb
197
- <%= ajax_pagination :pagination => "menu", :reload => {:urlpart => "path", :urlregex => "^.*$"}, :loadzone => true do %>
198
- <%= yield %>
199
- <% end %>
200
- ```
201
-
202
- In this case, whatever is inside the yield will not need to call ajax_pagination_loadzone.
203
-
204
- ### Browser History
205
-
206
- The back and forward buttons on your browser may not work properly yet. It will work as long as the link includes distinct query parameter with the same name as the pagination name for the set. For example, if the name of the pagination set is "page" (the default), when the browser url changes, AJAX Pagination looks for a change in the links query parameter with the same name, such as if the url changes from /path/to/controller?page=4 to /path/to/controller?page=9, then AJAX Pagination knows that the content corresponding to the pagination set needs reloading. The absence of the parameter is a distinct state, so changes such as /path/to/controller to /path/to/controller?page=0 are detected.
207
-
208
- However, if the pagination is to different controllers, eg. url changes from /ControllerA to /ControllerB, AJAX Pagination will not reload the content, because the name of the pagination set is "page", and the url ?page=... parameter has not changed. There are some options that can be passed to ajax_pagination, through the reload option.
209
-
210
- ```erb
211
- <%= ajax_pagination :reload => {:query => "watching"} %>
212
- ```
213
-
214
- By passing reload a hash, mapping query to watching, AJAX Pagination will reload the content if the query parameter named "watching" changes. For example, if the url changes from ?watching=A to ?watching=B.
215
-
216
- For more flexibility, a regular expression can be passed like so:
217
-
218
- ```erb
219
- <%= ajax_pagination :reload => {:urlregex => "page=([0-9]+)", :regexindex => 1} %>
220
- ```
221
-
222
- Which applies the regex expression /page=([0-9]+)/ to the url. The parameter regexindex then selects the nth matching subexpression, on which changes are detected. The subexpression indexed 0 is the complete match. The subexpression index 1 is the page number in this case. So when that changes, the page is reloaded.
223
-
224
- For more flexibility, a number of conditions can be passed in an array. If any of them change, the content is reloaded.
225
-
226
- ```erb
227
- <%= ajax_pagination :reload => [{:urlregex => "page=([0-9]+)", :regexindex => 1},{:query => "watching"}] %>
228
- ```
229
-
230
- Sometimes, you may have a small section of the page which is paginated, but for which you do not want to change the url. In effect, the page you are on should remain the same, simply with a cool effect, which changes the content displayed. This would mean that the new content loaded does not add to browser history.
231
-
232
- By default, the url does get changed, and browser history is added to. To turn this off, you can set :history => false, eg:
233
-
234
- ```erb
235
- <%= ajax_pagination :history => false %>
236
- ```
237
-
238
- When history is turned off, by default, reload is also set to never reload the content.
239
-
240
- ### Link and Form helpers
241
- For individual links, you can ajaxify them using ajax_link_to with the same format as the link_to helper, but making sure to pass a pagination option:
242
-
243
- ```erb
244
- <%= ajax_link_to "Name", posts_url, :pagination => "page" %>
245
- ```
246
-
247
- Similarly, there exist AJAX form helpers, again with the same format as the original form helpers:
248
-
249
- ```erb
250
- <%= ajax_form_tag posts_url, :method => "post", :class => "myclass", :pagination => "page" do %>
251
- ...
252
- <% end %>
253
-
254
- <%= ajax_form_for @post, :method => "post", :html => {:class => "myclass", :pagination => "menu"} do %>
255
- ...
256
- <% end %>
257
- ```
258
-
259
- Note that these form helpers actually use another helper method ajax_options, with the original non-ajax helpers. This means that you can also use:
260
-
261
- ```erb
262
- <%= link_to "Name", posts_url, ajax_options :pagination => "page" %>
263
-
264
- <%= form_tag posts_url, ajax_options :method => "post", :class => "myclass", :pagination => "page" do %>
265
- ...
266
- <% end %>
267
-
268
- <%= form_for @post, :method => "post", :html => ajax_options({:class => "myclass", :pagination => "menu"}) do %>
269
- ...
270
- <% end %>
271
- ```
272
-
273
- This is actually a powerful feature, because though you would simply use the ajax_link_to, ajax_form_tag, ajax_form_for tags as shorthand, if you are using another helper method (eg. one from Formtastic or Simple Form gems), you can use ajax_options with that helper method.
274
-
275
- ### Initializer
276
- You can configure AJAX Pagination in the initializer. Run ```
277
- rails generate ajax_pagination:install
278
- ``` to get the initializer file.
53
+ Alternatively, to see the API, see [RDoc](http://rdoc.info/gems/ajax_pagination/frames).
279
54
 
280
55
  ## Example Application
281
56
  This gem contains an example application (actually, it is there also for testing purposes), however it is nevertheless a good example.
@@ -292,26 +67,6 @@ bundle exec rails server
292
67
 
293
68
  Then point your browser to http://localhost:3000/
294
69
 
295
- ## AJAX Call
296
- The AJAX Call is triggered by a link wrapped in any container with a certain class. The AJAX Call is to the same address, but with the ?pagination=NAME parameter added. The format requested is javascript. If the controller also returns javascript for other uses, AJAX Pagination does not necessarily prevent such uses. The ajax_pagination(format, :pagination => "page") function in the controller handles the AJAX Call when the format is javascript, and the ?pagination parameter is set to the correct string. It also returns true if the pagination parameter matches. Therefore, you can use use the javascript format when it does not match, as shown below:
297
-
298
- ```ruby
299
- respond_to do |format|
300
- format.html # index.html.erb
301
- format.js unless ajax_pagination(format)
302
- end
303
- ```
304
-
305
- Note that **unless** does not need to be used, since respond_to is actually sensitive to the ordering, so an equivalent effect is achieved with:
306
-
307
- ```ruby
308
- respond_to do |format|
309
- format.html # index.html.erb
310
- ajax_pagination(format)
311
- format.js # index.js.erb
312
- end
313
- ```
314
-
315
70
  ## Javascript Dependency
316
71
  As well as the included ajax_pagination.js file, this gem uses jquery.ba-bbq.js and jquery.url.js, which are jquery plugins. They are included in the gem as assets already to simplify installation. ajax_pagination.js will automatically require jquery.ba-bbq.js, and jquery.url.js.
317
72
 
data/Rakefile CHANGED
@@ -5,17 +5,24 @@ RSpec::Core::RakeTask.new(:spec)
5
5
 
6
6
  task :travis do
7
7
  serverport = IO.read(File.expand_path("../spec/PORT",__FILE__)).strip # port number that we are using
8
+ serverslowport = IO.read(File.expand_path("../spec/SLOWPORT",__FILE__)).strip # port number that we are using
9
+
8
10
  system("cp spec/rails_app/db/development.sqlite3 spec/rails_app/db/test.sqlite3") # take a copy of the development database
9
11
  system("mkdir -p spec/rails_app/vendor/assets/javascripts") # directory to plonk javascripts from dependent gems
10
12
  # obtain jquery javascript assets (this is because sprockets cannot find these files otherwise, when going through nested bundles)
11
13
  # Note that the spec/rails_app/vendor directory is .gitignore because these are generated files
12
14
  system("cp `bundle show jquery-rails`/vendor/assets/javascripts/* spec/rails_app/vendor/assets/javascripts/")
13
15
  system("cp `bundle show jquery-historyjs`/vendor/assets/javascripts/* spec/rails_app/vendor/assets/javascripts/")
16
+
17
+ # startup test servers
14
18
  system("(cd spec/rails_app/ && RAILS_ENV=test bundle exec rails server -d --port=#{serverport})") # daemonized rails server
19
+ system("(cd spec/rails_app/ && RAILS_ENV=test AJAX_DELAY=1.5 bundle exec rails server -d --port=#{serverslowport})") # daemonized rails server
15
20
  system("bundle exec rake spec")
16
21
  unless $?.exitstatus == 0
17
22
  system("kill -9 `lsof -i :#{serverport} -t`") # kills rails server
23
+ system("kill -9 `lsof -i :#{serverslowport} -t`") # kills rails server
18
24
  raise "spec failed!"
19
25
  end
20
26
  system("kill -9 `lsof -i :#{serverport} -t`") # kills rails server
27
+ system("kill -9 `lsof -i :#{serverslowport} -t`") # kills rails server
21
28
  end
@@ -1,8 +1,3 @@
1
- begin
2
- require 'will_paginate' if Gem::Specification.find_by_name('will_paginate') # needed for testing dummy application
3
- rescue Gem::LoadError # in case using version without fix for this
4
- end
5
-
6
1
  module AjaxPagination
7
2
  # This module is automatically added to all views, providing helper methods.
8
3
  module HelperAdditions
@@ -31,7 +26,7 @@ module AjaxPagination
31
26
  # <li><%= link_to "About", pages_about_url %></li>
32
27
  # </ul>
33
28
  # </div>
34
- # <%= ajax_pagination :pagination => "menu", :reload => {:urlpart => "path", :urlregex => "^.*$"} do %>
29
+ # <%= ajax_pagination :pagination => "" do %>
35
30
  # <%= yield %>
36
31
  # <% end %>
37
32
  #
@@ -48,31 +43,30 @@ module AjaxPagination
48
43
  # files, in which case, the behaviour is the same as the render method in views.
49
44
  #
50
45
  # [:+reload+]
51
- # Used to detect whether the partial needs reloading, based on how the url changes. When pagination links are
52
- # clicked, they are easily detected, and will load the new content automatically. When the browser
53
- # back/forwards buttons are used, AJAX Pagination needs to know whether the content inside this pagination
54
- # partial needs reloading. This is not certain, because the webpage may contain multiple pagination partials,
55
- # and moreover, the page may have other functionality using the History.pushState feature. Defaults to nil.
56
- #
46
+ # Can be used to tweak the logic detecting that a page section is trying to reload the same page content. If there
47
+ # are multiple urls that loads the same page content into a section, AJAX Pagination will not normally detect that.
48
+ # Since the urls are different, it is assumed they have different content, therefore, a new history item will
49
+ # normally be added for it, and when jumping between two history items with the same content in this section,
50
+ # but different urls, the content will still be reloaded.
51
+ #
52
+ # If this option is used, it identifies certain areas of the url which must differ if the page content will be different.
53
+ # If all areas specified is the same, two urls will be assumed to reference the same content for this section.
54
+ #
57
55
  # If passed a hash of the form :+query+ => "parametername", AJAX Pagination will parse the url, to find
58
- # the parameter +parametername+ inside the query string (ie. /path/?parametername=value). When it changes,
59
- # the partial is reloaded.
56
+ # the parameter +parametername+ inside the query string (ie. /path/?parametername=value).
60
57
  #
61
58
  # If passed a hash of the form :+urlregex+ => "regularexpression", AJAX Pagination will apply the regular
62
- # expression to the url. If a particular subexpression of the match changes, the partial is reloaded. The
59
+ # expression to the url. If a particular subexpression of the match changes, the urls are regarded as different. The
63
60
  # subexpression used defaults to the whole match. If the hash includes :+regexindex+ => N, the Nth subexpression
64
61
  # is used. If the hash also includes :+urlpart+, then the regular expression will only be applied to part of the
65
62
  # url. The part it is applied to depends on the string passed. Allowed strings are any attributes as given at
66
63
  # https://github.com/allmarkedup/jQuery-URL-Parser. Possible attributes include: "source", "protocol", "host",
67
- # "port", "relative", "path", "directory", "file", "query". Notice in the above example for the application
68
- # layout, how :urlpart => "path" is passed as a reload condition.
64
+ # "port", "relative", "path", "directory", "file", "query".
69
65
  #
70
66
  # Different parts of the url can be watched for any changes, by passing an array of hashes. For example:
71
67
  #
72
68
  # <%= ajax_pagination :reload => [{:urlregex => "page=([0-9]+)", :regexindex => 1},{:query => "watching"}] %>
73
69
  #
74
- # If nil, AJAX Pagination acts as if it was passed {:query => options [:pagination]}.
75
- #
76
70
  # [:+image+]
77
71
  # Specify another image to be used as the loading image. The string passed is an image in the assets pipeline.
78
72
  # If not specified, the default loading image is used.
@@ -86,8 +80,7 @@ module AjaxPagination
86
80
  # true. Therefore, (sub)pages accessed through AJAX Pagination act as if a whole new page was accessed.
87
81
  #
88
82
  # If false then it is as if no new page is accessed, and the history is not changed. It therefore appears as if following
89
- # the link simply creates a cool AJAX effect on the current page. If false, then :reload defaults to {:urlregex => ""},
90
- # meaning that it will never reload when browser back/forward buttons are used, whether the url changes or not.
83
+ # the link simply creates a cool AJAX effect on the current page.
91
84
  #
92
85
  def ajax_pagination(options = {})
93
86
  pagination = options[:pagination] || 'page' # by default the name of the pagination is 'page'
@@ -96,7 +89,6 @@ module AjaxPagination
96
89
  data = {};
97
90
  if options.has_key? :history
98
91
  data[:history] = (options[:history] != false)
99
- data[:reload] = {:urlregex => ""} unless data[:history] # by default never reloads a history-less section
100
92
  end
101
93
  case options[:reload].class.to_s
102
94
  when "Hash", "Array"
@@ -1,3 +1,3 @@
1
1
  module AjaxPagination
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end