? 591302.3.patch ? 591302.4.patch Index: views.module =================================================================== RCS file: /cvs/drupal/contributions/modules/views/views.module,v retrieving revision 1.341.4.39 diff -u -p -r1.341.4.39 views.module --- views.module 26 Oct 2010 05:05:27 -0000 1.341.4.39 +++ views.module 28 Oct 2010 19:47:16 -0000 @@ -180,9 +180,11 @@ function views_menu() { $items['views/ajax'] = array( 'title' => 'Views', 'page callback' => 'views_ajax', + 'delivery callback' => 'ajax_deliver', 'access callback' => TRUE, 'description' => 'Ajax callback for view loading.', 'type' => MENU_CALLBACK, + 'file' => 'includes/ajax.inc', ); // Path is not admin/structure/views due to menu complications with the wildcards from // the generic ajax callback. Index: includes/ajax.inc =================================================================== RCS file: /cvs/drupal/contributions/modules/views/includes/ajax.inc,v retrieving revision 1.20.4.13 diff -u -p -r1.20.4.13 ajax.inc --- includes/ajax.inc 17 Oct 2010 10:42:44 -0000 1.20.4.13 +++ includes/ajax.inc 28 Oct 2010 19:47:16 -0000 @@ -26,44 +26,32 @@ function views_ajax() { $arg = explode('/', $_REQUEST['view_path']); - if ($arg[0] == 'admin' || (variable_get('node_admin_theme', '0') && $arg[0] == 'node' && ($arg[1] == 'add' || $arg[2] == 'edit'))) { - global $custom_theme; - $custom_theme = variable_get('admin_theme', '0'); - drupal_add_css(drupal_get_path('module', 'system') .'/admin.css', 'module'); - } // Load the view. - if ($view = views_get_view($name)) { - if ($view->access($display_id)) { - - // Fix 'q' for paging. - if (!empty($path)) { - $_GET['q'] = $path; - } + $view = views_get_view($name); + if ($view && $view->access($display_id)) { + // Fix 'q' for paging. + if (!empty($path)) { + $_GET['q'] = $path; + } - // Override the display's pager_element with the one actually used. - if (isset($pager_element)) { - $view->display[$display_id]->handler->set_option('pager_element', $pager_element); - } - // Reuse the same DOM id so it matches that in Drupal.settings. - $view->dom_id = $dom_id; + // Override the display's pager_element with the one actually used. + if (isset($pager_element)) { + $view->display[$display_id]->handler->set_option('pager_element', $pager_element); + } + // Reuse the same DOM id so it matches that in Drupal.settings. + $view->dom_id = $dom_id; - $errors = $view->validate(); - if ($errors === TRUE) { - $commands[] = ajax_command_replace('#' . $domid, $view->get_title()); - $commands[] = ajax_command_replace('#' . $dom_id, $view->preview($display_id, $args)); - } - else { - foreach ($errors as $error) { - drupal_set_message($error, 'error'); - } + $errors = $view->validate(); + if ($errors === TRUE) { + $commands[] = ajax_command_replace('.view-dom-id-' . $dom_id, $view->preview($display_id, $args)); + } + else { + foreach ($errors as $error) { + drupal_set_message($error, 'error'); } } } - - $messages = theme('status_messages'); - $commands[] = ajax_command_replace('.views-messages', $messages); - - return $commands; + return array('#type' => 'ajax', '#commands' => $commands); } } Index: js/ajax_view.js =================================================================== RCS file: /cvs/drupal/contributions/modules/views/js/ajax_view.js,v retrieving revision 1.19.4.3 diff -u -p -r1.19.4.3 ajax_view.js --- js/ajax_view.js 11 May 2010 21:05:11 -0000 1.19.4.3 +++ js/ajax_view.js 28 Oct 2010 19:47:16 -0000 @@ -7,40 +7,11 @@ */ (function ($) { -Drupal.Views.Ajax = Drupal.Views.Ajax || {}; - -/** - * An ajax responder that accepts a packet of JSON data and acts appropriately. - * - * The following fields control behavior. - * - 'display': Display the associated data in the view area. - */ -Drupal.Views.Ajax.ajaxViewResponse = function(target, response) { - - if (response.debug) { - alert(response.debug); - } - - var $view = $(target); - - // Check the 'display' for data. - if (response.status && response.display) { - var $newView = $(response.display); - $view.replaceWith($newView); - $view = $newView; - Drupal.attachBehaviors($view.parent()); - } - - if (response.messages) { - // Show any messages (but first remove old ones, if there are any). - $view.find('.views-messages').remove().end().prepend(response.messages); - } -}; - /** - * Ajax behavior for views. + * Attaches the AJAX behavior to Views exposed filter forms and key View links. */ -Drupal.behaviors.ViewsAjaxView = function() { +Drupal.behaviors.ViewsAjaxView = {}; +Drupal.behaviors.ViewsAjaxView.attach = function() { if (Drupal.settings && Drupal.settings.views && Drupal.settings.views.ajaxViews) { var ajax_path = Drupal.settings.views.ajax_path; // If there are multiple views this might've ended up showing up multiple times. @@ -56,44 +27,38 @@ Drupal.behaviors.ViewsAjaxView = functio view = '.view-id-' + settings.view_name + '.view-display-id-' + settings.view_display_id; } - // Process exposed filter forms. $('form#views-exposed-form-' + settings.view_name.replace(/_/g, '-') + '-' + settings.view_display_id.replace(/_/g, '-')) .filter(':not(.views-processed)') .each(function () { - // remove 'q' from the form; it's there for clean URLs - // so that it submits to the right place with regular submit - // but this method is submitting elsewhere. - $('input[name=q]', this).remove(); - var form = this; - // ajaxSubmit doesn't accept a data argument, so we have to - // pass additional fields this way. - $.each(settings, function(key, setting) { - $(form).append(''); + var button = $('input[type=submit]', this); + button.form = this; + + var ajax = new Drupal.ajax($(button).attr('id'), button, { + url: ajax_path, + submit: settings, + setClick: true, + event: 'click', + selector: view, + progress: { type: 'throbber' } }); + // Override HTTP method type and beforeSerialize method. + // + // Note that by using HTTP GET and overriding beforeSerialize() the + // request bypasses adding ajax_html_ids and ajax_page_state to the + // the AJAX request. This is necessary as including these state vars + // often (almost always?) blows the URL length limit on many servers. + // + // @TODO: Without these state vars, the ajax response cannot + // dynamically add js/css to the page and it may have trouble properly + // generating DOM ids generated by drupal_html_id(). Fixing this + // problem requires reducing the amount of information that needs to be + // passed back to Drupal and the functionality surrounding these two + // states. + ajax.options.type = 'GET'; + ajax.beforeSerialize = function(element_settings, options) { return; }; }) .addClass('views-processed') - .submit(function () { - $('input[type=submit], button', this).after(' '); - var object = this; - $(this).ajaxSubmit({ - url: ajax_path, - type: 'GET', - success: function(response) { - // Call all callbacks. - if (response.__callbacks) { - $.each(response.__callbacks, function(i, callback) { - eval(callback)(view, response); - }); - $('.views-throbbing', object).remove(); - } - }, - error: function() { alert(Drupal.t("An error occurred at @path.", {'@path': ajax_path})); $('.views-throbbing', object).remove(); }, - dataType: 'json' - }); - - return false; - }); $(view).filter(':not(.views-processed)') // Don't attach to nested views. Doing so would attach multiple behaviors @@ -121,48 +86,25 @@ Drupal.behaviors.ViewsAjaxView = functio // Extract argument data from the URL. Drupal.Views.parseViewArgs($(this).attr('href'), settings.view_base_path) ); - $(this).click(function () { - $.extend(viewData, Drupal.Views.parseViewArgs($(this).attr('href'), settings.view_base_path)); - $(this).addClass('views-throbbing'); - $.ajax({ - url: ajax_path, - type: 'GET', - data: viewData, - success: function(response) { - $(this).removeClass('views-throbbing'); - // Scroll to the top of the view. This will allow users - // to browse newly loaded content after e.g. clicking a pager - // link. - var offset = $(target).offset(); - // We can't guarantee that the scrollable object should be - // the body, as the view could be embedded in something - // more complex such as a modal popup. Recurse up the DOM - // and scroll the first element that has a non-zero top. - var scrollTarget = target; - while ($(scrollTarget).scrollTop() == 0 && $(scrollTarget).parent()) { - scrollTarget = $(scrollTarget).parent() - } - // Only scroll upward - if (offset.top - 10 < $(scrollTarget).scrollTop()) { - $(scrollTarget).animate({scrollTop: (offset.top - 10)}, 500); - } - // Call all callbacks. - if (response.__callbacks) { - $.each(response.__callbacks, function(i, callback) { - eval(callback)(target, response); - }); - } - }, - error: function() { $(this).removeClass('views-throbbing'); alert(Drupal.t("An error occurred at @path.", {'@path': ajax_path})); }, - dataType: 'json' - }); - return false; + // For anchor tags, these will go to the target of the anchor rather + // than the usual location. + $.extend(viewData, Drupal.Views.parseViewArgs($(this).attr('href'), settings.view_base_path)); + + var ajax = new Drupal.ajax(false, this, { + url: ajax_path, + submit: viewData, + event: 'click', + selector: view }); + + // Override HTTP method type and beforeSerialize method. + // See note above. + ajax.options.type = 'GET'; + ajax.beforeSerialize = function(element_settings, options) { return; }; }); // .each function () { }); // $view.filter().each }); // .each Drupal.settings.views.ajaxViews } // if }; - })(jQuery); Index: theme/theme.inc =================================================================== RCS file: /cvs/drupal/contributions/modules/views/theme/theme.inc,v retrieving revision 1.84.4.27 diff -u -p -r1.84.4.27 theme.inc --- theme/theme.inc 12 Oct 2010 21:31:52 -0000 1.84.4.27 +++ theme/theme.inc 28 Oct 2010 19:47:16 -0000 @@ -146,6 +146,7 @@ function template_preprocess_views_view( ); drupal_add_js($settings, 'setting'); + drupal_add_js('misc/ajax.js', array('group' => JS_LIBRARY)); views_add_js('ajax_view'); } // Flatten the classes to a string for the template file.