2009-05-17 11:16:51 +00:00
|
|
|
/**
|
2017-05-19 22:12:53 +00:00
|
|
|
* DO NOT EDIT THIS FILE.
|
|
|
|
* See the following change record for more information,
|
2017-05-23 14:30:14 +00:00
|
|
|
* https://www.drupal.org/node/2815083
|
2017-05-19 22:12:53 +00:00
|
|
|
* @preserve
|
|
|
|
**/
|
2015-06-05 20:17:55 +00:00
|
|
|
|
2013-09-21 23:39:42 +00:00
|
|
|
(function ($, Drupal, drupalSettings) {
|
2014-01-27 21:41:32 +00:00
|
|
|
Drupal.behaviors.ViewsAjaxView = {};
|
2020-01-30 09:08:38 +00:00
|
|
|
|
2018-07-13 22:09:39 +00:00
|
|
|
Drupal.behaviors.ViewsAjaxView.attach = function (context, settings) {
|
|
|
|
if (settings && settings.views && settings.views.ajaxViews) {
|
2021-12-18 06:12:16 +00:00
|
|
|
const {
|
|
|
|
views: {
|
|
|
|
ajaxViews
|
|
|
|
}
|
|
|
|
} = settings;
|
|
|
|
Object.keys(ajaxViews || {}).forEach(i => {
|
2018-01-03 23:25:46 +00:00
|
|
|
Drupal.views.instances[i] = new Drupal.views.ajaxView(ajaxViews[i]);
|
|
|
|
});
|
2013-10-09 05:04:56 +00:00
|
|
|
}
|
2014-01-27 21:41:32 +00:00
|
|
|
};
|
2020-01-30 09:08:38 +00:00
|
|
|
|
2021-12-18 06:12:16 +00:00
|
|
|
Drupal.behaviors.ViewsAjaxView.detach = (context, settings, trigger) => {
|
2018-07-13 22:09:39 +00:00
|
|
|
if (trigger === 'unload') {
|
|
|
|
if (settings && settings.views && settings.views.ajaxViews) {
|
2021-12-18 06:12:16 +00:00
|
|
|
const {
|
|
|
|
views: {
|
|
|
|
ajaxViews
|
|
|
|
}
|
|
|
|
} = settings;
|
|
|
|
Object.keys(ajaxViews || {}).forEach(i => {
|
|
|
|
const selector = `.js-view-dom-id-${ajaxViews[i].view_dom_id}`;
|
2020-01-30 09:08:38 +00:00
|
|
|
|
2018-07-13 22:09:39 +00:00
|
|
|
if ($(selector, context).length) {
|
|
|
|
delete Drupal.views.instances[i];
|
|
|
|
delete settings.views.ajaxViews[i];
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2009-05-17 11:16:51 +00:00
|
|
|
|
2014-01-27 21:41:32 +00:00
|
|
|
Drupal.views = {};
|
|
|
|
Drupal.views.instances = {};
|
2009-05-17 11:16:51 +00:00
|
|
|
|
2014-01-27 21:41:32 +00:00
|
|
|
Drupal.views.ajaxView = function (settings) {
|
2021-12-18 06:12:16 +00:00
|
|
|
const selector = `.js-view-dom-id-${settings.view_dom_id}`;
|
2014-01-27 21:41:32 +00:00
|
|
|
this.$view = $(selector);
|
2021-12-18 06:12:16 +00:00
|
|
|
let ajaxPath = drupalSettings.views.ajax_path;
|
2014-01-27 21:41:32 +00:00
|
|
|
|
2017-12-03 16:16:29 +00:00
|
|
|
if (ajaxPath.constructor.toString().indexOf('Array') !== -1) {
|
|
|
|
ajaxPath = ajaxPath[0];
|
2014-01-27 21:41:32 +00:00
|
|
|
}
|
|
|
|
|
2021-12-18 06:12:16 +00:00
|
|
|
let queryString = window.location.search || '';
|
2020-01-30 09:08:38 +00:00
|
|
|
|
2009-05-17 11:16:51 +00:00
|
|
|
if (queryString !== '') {
|
2014-01-27 21:41:32 +00:00
|
|
|
queryString = queryString.slice(1).replace(/q=[^&]+&?|&?render=[^&]+/, '');
|
2020-01-30 09:08:38 +00:00
|
|
|
|
2014-01-27 21:41:32 +00:00
|
|
|
if (queryString !== '') {
|
2017-12-03 16:16:29 +00:00
|
|
|
queryString = (/\?/.test(ajaxPath) ? '&' : '?') + queryString;
|
2014-01-27 21:41:32 +00:00
|
|
|
}
|
2009-05-17 11:16:51 +00:00
|
|
|
}
|
2014-01-27 21:41:32 +00:00
|
|
|
|
|
|
|
this.element_settings = {
|
2017-12-03 16:16:29 +00:00
|
|
|
url: ajaxPath + queryString,
|
2014-01-27 21:41:32 +00:00
|
|
|
submit: settings,
|
|
|
|
setClick: true,
|
|
|
|
event: 'click',
|
2021-12-18 06:12:16 +00:00
|
|
|
selector,
|
2020-01-30 09:08:38 +00:00
|
|
|
progress: {
|
|
|
|
type: 'fullscreen'
|
|
|
|
}
|
2014-01-27 21:41:32 +00:00
|
|
|
};
|
|
|
|
this.settings = settings;
|
2021-12-18 06:12:16 +00:00
|
|
|
this.$exposed_form = $(`form#views-exposed-form-${settings.view_name.replace(/_/g, '-')}-${settings.view_display_id.replace(/_/g, '-')}`);
|
2021-08-10 10:05:02 +00:00
|
|
|
once('exposed-form', this.$exposed_form).forEach($.proxy(this.attachExposedFormAjax, this));
|
|
|
|
once('ajax-pager', this.$view.filter($.proxy(this.filterNestedViews, this))).forEach($.proxy(this.attachPagerAjax, this));
|
2021-12-18 06:12:16 +00:00
|
|
|
const selfSettings = $.extend({}, this.element_settings, {
|
2015-05-20 11:02:57 +00:00
|
|
|
event: 'RefreshView',
|
|
|
|
base: this.selector,
|
2016-02-23 10:24:24 +00:00
|
|
|
element: this.$view.get(0)
|
2015-05-20 11:02:57 +00:00
|
|
|
});
|
2017-12-03 16:16:29 +00:00
|
|
|
this.refreshViewAjax = Drupal.ajax(selfSettings);
|
2009-05-17 11:16:51 +00:00
|
|
|
};
|
|
|
|
|
2014-01-27 21:41:32 +00:00
|
|
|
Drupal.views.ajaxView.prototype.attachExposedFormAjax = function () {
|
2021-12-18 06:12:16 +00:00
|
|
|
const that = this;
|
2015-07-22 14:50:11 +00:00
|
|
|
this.exposedFormAjax = [];
|
Issue #1551534 by Lendude, vsujeetkumar, neclimdul, b_sharpe, devert, bcn, henkholtrop, heykarthikwithu, richmac, seanB, casey, mishac, alansaviolobo, idebr, lauriii, dawehner, alexpott, BramDriesen, randell, ilya.no, muka, DamienMcKenna, Dom., dnewkerk, tim-diels, natted, slayne40, Spry_Julia, Jibus, cpliakas, pbouchereau, S3b0uN3t, HongPong, rfbrandsma, grantkruger, sanderwind, borisson_, nerdacus, mglaman, mvwensen, jmickela, droplet: Submit buttons themed as <button> element fail to trigger ajax in Views exposed forms
2021-06-30 18:13:20 +00:00
|
|
|
$('input[type=submit], button[type=submit], input[type=image]', this.$exposed_form).not('[data-drupal-selector=edit-reset]').each(function (index) {
|
2021-12-18 06:12:16 +00:00
|
|
|
const selfSettings = $.extend({}, that.element_settings, {
|
2015-07-22 14:50:11 +00:00
|
|
|
base: $(this).attr('id'),
|
|
|
|
element: this
|
|
|
|
});
|
2017-12-03 16:16:29 +00:00
|
|
|
that.exposedFormAjax[index] = Drupal.ajax(selfSettings);
|
2015-05-20 11:02:57 +00:00
|
|
|
});
|
2014-01-27 21:41:32 +00:00
|
|
|
};
|
2009-05-17 11:16:51 +00:00
|
|
|
|
2014-01-27 21:41:32 +00:00
|
|
|
Drupal.views.ajaxView.prototype.filterNestedViews = function () {
|
2016-11-21 13:21:00 +00:00
|
|
|
return !this.$view.parents('.view').length;
|
2014-01-27 21:41:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Drupal.views.ajaxView.prototype.attachPagerAjax = function () {
|
2017-05-19 22:12:53 +00:00
|
|
|
this.$view.find('ul.js-pager__items > li > a, th.views-field a, .attachment .views-summary a').each($.proxy(this.attachPagerLinkAjax, this));
|
2014-01-27 21:41:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Drupal.views.ajaxView.prototype.attachPagerLinkAjax = function (id, link) {
|
2021-12-18 06:12:16 +00:00
|
|
|
const $link = $(link);
|
|
|
|
const viewData = {};
|
|
|
|
const href = $link.attr('href');
|
2017-05-19 22:12:53 +00:00
|
|
|
$.extend(viewData, this.settings, Drupal.Views.parseQueryString(href), Drupal.Views.parseViewArgs(href, this.settings.view_base_path));
|
2021-12-18 06:12:16 +00:00
|
|
|
const selfSettings = $.extend({}, this.element_settings, {
|
2015-05-20 11:02:57 +00:00
|
|
|
submit: viewData,
|
|
|
|
base: false,
|
2016-02-23 10:24:24 +00:00
|
|
|
element: link
|
2015-05-20 11:02:57 +00:00
|
|
|
});
|
2017-12-03 16:16:29 +00:00
|
|
|
this.pagerAjax = Drupal.ajax(selfSettings);
|
2014-01-27 21:41:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Drupal.AjaxCommands.prototype.viewsScrollTop = function (ajax, response) {
|
2021-12-18 06:12:16 +00:00
|
|
|
const offset = $(response.selector).offset();
|
|
|
|
let scrollTarget = response.selector;
|
2020-01-30 09:08:38 +00:00
|
|
|
|
2014-01-27 21:41:32 +00:00
|
|
|
while ($(scrollTarget).scrollTop() === 0 && $(scrollTarget).parent()) {
|
|
|
|
scrollTarget = $(scrollTarget).parent();
|
|
|
|
}
|
2017-05-19 22:12:53 +00:00
|
|
|
|
2014-01-27 21:41:32 +00:00
|
|
|
if (offset.top - 10 < $(scrollTarget).scrollTop()) {
|
2020-01-30 09:08:38 +00:00
|
|
|
$(scrollTarget).animate({
|
|
|
|
scrollTop: offset.top - 10
|
|
|
|
}, 500);
|
2014-01-27 21:41:32 +00:00
|
|
|
}
|
|
|
|
};
|
2017-05-19 22:12:53 +00:00
|
|
|
})(jQuery, Drupal, drupalSettings);
|