Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFC] Native dialogs replacing the Bootstrap ones #39344

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build/build-modules-js/javascript/compile-to-es2017.es6.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ module.exports.handleESMFile = async (file) => {
const minifiedCss = await getWcMinifiedCss(file);
const bundle = await rollup.rollup({
input: resolve(file),
inlineDynamicImports: true,
plugins: [
nodeResolve({
preferBuiltins: false,
Expand Down
37 changes: 34 additions & 3 deletions build/media_source/plg_editors_tinymce/js/tinymce.es6.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,36 @@
((tinyMCE, Joomla, window, document) => {
'use strict';

function openJoomlaModal(button) {
const modalContainer = document.createElement('joomla-modal');
modalContainer.setAttribute('id', 'tinymce-j-modal');
// modalContainer.setAttribute('class', `maximum header-two-btn`);
modalContainer.setAttribute('title', `Select ${button.text}`);
modalContainer.setAttribute('url', button.href);
modalContainer.setAttribute('close-text', 'Clooooooose');
modalContainer.setAttribute('click-outside', false);

document.body.append(modalContainer);
modalContainer.open();
Joomla.Modal.setCurrent(modalContainer)

const matches = /e_name=(.*?)\&/.exec(button.href)
if (matches.length === 2) {
const buttonSaveSelectedElement = document.createElement('button');
buttonSaveSelectedElement.setAttribute('type', 'button');
buttonSaveSelectedElement.textContent = 'Select';

function onSelected() {
Joomla.getImage(parent.window.Joomla.selectedMediaFile, button.id, modalContainer);
modalContainer.querySelector('dialog').close();
Joomla.Modal.setCurrent(null)
}

buttonSaveSelectedElement.addEventListener('click', onSelected);
modalContainer.querySelector('header button').insertAdjacentElement('afterend', buttonSaveSelectedElement);
}
}

Joomla.JoomlaTinyMCE = {
/**
* Find all TinyMCE elements and initialize TinyMCE instance for each
Expand Down Expand Up @@ -98,9 +128,10 @@
}

if (xtdButton.href) {
tmp.onAction = () => {
document.getElementById(`${xtdButton.id}_modal`).open();
};
tmp.href = xtdButton.href;
tmp.editor = element;
tmp.id = element.id;
tmp.onAction = () => openJoomlaModal(tmp);
} else {
tmp.onAction = () => {
// eslint-disable-next-line no-new-func
Expand Down
82 changes: 82 additions & 0 deletions build/media_source/system/css/joomla-modal.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@

dialog:modal {
/*
From BS 5.2
*/
border-color: grey;
border-width: 1px;
border-radius: 0.5rem;
width: calc(100dvw - 2em);
height: calc(100dvw - 4em);

/* clamp(min(10em, calc(100dvw - 2em)), calc(100dvw - 2em), 40em); */
}

dialog::backdrop {
background-color: black;
opacity: .8
}

dialog:modal iframe {
width: 100%;
height: 100vh;
border: none;
}

dialog:modal header {
margin: -1em;
display: flex;
align-items: center;
justify-items: start;
border-bottom: 1px inset grey;
}

dialog:modal header > *:nth-child(1) {
padding-inline-start: 1em;
}

dialog:modal header > *:nth-child(2) {
border: none;
background-color: transparent;
box-sizing: content-box;
width: 1em;
height: 1em;
padding: .25em .25em;
color: #000;
background: transparent url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='%23000'%3e%3cpath d='M.293.293a1 1 0 0 1 1.414 0L8 6.586 14.293.293a1 1 0 1 1 1.414 1.414L9.414 8l6.293 6.293a1 1 0 0 1-1.414 1.414L8 9.414l-6.293 6.293a1 1 0 0 1-1.414-1.414L6.586 8 .293 1.707a1 1 0 0 1 0-1.414z'/%3e%3c/svg%3e") center/1em auto no-repeat;
border: 0;
border-radius: .375rem;
opacity: .5;
margin-inline-start: auto;
margin-inline-end: 2em;
}

dialog:modal article {
margin-top: 2em;
}

joomla-modal.maximum.header-two-btn header > *:nth-child(1) {
padding-inline-start: 1em;
}

joomla-modal.maximum.header-two-btn header > *:nth-child(2) {
margin-inline-start: auto;
margin-inline-end: 1em;
background: unset;
}


joomla-modal.maximum.header-two-btn header > *:nth-child(3) {
border: none;
background-color: transparent;
box-sizing: content-box;
width: 1em;
height: 1em;
padding: .25em .25em;
color: #000;
background: transparent url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='%23000'%3e%3cpath d='M.293.293a1 1 0 0 1 1.414 0L8 6.586 14.293.293a1 1 0 1 1 1.414 1.414L9.414 8l6.293 6.293a1 1 0 0 1-1.414 1.414L8 9.414l-6.293 6.293a1 1 0 0 1-1.414-1.414L6.586 8 .293 1.707a1 1 0 0 1 0-1.414z'/%3e%3c/svg%3e") center/1em auto no-repeat;
border: 0;
border-radius: .375rem;
opacity: .5;
margin-inline-end: 2em;
}
41 changes: 22 additions & 19 deletions build/media_source/system/js/fields/joomla-field-media.w-c.es6.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,6 @@ class JoomlaFieldMedia extends HTMLElement {

set url(value) { this.setAttribute('url', value); }

get modalContainer() { return this.getAttribute('modal-container'); }

set modalContainer(value) { this.setAttribute('modal-container', value); }

get input() { return this.getAttribute('input'); }

set input(value) { this.setAttribute('input', value); }
Expand Down Expand Up @@ -104,25 +100,17 @@ class JoomlaFieldMedia extends HTMLElement {
this.button = this.querySelector(this.buttonSelect);
this.inputElement = this.querySelector(this.input);
this.buttonClearEl = this.querySelector(this.buttonClear);
this.modalElement = this.querySelector('.joomla-modal');
this.buttonSaveSelectedElement = this.querySelector(this.buttonSaveSelected);
this.buttonSaveSelectedElement = document.createElement('button');
this.buttonSaveSelectedElement.setAttribute('type', 'button');
this.buttonSaveSelectedElement.textContent = 'Select';
this.previewElement = this.querySelector('.field-media-preview');

if (!this.button || !this.inputElement || !this.buttonClearEl || !this.modalElement
|| !this.buttonSaveSelectedElement) {
if (!this.button || !this.inputElement || !this.buttonClearEl || !this.buttonSaveSelectedElement) {
throw new Error('Misconfiguaration...');
}

this.button.addEventListener('click', this.show);

// Bootstrap modal init
if (this.modalElement
&& window.bootstrap
&& window.bootstrap.Modal
&& !window.bootstrap.Modal.getInstance(this.modalElement)) {
Joomla.initialiseModal(this.modalElement, { isJoomla: true });
}

if (this.buttonClearEl) {
this.buttonClearEl.addEventListener('click', this.clearValue);
}
Expand Down Expand Up @@ -159,8 +147,20 @@ class JoomlaFieldMedia extends HTMLElement {
}

show() {
this.modalElement.open();
this.modalContainer = document.createElement('joomla-modal');
this.modalContainer.setAttribute('id', 'media-select-modal');
this.modalContainer.setAttribute('class', 'maximum header-two-btn');
this.modalContainer.setAttribute('title', 'Select Media');
this.modalContainer.setAttribute('url', this.url.replace('{field-media-id}', this.inputElement.getAttribute('id')));
this.modalContainer.setAttribute('close-text', 'Clooooooose');
this.modalContainer.setAttribute('click-outside', false);

this.append(this.modalContainer);
this.modalContainer.open();

this.modalContainer.querySelector('header button').insertAdjacentElement('beforebegin', this.buttonSaveSelectedElement);

Joomla.Modal.setCurrent(this.modalContainer.querySelector('dialog'));
Joomla.selectedMediaFile = {};

this.buttonSaveSelectedElement.addEventListener('click', this.onSelected);
Expand All @@ -176,7 +176,9 @@ class JoomlaFieldMedia extends HTMLElement {
}

Joomla.selectedMediaFile = {};
Joomla.Modal.getCurrent().close();
this.modalContainer.querySelector('dialog').close();
Joomla.Modal.setCurrent(null);
// Joomla.Modal.getCurrent().close();
}

setValue(value) {
Expand Down Expand Up @@ -363,4 +365,5 @@ class JoomlaFieldMedia extends HTMLElement {
}
}
}
customElements.define('joomla-field-media', JoomlaFieldMedia);

customElements.whenDefined('joomla-modal').then(() => customElements.define('joomla-field-media', JoomlaFieldMedia));
Loading