ajax_pagination 0.6.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -1,3 +1,9 @@
1
+ ## v0.6.1
2
+ * the ajaxp:done event now sends an extra argument - the ajax_loadzone DOM element. This makes it easier for the event handler to make animations involving the loadzone. If it does not exist, null is returned.
3
+ * one set of internally used data-pagination attributes has been renamed to data-ajax_section_id.
4
+ * the ?pagination= querystring parameter has been renamed to ajax_section.
5
+ * Fixed Travis CI tests to start up WEBrick servers with the correct rails version.
6
+
1
7
  ## v0.6.0
2
8
  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
9
 
data/Rakefile CHANGED
@@ -20,11 +20,12 @@ task :travis do
20
20
  system("cp `bundle show jquery-rails`/vendor/assets/javascripts/* spec/rails30_app/public/javascripts/")
21
21
  system("cp `bundle show jquery-historyjs`/vendor/assets/javascripts/* spec/rails30_app/public/javascripts/")
22
22
  system("(cd spec/rails30_app/ && bundle exec rails generate ajax_pagination:assets --force)")
23
-
24
- # startup test servers
25
- system("(cd spec/rails_app/ && RAILS_ENV=test bundle exec rails server -d --port=#{serverport})") # daemonized rails server
26
- system("(cd spec/rails_app/ && RAILS_ENV=test AJAX_DELAY=1.5 bundle exec rails server -d --port=#{serverslowport})") # daemonized rails server
27
- system("(cd spec/rails30_app/ && RAILS_ENV=test AJAX_DELAY=1.5 bundle exec rails server -d --port=#{r30serverport})") # daemonized rails server
23
+ Bundler.with_clean_env do
24
+ # startup test servers
25
+ system("(export BUNDLE_GEMFILE=`pwd`/spec/rails_app/Gemfile; cd spec/rails_app/ && (bundle | grep -e 'Your bundle .*$') && RAILS_ENV=test bundle exec rails server -d --port=#{serverport})") # daemonized rails server
26
+ system("(export BUNDLE_GEMFILE=`pwd`/spec/rails_app/Gemfile; cd spec/rails_app/ && (bundle | grep -e 'Your bundle .*$') && RAILS_ENV=test AJAX_DELAY=1.5 bundle exec rails server -d --port=#{serverslowport})") # daemonized rails server
27
+ system("(export BUNDLE_GEMFILE=`pwd`/spec/rails30_app/Gemfile; cd spec/rails30_app/ && (bundle | grep -e 'Your bundle .*$') && RAILS_ENV=test AJAX_DELAY=1.5 bundle exec rails server -d --port=#{r30serverport})") # daemonized rails server
28
+ end
28
29
  system("bundle exec rake spec")
29
30
  unless $?.exitstatus == 0
30
31
  system("kill -9 `lsof -i :#{serverport} -t`") # kills rails server
@@ -7,9 +7,6 @@ module AjaxPagination
7
7
  # [:+section_id+]
8
8
  # The AJAX section name which should be matched to invoke AJAX Pagination response. Defaults to "global".
9
9
  #
10
- # [:+pagination+]
11
- # Deprecated. Alias for section_id.
12
- #
13
10
  # [:+render+]
14
11
  # Overrides default render behaviour for AJAX Pagination, which is to render the partial with name matching the section_id option,
15
12
  # or if it does not exist, renders the default template
@@ -17,12 +14,12 @@ module AjaxPagination
17
14
  def ajax_respond(options = {});
18
15
  # 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)
19
16
  default_render = self.instance_method(:default_render) # get a reference to original method
20
- section_id = options[:section_id] || options[:pagination] || "global"
17
+ section_id = options[:section_id] || "global"
21
18
  view = options[:render] || nil
22
19
  define_method(:default_render) do |*args|
23
20
  if ajax_section && ajax_section == section_id && request.format == "html" # override if calling AJAX Pagination
24
21
  unless view
