2 * DO NOT EDIT THIS FILE.
3 * See the following change record for more information,
4 * https://www.drupal.org/node/2815083
8 (function ($, Drupal, drupalSettings) {
9 Drupal.behaviors.ViewsAjaxView = {};
10 Drupal.behaviors.ViewsAjaxView.attach = function () {
11 if (drupalSettings && drupalSettings.views && drupalSettings.views.ajaxViews) {
12 var ajaxViews = drupalSettings.views.ajaxViews;
13 Object.keys(ajaxViews || {}).forEach(function (i) {
14 Drupal.views.instances[i] = new Drupal.views.ajaxView(ajaxViews[i]);
21 Drupal.views.instances = {};
23 Drupal.views.ajaxView = function (settings) {
24 var selector = '.js-view-dom-id-' + settings.view_dom_id;
25 this.$view = $(selector);
27 var ajaxPath = drupalSettings.views.ajax_path;
29 if (ajaxPath.constructor.toString().indexOf('Array') !== -1) {
30 ajaxPath = ajaxPath[0];
33 var queryString = window.location.search || '';
34 if (queryString !== '') {
35 queryString = queryString.slice(1).replace(/q=[^&]+&?|&?render=[^&]+/, '');
36 if (queryString !== '') {
37 queryString = (/\?/.test(ajaxPath) ? '&' : '?') + queryString;
41 this.element_settings = {
42 url: ajaxPath + queryString,
47 progress: { type: 'fullscreen' }
50 this.settings = settings;
52 this.$exposed_form = $('form#views-exposed-form-' + settings.view_name.replace(/_/g, '-') + '-' + settings.view_display_id.replace(/_/g, '-'));
53 this.$exposed_form.once('exposed-form').each($.proxy(this.attachExposedFormAjax, this));
55 this.$view.filter($.proxy(this.filterNestedViews, this)).once('ajax-pager').each($.proxy(this.attachPagerAjax, this));
57 var selfSettings = $.extend({}, this.element_settings, {
60 element: this.$view.get(0)
62 this.refreshViewAjax = Drupal.ajax(selfSettings);
65 Drupal.views.ajaxView.prototype.attachExposedFormAjax = function () {
67 this.exposedFormAjax = [];
69 $('input[type=submit], input[type=image]', this.$exposed_form).not('[data-drupal-selector=edit-reset]').each(function (index) {
70 var selfSettings = $.extend({}, that.element_settings, {
71 base: $(this).attr('id'),
74 that.exposedFormAjax[index] = Drupal.ajax(selfSettings);
78 Drupal.views.ajaxView.prototype.filterNestedViews = function () {
79 return !this.$view.parents('.view').length;
82 Drupal.views.ajaxView.prototype.attachPagerAjax = function () {
83 this.$view.find('ul.js-pager__items > li > a, th.views-field a, .attachment .views-summary a').each($.proxy(this.attachPagerLinkAjax, this));
86 Drupal.views.ajaxView.prototype.attachPagerLinkAjax = function (id, link) {
89 var href = $link.attr('href');
91 $.extend(viewData, this.settings, Drupal.Views.parseQueryString(href), Drupal.Views.parseViewArgs(href, this.settings.view_base_path));
93 var selfSettings = $.extend({}, this.element_settings, {
98 this.pagerAjax = Drupal.ajax(selfSettings);
101 Drupal.AjaxCommands.prototype.viewsScrollTop = function (ajax, response) {
102 var offset = $(response.selector).offset();
104 var scrollTarget = response.selector;
105 while ($(scrollTarget).scrollTop() === 0 && $(scrollTarget).parent()) {
106 scrollTarget = $(scrollTarget).parent();
109 if (offset.top - 10 < $(scrollTarget).scrollTop()) {
110 $(scrollTarget).animate({ scrollTop: offset.top - 10 }, 500);
113 })(jQuery, Drupal, drupalSettings);