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.
@@ -4,11 +4,13 @@ module SetAjaxSection
4
4
  def ajax_section= (name)
5
5
  @_ajax_section = name
6
6
  end
7
+ def controller_path
8
+ "dummycontroller"
9
+ end
7
10
  end
8
11
 
9
12
  describe AjaxPagination::ControllerAdditions do
10
- def stub_pagination(name)
11
- @controller.stub!(:params).and_return({:pagination => name, :controller => "dummycontroller"})
13
+ def stub_ajax_section(name)
12
14
  @controller.ajax_section = name
13
15
  end
14
16
  def stub_request_format_html(bool)
@@ -33,40 +35,40 @@ describe AjaxPagination::ControllerAdditions do
33
35
  end
34
36
 
35
37
  describe 'ajax_respond' do
36
- it 'should not render when pagination parameter not defined' do
38
+ it 'should not render when section_id parameter not defined' do
37
39
  @controller.ajax_respond(@formatter).should be_false
38
- @controller.ajax_respond(@formatter, :pagination => :page).should be_false
39
- @controller.ajax_respond(@formatter, :pagination => 'page').should be_false
40
- @controller.ajax_respond(@formatter, :pagination => 'page2').should be_false
40
+ @controller.ajax_respond(@formatter, :section_id => :page).should be_false
41
+ @controller.ajax_respond(@formatter, :section_id => 'page').should be_false
42
+ @controller.ajax_respond(@formatter, :section_id => 'page2').should be_false
41
43
  @formatter.html.should == 0
42
44
  end
43
- it 'should render when pagination parameter matches' do
44
- stub_pagination('global')
45
+ it 'should render when section_id parameter matches' do
46
+ stub_ajax_section('global')
45
47
  @controller.ajax_respond(@formatter).should be_true
46
48
  @formatter.html.should == 1 # detects html function was called once (but checking also calls the function) ...
47
- stub_pagination('page')
48
- @controller.ajax_respond(@formatter, :pagination => :page).should be_true
49
+ stub_ajax_section('page')
50
+ @controller.ajax_respond(@formatter, :section_id => :page).should be_true
49
51
  @formatter.html.should == 3 # ... which is why the next check should be 2 more html function calls
50
- @controller.ajax_respond(@formatter, :pagination => 'page').should be_true
52
+ @controller.ajax_respond(@formatter, :section_id => 'page').should be_true
51
53
  @formatter.html.should == 5
52
- stub_pagination('pageX')
53
- @controller.ajax_respond(@formatter, :pagination => 'pageX').should be_true
54
+ stub_ajax_section('pageX')
55
+ @controller.ajax_respond(@formatter, :section_id => 'pageX').should be_true
54
56
  @formatter.html.should == 7
55
57
  stub_lookup_context(['matching_partial_found'])
56
- @controller.ajax_respond(@formatter, :pagination => 'pageX').should be_true
58
+ @controller.ajax_respond(@formatter, :section_id => 'pageX').should be_true
57
59
  @formatter.html.should == 9
58
- stub_pagination('global')
60
+ stub_ajax_section('global')
59
61
  @controller.ajax_respond(@formatter).should be_true
60
62
  @formatter.html.should == 11
61
63
 
62
64
  end
63
- it 'should not render when pagination parameter does not match' do
64
- stub_pagination('notpage')
65
+ it 'should not render when section_id parameter does not match' do
66
+ stub_ajax_section('notpage')
65
67
  @controller.ajax_respond(@formatter).should be_false
66
- @controller.ajax_respond(@formatter, :pagination => :page).should be_false
67
- @controller.ajax_respond(@formatter, :pagination => 'page').should be_false
68
- stub_pagination('notpageX')
69
- @controller.ajax_respond(@formatter, :pagination => 'pageX').should be_false
68
+ @controller.ajax_respond(@formatter, :section_id => :page).should be_false
69
+ @controller.ajax_respond(@formatter, :section_id => 'page').should be_false
70
+ stub_ajax_section('notpageX')
71
+ @controller.ajax_respond(@formatter, :section_id => 'pageX').should be_false
70
72
  @formatter.html.should == 0
