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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
d7e2ac2
JoomlaPopup script
Fedik Mar 18, 2023
63ff698
js/css cs
Fedik Mar 18, 2023
123928c
Rename popup to dialog
Fedik Mar 19, 2023
e08f3bc
Clean html
Fedik Mar 19, 2023
b078769
Update comments
Fedik Mar 19, 2023
49f4d9b
Sync. Merge branch '4.4-dev' into jpopup2
Fedik Mar 26, 2023
ac322bb
Cancelable alert
Fedik Mar 26, 2023
6f931d0
Src for inline content
Fedik Mar 26, 2023
1db2038
Merge branch '5.0-dev' into jpopup2
Fedik Apr 7, 2023
23ae1a0
Improve parentElement handling
Fedik Apr 8, 2023
d9ecd0c
Simplify
Fedik Apr 8, 2023
6ee97fe
Merge branch '5.0-dev' into jpopup2
Fedik Apr 11, 2023
342e04a
Dispatch joomla:updated for inline content
Fedik Apr 11, 2023
ba8ed82
Improve parent lookup
Fedik Apr 11, 2023
3c5ba79
Data stuff
Fedik Apr 12, 2023
34c9a5f
Merge branch '5.0-dev' into jpopup2
Fedik Apr 23, 2023
ce5172f
Sync. Merge branch '5.0-dev' into jpopup2
Fedik May 6, 2023
619be36
Useless export
Fedik Jul 2, 2023
18ab55c
Sync. Merge branch '5.0-dev' into jpopup2
Fedik Jul 2, 2023
baa1630
Sync. Merge branch '5.0-dev' into jpopup2
Fedik Aug 11, 2023
f7eb41d
Bubbling
Fedik Aug 11, 2023
866ec7d
Joomla dialog as module
Fedik Aug 12, 2023
565890f
Bubbling
Fedik Aug 12, 2023
1077193
Merge branch '5.0-dev' into jpopup2
Fedik Aug 14, 2023
f5b9c69
Merge branch 'jpopup2-as-module' into jpopup2
Fedik Aug 14, 2023
8c28df2
Fix getFooter
Fedik Aug 15, 2023
f2a69eb
Enlarge default size of iframe
Fedik Aug 15, 2023
edff245
Cassiopeia dialog css
Fedik Aug 15, 2023
a672769
css cs
Fedik Aug 15, 2023
333acc8
Check attributes when element rendered initially
Fedik Aug 15, 2023
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 @@ -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