Skip to content

Commit

Permalink
[5.0][RFC] Joomla Dialog (popup) script. Free, without CC and registr…
Browse files Browse the repository at this point in the history
…ation (#40150)

* JoomlaPopup script

Squashed commit of the following:

commit cd37244
Author: Fedik <[email protected]>
Date:   Sat Mar 18 14:14:43 2023 +0200

    Popup customisable buttons location

commit 64c1197
Author: Fedik <[email protected]>
Date:   Sat Mar 18 11:51:33 2023 +0200

    Popup setCurrent

commit 43e20c6
Author: Fedik <[email protected]>
Date:   Sat Mar 18 11:39:51 2023 +0200

    Popup setCurrent, and cancelable

commit 8e68503
Author: Fedik <[email protected]>
Date:   Sat Mar 18 11:29:25 2023 +0200

    Popup handle anchor click, and caching

commit c784170
Author: Fedik <[email protected]>
Date:   Sat Mar 18 10:52:50 2023 +0200

    Popup helper, aliases

commit 225267f
Author: Fedik <[email protected]>
Date:   Fri Mar 17 18:09:40 2023 +0200

    Popup basic styling

commit 5071c3b
Author: Fedik <[email protected]>
Date:   Fri Mar 17 18:01:30 2023 +0200

    Popup basic styling

commit a5aeb0a
Author: Fedik <[email protected]>
Date:   Fri Mar 17 16:40:17 2023 +0200

    Popup basic styling

commit 79a2a93
Author: Fedik <[email protected]>
Date:   Fri Mar 17 16:00:15 2023 +0200

    Popup basic styling

commit 0b739fb
Author: Fedik <[email protected]>
Date:   Fri Mar 17 15:40:03 2023 +0200

    Popup basic styling

commit 2f8d5a1
Author: Fedik <[email protected]>
Date:   Fri Mar 17 14:54:17 2023 +0200

    Can cancel

commit b5512f9
Merge: 5d83527 cb1d517
Author: Fedik <[email protected]>
Date:   Fri Mar 17 14:36:58 2023 +0200

    Merge branch '4.3-dev' into jpopup

commit 5d83527
Author: Fedik <[email protected]>
Date:   Sun Mar 12 18:45:10 2023 +0200

    Joomla popup base css

commit c9abff7
Author: Fedik <[email protected]>
Date:   Sun Mar 12 17:48:00 2023 +0200

    Joomla popup destroy

commit 5b42c28
Author: Fedik <[email protected]>
Date:   Sun Mar 12 17:45:37 2023 +0200

    Joomla popup lang

commit d3adea8
Author: Fedik <[email protected]>
Date:   Sun Mar 12 17:37:05 2023 +0200

    Joomla popup jscs

commit 6923750
Author: Fedik <[email protected]>
Date:   Sun Mar 12 17:35:34 2023 +0200

    Joomla popup alert/confirm handle cancel

commit 25b6b16
Author: Fedik <[email protected]>
Date:   Sun Mar 12 17:25:31 2023 +0200

    Joomla popup cleanup

commit fd01507
Author: Fedik <[email protected]>
Date:   Sun Mar 12 17:12:00 2023 +0200

    Joomla popup jscs

commit 623bffe
Author: Fedik <[email protected]>
Date:   Sun Mar 12 17:09:40 2023 +0200

    Joomla popup alert promise

commit e726f5f
Author: Fedik <[email protected]>
Date:   Sun Mar 12 16:51:40 2023 +0200

    Joomla popup jscs

commit 92a05b6
Author: Fedik <[email protected]>
Date:   Sun Mar 12 16:32:47 2023 +0200

    Joomla popup confirm with promise

commit 42895bc
Author: Fedik <[email protected]>
Date:   Sun Mar 12 16:26:11 2023 +0200

    Joomla popup events

commit e64f68a
Author: Fedik <[email protected]>
Date:   Sun Mar 12 16:22:23 2023 +0200

    Joomla popup events

commit 4bee835
Author: Fedik <[email protected]>
Date:   Sun Mar 12 15:39:47 2023 +0200

    Joomla popup auto-create

commit 394ce08
Author: Fedik <[email protected]>
Date:   Sun Mar 12 15:07:13 2023 +0200

    Joomla popup

commit ac66242
Author: Fedik <[email protected]>
Date:   Sun Mar 12 14:53:16 2023 +0200

    Joomla popup docs

commit e4d87bf
Author: Fedik <[email protected]>
Date:   Sun Mar 12 14:26:11 2023 +0200

    Joomla popup image, ajax

commit 4b10bbe
Author: Fedik <[email protected]>
Date:   Sun Mar 12 13:17:31 2023 +0200

    Joomla popup iframe

commit 839cf43
Author: Fedik <[email protected]>
Date:   Sun Mar 12 12:39:11 2023 +0200

    Joomla popup sizes and close

commit 2371cd0
Author: Fedik <[email protected]>
Date:   Sun Mar 12 12:00:54 2023 +0200

    Joomla popup render layout

commit 7aafc4d
Author: Fedik <[email protected]>
Date:   Sun Mar 12 11:19:35 2023 +0200

    Joomla popup statics

commit 658dd88
Author: Fedik <[email protected]>
Date:   Sat Mar 11 20:21:22 2023 +0200

    Joomla popup

commit 27486ab
Author: Fedik <[email protected]>
Date:   Sat Mar 11 19:03:11 2023 +0200

    Joomla popup

commit 7e4398d
Author: Fedik <[email protected]>
Date:   Sat Mar 11 17:07:02 2023 +0200

    Joomla popup

* js/css cs

* Rename popup to dialog

* Clean html

* Update comments

* Cancelable alert

* Src for inline content

* Improve parentElement handling

* Simplify

* Dispatch joomla:updated for inline content

* Improve parent lookup

* Data stuff

* Useless export

* Bubbling

* Joomla dialog as module

* Bubbling

* Fix getFooter

* Enlarge default size of iframe

* Cassiopeia dialog css

* css cs

* Check attributes when element rendered initially
  • Loading branch information
Fedik authored Aug 21, 2023
1 parent 0bf4b43 commit ecc67a0
Show file tree
Hide file tree
Showing 6 changed files with 992 additions and 0 deletions.
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 @@ -56,6 +56,7 @@ const collectExternals = () => {
externalModules.push(
'cropper-module',
'codemirror',
'joomla.dialog',
);

// Codemirror modules
Expand Down
21 changes: 21 additions & 0 deletions build/media_source/system/joomla.asset.json
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,27 @@
"webcomponent.toolbar-button-legacy"
]
},
{
"name": "joomla.dialog",
"type": "script",
"uri": "system/joomla-dialog.min.js",
"importmap": true,
"dependencies": [
"wcpolyfill",
"core"
]
},
{
"name": "joomla.dialog-autocreate",
"type": "script",
"uri": "system/joomla-dialog-autocreate.min.js",
"attributes": {
"type": "module"
},
"dependencies": [
"joomla.dialog"
]
},
{
"name": "list-view",
"type": "script",
Expand Down
64 changes: 64 additions & 0 deletions build/media_source/system/js/joomla-dialog-autocreate.es6.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/**
* @copyright (C) 2023 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

// eslint-disable-next-line import/no-unresolved
import JoomlaDialog from 'joomla.dialog';

/**
* Auto create a popup dynamically on click, eg:
*
* <button type="button" data-joomla-dialog='{"popupType": "iframe", "src": "content/url.html"}'>Click</button>
* <button type="button" data-joomla-dialog='{"popupType": "inline", "popupContent": "#id-of-content-element"}'>Click</button>
* <a href="content/url.html" data-joomla-dialog>Click</a>
*/
const delegateSelector = '[data-joomla-dialog]';
const configDataAttr = 'joomlaDialog';
const configCacheFlag = 'joomlaDialogCache';

document.addEventListener('click', (event) => {
const triggerEl = event.target.closest(delegateSelector);
if (!triggerEl) return;
event.preventDefault();

// Check for cached instance
const cacheable = !!triggerEl.dataset[configCacheFlag];
if (cacheable && triggerEl.JoomlaDialogInstance) {
Joomla.Modal.setCurrent(triggerEl.JoomlaDialogInstance);
triggerEl.JoomlaDialogInstance.show();
return;
}
// Parse config
const config = triggerEl.dataset[configDataAttr] ? JSON.parse(triggerEl.dataset[configDataAttr]) : {};

// Check if the click is on anchor
if (triggerEl.nodeName === 'A') {
if (!config.popupType) {
config.popupType = triggerEl.hash ? 'inline' : 'iframe';
}
if (!config.src && config.popupType === 'iframe') {
config.src = triggerEl.href;
} else if (!config.src && config.popupType === 'inline') {
config.src = triggerEl.hash;
}
}

// Template not allowed here
delete config.popupTemplate;

const popup = new JoomlaDialog(config);
if (cacheable) {
triggerEl.JoomlaDialogInstance = popup;
}

popup.addEventListener('joomla-dialog:close', () => {
Joomla.Modal.setCurrent(null);
if (!cacheable) {
popup.destroy();
}
});

Joomla.Modal.setCurrent(popup);
popup.show();
});
Loading

0 comments on commit ecc67a0

Please sign in to comment.