Chris@0: /** Chris@0: * DO NOT EDIT THIS FILE. Chris@0: * See the following change record for more information, Chris@0: * https://www.drupal.org/node/2815083 Chris@0: * @preserve Chris@0: **/ Chris@0: Chris@0: (function ($, Drupal, drupalSettings) { Chris@0: Drupal.behaviors.ViewsAjaxView = {}; Chris@17: Drupal.behaviors.ViewsAjaxView.attach = function (context, settings) { Chris@17: if (settings && settings.views && settings.views.ajaxViews) { Chris@17: var ajaxViews = settings.views.ajaxViews; Chris@17: Chris@14: Object.keys(ajaxViews || {}).forEach(function (i) { Chris@14: Drupal.views.instances[i] = new Drupal.views.ajaxView(ajaxViews[i]); Chris@14: }); Chris@0: } Chris@0: }; Chris@17: Drupal.behaviors.ViewsAjaxView.detach = function (context, settings, trigger) { Chris@17: if (trigger === 'unload') { Chris@17: if (settings && settings.views && settings.views.ajaxViews) { Chris@17: var ajaxViews = settings.views.ajaxViews; Chris@17: Chris@17: Object.keys(ajaxViews || {}).forEach(function (i) { Chris@17: var selector = '.js-view-dom-id-' + ajaxViews[i].view_dom_id; Chris@17: if ($(selector, context).length) { Chris@17: delete Drupal.views.instances[i]; Chris@17: delete settings.views.ajaxViews[i]; Chris@17: } Chris@17: }); Chris@17: } Chris@17: } Chris@17: }; Chris@0: Chris@0: Drupal.views = {}; Chris@0: Chris@0: Drupal.views.instances = {}; Chris@0: Chris@0: Drupal.views.ajaxView = function (settings) { Chris@0: var selector = '.js-view-dom-id-' + settings.view_dom_id; Chris@0: this.$view = $(selector); Chris@0: Chris@14: var ajaxPath = drupalSettings.views.ajax_path; Chris@0: Chris@14: if (ajaxPath.constructor.toString().indexOf('Array') !== -1) { Chris@14: ajaxPath = ajaxPath[0]; Chris@0: } Chris@0: Chris@0: var queryString = window.location.search || ''; Chris@0: if (queryString !== '') { Chris@0: queryString = queryString.slice(1).replace(/q=[^&]+&?|&?render=[^&]+/, ''); Chris@0: if (queryString !== '') { Chris@14: queryString = (/\?/.test(ajaxPath) ? '&' : '?') + queryString; Chris@0: } Chris@0: } Chris@0: Chris@0: this.element_settings = { Chris@14: url: ajaxPath + queryString, Chris@0: submit: settings, Chris@0: setClick: true, Chris@0: event: 'click', Chris@0: selector: selector, Chris@0: progress: { type: 'fullscreen' } Chris@0: }; Chris@0: Chris@0: this.settings = settings; Chris@0: Chris@0: this.$exposed_form = $('form#views-exposed-form-' + settings.view_name.replace(/_/g, '-') + '-' + settings.view_display_id.replace(/_/g, '-')); Chris@0: this.$exposed_form.once('exposed-form').each($.proxy(this.attachExposedFormAjax, this)); Chris@0: Chris@0: this.$view.filter($.proxy(this.filterNestedViews, this)).once('ajax-pager').each($.proxy(this.attachPagerAjax, this)); Chris@0: Chris@14: var selfSettings = $.extend({}, this.element_settings, { Chris@0: event: 'RefreshView', Chris@0: base: this.selector, Chris@0: element: this.$view.get(0) Chris@0: }); Chris@14: this.refreshViewAjax = Drupal.ajax(selfSettings); Chris@0: }; Chris@0: Chris@0: Drupal.views.ajaxView.prototype.attachExposedFormAjax = function () { Chris@0: var that = this; Chris@0: this.exposedFormAjax = []; Chris@0: Chris@0: $('input[type=submit], input[type=image]', this.$exposed_form).not('[data-drupal-selector=edit-reset]').each(function (index) { Chris@14: var selfSettings = $.extend({}, that.element_settings, { Chris@0: base: $(this).attr('id'), Chris@0: element: this Chris@0: }); Chris@14: that.exposedFormAjax[index] = Drupal.ajax(selfSettings); Chris@0: }); Chris@0: }; Chris@0: Chris@0: Drupal.views.ajaxView.prototype.filterNestedViews = function () { Chris@0: return !this.$view.parents('.view').length; Chris@0: }; Chris@0: Chris@0: Drupal.views.ajaxView.prototype.attachPagerAjax = function () { Chris@0: this.$view.find('ul.js-pager__items > li > a, th.views-field a, .attachment .views-summary a').each($.proxy(this.attachPagerLinkAjax, this)); Chris@0: }; Chris@0: Chris@0: Drupal.views.ajaxView.prototype.attachPagerLinkAjax = function (id, link) { Chris@0: var $link = $(link); Chris@0: var viewData = {}; Chris@0: var href = $link.attr('href'); Chris@0: Chris@0: $.extend(viewData, this.settings, Drupal.Views.parseQueryString(href), Drupal.Views.parseViewArgs(href, this.settings.view_base_path)); Chris@0: Chris@14: var selfSettings = $.extend({}, this.element_settings, { Chris@0: submit: viewData, Chris@0: base: false, Chris@0: element: link Chris@0: }); Chris@14: this.pagerAjax = Drupal.ajax(selfSettings); Chris@0: }; Chris@0: Chris@0: Drupal.AjaxCommands.prototype.viewsScrollTop = function (ajax, response) { Chris@0: var offset = $(response.selector).offset(); Chris@0: Chris@0: var scrollTarget = response.selector; Chris@0: while ($(scrollTarget).scrollTop() === 0 && $(scrollTarget).parent()) { Chris@0: scrollTarget = $(scrollTarget).parent(); Chris@0: } Chris@0: Chris@0: if (offset.top - 10 < $(scrollTarget).scrollTop()) { Chris@0: $(scrollTarget).animate({ scrollTop: offset.top - 10 }, 500); Chris@0: } Chris@0: }; Chris@0: })(jQuery, Drupal, drupalSettings);