25
- if lookup_context.find_all("#{params[:controller]}/_#{ajax_section}").any?
22
+ if lookup_context.find_all(controller_path + "/_" + ajax_section).any?
26
23
  view = { :partial => ajax_section } # render partial, layout is off
27
24
  else
28
25
  view = { :layout => false } # render default view, but turn off layout
@@ -45,8 +42,11 @@ module AjaxPagination
45
42
  end
46
43
 
47
44
  base.before_filter do
48
- @_ajax_section = request.GET[:pagination] || params[:pagination]
49
- params.delete(:pagination) if request.get?
45
+ # simply manipulating querystring will not get ajax response (in production mode)
46
+ if request.xhr? || Rails.env == 'development'
47
+ @_ajax_section = request.GET[:ajax_section] || params[:ajax_section]
48
+ params.delete(:ajax_section) if request.get?
49
+ end
50
50
  end
51
51
  end
52
52
 
@@ -77,9 +77,6 @@ module AjaxPagination
77
77
  # Changes the AJAX section name triggering this response. Triggered when ajax_section == options [:section_id].
78
78
  # Defaults to "global"
79
79
  #
80
- # [:+pagination+]
81
- # Deprecated. Alias for section_id
82
- #
83
80
  # [:+render+]
84
81
  # Changes the default template/partial that is rendered by this response. The value can be any object,
85
82
  # and is rendered directly. The render behaviour is the same as the render method in controllers. If this option is not used,
@@ -95,11 +92,11 @@ module AjaxPagination
95
92
  # end
96
93
  #
97
94
  def ajax_respond(format,options = {})
98
- if ajax_section == (options[:section_id] || options[:pagination] || 'global').to_s
95
+ if ajax_section == (options[:section_id] || 'global').to_s
99
96
  if options[:render]
100
97
  view = options[:render] # render non partial
101
- elsif lookup_context.find_all(params[:controller] + "/_" + ajax_section).any?
102
- view = {:partial => ajax_section} # render partial of the same name as pagination
98
+ elsif lookup_context.find_all(controller_path + "/_" + ajax_section).any?
99
+ view = {:partial => ajax_section} # render partial of the same name as section_id
103
100
  else # render usual view
104
101
  view = {}
105
102
  end
@@ -162,7 +159,7 @@ module AjaxPagination
162
159
  # This filter should not affect other uses, because only AJAX calls trigger this. In addition, a ?pagination= parameter is required.
163
160
  # Therefore other AJAX libraries or usage otherwise should not be affected.
164
161
  def ajax_pagination_redirect
165
- if request.xhr? && ajax_section && response.status==302 # alter redirect response so that it can be detected by the client javascript
162
+ if ajax_section && response.status==302 # alter redirect response so that it can be detected by the client javascript
166
163
  response.status = 200 # change response to OK, location header is preserved, so AJAX can get the new page manually
167
164
  end
168
165
  end
@@ -33,12 +33,9 @@ module AjaxPagination
33
33
  # Options:
34
34
  # [:+id+]
35
35
  # Changes the AJAX section name, which is used for requesting new content, and to uniquely identify the
36
- # wrapping div tag. The name passed here should be the same as the pagination name used in the controller
36
+ # wrapping div tag. This section id will be referred to in the controller
37
37
  # respond_to block. Defaults to "global".
38
38
  #
39
- # [:+pagination+]
40
- # Deprecated. Alias for name.
41
- #
42
39
  # [:+render+]
43
40
  # Changes the partial which is rendered. Defaults to +options [:name]+. The partial should generally
44
41
  # be the same as that given in the controller respond_to block, unless you are doing something strange. If a
@@ -86,9 +83,9 @@ module AjaxPagination
86
83
  # the link simply creates a cool AJAX effect on the current page.
87
84
  #
88
85
  def ajax_section(options = {})
89
- section_id = options[:id] || options[:pagination] || 'global' # by default the name of the section is 'global'
86
+ section_id = options[:id] || 'global' # by default the name of the section is 'global'
90
87
  partial = options[:render] || section_id # default partial rendered is the name of the section
