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

[5.0][RFC] Joomla Dialog (popup) script. Free, without CC and registration #40150

Merged
merged 30 commits into from
Aug 21, 2023

Conversation

Fedik
Copy link
Member

@Fedik Fedik commented Mar 18, 2023

Summary of Changes

This is implementation of own popup/modal/dialog independend from bootstrap and other traps.
As continue of #32473 discussion.

At current point of time the PR provides only popup implementation, the script should be ready to use.
And the integration will come.

I made it for 4.x to be able easily test on "production" codebase. However main target (If I ever finish it) probably > 5.x.

The PR does not provide a separate stylesheet for popup, the styling should be done within template (example can find in _modal.scss of this PR).
(At bare it use native dialog styling)

What and why is Joomla Dialog

The script allow to create a popup/dialog programaticaly, that in oposite to current Bootstrap implementation, when modal should be prerendered in HTML. This allows more simple integration on client side without involving server side.

It basicaly a wrapper around native dialog element.

Joomla Dialog script allows to display dialog with following content:

  • inline - text or html content;
  • iframe - embed/remote content, in iframe;
  • ajax - same as inline but the content loaded through ajax request;
  • image - image lightbox;

Also it provides helper methods for alert() and confirm() dialogs.
Provides helper to bind page button/anchor to show the popup, for basic stuff, without extra js needed.

Usage examples

<?php $wa->useScript('joomla.dialog'); ?>
// Inline 
const dialog = new JoomlaDialog({
  textHeader: 'The header',
  popupContent: '<p class="p-3">Popup content text</p>',
});
dialog.show();

// IFrame
const dialog = new JoomlaDialog({
  popupType: 'iframe',
  textHeader: 'The header',
  src: 'index.php?option=com_content&view=articles&tmpl=component&layout=modal',
});
dialog.show();

// Ajax
const dialog = new JoomlaDialog({
  popupType: 'ajax',
  textHeader: 'The header',
  src: 'index.php?option=com_content&view=articles&tmpl=component&layout=modal',
});
dialog.show();

// Image
const dialog = new JoomlaDialog({
  popupType: 'image',
  src: '../images/headers/walden-pond.jpg',
});
dialog.show();

Any property can be set as instance property or in class constructor. This two is equal:

// Proprty in class constructor
const dialog = new JoomlaDialog({
  textHeader: 'The header',
  popupContent: '<p class="p-3">Popup content text</p>',
});

// Proprty in to class instance
const dialog = new JoomlaDialog();
dialog.textHeader = 'The header';
dialog.popupContent = '<p class="p-3">Popup content text</p>';

Other options:

// Optional sizing:
dialog.width = '80vw';
dialog.height = '80vh';

// Definig your own buttons:
dialog.popupButtons = [
  { label: 'Yes', onClick: () => dialog.close() },
  { label: 'No', onClick: () => dialog.close(), className: 'btn btn-outline-danger ms-2' },
];

Alert and Confirm usage:

// Alert
JoomlaDialog.alert('Chase ball of string eat plants, meow')
  .then(() => { 
    console.log('All done'); 
  });

// Confirmation
JoomlaDialog.confirm('Cheese on toast airedale the big cheese?')
  .then((result) => { 
    console.log(result ? 'Okay' : 'Not okay'); 
  });

Binding button/anchor for basic stuff

<?php $wa->useScript('joomla.dialog-autocreate'); ?>

<button class="btn btn-primary" type="button"
    data-joomla-dialog='{"popupType": "iframe", "width":"80vw", "height": "80vh", "src":"index.php?option=com_content&view=articles&tmpl=component&layout=modal"}'>Click</button>

<button class="btn btn-primary" type="button"
    data-joomla-dialog='{"popupType": "inline", "src":"#popupText", "width": "fit-content", "height": "fit-content"}'>Click</button>

<a href="index.php?option=com_content&view=articles&tmpl=component&layout=modal"
  data-joomla-dialog class="btn btn-outline-primary">Click</a>
<a href="#popupText" data-joomla-dialog class="btn btn-outline-primary">Click</a>

<template id="popupText"><p class="p-3">Popup content text</p></template>

Testing Instructions

Can test any of examples above.
Apply patch, run npm install.
Then add $wa->useScript('joomla.dialog'); in to index.php of the admin template.
And one of example js/html wherever you want. Eg. in to index.php (will show 2 popup on load):

<script type="module">
import JoomlaDialog from 'joomla.dialog';

JoomlaDialog.alert('Chase ball of string eat plants, meow')
  .then(() => { 
    console.log('All done'); 
  });

