Skip to content
Snippets Groups Projects

Issue #3441168: Remove jQuery dependency

4 unresolved threads
3 files
+ 38
42
Compare changes
  • Side-by-side
  • Inline
Files
3
+ 14
17
/**
* @file
* Allows views to be loaded via data attributes..
* Allows views to be loaded via data attributes.
*/
(function ($, Drupal) {
(function (Drupal, once) {
'use strict';
@@ -10,33 +10,31 @@
attach: function (context) {
// Attach ajax action to any item.
const elements = once('attach-ajax-links', '[data-lv-id]', context);
elements.forEach(this.attachLazyAjax);
elements.forEach(this.attachLazyAjax.bind(this));
},
attachLazyAjax: function (item, idx) {
var $el = $(item);
var view_id = $el.attr('data-lv-id');
var view_display = $el.attr('data-lv-display') || false;
var view_id = item.getAttribute('data-lv-id');
Please register or sign in to reply
var view_display = item.getAttribute('data-lv-display') || false;
// Need a display.
if (!view_id || !view_display) return;
// @todo move these to a defaults extend.
var view_args = $el.attr('data-lv-args') || {};
var view_dom_id = $el.attr('data-lv-target') || 'lazy-view';
var execute = $el.attr('data-lv-execute') || false;
var view_args = item.getAttribute('data-lv-args') || {};
var view_dom_id = item.getAttribute('data-lv-target') || 'lazy-view';
var execute = item.getAttribute('data-lv-execute') || false;
// Allows for not adding the prefix
var target_exists = $('.js-view-dom-id-' + view_dom_id).length;
var target_exists = document.querySelectorAll('.js-view-dom-id-' + view_dom_id).length;
if (!target_exists) {
var $target = $('.' + view_dom_id + ', #' + view_dom_id);
if ($target.length) {
var target = document.querySelector('.' + view_dom_id + ', #' + view_dom_id);
    • Previous jQuery functionality would've supported multiple instances, this should use querySelectorAll() and forEach to add the class.

Please register or sign in to reply
if (target) {
target.classList.add('js-view-dom-id-' + view_dom_id);
target_exists = true;
$target.addClass('js-view-dom-id-' + view_dom_id);
}
}
// Do nothing if no placholder.
// Do nothing if no placeholder.
if (target_exists) {
// Everything we need to specify about the view.
@@ -66,5 +64,4 @@
}
};
})(jQuery, Drupal);
})(Drupal, once);
Loading