91
- divoptions = { :id => "#{section_id}", :class => "paginated_section" }
88
+ divoptions = { :id => "#{section_id}", :class => "ajax_section" }
92
89
  data = {};
93
90
  if options.has_key? :history
94
91
  data[:history] = (options[:history] != false)
@@ -100,7 +97,7 @@ module AjaxPagination
100
97
  data[:image] = asset_path options[:image] if options[:image].class.to_s == "String"
101
98
  divoptions["data-pagination"] = data.to_json if !data.empty?
102
99
  if options[:loadzone]
103
- divoptions[:class] = "paginated_section paginated_content"
100
+ divoptions[:class] = "ajax_section ajax_loadzone"
104
101
  divoptions[:style] = "position: relative;"
105
102
  end
106
103
  content_tag :div, divoptions do
@@ -130,7 +127,7 @@ module AjaxPagination
130
127
  # <% end %>
131
128
  #
132
129
  def ajax_loadzone()
133
- content_tag :div, :class => "paginated_content", :style => "position: relative;" do
130
+ content_tag :div, :class => "ajax_loadzone", :style => "position: relative;" do
134
131
  yield
135
132
  end
136
133
  end
@@ -150,7 +147,7 @@ module AjaxPagination
150
147
  #
151
148
  def ajax_links(options = {})
152
149
  section_id = options[:section_id] || 'global'
153
- content_tag :div, "data-pagination" => section_id, :class => ((Array(options[:class]) || []) + ["ajaxpagination"]).join(" ") do
150
+ content_tag :div, "data-ajax_section_id" => section_id, :class => ((Array(options[:class]) || []) + ["ajaxpagination"]).join(" ") do
154
151
  yield
155
152
  end
156
153
  end
@@ -167,7 +164,7 @@ module AjaxPagination
167
164
  # <%= link_to "Name", posts_url, ajax_options :section_id => "page" %>
168
165
  #
169
166
  def ajax_options(html_options = {})
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
167
+ html_options["data-ajax_section_id".to_sym] = html_options.delete(:section_id) || "global" # renames the option section_id to data-ajax_section_id
171
168
  html_options[:remote] = true
172
169
  html_options["data-type".to_sym] ||= html_options.delete("data-type") || 'html'
173
170
  html_options
@@ -1,3 +1,3 @@
1
1
  module AjaxPagination
2
- VERSION = "0.6.0"
2
+ VERSION = "0.6.1"
3
3
  end
@@ -2,7 +2,7 @@
2
2
  //= require jquery.url
3
3
 
4
4
  /*
5
- * AJAX Pagination: Ajaxifying your navigation
5
+ * AJAX Pagination v<%= AjaxPagination::VERSION %>: Ajaxifying your navigation
6
6
  * https://github.com/ronalchn/ajax_pagination
7
7
  *
8
8
  * Copyright (c) 2012 Ronald Ping Man Chan
@@ -44,19 +44,19 @@ jQuery(document).ready(function () {
44
44
  ////// $.ajax_pagination API //////
45
45
  ///////////////////////////////////
46
46
  // selector function for pagination object
47
- $.ajax_pagination = function (pagination_name) {
48
- return new pagination_object(pagination_name);
47
+ $.ajax_pagination = function (section_id) {
48
+ return new ajax_section_object(section_id);
49
49
  };
50
50
  $.ajax_pagination.version = '<%= AjaxPagination::VERSION %>';
51
51
  $.ajax_pagination.enabled = true;
52
- function pagination_object(pagination_name) {
52
+ function ajax_section_object(section_id) {
53
53
  this.get = function(url,options) {
54
54
  if (options === undefined) options = {};
55
55
  if (options.history === undefined) options.history = true;
56
- swapPage(pagination_name,url,options.history);
56
+ swapPage(section_id,url,options.history);
57
57
  }
58
58
  this.exists = function() {
59
- return $('#' + pagination_name).length == 1;
59
+ return $('#' + section_id).length == 1;
60
60
  }
61
61
  }
62
62
  /////////////////////////////
@@ -66,42 +66,44 @@ jQuery(document).ready(function () {
66
66
  var pagination_url = location.href; // url we came from, so we can see transitions of the url
67
67
  var history_state = {ajax_pagination_set:true}; // current history state
68
68
 
69
- function display_pagination_loader(pagination_name) {
70
- var paginated_section = getSection(pagination_name);
71
- if (pagination_loader_state[pagination_name] === undefined) { // show loader if not already shown
72
- if ($.rails.fire(getSection(pagination_name),"ajaxp:loading")) {
73
- var paginated_content;
74
- if (paginated_section.hasClass("paginated_content")) paginated_content = paginated_section; // if the whole section is a loading zone
75
- else paginated_content = paginated_section.children(".paginated_content").first(); // don't want to support multiple loader images
76
- var height = paginated_content.height();
69
+ function display_pagination_loader(section_id) {
70
+ var ajax_section = getSection(section_id);
71
+ if (pagination_loader_state[section_id] === undefined) { // show loader if not already shown
72
+ // get the ajax_loadzone DOM element
73
+ var ajax_loadzone;
74
+ if (ajax_section.hasClass("ajax_loadzone")) ajax_loadzone = ajax_section; // if the whole section is a loading zone
75
+ else ajax_loadzone = ajax_section.children(".ajax_loadzone").first(); // don't want to support multiple loader images
76
+
77
+ if ($.rails.fire(getSection(section_id),"ajaxp:loading",[ajax_loadzone.get(0)])) {
78
+ var height = ajax_loadzone.height();
77
79
  // setup loading look
78
80
  var img = document.createElement("IMG");
79
- if (paginated_section.data("pagination") !== undefined && paginated_section.data("pagination").image !== undefined) img.src = paginated_section.data("pagination").image;
81
+ if (ajax_section.data("pagination") !== undefined && ajax_section.data("pagination").image !== undefined) img.src = ajax_section.data("pagination").image;
80
82
  else img.src = "<%= asset_path AjaxPagination.loading_image %>";
81
83
  var margin = Math.round(height>400?50:(height/8));
82
84
  $(img).addClass('ajaxpagination-loader');
83
85
  var div = document.createElement("DIV");
84
86
  $(div).addClass('ajaxpagination-loadzone');
85
87
  $(div).append("<div class=\"margin-top\" />").append(img);
86
- paginated_content.wrapInner("<div class=\"ajaxpagination-oldcontent\" />");
87
- paginated_content.append(div);
88
+ ajax_loadzone.wrapInner("<div class=\"ajaxpagination-oldcontent\" />");
89
+ ajax_loadzone.append(div);
88
90
  }
89
91
  }
90
- if ($.rails.fire(getSection(pagination_name),"ajaxp:focus")) {
91
- // scroll to top of paginated_section if it is not visible
92
- if ($(document).scrollTop() > paginated_section.offset().top - <%= AjaxPagination.scroll_margin %>) {
93
- $(document).scrollTop(paginated_section.offset().top - <%= AjaxPagination.scroll_margin %>);
92
+ if ($.rails.fire(getSection(section_id),"ajaxp:focus")) {
93
+ // scroll to top of ajax_section if it is not visible
94
+ if ($(document).scrollTop() > ajax_section.offset().top - <%= AjaxPagination.scroll_margin %>) {
95
+ $(document).scrollTop(ajax_section.offset().top - <%= AjaxPagination.scroll_margin %>);
94
96
  }
95
97
  }
96
98
  }
97
- function getSection(pagination_name) {
98
- var id = "#" + pagination_name; // element id we are looking for
99
+ function getSection(section_id) {
100
+ var id = "#" + section_id; // element id we are looking for
99
101
  return $(id);
100
102
  }
101
103
  function getSectionName(section) {
102
104
  var id = section.attr("id");
103
105
  if (id === undefined) return undefined; // no name
104
- return id; // id = pagination_name
106
+ return id; // id = section_id
105
107
  }
106
108
  function getSectionNames(sections) {
107
109
  var names = new Array();
@@ -120,9 +122,9 @@ jQuery(document).ready(function () {
120
122
  return false; // doesn't intersect
121
123
  }
122
124
  // whether change of state is a reload
123
- function isReload(pagination_name,from,to) {
125
+ function isReload(section_id,from,to) {
124
126
  if (from == to) return true; // same url - always a reload
125
- var section = getSection(pagination_name);
127
+ var section = getSection(section_id);
126
128
  if (section.length == 0) return false;
127
129
 
128
130
  // if data-pagination is not defined, then no reload can be detected
@@ -154,25 +156,25 @@ jQuery(document).ready(function () {
154
156
  }
155
157
  // when this function is used beforeSend of an AJAX request, will use the resulting content in a section of the page
156
158
  // 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
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
158
- function beforeSendHandler(pagination_name,jqXHR,settings) {
159
- var id = "#" + pagination_name; // element id we are looking for
159
+ // 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 section_id argument
160
+ function beforeSendHandler(section_id,jqXHR,settings) {
161
+ var id = "#" + section_id; // element id we are looking for
160
162
  var requesturl = settings.url;
161
- var countid = $('[id="' + pagination_name + '"]').length;
163
+ var countid = $('[id="' + section_id + '"]').length;
162
164
  if (countid != 1) { // something wrong, cannot find unique section to load page into
163
165
  <% if AjaxPagination.warnings %>
164
- alert("AJAX Pagination UNIQUE_SECTION_NOT_FOUND:\nExpected one pagination section called " + pagination_name + ", found " + countid);
166
+ alert("AJAX Pagination UNIQUE_SECTION_NOT_FOUND:\nExpected one section with id of " + section_id + ", found " + countid);
165
167
  <% end %>
166
168
  return false; // continue AJAX normally
167
169
  }
168
- if (!$.rails.fire(getSection(pagination_name),"ajaxp:beforeSend",[jqXHR,settings])) return false;
169
- display_pagination_loader(pagination_name);
170
+ if (!$.rails.fire(getSection(section_id),"ajaxp:beforeSend",[jqXHR,settings])) return false;
171
+ display_pagination_loader(section_id);
170
172
  // register callbacks for other events
171
173
  jqXHR.done(function(data, textStatus, jqXHR) {
172
- if (requesturl != pagination_loader_state[pagination_name]) return; // ignore stale content
174
+ if (requesturl != pagination_loader_state[section_id]) return; // ignore stale content
173
175
  if (jqXHR.status == 200 && jqXHR.getResponseHeader('Location') !== null) { // special AJAX redirect
174
176
  var redirecturl = jqXHR.getResponseHeader('Location');
175
- swapPage(pagination_name,redirecturl);
177
+ swapPage(section_id,redirecturl);
176
178
  pagination_url = redirecturl;
177
179
  History.replaceState(history_state,document.title,redirecturl); // state not changed
178
180
  return;
@@ -190,7 +192,7 @@ jQuery(document).ready(function () {
190
192
  if (content.length>0) {
191
193
  content = content.html();
192
194
  <% if AjaxPagination.warnings %>
193
- alert("AJAX Pagination EXTRA_CONTENT_DISCARDED:\nExtra content returned by AJAX request ignored. Only a portion of the page content returned by the server was required. To fix this, explicitly call ajax_respond :pagination => \"" + pagination_name + "\" to render only the partial view required. This warning can be turned off in the ajax_pagination initializer file.");
195
+ alert("AJAX Pagination EXTRA_CONTENT_DISCARDED:\nExtra content returned by AJAX request ignored. Only a portion of the page content returned by the server was required. To fix this, explicitly call ajax_respond :section_id => \"" + section_id + "\" to render only the partial view required. This warning can be turned off in the ajax_pagination initializer file.");
194
196
  <% end %>
195
197
  }
196
198
  else { // otherwise use all the content, including any scripts - we consider scripts specifically returned in the partial probably should be re-run
@@ -199,76 +201,67 @@ jQuery(document).ready(function () {
199
201
  else content = page.html(); // otherwise include the whole html snippet
200
202
  }
201
203
 
202
- if ($.rails.fire(getSection(pagination_name),"ajaxp:done",[content])) $(id).html(content);
204
+ if ($.rails.fire(getSection(section_id),"ajaxp:done",[content])) $(id).html(content);
203
205
 
204
- delete pagination_loader_state[pagination_name]; // not waiting for page anymore
206
+ delete pagination_loader_state[section_id]; // not waiting for page anymore
205
207
 
206
- $.rails.fire(getSection(pagination_name),"ajaxp:loaded");
208
+ $.rails.fire(getSection(section_id),"ajaxp:loaded");
207
209
  });
208
210
  jqXHR.fail(function(jqXHR, textStatus, errorThrown) {
209
- if (requesturl != pagination_loader_state[pagination_name]) return; // ignore stale content
210
- if ($.rails.fire(getSection(pagination_name),"ajaxp:fail",[jqXHR.responseText])) $(id).html(jqXHR.responseText);
211
+ if (requesturl != pagination_loader_state[section_id]) return; // ignore stale content
212
+ if ($.rails.fire(getSection(section_id),"ajaxp:fail",[jqXHR.responseText])) $(id).html(jqXHR.responseText);
211
213
 
212
- delete pagination_loader_state[pagination_name]; // not waiting for page anymore
214
+ delete pagination_loader_state[section_id]; // not waiting for page anymore
213
215
 
214
- $.rails.fire(getSection(pagination_name),"ajaxp:loaded");
216
+ $.rails.fire(getSection(section_id),"ajaxp:loaded");
215
217
  });
216
218
  return true;
217
219
  }
218
- function swapPage(pagination_name, requesturl, history) { // swaps the page at pagination_name to that from requesturl (used by History.popState, therefore no remote link has been clicked)
220
+ function swapPage(section_id, requesturl, history) { // swaps the page at section_id to that from requesturl (used by History.popState, therefore no remote link has been clicked)
219
221
  if (history === undefined) history = false;
220
222
  // send our own ajax request, and tie it into the beforeSendHandler used for jquery-ujs as well
221
- if (!$.rails.fire(getSection(pagination_name),"ajaxp:before",[requesturl,undefined])) return false;
222
- $.ajax({url: requesturl, data: {pagination:pagination_name},
223
+ if (!$.rails.fire(getSection(section_id),"ajaxp:before",[requesturl,undefined])) return false;
224
+ $.ajax({url: requesturl, data: {ajax_section:section_id},
223
225
  dataType: 'html',
224
226
  beforeSend: function (jqXHR,settings) {
225
- var result = beforeSendHandler(pagination_name,jqXHR,settings);
227
+ var result = beforeSendHandler(section_id,jqXHR,settings);
226
228
  if (result) {
227
- if (history) pushHistory(pagination_name,settings.url);
228
- pagination_loader_state[pagination_name] = settings.url; // remember which page number we are waiting for
229
+ if (history) pushHistory(section_id,settings.url);
230
+ pagination_loader_state[section_id] = settings.url; // remember which page number we are waiting for
229
231
  }
230
232
  return result;
231
233
  }
232
234
  });
233
235
  }
234
- function pushHistory(pagination_name,url) {
235
- var data = $("#" + pagination_name).data("pagination");
236
+ function pushHistory(section_id,url) {
237
+ var data = $("#" + section_id).data("pagination");
236
238
  if (data === undefined || data.history === undefined || data.history) { // check that history is not disabled
237
239
  // construct visible url
238
240
  var data = $.deparam.querystring($.url(url).attr('query'));
239
- delete data['pagination'];
241
+ delete data['ajax_section'];
240
242
  pagination_url = $.param.querystring(url,data,2);
241
- if (isReload(pagination_name,url,location.href)) History.replaceState(history_state,document.title,pagination_url);
243
+ if (isReload(section_id,url,location.href)) History.replaceState(history_state,document.title,pagination_url);
242
244
  else { // not just a reload of current page, so do actual pushState
243
245
  // change current history state, and push it on
244
246
  if (history_state.ajax_pagination === undefined) history_state.ajax_pagination = new Array();
245
- var fieldname = "_" + pagination_name;
247
+ var fieldname = "_" + section_id;
246
248
  if (history_state.ajax_pagination[fieldname] === undefined) history_state.ajax_pagination[fieldname]=1;
247
249
  else history_state.ajax_pagination[fieldname]++;
248
250
  History.pushState(history_state,document.title,pagination_url); // push state
249
251
  }
250
252
  }
251
253
  }
252
- // these special containers are for convenience only, to apply the required data-remote, data-pagination attributes to all links inside
254
+ // these special containers are for convenience only, to apply the required data-remote, data-ajax_section_id attributes to all links inside
253
255
  $(document).on("click", ".ajaxpagination a", function(e) {
254
256
  // ignore if already selected by jquery-ujs
255
257
  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
256
- // find out what data-pagination should be set to
258
+ // find out what data-ajax_section_id should be set to
257
259
  var pagination_container = $(this).closest(".ajaxpagination"); // container of links (use to check for data-pagination first)
258
- var pagination_name = pagination_container.data('pagination');
259
- if (pagination_name === undefined) {
260
- pagination_name = $(this).closest(".paginated_section").attr("id"); // if data-pagination not present, search up the tree for a suitable section
261
- if (pagination_name == null) {
262
- <% if AjaxPagination.warnings %>
263
- alert("AJAX Pagination MISSING_REFERENCE:\nNo pagination section id given for link, and none could be implicitly assigned, AJAX cancelled for this request");
264
- <% end %>
265
- return true; // pagination not set up properly
266
- }
267
- }
260
+ var section_id = pagination_container.data('ajax_section_id');
268
261
 
269
- // set data-remote, data-pagination
262
+ // set data-remote, data-ajax_section_id
270
263
  $(this).attr({'data-remote':'true'}); // needs to be set so that the jquery-ujs selectors work
271
- $(this).data({'remote':'true','pagination':pagination_name}); // needs to be set because attributes only read into jquery's data memory once
264
+ $(this).data({'remote':'true','ajax_section_id':section_id}); // needs to be set because attributes only read into jquery's data memory once
272
265
  if ($(this).data('type') === undefined) { // to be moved to ajax:before filter when https://github.com/rails/jquery-ujs/pull/241 is successful, and jquery-rails minimum version updated
273
266
  $(this).data('type','html'); // AJAX Pagination requests return html be default
274
267
  }
@@ -280,24 +273,24 @@ jQuery(document).ready(function () {
280
273
  return false;
281
274
  });
282
275
  $(document).on("ajax:before","a, " + $.rails.inputChangeSelector, function() {
283
- var pagination_name = $(this).data('pagination');
284
- if (pagination_name === undefined) return true; // this is not an AJAX Pagination AJAX request
285
- $(this).data('params',$.extend($(this).data('params'),{'pagination':pagination_name})); // add data-pagination to the params data
286
- return $.rails.fire(getSection(pagination_name),"ajaxp:before",[this.href,$(this).data('method')]);
276
+ var section_id = $(this).data('ajax_section_id');
277
+ if (section_id === undefined) return true; // this is not an AJAX Pagination AJAX request
278
+ $(this).data('params',$.extend($(this).data('params'),{'ajax_section':section_id})); // add data-pagination to the params data
279
+ return $.rails.fire(getSection(section_id),"ajaxp:before",[this.href,$(this).data('method')]);
287
280
  });
288
281
  $(document).on("ajax:before","form", function() {
289
- var pagination_name = $(this).data('pagination');
290
- if (pagination_name === undefined) return true; // this is not an AJAX Pagination AJAX request
282
+ var section_id = $(this).data('ajax_section_id');
283
+ if (section_id === undefined) return true; // this is not an AJAX Pagination AJAX request
291
284
  // alter action to include pagination parameter in the GET part of the action url
292
- $(this).attr('action',$.param.querystring($(this).attr('action'),{pagination:pagination_name}));
293
- return $.rails.fire(getSection(pagination_name),"ajaxp:before",[$(this).attr('action'),$(this).data('method')]);
285
+ $(this).attr('action',$.param.querystring($(this).attr('action'),{ajax_section:section_id}));
286
+ return $.rails.fire(getSection(section_id),"ajaxp:before",[$(this).attr('action'),$(this).data('method')]);
294
287
  });
295
288
  $(document).on("ajax:beforeSend","a, form, " + $.rails.inputChangeSelector, function (e,jqXHR,settings) {
296
- var pagination_name = $(this).data('pagination');
297
- if (pagination_name === undefined) return true; // this is not an AJAX Pagination AJAX request
298
- if (beforeSendHandler(pagination_name,jqXHR,settings)) {
299
- pushHistory(pagination_name,settings.url);
300
- pagination_loader_state[pagination_name] = settings.url;
289
+ var section_id = $(this).data('ajax_section_id');
290
+ if (section_id === undefined) return true; // this is not an AJAX Pagination AJAX request
291
+ if (beforeSendHandler(section_id,jqXHR,settings)) {
292
+ pushHistory(section_id,settings.url);
293
+ pagination_loader_state[section_id] = settings.url;
301
294
  }
302
295
  return true;
303
296
  });
@@ -332,11 +325,11 @@ jQuery(document).ready(function () {
332
325
  }
333
326
  history_state = state; // we can update our view of the state now
334
327
 
335
- changedsections.sort(); // sort the pagination_names stored in array
328
+ changedsections.sort(); // sort the section_ids stored in array
336
329
  for (var i = 0; i < changedsections.length; i++) {
337
330
  var section = getSection(changedsections[i]);
338
331
  if (section.length == 0) continue; // no longer exists on page (meaning it does not need reloading)
339
- var parentsections = getSectionNames(section.parents(".paginated_section"));
332
+ var parentsections = getSectionNames(section.parents(".ajax_section"));
340
333
  parentsections.sort();
341
334
  // check for intersection
342
335
  if (!intersects(changedsections,parentsections)) { // no intersection, load new content in this section
@@ -350,21 +343,21 @@ jQuery(document).ready(function () {
350
343
  History.Adapter.trigger(window,"popstate"); // update stuff on page load
351
344
 
352
345
  // trigger a loaded event on each section on initial page load
353
- $.rails.fire($(".paginated_section"),"ajaxp:loaded");
346
+ $.rails.fire($(".ajax_section"),"ajaxp:loaded");
354
347
  }
355
348
  else {
356
349
  // AJAX Pagination is disabled, we need to tidy up a few things to keep things working
357
350
 
358
351
  // remove remote attribute globally
359
- $("a[data-pagination]").removeData('remote');
360
- $("a[data-pagination]").removeAttr('data-remote');
361
- $("form[data-pagination]").removeData('remote');
362
- $("form[data-pagination]").removeAttr('data-remote');
352
+ $("a[data-ajax_section_id]").removeData('remote');
353
+ $("a[data-ajax_section_id]").removeAttr('data-remote');
354
+ $("form[data-ajax_section_id]").removeData('remote');
355
+ $("form[data-ajax_section_id]").removeAttr('data-remote');
363
356
 
364
357
  // set an event handler to remove the remote attribute if new content is loaded with AJAX Pagination
365
- $(document).children().add(".paginated_section").delegate("a, input, form","click.rails change.rails submit.rails", function(event) {
358
+ $(document).children().add(".ajax_section").delegate("a, input, form","click.rails change.rails submit.rails", function(event) {
366
359
  var element = $(event.target);
367
- if (element.data('pagination') === undefined) return true;
360
+ if (element.data('ajax_section_id') === undefined) return true;
368
361
  else {
369
362
  element.removeData('remote');
370
363
  element.removeAttr('data-remote');