Module: AjaxPagination::HelperAdditions
- Defined in:
- lib/ajax_pagination/helper_additions.rb
Overview
This module is automatically added to all views, providing helper methods.
Instance Method Summary (collapse)
-
- (Object) ajax_pagination(options = {})
Renders a partial wrapped in a div tag.
-
- (Object) ajax_pagination_loadzone
Wraps content in a div tag.
Instance Method Details
- (Object) ajax_pagination(options = {})
Renders a partial wrapped in a div tag. When the page content displayed in the partial needs changing AJAX Pagination will replace content inside this div tag, with the new content returned by the controller (To manage that, see ajax_pagination in ControllerAdditions).
Call this method instead of render to display the partial representing the page content:
Listing Comments:
<%= ajax_pagination %>
<%= link_to 'New Comment', new_comment_path %>
Options:
- :pagination
-
Changes the pagination name, which is used for requesting new content, and to uniquely identify the wrapping div tag. The name passed here should be the same as the pagination name used in the controller respond_to block. Defaults to "page".
- :partial
-
Changes the partial which is rendered. Defaults to +options+. The partial should generally be the same as that given in the controller respond_to block, unless you are doing something strange.
- :reload
-
Used to detect whether the partial needs reloading, based on how the url changes. When pagination links are clicked, they are easily detected, and will load the new content automatically. When the browser back/forwards buttons are used, AJAX Pagination needs to know whether the content inside this pagination partial needs reloading. This is not certain, because the webpage may contain multiple pagination partials, and moreover, the page may have other functionality using the History.pushState feature. Defaults to nil.
If passed a hash of the form :query => "parametername", AJAX Pagination will parse the url, to find the parameter parametername inside the query string (ie. /path/?parametername=value). When it changes, the partial is reloaded.
If passed a hash of the form :urlregex => "regularexpression", AJAX Pagination will apply the regular expression to the url. If a particular subexpression of the match changes, the partial is reloaded. The subexpression used defaults to the whole match. If the hash includes :regexindex => N, the Nth subexpression is used.
Different parts of the url can be watched for any changes, by passing an array of hashes. For example:
<%= ajax_pagination :reload => [{:urlregex => "page=([0-9]+)", :regexindex => 1},{:query => "watching"}] %>If nil, AJAX Pagination acts as if it was passed => options.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/ajax_pagination/helper_additions.rb', line 48 def ajax_pagination( = {}) pagination = [:pagination] || 'page' # by default the name of the pagination is 'page' partial = [:partial] || pagination # default partial rendered is the name of the pagination reload = [:reload] = { :id => "#{pagination}_paginated_section", :class => "paginated_section" } case reload.class.to_s when "String" ["data-reload"] = reload when "Hash", "Array" ["data-reload"] = reload.to_json end content_tag :div, do render partial end end |
- (Object) ajax_pagination_loadzone
Wraps content in a div tag. AJAX Pagination uses this to display visual loading cues. When a partial is reloaded, it may take some time. In the meanwhile, AJAX Pagination will look in the partial amoung its immediate child for this tag. If this tag exists, it will cover this tag with a semi-transparent rectangle, and make the old partial unclickable (links and other elements are therefore disabled). A loading image is also displayed above the content.
Use this tag in your partial, wrapped around all the content you want to disable. For example, if you are displaying pagination links which you do not want to disable, as well as content you wish to disable, you partial might contain:
<%= will_paginate @objects, :params => { :pagination => nil } %>
<%= ajax_pagination_loadzone do %>
All content here is covered by a semi-transparent rectangle.
A loading image is displayed on top, and any links here are unclickable
<% end %>
80 81 82 83 84 85 86 |
# File 'lib/ajax_pagination/helper_additions.rb', line 80 def ajax_pagination_loadzone() content_tag :div, :class => "paginated_content", :style => "position: relative" do content_tag :div do # for changing the opacity yield end end end |