From e72d22b180c56409e3413cf3e30503ed920bb674 Mon Sep 17 00:00:00 2001 From: Mark Carver Date: Tue, 23 Apr 2013 19:19:34 -0500 Subject: Issue #1907472 by Mark Carver: Pager in views with ajax --- includes/pager.inc | 2 +- includes/theme.inc | 10 +++++++++- js/ajax_view.js | 12 ++++++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 js/ajax_view.js diff --git a/includes/pager.inc b/includes/pager.inc index cab241f..4b4301b 100644 --- a/includes/pager.inc +++ b/includes/pager.inc @@ -80,7 +80,7 @@ function bootstrap_pager($variables) { if ($i > 1) { $items[] = array( 'class' => array('pager-ellipsis', 'disabled'), - 'data' => '', + 'data' => '', ); } // Now generate the actual pager piece. diff --git a/includes/theme.inc b/includes/theme.inc index f5c511f..ce6f2da 100644 --- a/includes/theme.inc +++ b/includes/theme.inc @@ -298,13 +298,21 @@ function bootstrap_js_alter(&$js) { libraries_load('bootstrap', 'minified'); } + $theme_path = drupal_get_path('theme', 'bootstrap'); + // Replace core progress bar JS with the Bootstrap equivilent. if (isset($js['misc/progress.js']) && !empty($js['misc/progress.js'])) { unset($js['misc/progress.js']); - $progress = drupal_get_path('theme', 'bootstrap') . '/js/progress.js'; + $progress = $theme_path . '/js/progress.js'; $js[$progress] = drupal_js_defaults($progress); } + // Fix broken Views AJAX pagers. + if (module_exists('views') && !empty($js[drupal_get_path('module', 'views') . '/js/ajax_view.js'])) { + $ajax_view = $theme_path . '/js/ajax_view.js'; + $js[$ajax_view] = drupal_js_defaults($ajax_view); + } + $js = array_diff_key($js, $excludes); if (theme_get_setting('cdn_bootstrap')) { $files[] = '//netdna.bootstrapcdn.com/twitter-bootstrap/'. theme_get_setting('cdn_bootstrap_version') .'/js/bootstrap.min.js'; diff --git a/js/ajax_view.js b/js/ajax_view.js new file mode 100644 index 0000000..ec6b55d --- /dev/null +++ b/js/ajax_view.js @@ -0,0 +1,12 @@ +(function ($) { + +/** + * Override Views prototype function so it can recognize Bootstrap AJAX pagers. + * Attach the ajax behavior to each link. + */ +Drupal.views.ajaxView.prototype.attachPagerAjax = function() { + this.$view.find('ul.pager > li > a, th.views-field a, .attachment .views-summary a, .pagination ul li a') + .each(jQuery.proxy(this.attachPagerLinkAjax, this)); +}; + +})(jQuery); -- 1.8.2