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 for (var i in ajaxViews) {
14 if (ajaxViews.hasOwnProperty(i)) {
15 Drupal.views.instances[i] = new Drupal.views.ajaxView(ajaxViews[i]);
23 Drupal.views.instances = {};
25 Drupal.views.ajaxView = function (settings) {
26 var selector = '.js-view-dom-id-' + settings.view_dom_id;
27 this.$view = $(selector);
29 var ajax_path = drupalSettings.views.ajax_path;
31 if (ajax_path.constructor.toString().indexOf('Array') !== -1) {
32 ajax_path = ajax_path[0];
35 var queryString = window.location.search || '';
36 if (queryString !== '') {
37 queryString = queryString.slice(1).replace(/q=[^&]+&?|&?render=[^&]+/, '');
38 if (queryString !== '') {
39 queryString = (/\?/.test(ajax_path) ? '&' : '?') + queryString;
43 this.element_settings = {
44 url: ajax_path + queryString,
49 progress: { type: 'fullscreen' }
52 this.settings = settings;
54 this.$exposed_form = $('form#views-exposed-form-' + settings.view_name.replace(/_/g, '-') + '-' + settings.view_display_id.replace(/_/g, '-'));
55 this.$exposed_form.once('exposed-form').each($.proxy(this.attachExposedFormAjax, this));
57 this.$view.filter($.proxy(this.filterNestedViews, this)).once('ajax-pager').each($.proxy(this.attachPagerAjax, this));
59 var self_settings = $.extend({}, this.element_settings, {
62 element: this.$view.get(0)
64 this.refreshViewAjax = Drupal.ajax(self_settings);
67 Drupal.views.ajaxView.prototype.attachExposedFormAjax = function () {
69 this.exposedFormAjax = [];
71 $('input[type=submit], input[type=image]', this.$exposed_form).not('[data-drupal-selector=edit-reset]').each(function (index) {
72 var self_settings = $.extend({}, that.element_settings, {
73 base: $(this).attr('id'),
76 that.exposedFormAjax[index] = Drupal.ajax(self_settings);
80 Drupal.views.ajaxView.prototype.filterNestedViews = function () {
81 return !this.$view.parents('.view').length;
84 Drupal.views.ajaxView.prototype.attachPagerAjax = function () {
85 this.$view.find('ul.js-pager__items > li > a, th.views-field a, .attachment .views-summary a').each($.proxy(this.attachPagerLinkAjax, this));
88 Drupal.views.ajaxView.prototype.attachPagerLinkAjax = function (id, link) {
91 var href = $link.attr('href');
93 $.extend(viewData, this.settings, Drupal.Views.parseQueryString(href), Drupal.Views.parseViewArgs(href, this.settings.view_base_path));
95 var self_settings = $.extend({}, this.element_settings, {
100 this.pagerAjax = Drupal.ajax(self_settings);
103 Drupal.AjaxCommands.prototype.viewsScrollTop = function (ajax, response) {
104 var offset = $(response.selector).offset();
106 var scrollTarget = response.selector;
107 while ($(scrollTarget).scrollTop() === 0 && $(scrollTarget).parent()) {
108 scrollTarget = $(scrollTarget).parent();
111 if (offset.top - 10 < $(scrollTarget).scrollTop()) {
112 $(scrollTarget).animate({ scrollTop: offset.top - 10 }, 500);
115 })(jQuery, Drupal, drupalSettings);