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 (context, settings) {
11 if (settings && settings.views && settings.views.ajaxViews) {
12 var ajaxViews = settings.views.ajaxViews;
14 Object.keys(ajaxViews || {}).forEach(function (i) {
15 Drupal.views.instances[i] = new Drupal.views.ajaxView(ajaxViews[i]);
19 Drupal.behaviors.ViewsAjaxView.detach = function (context, settings, trigger) {
20 if (trigger === 'unload') {
21 if (settings && settings.views && settings.views.ajaxViews) {
22 var ajaxViews = settings.views.ajaxViews;
24 Object.keys(ajaxViews || {}).forEach(function (i) {
25 var selector = '.js-view-dom-id-' + ajaxViews[i].view_dom_id;
26 if ($(selector, context).length) {
27 delete Drupal.views.instances[i];
28 delete settings.views.ajaxViews[i];
37 Drupal.views.instances = {};
39 Drupal.views.ajaxView = function (settings) {
40 var selector = '.js-view-dom-id-' + settings.view_dom_id;
41 this.$view = $(selector);
43 var ajaxPath = drupalSettings.views.ajax_path;
45 if (ajaxPath.constructor.toString().indexOf('Array') !== -1) {
46 ajaxPath = ajaxPath[0];
49 var queryString = window.location.search || '';
50 if (queryString !== '') {
51 queryString = queryString.slice(1).replace(/q=[^&]+&?|&?render=[^&]+/, '');
52 if (queryString !== '') {
53 queryString = (/\?/.test(ajaxPath) ? '&' : '?') + queryString;
57 this.element_settings = {
58 url: ajaxPath + queryString,
63 progress: { type: 'fullscreen' }
66 this.settings = settings;
68 this.$exposed_form = $('form#views-exposed-form-' + settings.view_name.replace(/_/g, '-') + '-' + settings.view_display_id.replace(/_/g, '-'));
69 this.$exposed_form.once('exposed-form').each($.proxy(this.attachExposedFormAjax, this));
71 this.$view.filter($.proxy(this.filterNestedViews, this)).once('ajax-pager').each($.proxy(this.attachPagerAjax, this));
73 var selfSettings = $.extend({}, this.element_settings, {
76 element: this.$view.get(0)
78 this.refreshViewAjax = Drupal.ajax(selfSettings);
81 Drupal.views.ajaxView.prototype.attachExposedFormAjax = function () {
83 this.exposedFormAjax = [];
85 $('input[type=submit], input[type=image]', this.$exposed_form).not('[data-drupal-selector=edit-reset]').each(function (index) {
86 var selfSettings = $.extend({}, that.element_settings, {
87 base: $(this).attr('id'),
90 that.exposedFormAjax[index] = Drupal.ajax(selfSettings);
94 Drupal.views.ajaxView.prototype.filterNestedViews = function () {
95 return !this.$view.parents('.view').length;
98 Drupal.views.ajaxView.prototype.attachPagerAjax = function () {
99 this.$view.find('ul.js-pager__items > li > a, th.views-field a, .attachment .views-summary a').each($.proxy(this.attachPagerLinkAjax, this));
102 Drupal.views.ajaxView.prototype.attachPagerLinkAjax = function (id, link) {
105 var href = $link.attr('href');
107 $.extend(viewData, this.settings, Drupal.Views.parseQueryString(href), Drupal.Views.parseViewArgs(href, this.settings.view_base_path));
109 var selfSettings = $.extend({}, this.element_settings, {
114 this.pagerAjax = Drupal.ajax(selfSettings);
117 Drupal.AjaxCommands.prototype.viewsScrollTop = function (ajax, response) {
118 var offset = $(response.selector).offset();
120 var scrollTarget = response.selector;
121 while ($(scrollTarget).scrollTop() === 0 && $(scrollTarget).parent()) {
122 scrollTarget = $(scrollTarget).parent();
125 if (offset.top - 10 < $(scrollTarget).scrollTop()) {
126 $(scrollTarget).animate({ scrollTop: offset.top - 10 }, 500);
129 })(jQuery, Drupal, drupalSettings);