Problem/Motivation
While working on this issue #2035643: Views ajax support for the views content display I had some minor issue with the current ajax handling.
The handling fails if there are multiple elements that match the views css selector.
This isn't really a problem with the default views handling but with the Views Content module provided by ctools it's possible to split a view into pieces.
Thus I've made some small changes to ensure the ajax handling doesn't fail in such a case.
Proposed resolution
To avoid that the pager links trigger the loading multiple times on a single click use once()
instead each()
when registering the event handler.
To avoid that the viewsScrollTop
throws an JS error and breaks the whole ajax handling add a check if offset
is really usable.
Remaining tasks
reviews needed
User interface changes
None
API changes
None
Related Issues
Comment | File | Size | Author |
---|---|---|---|
#8 | views-more_flexible_defensive_ajax_handling-2035657-8.patch | 2.74 KB | Andrew Answer |
|
Comments
Comment #1
das-peter CreditAttribution: das-peter commentedUpdated patch.
The current ajax handling has some drawbacks:
exposedFormAjax
,pagerAjax
,refreshViewAjax
are lost after an ajax request is handled.Thus the ajax configuration isn't accessible anymore for other scripts.
I've added code to store the value of those variables in the jQuery data handling now. That keeps it accessible.
The variables are still in place, but I wouldn't reccommend to rely on those.
I've changed the code to register the events / ajaxs handling that way that it can deal with multiple elements with the views dom id.
Comment #2
dawehnerThe other drupal.ajax instance is stored on Drupal.views.instances, maybe we should unify that somehow? I don't know whether data attributes or actual variables are the better approach.
Comment #3
das-peter CreditAttribution: das-peter commentedFinally I found some time to continue working on this.
To avoid storing the ajax configurations in the elements using e.g.
$('input[type=submit], button[type=submit], input[type=image]', this.$exposed_form).data('exposedFormAjax', this.exposedFormAjax);
I had to ensure thatDrupal.views.instances[i]
really is unique and it contains all the settings even if the handling is triggered multiple times for the same view.This can happen if e.g. the ctools views content type is used (The patched one (#2035643: Views ajax support for the views content display) or this sandbox: https://drupal.org/sandbox/daspeter/2149085).
With the patch you can access and manipulate the ajax object before firing them:
Code from this sandbox: https://drupal.org/sandbox/daspeter/2165417
Comment #4
das-peter CreditAttribution: das-peter commentedI just had the possibility to test this in another, very simple, setup and it works like a charm (exposed filter, sort and ajax facets).
Comment #5
oxyc CreditAttribution: oxyc as a volunteer commentedReroll (without removing the trigger)
Comment #6
Chris Matthews CreditAttribution: Chris Matthews as a volunteer commentedThe 3 year old patch in #5 to ajax_view.js does not apply to the latest views 7.x-3.x-dev and if still relevant needs to be rerolled.
Comment #7
Andrew Answer CreditAttribution: Andrew Answer as a volunteer commentedPatch rerolled.
Comment #8
Andrew Answer CreditAttribution: Andrew Answer as a volunteer commentedFix.