Skip to content

Commit

Permalink
Popup helper, aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
Fedik committed Mar 18, 2023
1 parent 225267f commit c784170
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 3 deletions.
3 changes: 2 additions & 1 deletion build/media_source/system/joomla.asset.json
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,8 @@
"type": "module"
},
"dependencies": [
"wcpolyfill"
"wcpolyfill",
"core"
]
},
{
Expand Down
47 changes: 45 additions & 2 deletions build/media_source/system/js/joomla-popup.w-c.es6.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ const popupTemplate = `<div class="joomla-popup-container">
</div>`;

/**
* JoomlaPopup class implementation for <joomla-popup> element
* JoomlaPopup class for Joomla Dialog implementation.
* With use of <joomla-popup> custom element as dialog holder.
*/
class JoomlaPopup extends HTMLElement {
/**
Expand Down Expand Up @@ -326,6 +327,16 @@ class JoomlaPopup extends HTMLElement {
return this;
}

/**
* Return the popup header element.
* @returns {HTMLElement|boolean}
*/
getHeader() {
this.renderLayout();

return this.popupTmplH || false;
}

/**
* Return the popup body element.
* @returns {HTMLElement}
Expand All @@ -346,6 +357,16 @@ class JoomlaPopup extends HTMLElement {
return this.popupContentElement || this.popupTmplB;
}

/**
* Return the popup footer element.
* @returns {HTMLElement|boolean}
*/
getFooter() {
this.renderLayout();

return this.popupTmplB || false;
}

/**
* Open the popup as modal window.
* Will append the element to Document body if not appended before.
Expand All @@ -362,6 +383,14 @@ class JoomlaPopup extends HTMLElement {
return this;
}

/**
* Alias for show() method.
* @returns {JoomlaPopup}
*/
open() {
return this.show();
}

/**
* Closes the popup
*
Expand All @@ -376,6 +405,14 @@ class JoomlaPopup extends HTMLElement {
return this;
}

/**
* Alias for close() method.
* @returns {JoomlaPopup}
*/
hide() {
return this.close();
}

/**
* Destroys the popup.
*/
Expand Down Expand Up @@ -460,7 +497,13 @@ class JoomlaPopup extends HTMLElement {
window.JoomlaPopup = JoomlaPopup;
customElements.define('joomla-popup', JoomlaPopup);

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

Expand Down

0 comments on commit c784170

Please sign in to comment.