ajax_pagination 0.6.2 → 0.6.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,7 @@
1
+ ## v0.6.3
2
+ * Internal spec build changes
3
+ * ajax_pagination.js now requires other javascript dependencies, so developers no longer need to require dependencies as well in application manifest anymore (note, it can still be required - sprockets should ensure only 1 copy of each js file is included)
4
+
1
5
  ## v0.6.2
2
6
  * Added :except and :only options to the ajax_respond class method (to specify actions which trigger responding to AJAX request)
3
7
  * Converted ajax_section method to return symbol instead of string, and using symbols for both sections and actions internally (strings passed into methods will be converted into symbols)
data/README.md CHANGED
@@ -18,13 +18,10 @@ Assuming, you are using the asset pipeline, add to your Gemfile:
18
18
 
19
19
  and run the bundle install command.
20
20
 
21
- Then add to your asset manifests,
21
+ Then add ajax_pagination to your asset manifests,
22
22
 
23
23
  ```js
24
24
  // app/assets/javascripts/application.js
25
- //= require jquery
26
- //= require jquery_ujs
27
- //= require history
28
25
  //= require ajax_pagination
29
26
  ```
30
27
 
@@ -34,7 +31,7 @@ Then add to your asset manifests,
34
31
  */
35
32
  ```
36
33
 
37
- To use this on Rails 3.0, or without using the asset pipeline, read [Installation without the Asset Pipeline](https://github.com/ronalchn/ajax_pagination/wiki/Installing-without-the-Asset-Pipeline) guide.
34
+ To use this on Rails 3.0, or without using the asset pipeline, read the [Installation without the Asset Pipeline](https://github.com/ronalchn/ajax_pagination/wiki/Installing-without-the-Asset-Pipeline) guide.
38
35
 
39
36
  ## Basic Usage
40
37
  In the ActionView, use ajax_section to declare a section, and ajax_link_to to create a link loading content into the section:
@@ -115,4 +112,4 @@ If you want to use this program under a different license, please contact me.
115
112
  All pull requests to my repository will be assumed to assign to me non-exclusive rights for perpertual usage for any use whatsoever for those modifications to Ronald Ping Man Chan. If you do not have the power to assign that right, do not submit a pull request. This allows me to release the software under a more permissible license in the future if I want.
116
113
  Ronald
117
114
 
118
- The software is released under LGPL. The LGPL License on this software means that this Gem can be used in any software (proprietary or otherwise), by using the gem command. However, the gem cannot be included directly in proprietary software (eg. as a plugin), without distributions of the software being under LGPL. Distribution of this Gem must be released under the LGPL as well.
115
+ The software is released under LGPL. This means that this Gem can be used in any software (proprietary or otherwise), by using the gem command for installation. However, the gem cannot be included directly in proprietary software (eg. as a plugin), without distributions of the software being under LGPL. Distribution of this Gem may only be released under a license LGPL is compatible with.
data/Rakefile CHANGED
@@ -9,17 +9,7 @@ task :travis do
9
9
  r30serverport = IO.read(File.expand_path("../spec/R30PORT",__FILE__)).strip # port number that we are using
10
10
 
11
11
  system("cp spec/rails_app/db/development.sqlite3 spec/rails_app/db/test.sqlite3") # take a copy of the development database
12
- system("mkdir -p spec/rails_app/vendor/assets/javascripts") # directory to plonk javascripts from dependent gems
13
- # obtain jquery javascript assets (this is because sprockets cannot find these files otherwise, when going through nested bundles)
14
- # Note that the spec/rails_app/vendor directory is .gitignore because these are generated files
15
- system("cp `bundle show jquery-rails`/vendor/assets/javascripts/* spec/rails_app/vendor/assets/javascripts/")
16
- system("cp `bundle show jquery-historyjs`/vendor/assets/javascripts/* spec/rails_app/vendor/assets/javascripts/")
17
12
 
18
- # recreate assets for rails 3.0 app - delete them first
19
- system("mkdir -p spec/rails30_app/public/javascripts")
20
- system("cp `bundle show jquery-rails`/vendor/assets/javascripts/* spec/rails30_app/public/javascripts/")
21
- system("cp `bundle show jquery-historyjs`/vendor/assets/javascripts/* spec/rails30_app/public/javascripts/")
22
- system("(cd spec/rails30_app/ && bundle exec rails generate ajax_pagination:assets --force)")
23
13
  Bundler.with_clean_env do
24
14
  # startup test servers
25
15
  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
@@ -1,3 +1,3 @@
1
1
  module AjaxPagination
2
- VERSION = "0.6.2"
2
+ VERSION = "0.6.3"
3
3
  end
@@ -1,3 +1,6 @@
1
+ //= require jquery
2
+ //= require jquery_ujs
3
+ //= require history
1
4
  //= require jquery.ba-bbq
2
5
  //= require jquery.url
3
6
 
@@ -5,4 +5,6 @@ db/*.sqlite3
5
5
  tmp/
6
6
  log/*.log
7
7
  vendor
8
-
8
+ /public/javascripts
9
+ /public/stylesheets/ajax_pagination*
10
+ /public/images/ajax-loader.gif
@@ -8,8 +8,8 @@
8
8
  <%= javascript_include_tag "jquery" %>
9
9
  <%= javascript_include_tag "jquery_ujs" %>
10
10
  <%= javascript_include_tag "json2" %>
11
- <%= javascript_include_tag "history_core" %>
12
- <%= javascript_include_tag "history_adapter_jquery" %>
11
+ <%= javascript_include_tag "history" %>
12
+ <%= javascript_include_tag "history.adapter.jquery" %>
13
13
  <%= javascript_include_tag "jquery.ba-bbq" %>
14
14
  <%= javascript_include_tag "jquery.url" %>
15
15
  <%= javascript_include_tag "ajax_pagination" %>
@@ -0,0 +1,8 @@
1
+ require 'rails/generators'
2
+
3
+ # regenerates assets into /public/javascripts, /public/stylesheets, /public/images folders
4
+
5
+ Rails::Generators.invoke("jquery:install",["-f"]);
6
+ Rails::Generators.invoke("historyjs:install",["-f"]);
7
+ Rails::Generators.invoke("ajax_pagination:assets",["-f"]);
8
+
@@ -14,4 +14,3 @@
14
14
  //= require jquery_ujs
15
15
  //= require history
16
16
  //= require ajax_pagination
17
- //= require_tree .
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ajax_pagination
3
3
  version: !ruby/object:Gem::Version
4
- hash: 3
4
+ hash: 1
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 6
9
- - 2
10
- version: 0.6.2
9
+ - 3
10
+ version: 0.6.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ronald Ping Man Chan
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-03-16 00:00:00 Z
18
+ date: 2012-03-17 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: rake
@@ -205,6 +205,7 @@ files:
205
205
  - spec/rails30_app/config/environments/production.rb
206
206
  - spec/rails30_app/config/environments/test.rb
207
207
  - spec/rails30_app/config/initializers/ajax_pagination.rb
208
+ - spec/rails30_app/config/initializers/assets.rb
208
209
  - spec/rails30_app/config/initializers/backtrace_silencers.rb
209
210
  - spec/rails30_app/config/initializers/inflections.rb
210
211
  - spec/rails30_app/config/initializers/mime_types.rb
@@ -217,21 +218,6 @@ files:
217
218
  - spec/rails30_app/public/422.html
218
219
  - spec/rails30_app/public/500.html
219
220
  - spec/rails30_app/public/favicon.ico
220
- - spec/rails30_app/public/images/ajax-loader.gif
221
- - spec/rails30_app/public/javascripts/ajax_pagination.js
222
- - spec/rails30_app/public/javascripts/history.js
223
- - spec/rails30_app/public/javascripts/history_adapter_jquery.js
224
- - spec/rails30_app/public/javascripts/history_core.js
225
- - spec/rails30_app/public/javascripts/history_html4.js
226
- - spec/rails30_app/public/javascripts/jquery-ui.js
227
- - spec/rails30_app/public/javascripts/jquery-ui.min.js
228
- - spec/rails30_app/public/javascripts/jquery.ba-bbq.js
229
- - spec/rails30_app/public/javascripts/jquery.js
230
- - spec/rails30_app/public/javascripts/jquery.min.js
231
- - spec/rails30_app/public/javascripts/jquery.url.js
232
- - spec/rails30_app/public/javascripts/jquery_ujs.js
233
- - spec/rails30_app/public/javascripts/json2.js
234
- - spec/rails30_app/public/stylesheets/ajax_pagination.css
235
221
  - spec/rails30_app/public/stylesheets/application.css
236
222
  - spec/rails30_app/public/stylesheets/scaffold.css
237
223
  - spec/rails30_app/script/rails
@@ -1,370 +0,0 @@
1
- //= require jquery.ba-bbq
2
- //= require jquery.url
3
-
4
- /*
5
- * AJAX Pagination v0.6.2.alpha: Ajaxifying your navigation
6
- * https://github.com/ronalchn/ajax_pagination
7
- *
8
- * Copyright (c) 2012 Ronald Ping Man Chan
9
- * Distributed under the LGPL license
10
- *
11
- * Although the ajax_pagination gem as a whole is distributed under LGPL, I am expressly permitting users to minify and concatenate this javascript file
12
- * with other javascript files, as long as it is through an automatic asset management process (eg. Sprockets), and the automatic asset
13
- * management process obtains this javascript file as a separate file via dynamically linked means (ie. with this file left in the separately
14
- * installed ajax_pagination gem).
15
- * ~ Ronald Chan
16
- */
17
- jQuery(document).ready(function () {
18
- function minVersion(version) {
19
- var $vrs = window.jQuery.fn.jquery.split('.'),
20
- min = version.split('.');
21
- for (var i=0, len=min.length; i<len; i++) {
22
- if ($vrs[i]) {
23
- min[i] = parseInt(min[i],10);
24
- $vrs[i] = parseInt($vrs[i],10);
25
- if ($vrs[i] < min[i]) return false;
26
- else if ($vrs[i] > min[i]) return true;
27
- }
28
- else return false;
29
- }
30
- return true;
31
- }
32
-
33
-
34
- if (!(History && minVersion('1.7'))) { // dependencies missing
35
- var missing = "";
36
- if (!History) missing += "\nHistory.js not installed";
37
- if (!minVersion('1.7')) missing += "\njQuery version 1.7+ not installed. Currently installed: jQuery " + window.jQuery.fn.jquery;
38
- alert("AJAX Pagination MISSING_DEPENDENCIES:" + missing);
39
- }
40
-
41
- (function( $ ) { // on document ready
42
- if (History && History.enabled && minVersion('1.7')) {
43
- ///////////////////////////////////
44
- ////// $.ajax_pagination API //////
45
- ///////////////////////////////////
46
- // selector function for pagination object
47
- $.ajax_pagination = function (section_id) {
48
- return new ajax_section_object(section_id);
49
- };
50
- $.ajax_pagination.version = '0.6.2.alpha';
51
- $.ajax_pagination.enabled = true;
52
- function ajax_section_object(section_id) {
53
- this.get = function(url,options) {
54
- if (options === undefined) options = {};
55
- if (options.history === undefined) options.history = true;
56
- swapPage(section_id,url,options.history);
57
- }
58
- this.exists = function() {
59
- return $('#' + section_id).length == 1;
60
- }
61
- }
62
- /////////////////////////////
63
- ////// Basic Internals //////
64
- /////////////////////////////
65
- var pagination_loader_state = new Array(); // the page we are waiting for
66
- var pagination_url = location.href; // url we came from, so we can see transitions of the url
67
- var history_state = {ajax_pagination_set:true}; // current history state
68
-
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();
79
- // setup loading look
80
- var img = document.createElement("IMG");
81
- if (ajax_section.data("pagination") !== undefined && ajax_section.data("pagination").image !== undefined) img.src = ajax_section.data("pagination").image;
82
- else img.src = "/images/ajax-loader.gif";
83
- var margin = Math.round(height>400?50:(height/8));
84
- $(img).addClass('ajaxpagination-loader');
85
- var div = document.createElement("DIV");
86
- $(div).addClass('ajaxpagination-loadzone');
87
- $(div).append("<div class=\"margin-top\" />").append(img);
88
- ajax_loadzone.wrapInner("<div class=\"ajaxpagination-oldcontent\" />");
89
- ajax_loadzone.append(div);
90
- }
91
- }
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);
96
- }
97
- }
98
- }
99
- function getSection(section_id) {
100
- var id = "#" + section_id; // element id we are looking for
101
- return $(id);
102
- }
103
- function getSectionName(section) {
104
- var id = section.attr("id");
105
- if (id === undefined) return undefined; // no name
106
- return id; // id = section_id
107
- }
108
- function getSectionNames(sections) {
109
- var names = new Array();
110
- sections.each(function () {
111
- names.push(getSectionName($(this)));
112
- });
113
- return names;
114
- }
115
- function intersects(a,b) { // do the arrays a and b intersect?
116
- var i=0, j=0;
117
- while (i < a.length && j < b.length) {
118
- if (a[i]<b[j]) i++;
119
- else if (a[i]>b[j]) j++;
120
- else return true; // intersects
121
- }
122
- return false; // doesn't intersect
123
- }
124
- // whether change of state is a reload
125
- function isReload(section_id,from,to) {
126
- if (from == to) return true; // same url - always a reload
127
- var section = getSection(section_id);
128
- if (section.length == 0) return false;
129
-
130
- // if data-pagination is not defined, then no reload can be detected
131
- if (section.data('pagination') === undefined || section.data('pagination').reload === undefined) return false;
132
-
133
- var reload = section.data('pagination').reload;
134
- if (!(reload instanceof Array)) reload = new Array(reload);
135
- for (i=0;i<reload.length;i++) {
136
- if (reload[i].query !== undefined) {
137
- if ($.deparam.querystring(from)[reload[i].query] !== $.deparam.querystring(to)[reload[i].query]) return false;
138
- }
139
- if (reload[i].urlregex !== undefined) {
140
- var fstr = from, tstr = to;
141
- if (reload[i].urlpart !== undefined) {
142
- fstr = $.url(from,true).attr(reload[i].urlpart);
143
- tstr = $.url(to,true).attr(reload[i].urlpart);
144
- if (typeof(fstr)!="string" || typeof(tstr)!="string") continue; // skip
145
- }
146
- var index = 0;
147
- if (reload[i].regexindex !== undefined) index = reload[i].regexindex;
148
- var regex = new RegExp(reload[i].urlregex);
149
- var frommatch = regex.exec(fstr), tomatch = regex.exec(tstr);
150
- if (frommatch != null && frommatch.length>=index) frommatch = frommatch[index];
151
- if (tomatch != null && tomatch.length>=index) tomatch = tomatch[index];
152
- if (frommatch !== tomatch) return false;
153
- }
154
- }
155
- return true;
156
- }
157
- // when this function is used beforeSend of an AJAX request, will use the resulting content in a section of the page
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
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
162
- var requesturl = settings.url;
163
- var countid = $('[id="' + section_id + '"]').length;
164
- if (countid != 1) { // something wrong, cannot find unique section to load page into
165
-
166
- alert("AJAX Pagination UNIQUE_SECTION_NOT_FOUND:\nExpected one section with id of " + section_id + ", found " + countid);
167
-
168
- return false; // continue AJAX normally
169
- }
170
- if (!$.rails.fire(getSection(section_id),"ajaxp:beforeSend",[jqXHR,settings])) return false;
171
- display_pagination_loader(section_id);
172
- // register callbacks for other events
173
- jqXHR.done(function(data, textStatus, jqXHR) {
174
- if (requesturl != pagination_loader_state[section_id]) return; // ignore stale content
175
- if (jqXHR.status == 200 && jqXHR.getResponseHeader('Location') !== null) { // special AJAX redirect
176
- var redirecturl = jqXHR.getResponseHeader('Location');
177
- swapPage(section_id,redirecturl);
178
- pagination_url = redirecturl;
179
- History.replaceState(history_state,document.title,redirecturl); // state not changed
180
- return;
181
- }
182
- // find matching element id in data, after removing script tags
183
- var page = $("<div />");
184
- page[0].innerHTML = data; // put response in DOM without executing scripts
185
-
186
- // if page contains a title, use it
187
- var title = page.find("title");
188
- if (title.length>0) History.replaceState(history_state,title.html(),location.href);
189
-
190
- // get page contents
191
- var content = page.find(id);
192
- if (content.length>0) {
193
- content = content.html();
194
-
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.");
196
-
197
- }
198
- else { // otherwise use all the content, including any scripts - we consider scripts specifically returned in the partial probably should be re-run
199
- content = page.find("body"); // does not tend to work since browsers strip out the html, head, body tags
200
- if (content.length>0) content = content.html(); // if it has a body tag, only include its contents (for full html structure), leaving out <head> etc sections.
201
- else content = page.html(); // otherwise include the whole html snippet
202
- }
203
-
204
- if ($.rails.fire(getSection(section_id),"ajaxp:done",[content])) $(id).html(content);
205
-
206
- delete pagination_loader_state[section_id]; // not waiting for page anymore
207
-
208
- $.rails.fire(getSection(section_id),"ajaxp:loaded");
209
- });
210
- jqXHR.fail(function(jqXHR, textStatus, errorThrown) {
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);
213
-
214
- delete pagination_loader_state[section_id]; // not waiting for page anymore
215
-
216
- $.rails.fire(getSection(section_id),"ajaxp:loaded");
217
- });
218
- return true;
219
- }
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)
221
- if (history === undefined) history = false;
222
- // send our own ajax request, and tie it into the beforeSendHandler used for jquery-ujs as well
223
- if (!$.rails.fire(getSection(section_id),"ajaxp:before",[requesturl,undefined])) return false;
224
- $.ajax({url: requesturl, data: {ajax_section:section_id},
225
- dataType: 'html',
226
- beforeSend: function (jqXHR,settings) {
227
- var result = beforeSendHandler(section_id,jqXHR,settings);
228
- if (result) {
229
- if (history) pushHistory(section_id,settings.url);
230
- pagination_loader_state[section_id] = settings.url; // remember which page number we are waiting for
231
- }
232
- return result;
233
- }
234
- });
235
- }
236
- function pushHistory(section_id,url) {
237
- var data = $("#" + section_id).data("pagination");
238
- if (data === undefined || data.history === undefined || data.history) { // check that history is not disabled
239
- // construct visible url
240
- var data = $.deparam.querystring($.url(url).attr('query'));
241
- delete data['ajax_section'];
242
- pagination_url = $.param.querystring(url,data,2);
243
- if (isReload(section_id,url,location.href)) History.replaceState(history_state,document.title,pagination_url);
244
- else { // not just a reload of current page, so do actual pushState
245
- // change current history state, and push it on
246
- if (history_state.ajax_pagination === undefined) history_state.ajax_pagination = new Array();
247
- var fieldname = "_" + section_id;
248
- if (history_state.ajax_pagination[fieldname] === undefined) history_state.ajax_pagination[fieldname]=1;
249
- else history_state.ajax_pagination[fieldname]++;
250
- History.pushState(history_state,document.title,pagination_url); // push state
251
- }
252
- }
253
- }
254
- // these special containers are for convenience only, to apply the required data-remote, data-ajax_section_id attributes to all links inside
255
- $(document).on("click", ".ajaxpagination a", function(e) {
256
- // ignore if already selected by jquery-ujs
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
258
- // find out what data-ajax_section_id should be set to
259
- var pagination_container = $(this).closest(".ajaxpagination"); // container of links (use to check for data-pagination first)
260
- var section_id = pagination_container.data('ajax_section_id');
261
-
262
- // set data-remote, data-ajax_section_id
263
- $(this).attr({'data-remote':'true'}); // needs to be set so that the jquery-ujs selectors work
264
- $(this).data({'remote':'true','ajax_section_id':section_id}); // needs to be set because attributes only read into jquery's data memory once
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
266
- $(this).data('type','html'); // AJAX Pagination requests return html be default
267
- }
268
- // stop this event from having further effect (because we do not know if jquery-ujs's event handler executed before or after us)
269
- e.preventDefault();
270
- e.stopImmediatePropagation();
271
- // pass it on the jquery-ujs
272
- $.rails.handleRemote($(this));
273
- return false;
274
- });
275
- $(document).on("ajax:before","a, " + $.rails.inputChangeSelector, function() {
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')]);
280
- });
281
- $(document).on("ajax:before","form", function() {
282
- var section_id = $(this).data('ajax_section_id');
283
- if (section_id === undefined) return true; // this is not an AJAX Pagination AJAX request
284
- // alter action to include pagination parameter in the GET part of the action url
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')]);
287
- });
288
- $(document).on("ajax:beforeSend","a, form, " + $.rails.inputChangeSelector, function (e,jqXHR,settings) {
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;
294
- }
295
- return true;
296
- });
297
- History.Adapter.bind(window,'popstate',function(e){ // popstate, but can work with hash changes as well
298
- //var from = pagination_url, to = location.href; // from what state to what other state
299
- var state = History.getState().data || {};
300
- state.ajax_pagination = state.ajax_pagination || {};
301
- history_state.ajax_pagination = history_state.ajax_pagination || {};
302
- if (!state.ajax_pagination_set) { // page first visited (if refresh, state remains)
303
- state.ajax_pagination = history_state.ajax_pagination; // put current known state in
304
- state.ajax_pagination_set = true; // special flag so that we know its touched
305
- History.replaceState(state,document.title,location.href);
306
- return;
307
- }
308
- var allsections = {};
309
- for (var field in state.ajax_pagination) {
310
- //if (getSection(field.substr(1)).length == 0) delete state.ajax_pagination[field]; // section no longer exists in current page, so can be deleted
311
- // edit it cannot be deleted anymore, because if history changes, section tree node not necessarily reloaded
312
- allsections[field] = true;
313
- }
314
- for (var field in history_state.ajax_pagination) allsections[field] = true;
315
-
316
- var changedsections = new Array();
317
- for (var section in allsections) {
318
- var from = history_state.ajax_pagination[section] || 0;
319
- var to = state.ajax_pagination[section] || 0;
320
- if (from != to) {
321
- // schedule for loading only if not a refresh (changing browser history does not cause a refresh unless it is explicitly requested)
322
- //alert('testing ' + section);
323
- if (!isReload(section.substr(1),location.href,pagination_url)) changedsections.push(section.substr(1)); // this section changed
324
- }
325
- }
326
- history_state = state; // we can update our view of the state now
327
-
328
- changedsections.sort(); // sort the section_ids stored in array
329
- for (var i = 0; i < changedsections.length; i++) {
330
- var section = getSection(changedsections[i]);
331
- if (section.length == 0) continue; // no longer exists on page (meaning it does not need reloading)
332
- var parentsections = getSectionNames(section.parents(".ajax_section"));
333
- parentsections.sort();
334
- // check for intersection
335
- if (!intersects(changedsections,parentsections)) { // no intersection, load new content in this section
336
- swapPage(changedsections[i],location.href);
337
- }
338
- }
339
-
340
- pagination_url = location.href; // update url (new url recognised)
341
- });
342
-
343
- History.Adapter.trigger(window,"popstate"); // update stuff on page load
344
-
345
- // trigger a loaded event on each section on initial page load
346
- $.rails.fire($(".ajax_section"),"ajaxp:loaded");
347
- }
348
- else {
349
- // AJAX Pagination is disabled, we need to tidy up a few things to keep things working
350
-
351
- // remove remote attribute globally
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');
356
-
357
- // set an event handler to remove the remote attribute if new content is loaded with AJAX Pagination
358
- $(document).children().add(".ajax_section").delegate("a, input, form","click.rails change.rails submit.rails", function(event) {
359
- var element = $(event.target);
360
- if (element.data('ajax_section_id') === undefined) return true;
361
- else {
362
- element.removeData('remote');
363
- element.removeAttr('data-remote');
364
- }
365
- }); // note using delegate for this instance for backwards compatibility, since might be disabled due to old jQuery version
366
-
367
- }
368
- })( jQuery );
369
- });
370
-