Fixing some technical errors when avoiding importing the `converse` global with bootstrap modal API.
This commit is contained in:
SilverYoCha 2023-06-27 09:38:58 +02:00 committed by JC Brand
parent 94963662e7
commit e18fdd56b1
2 changed files with 13 additions and 6 deletions

View File

@ -4,7 +4,7 @@ import log from "@converse/headless/log";
import sizzle from 'sizzle'; import sizzle from 'sizzle';
import tplAlertComponent from "./templates/modal-alert.js"; import tplAlertComponent from "./templates/modal-alert.js";
import { View } from '@converse/skeletor/src/view.js'; import { View } from '@converse/skeletor/src/view.js';
import { addClass, removeElement } from '../../utils/html.js'; import { hasClass, addClass, removeElement, removeClass } from '../../utils/html.js';
import { render } from 'lit'; import { render } from 'lit';
import './styles/_modal.scss'; import './styles/_modal.scss';
@ -43,7 +43,7 @@ const BaseModal = View.extend({
}, },
onHide () { onHide () {
u.removeClass('selected', this.trigger_el); removeClass('selected', this.trigger_el);
!this.persistent && api.modal.remove(this); !this.persistent && api.modal.remove(this);
}, },

View File

@ -236,14 +236,20 @@ u.getLastChildElement = function (el, selector = '*') {
return last_el; return last_el;
}; };
u.hasClass = function (className, el) {
return el instanceof Element && el.classList.contains(className);
};
u.toggleClass = function (className, el) { u.toggleClass = function (className, el) {
u.hasClass(className, el) ? removeClass(className, el) : addClass(className, el); u.hasClass(className, el) ? removeClass(className, el) : addClass(className, el);
}; };
/**
* Has an element a class?
* @method u#hasClass
* @param { string } className
* @param { Element } el
*/
export function hasClass (className, el) {
return el instanceof Element && el.classList.contains(className);
}
/** /**
* Add a class to an element. * Add a class to an element.
* @method u#addClass * @method u#addClass
@ -615,6 +621,7 @@ u.xForm2TemplateResult = function (field, stanza, options={}) {
}; };
Object.assign(u, { Object.assign(u, {
hasClass,
addClass, addClass,
ancestor, ancestor,
getOOBURLMarkup, getOOBURLMarkup,