JoomlaDialog.confirm('Cheese on toast airedale the big cheese?')
  .then((result) => { 
    console.log(result ? 'Okay' : 'Not okay'); 
  });
</script>

Link to documentations

Please select:

Issues for reference

@dgrammatiko I have stole some of your ideas from #39344, I hope you will not sue me :)

Squashed commit of the following:

commit cd37244
Author: Fedik <getthesite@gmail.com>
Date:   Sat Mar 18 14:14:43 2023 +0200

    Popup customisable buttons location

commit 64c1197
Author: Fedik <getthesite@gmail.com>
Date:   Sat Mar 18 11:51:33 2023 +0200

    Popup setCurrent

commit 43e20c6
Author: Fedik <getthesite@gmail.com>
Date:   Sat Mar 18 11:39:51 2023 +0200

    Popup setCurrent, and cancelable

commit 8e68503
Author: Fedik <getthesite@gmail.com>
Date:   Sat Mar 18 11:29:25 2023 +0200

    Popup handle anchor click, and caching

commit c784170
Author: Fedik <getthesite@gmail.com>
Date:   Sat Mar 18 10:52:50 2023 +0200

    Popup helper, aliases

commit 225267f
Author: Fedik <getthesite@gmail.com>
Date:   Fri Mar 17 18:09:40 2023 +0200

    Popup basic styling

commit 5071c3b
Author: Fedik <getthesite@gmail.com>
Date:   Fri Mar 17 18:01:30 2023 +0200

    Popup basic styling

commit a5aeb0a
Author: Fedik <getthesite@gmail.com>
Date:   Fri Mar 17 16:40:17 2023 +0200

    Popup basic styling

commit 79a2a93
Author: Fedik <getthesite@gmail.com>
Date:   Fri Mar 17 16:00:15 2023 +0200

    Popup basic styling

commit 0b739fb
Author: Fedik <getthesite@gmail.com>
Date:   Fri Mar 17 15:40:03 2023 +0200

    Popup basic styling

commit 2f8d5a1
Author: Fedik <getthesite@gmail.com>
Date:   Fri Mar 17 14:54:17 2023 +0200

    Can cancel

commit b5512f9
Merge: 5d83527 cb1d517
Author: Fedik <getthesite@gmail.com>
Date:   Fri Mar 17 14:36:58 2023 +0200

    Merge branch '4.3-dev' into jpopup

commit 5d83527
Author: Fedik <getthesite@gmail.com>
Date:   Sun Mar 12 18:45:10 2023 +0200

    Joomla popup base css

commit c9abff7
Author: Fedik <getthesite@gmail.com>
Date:   Sun Mar 12 17:48:00 2023 +0200

    Joomla popup destroy

commit 5b42c28
Author: Fedik <getthesite@gmail.com>
Date:   Sun Mar 12 17:45:37 2023 +0200

    Joomla popup lang

commit d3adea8
Author: Fedik <getthesite@gmail.com>
Date:   Sun Mar 12 17:37:05 2023 +0200

    Joomla popup jscs

commit 6923750
Author: Fedik <getthesite@gmail.com>
Date:   Sun Mar 12 17:35:34 2023 +0200

    Joomla popup alert/confirm handle cancel

commit 25b6b16
Author: Fedik <getthesite@gmail.com>
Date:   Sun Mar 12 17:25:31 2023 +0200

    Joomla popup cleanup

commit fd01507
Author: Fedik <getthesite@gmail.com>
Date:   Sun Mar 12 17:12:00 2023 +0200

    Joomla popup jscs

commit 623bffe
Author: Fedik <getthesite@gmail.com>
Date:   Sun Mar 12 17:09:40 2023 +0200

    Joomla popup alert promise

commit e726f5f
Author: Fedik <getthesite@gmail.com>
Date:   Sun Mar 12 16:51:40 2023 +0200

    Joomla popup jscs

commit 92a05b6
Author: Fedik <getthesite@gmail.com>
Date:   Sun Mar 12 16:32:47 2023 +0200

    Joomla popup confirm with promise

commit 42895bc
Author: Fedik <getthesite@gmail.com>
Date:   Sun Mar 12 16:26:11 2023 +0200

    Joomla popup events

commit e64f68a
Author: Fedik <getthesite@gmail.com>
Date:   Sun Mar 12 16:22:23 2023 +0200

    Joomla popup events

commit 4bee835
Author: Fedik <getthesite@gmail.com>
Date:   Sun Mar 12 15:39:47 2023 +0200

    Joomla popup auto-create

commit 394ce08
Author: Fedik <getthesite@gmail.com>
Date:   Sun Mar 12 15:07:13 2023 +0200

    Joomla popup

