Security update for Core, with self-updated composer
[yaffs-website] / web / core / modules / views / js / ajax_view.js
1 /**
2 * DO NOT EDIT THIS FILE.
3 * See the following change record for more information,
4 * https://www.drupal.org/node/2815083
5 * @preserve
6 **/
7
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]);
16         }
17       }
18     }
19   };
20
21   Drupal.views = {};
22
23   Drupal.views.instances = {};
24
25   Drupal.views.ajaxView = function (settings) {
26     var selector = '.js-view-dom-id-' + settings.view_dom_id;
27     this.$view = $(selector);
28
29     var ajax_path = drupalSettings.views.ajax_path;
30
31     if (ajax_path.constructor.toString().indexOf('Array') !== -1) {
32       ajax_path = ajax_path[0];
33     }
34
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;
40       }
41     }
42
43     this.element_settings = {
44       url: ajax_path + queryString,
45       submit: settings,
46       setClick: true,
47       event: 'click',
48       selector: selector,
49       progress: { type: 'fullscreen' }
50     };
51
52     this.settings = settings;
53
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));
56
57     this.$view.filter($.proxy(this.filterNestedViews, this)).once('ajax-pager').each($.proxy(this.attachPagerAjax, this));
58
59     var self_settings = $.extend({}, this.element_settings, {
60       event: 'RefreshView',
61       base: this.selector,
62       element: this.$view.get(0)
63     });
64     this.refreshViewAjax = Drupal.ajax(self_settings);
65   };
66
67   Drupal.views.ajaxView.prototype.attachExposedFormAjax = function () {
68     var that = this;
69     this.exposedFormAjax = [];
70
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'),
74         element: this
75       });
76       that.exposedFormAjax[index] = Drupal.ajax(self_settings);
77     });
78   };
79
80   Drupal.views.ajaxView.prototype.filterNestedViews = function () {
81     return !this.$view.parents('.view').length;
82   };
83
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));
86   };
87
88   Drupal.views.ajaxView.prototype.attachPagerLinkAjax = function (id, link) {
89     var $link = $(link);
90     var viewData = {};
91     var href = $link.attr('href');
92
93     $.extend(viewData, this.settings, Drupal.Views.parseQueryString(href), Drupal.Views.parseViewArgs(href, this.settings.view_base_path));
94
95     var self_settings = $.extend({}, this.element_settings, {
96       submit: viewData,
97       base: false,
98       element: link
99     });
100     this.pagerAjax = Drupal.ajax(self_settings);
101   };
102
103   Drupal.AjaxCommands.prototype.viewsScrollTop = function (ajax, response) {
104     var offset = $(response.selector).offset();
105
106     var scrollTarget = response.selector;
107     while ($(scrollTarget).scrollTop() === 0 && $(scrollTarget).parent()) {
108       scrollTarget = $(scrollTarget).parent();
109     }
110
111     if (offset.top - 10 < $(scrollTarget).scrollTop()) {
112       $(scrollTarget).animate({ scrollTop: offset.top - 10 }, 500);
113     }
114   };
115 })(jQuery, Drupal, drupalSettings);