Updated to Drupal 8.5. Core Media not yet in use.
[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       Object.keys(ajaxViews || {}).forEach(function (i) {
14         Drupal.views.instances[i] = new Drupal.views.ajaxView(ajaxViews[i]);
15       });
16     }
17   };
18
19   Drupal.views = {};
20
21   Drupal.views.instances = {};
22
23   Drupal.views.ajaxView = function (settings) {
24     var selector = '.js-view-dom-id-' + settings.view_dom_id;
25     this.$view = $(selector);
26
27     var ajaxPath = drupalSettings.views.ajax_path;
28
29     if (ajaxPath.constructor.toString().indexOf('Array') !== -1) {
30       ajaxPath = ajaxPath[0];
31     }
32
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;
38       }
39     }
40
41     this.element_settings = {
42       url: ajaxPath + queryString,
43       submit: settings,
44       setClick: true,
45       event: 'click',
46       selector: selector,
47       progress: { type: 'fullscreen' }
48     };
49
50     this.settings = settings;
51
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));
54
55     this.$view.filter($.proxy(this.filterNestedViews, this)).once('ajax-pager').each($.proxy(this.attachPagerAjax, this));
56
57     var selfSettings = $.extend({}, this.element_settings, {
58       event: 'RefreshView',
59       base: this.selector,
60       element: this.$view.get(0)
61     });
62     this.refreshViewAjax = Drupal.ajax(selfSettings);
63   };
64
65   Drupal.views.ajaxView.prototype.attachExposedFormAjax = function () {
66     var that = this;
67     this.exposedFormAjax = [];
68
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'),
72         element: this
73       });
74       that.exposedFormAjax[index] = Drupal.ajax(selfSettings);
75     });
76   };
77
78   Drupal.views.ajaxView.prototype.filterNestedViews = function () {
79     return !this.$view.parents('.view').length;
80   };
81
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));
84   };
85
86   Drupal.views.ajaxView.prototype.attachPagerLinkAjax = function (id, link) {
87     var $link = $(link);
88     var viewData = {};
89     var href = $link.attr('href');
90
91     $.extend(viewData, this.settings, Drupal.Views.parseQueryString(href), Drupal.Views.parseViewArgs(href, this.settings.view_base_path));
92
93     var selfSettings = $.extend({}, this.element_settings, {
94       submit: viewData,
95       base: false,
96       element: link
97     });
98     this.pagerAjax = Drupal.ajax(selfSettings);
99   };
100
101   Drupal.AjaxCommands.prototype.viewsScrollTop = function (ajax, response) {
102     var offset = $(response.selector).offset();
103
104     var scrollTarget = response.selector;
105     while ($(scrollTarget).scrollTop() === 0 && $(scrollTarget).parent()) {
106       scrollTarget = $(scrollTarget).parent();
107     }
108
109     if (offset.top - 10 < $(scrollTarget).scrollTop()) {
110       $(scrollTarget).animate({ scrollTop: offset.top - 10 }, 500);
111     }
112   };
113 })(jQuery, Drupal, drupalSettings);