commit ac66242
Author: Fedik <getthesite@gmail.com>
Date:   Sun Mar 12 14:53:16 2023 +0200

    Joomla popup docs

commit e4d87bf
Author: Fedik <getthesite@gmail.com>
Date:   Sun Mar 12 14:26:11 2023 +0200

    Joomla popup image, ajax

commit 4b10bbe
Author: Fedik <getthesite@gmail.com>
Date:   Sun Mar 12 13:17:31 2023 +0200

    Joomla popup iframe

commit 839cf43
Author: Fedik <getthesite@gmail.com>
Date:   Sun Mar 12 12:39:11 2023 +0200

    Joomla popup sizes and close

commit 2371cd0
Author: Fedik <getthesite@gmail.com>
Date:   Sun Mar 12 12:00:54 2023 +0200

    Joomla popup render layout

commit 7aafc4d
Author: Fedik <getthesite@gmail.com>
Date:   Sun Mar 12 11:19:35 2023 +0200

    Joomla popup statics

commit 658dd88
Author: Fedik <getthesite@gmail.com>
Date:   Sat Mar 11 20:21:22 2023 +0200

    Joomla popup

commit 27486ab
Author: Fedik <getthesite@gmail.com>
Date:   Sat Mar 11 19:03:11 2023 +0200

    Joomla popup

commit 7e4398d
Author: Fedik <getthesite@gmail.com>
Date:   Sat Mar 11 17:07:02 2023 +0200

    Joomla popup
@joomla-cms-bot joomla-cms-bot added NPM Resource Changed This Pull Request can't be tested by Patchtester PR-4.3-dev RFC Request for Comment labels Mar 18, 2023
@Fedik Fedik marked this pull request as draft March 18, 2023 14:23
@dgrammatiko
Copy link
Contributor

LGTM

I left couple of comments on insertAdjacentHTML but also before this goes to production it needs the dialog polyfill, you can copy over the code from https://github.com/dgrammatiko/joomla-modal/blob/main/src/index.js and add the package in the package.json (https://github.com/GoogleChrome/dialog-polyfill)

@Fedik
Copy link
Member Author

Fedik commented Mar 18, 2023

also before this goes to production it needs the dialog polyfill,

At time when it will happen, we will be no need polifill 😄
Well, yeah sure, can be added, but as last thing here, not really important for now.

@dgrammatiko
Copy link
Contributor

Well, yeah sure, can be added, but as last thing here, not really important for now

Sure, so apart the innerHML part everything else are spot on on what we had discussed. Maybe the anchor shouldn't be included, for a11y reasons, ie: the dialog should be opened from a button but that's bikeshedding that someone else should do.

I will try to play a bit with it tomorrow but I think it's already in very good shape

@dgrammatiko
Copy link
Contributor

@Fedik one little change: could you rename this to JoomlaDialog and all the instances of popup to dialog? The reason is that later this year the platform will have (already on chrome) the popover so this should be easily distinguishable

@Fedik
Copy link
Member Author

Fedik commented Mar 18, 2023

I see, makes sense, yes I will rename

@Fedik Fedik changed the title [RFC] Joomla Popup script. Free, without CC and registration [RFC] Joomla Dialog (popup) script. Free, without CC and registration Mar 19, 2023
@dgrammatiko
Copy link
Contributor

@laoneo could we have a decision for 4.4 here? This PR will unlock the fixes needed all around the broken repeatables, modal fields, etc
There's an actual implementation for the fields User and Media here: #40152

@laoneo
Copy link
Member

laoneo commented Mar 20, 2023

@dgrammatiko what for a decisions you expect? If this can go into 4.4? As @Fedik already mentioned in the pr description, this should finally be merged into 5.0 as 4.4 will not get any new features.

@dgrammatiko
Copy link
Contributor

So 4.3 was the last minor that had new features? Well, 🤬

@laoneo
Copy link
Member

laoneo commented Mar 20, 2023

What is the problem to ship it with 5.0? They will be released at the same time.

@dgrammatiko
Copy link
Contributor

What is the problem to ship it with 5.0? They will be released at the same time.

I guess some dev will be complaining, like the did with the WAM, that they need 2 different code snippets in order to support both v4 and v5...

@laoneo
Copy link
Member

laoneo commented Mar 20, 2023

As long as the old way still works, they should then use that. And yes, when they want the new dialog/popup/modal, then they need to have different code which is dependent on the Joomla version. I don't see this as a big issue.

@dgrammatiko
Copy link
Contributor

As long as the old way still works, they should then use that.

