diff -u b/js/ajax_view.js b/js/ajax_view.js
--- b/js/ajax_view.js
+++ b/js/ajax_view.js
@@ -14,42 +14,15 @@
Drupal.views.instances[i] = new Drupal.views.ajaxView(settings);
});
+ var originalHash = window.location.hash;
+ $(window).bind('hashchange', function(e) {
+ $('body').removeOnce('views-hash');
+ Drupal.views.ajaxView.prototype.ajaxUpdatePage(originalHash);
+ originalHash = location.hash;
+ });
+
+ Drupal.views.ajaxView.prototype.ajaxUpdatePage(originalHash);
- // Trigger the previous filtered search if the filter form id is in the URL hash.
- if (window.location.hash) {
- hash = Drupal.Views.getLocationHash();
- // Do we have a hash that corresponds to an auto-submit form?
- $exposed_form_submitted = $('form#views-exposed-form-'+ hash.f);
-
- if ($exposed_form_submitted.hasClass('ctools-auto-submit-full-form')) {
- $('body').once(function() {
- if (Drupal.Views.isNumeric(hash.p)) {
- var pageValue = $('').val(hash.p)
- $exposed_form_submitted.prepend(pageValue);
- }
- for (v in hash) {
- if (hash.hasOwnProperty(v)) {
- //Set the form element to the value form the hash.
- $exposed_form_submitted.find(('[name='+ v +']')).val(hash[v]);
- }
- }
- // @see Drupal.views.ajaxView.prototype.attachExposedFormAjax
- $exposed_form_submitted.find('input, select').first().change();
- });
- } else if (Drupal.Views.isNumeric(hash.p)) {
- // No filters, but check for page specified in location hash.
- $('body').once(function () {
- $('ul.pager .pager-item a').each( function() {
- var args = Drupal.Views.parseQueryString(this.href);
- if (hash.p == args.page) {
- $(this).click();
- return false;
- }
- return true;
- });
- });
- }
- }// end if hash
}
};
@@ -111,6 +84,57 @@
this.refreshViewAjax = new Drupal.ajax(this.selector, this.$view, self_settings);
};
+Drupal.views.ajaxView.prototype.ajaxUpdatePage = function(originalHash) {
+
+ // Trigger the previous filtered search if the filter form id is in the URL hash.
+ if (window.location.hash) {
+ hash = Drupal.Views.getLocationHash();
+ // Do we have a hash that corresponds to an auto-submit form?
+ $exposed_form_submitted = $('form#views-exposed-form-'+ hash.f);
+
+ if ($exposed_form_submitted.hasClass('ctools-auto-submit-full-form')) {
+ $('body').once('views-hash', function() {
+ if (Drupal.Views.isNumeric(hash.p)) {
+ var pageValue = $('').val(hash.p)
+ $exposed_form_submitted.prepend(pageValue);
+ }
+ for (v in hash) {
+ if (hash.hasOwnProperty(v)) {
+ // Set the form element to the value from the hash.
+ $exposed_form_submitted.find(('[name='+ v +']')).val(hash[v]);
+ }
+ }
+ // @see Drupal.views.ajaxView.prototype.attachExposedFormAjax
+ $exposed_form_submitted.find('input, select').first().change();
+ });
+ } else if (Drupal.Views.isNumeric(hash.p)) {
+ // No filters, but check for page specified in location hash.
+ $('body').once('views-hash', function () {
+ $('ul.pager .pager__item a').each( function() {
+ var args = Drupal.Views.parseQueryString(this.href);
+ if (hash.p == args.page) {
+ $(this).click();
+ return false;
+ }
+ return true;
+ });
+ });
+ }
+ } // end if hash
+ else {
+
+ // Handle the case of being on a different page of the view and
+ // pressing the back button until there is no hash.
+ var original = Drupal.Views.parseQueryString(originalHash.replace(/^#/g, ''));
+ if (Drupal.Views.isNumeric(original.p)) {
+ $('body').once('views-hash', function () {
+ $('ul.pager .pager__item--first a').click();
+ return false;
+ });
+ }
+ }
+}
+
/**
* Exposed forms use this to append their id as a URL hash so we can
* resubmit the form when the browser's "Back" button is used.
@@ -155,7 +179,7 @@
};
/**
- * Attach the ajax behavior to a singe link.
+ * Attach the ajax behavior to a single link.
*/
Drupal.views.ajaxView.prototype.attachPagerLinkAjax = function(id, link) {
var $link = $(link);
@@ -178,7 +202,7 @@
this.element_settings.submit = viewData;
this.pagerAjax = new Drupal.ajax(false, $link, this.element_settings);
- //Attach click handler to update hash
+ // Attach click handler to update hash
$link.click(this.pagerHandler);
};
diff -u b/js/base.js b/js/base.js
--- b/js/base.js
+++ b/js/base.js
@@ -116,7 +116,20 @@
Drupal.Views.updateLocationHash = function (data) {
hash = Drupal.Views.getLocationHash();
$.extend(hash, data);
- window.location.hash = decodeURIComponent($.param(hash));
+
+ // Iterate over URL parameters and unset any empty parameters, in order
+ // to prevent redundant history entries.
+ var hashObj = $.deparam($.param(hash));
+ $.each(hashObj, function(index, value) {
+ if (value == '') {
+ delete hashObj[index];
+ }
+ });
+
+ // Set new location hash, but only if it differs from the existing hash.
+ if (window.location.hash.replace(/^#/g, '') != $.param(hashObj)) {
+ window.location.hash = $.param(hashObj);
+ }
}
Drupal.Views.getLocationHash = function () {
only in patch2:
unchanged:
--- a/views.module
+++ b/views.module
@@ -1119,6 +1119,7 @@ function views_add_js($file) {
static $base = TRUE, $ajax = TRUE;
if ($base) {
drupal_add_js(drupal_get_path('module', 'views') . "/js/base.js");
+ drupal_add_js('/misc/jquery.ba-bbq.js');
$base = FALSE;
}
if ($ajax && in_array($file, array('ajax', 'ajax_view'))) {