71
73
  end
72
74
  end
@@ -75,26 +77,26 @@ describe AjaxPagination::ControllerAdditions do
75
77
  it 'should display partial when format is not html' do
76
78
  @controller.ajax_section_displayed?.should be_true
77
79
  end
78
- it 'should display partial when format is html but pagination is not defined' do
80
+ it 'should display partial when format is html but section_id is not defined' do
79
81
  stub_request_format_html(true)
80
82
  @controller.ajax_section_displayed?.should be_true
81
83
  end
82
- it 'should display partial when .html?pagination=pagename' do
84
+ it 'should display partial when .html?section_id=pagename' do
83
85
  stub_request_format_html(true)
84
- stub_pagination('global')
86
+ stub_ajax_section('global')
85
87
  @controller.ajax_section_displayed?.should be_true
86
- stub_pagination('page2')
88
+ stub_ajax_section('page2')
87
89
  @controller.ajax_section_displayed?('page2').should be_true
88
- stub_pagination('page3')
90
+ stub_ajax_section('page3')
89
91
  @controller.ajax_section_displayed?(:page3).should be_true
90
92
  end
91
93
  it 'should not display partial when .html?pagination!=pagename' do
92
94
  stub_request_format_html(true)
93
- stub_pagination('notpage')
95
+ stub_ajax_section('notpage')
94
96
  @controller.ajax_section_displayed?.should be_false
95
- stub_pagination('notpage2')
97
+ stub_ajax_section('notpage2')
96
98
  @controller.ajax_section_displayed?('page2').should be_false
97
- stub_pagination('notpage3')
99
+ stub_ajax_section('notpage3')
98
100
  @controller.ajax_section_displayed?(:page3).should be_false
99
101
  end
100
102
  end
@@ -18,11 +18,11 @@ describe AjaxPagination::HelperAdditions do
18
18
  @view.should_receive(:render).with('global')
19
19
  @view.ajax_section
20
20
  @view.should_receive(:render).with('page2')
21
- @view.ajax_section :pagination => 'page2' # renders the partial named :pagination if :partial not defined
21
+ @view.ajax_section :id => 'page2' # renders the partial named :id if :partial not defined
22
22
  @view.should_receive(:render).with('page3')
23
23
  @view.ajax_section :render => 'page3' # if partial defined, renders partial
24
24
  @view.should_receive(:render).with('pageX')
25
- @view.ajax_section :pagination => 'page10', :render => 'pageX' # even if pagination also defined as different value
25
+ @view.ajax_section :id => 'page10', :render => 'pageX' # even if id also defined as different value
26
26
  end
27
27
  end
28
28
  describe 'ajax_loadzone' do
@@ -21,14 +21,6 @@ describe 'javascript warnings', :js => true do
21
21
  page.should have_content("Disabled")
22
22
  end
23
23
 
24
- it 'warns about missing reference' do
25
- visit("http://localhost:#{SERVERPORT}/pages/warnings")
26
- find("#missingreferencelink").click
27
- alertmsg = page.driver.browser.switch_to.alert.text
28
- alertmsg.should include("MISSING_REFERENCE")
29
- page.driver.browser.switch_to.alert.accept
30
- end
31
-
32
24
  it 'warns about reference to more than one section of same id' do
33
25
  visit("http://localhost:#{SERVERPORT}/pages/warnings")
34
26
  find("#doublesectionlink").click
@@ -0,0 +1,96 @@
1
+ PATH
2
+ remote: ../..
3
+ specs:
4
+ ajax_pagination (0.6.1.alpha)
5
+ jquery-historyjs
6
+ jquery-rails (>= 1.0.17)
7
+ rails (>= 3.0)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ abstract (1.0.0)
13
+ actionmailer (3.0.12)
14
+ actionpack (= 3.0.12)
15
+ mail (~> 2.2.19)
16
+ actionpack (3.0.12)
17
+ activemodel (= 3.0.12)
18
+ activesupport (= 3.0.12)
19
+ builder (~> 2.1.2)
20
+ erubis (~> 2.6.6)
21
+ i18n (~> 0.5.0)
22
+ rack (~> 1.2.5)
23
+ rack-mount (~> 0.6.14)
24
+ rack-test (~> 0.5.7)
25
+ tzinfo (~> 0.3.23)
26
+ activemodel (3.0.12)
27
+ activesupport (= 3.0.12)
28
+ builder (~> 2.1.2)
29
+ i18n (~> 0.5.0)
30
+ activerecord (3.0.12)
31
+ activemodel (= 3.0.12)
32
+ activesupport (= 3.0.12)
33
+ arel (~> 2.0.10)
34
+ tzinfo (~> 0.3.23)
35
+ activeresource (3.0.12)
36
+ activemodel (= 3.0.12)
37
+ activesupport (= 3.0.12)
38
+ activesupport (3.0.12)
39
+ arel (2.0.10)
40
+ builder (2.1.2)
41
+ erubis (2.6.6)
42
+ abstract (>= 1.0.0)
43
+ i18n (0.5.0)
44
+ jquery-historyjs (0.2.3)
45
+ railties (>= 3.0)
46
+ thor (>= 0.14)
47
+ jquery-rails (1.0.19)
48
+ railties (~> 3.0)
49
+ thor (~> 0.14)
50
+ json (1.6.5)
51
+ mail (2.2.19)
52
+ activesupport (>= 2.3.6)
53
+ i18n (>= 0.4.0)
54
+ mime-types (~> 1.16)
55
+ treetop (~> 1.4.8)
56
+ mime-types (1.17.2)
57
+ polyglot (0.3.3)
58
+ rack (1.2.5)
59
+ rack-mount (0.6.14)
60
+ rack (>= 1.0.0)
61
+ rack-test (0.5.7)
62
+ rack (>= 1.0)
63
+ rails (3.0.12)
64
+ actionmailer (= 3.0.12)
65
+ actionpack (= 3.0.12)
66
+ activerecord (= 3.0.12)
67
+ activeresource (= 3.0.12)
68
+ activesupport (= 3.0.12)
69
+ bundler (~> 1.0)
70
+ railties (= 3.0.12)
71
+ railties (3.0.12)
72
+ actionpack (= 3.0.12)
73
+ activesupport (= 3.0.12)
74
+ rake (>= 0.8.7)
75
+ rdoc (~> 3.4)
76
+ thor (~> 0.14.4)
77
+ rake (0.9.2.2)
78
+ rdoc (3.12)
79
+ json (~> 1.4)
80
+ thor (0.14.6)
81
+ treetop (1.4.10)
82
+ polyglot
83
+ polyglot (>= 0.3.1)
84
+ tzinfo (0.3.32)
85
+ will_paginate (3.0.3)
86
+
87
+ PLATFORMS
88
+ ruby
89
+
90
+ DEPENDENCIES
91
+ ajax_pagination!
92
+ jquery-historyjs
93
+ jquery-rails
94
+ json
95
+ rails (~> 3.0.0)
96
+ will_paginate
@@ -2,7 +2,7 @@
2
2
  //= require jquery.url
3
3
 
4
4
  /*
5
- * AJAX Pagination: Ajaxifying your navigation
5
+ * AJAX Pagination v0.6.1.alpha: 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
- $.ajax_pagination.version = '0.6.0';
50
+ $.ajax_pagination.version = '0.6.1.alpha';
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 = "/images/ajax-loader.gif";
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 - 20) {
93
- $(document).scrollTop(paginated_section.offset().top - 20);
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 - 20) {
95
+ $(document).scrollTop(ajax_section.offset().top - 20);
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
 
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
 
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
 
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
 
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
-
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
-
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');