The old way (bootstrap) works but devs SHOULD NOT use them for fields, editor buttons, etc that are already broken right now because this approach is doing SSR (Server Side Rendering) of the modals which are incompatible with repeatable fields. Same goes for the category fields for different reason. My point is that the script should be introduced in the 4.x so the transition would be easier...

@Fedik
Copy link
Member Author

Fedik commented Mar 20, 2023

I think 5.x+ is fine, maybe we will get some better ideas untill then.
And I would like to finish #40082 before this, and try different approaches for (cross)editor buttons.

@dgrammatiko
Copy link
Contributor

And I would like to finish #40082 before this, and try different approaches for (cross)editor buttons.

I was thinking doing the first implementation with the buttons based on this PR and the #40082 but it needs also extending the Joomla.editors to have something like

Joomla.editors = {
  instances: {},
  buttonsCallbacks: {
    ['plg_editors-buttons_readmore']: () => { /* the code for the callback */ },
  },
}

@Fedik
Copy link
Member Author

Fedik commented Mar 20, 2023

I thinking about something generic, that can handle basic stuf without extra coding, and allow to be extended when needed.

@dgrammatiko
Copy link
Contributor

I thinking about something generic, that can handle basic stuf without extra coding, and allow to be extended when needed.

My idea for the editor buttons was:

  • create a new plugin group, ie editor-buttons and for J4/5 check both, with J6 only editor-buttons would exist
  • The plugin instead of returning a php object (CMSObject) would just register the buttons in the Joomla.editors as a JS object { name, icon, etc }
  • The plugin would register the onClick function on the Joomla.editors
  • The plugin would also return true on the PHP side if the plugin is enabled on the particular instance of the editor
  • The editor should render (client side) the buttons and bind either the modal or the onClick

This way on every repeatable instance the buttons will work as expected (the editor init function has the responsibility to handle those, ie: tiny will render them inside a toolbar but others could/would render them bellow the editing area)

@HLeithner
Copy link
Member

hmm, I thought more on a css file I can use in my own frontend template as base and not only cassiopia, what do you thing?

@Fedik
Copy link
Member Author

Fedik commented Aug 15, 2023

By default it use a browser default styling for dialog.
I have fixed iframe sizing, now it pretty usable without extra css.

Backdrop also there, it is browser default.

About footerText. I not very want to overload with features, and keep it simple.
However it still possible to customize:

const dialog = new JoomlaDialog();
dialog.textHeader = 'The header';
dialog.popupContent = '<strong>blabla very strong text</strong>';
// Customise footer
dialog.getFooter().insertAdjacentElement('afterbegin', (() => {
  const el = document.createElement('div');
  el.innerText = 'Footer text';
  return el;
})());
dialog.getFooter().classList.remove('empty');
dialog.show();

@HLeithner
Copy link
Member

thanks, I think it's a starting point, even if I would add a css which is (or could be) part of the webasset with a nicer styling

@coolcat-creations
Copy link
Contributor

Does this issue have something to do with this topic here?

#42291


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/40150.

@Fedik Fedik mentioned this pull request Nov 9, 2023
4 tasks
LadySolveig pushed a commit that referenced this pull request Nov 16, 2023
Use Dialog for Batch windows
* Batch: banners
* Batch: contacts
* Batch: newsfeed
* Batch: fields
* Batch: field groups
* Batch: menu
* Batch: modules
* Batch: tags
* Batch: users
see also the reference for implementation of the Joomla.Dialog #40150
LadySolveig pushed a commit that referenced this pull request Jan 14, 2024
Affects:
* Dashboard: add module
* Menus: add/edit module
* Menu item: Module Assignment tab

see also the reference for implementation of the Joomla.Dialog #40150
@Frank-MandarinFish
Copy link

Frank-MandarinFish commented Sep 19, 2024

Hey, since JoomlaDialog is now a module script I think it would be useful to have a little section in the manual that shows how this class can be used in "classic" non-module scripts, as the import function can only be called from another module script. The current manual gives the impression you can use the JoomlaDialog class in any script.

For example static:

<script type="module">
    import JoomlaDialog from "joomla.dialog";
    window.JoomlaDialog = JoomlaDialog;    
</script>

Or dynamic:

async function run() {
  const JoomlaDialog = await import("joomla.dialog");
  dialog = new JoomlaDialog();
}

This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/40150.

@fgsw
Copy link

fgsw commented Sep 21, 2024

I think it would be useful to have a little section in the manual

@Frank-MandarinFish As far as i know everybody can contribute to the manual

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature NPM Resource Changed This Pull Request can't be tested by Patchtester RFC Request for Comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants