Skip to content

Commit

Permalink
Core loader custom element rework
Browse files Browse the repository at this point in the history
  • Loading branch information
C-Lodder committed Feb 27, 2024
1 parent 3f6d646 commit 15d88f1
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 180 deletions.
10 changes: 2 additions & 8 deletions administrator/modules/mod_sampledata/tmpl/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,14 @@
use Joomla\CMS\Uri\Uri;

$app->getDocument()->getWebAssetManager()
->registerAndUseScript('mod_sampledata', 'mod_sampledata/sampledata-process.js', [], ['type' => 'module'], ['core']);
->registerAndUseScript('mod_sampledata', 'mod_sampledata/sampledata-process.js', [], ['type' => 'module'], ['core'])
->useScript('webcomponent.core-loader');

Text::script('MOD_SAMPLEDATA_COMPLETED');
Text::script('MOD_SAMPLEDATA_CONFIRM_START');
Text::script('MOD_SAMPLEDATA_ERROR_RESPONSE');
Text::script('MOD_SAMPLEDATA_INVALID_RESPONSE');
Text::script('MOD_SAMPLEDATA_ITEM_ALREADY_PROCESSED');

$app->getDocument()->addScriptOptions(
'sample-data',
[
'icon' => Uri::root(true) . '/media/system/images/ajax-loader.gif',
]
);
?>
<?php if ($items) : ?>
<ul id="sample-data-wrapper" class="list-group list-group-flush sample-data">
Expand Down
15 changes: 7 additions & 8 deletions build/media_source/mod_sampledata/js/sampledata-process.es6.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,15 @@ const sampledataAjax = (type, steps, step) => {
// Create paragraph
const para = document.createElement('p');
para.classList.add('loader-image');
para.classList.add('text-center');

// Create image
const img = document.createElement('img');
img.setAttribute('src', options.icon);
img.setAttribute('width', 30);
img.setAttribute('height', 30);
const loaderEl = document.createElement('joomla-core-loader');
loaderEl.setAttribute('inline', true);
loaderEl.setAttribute('size', 60);
loaderEl.setAttribute('color', 'transparent');

// Append everything
para.appendChild(img);
para.appendChild(loaderEl);
list.appendChild(para);
document.querySelector(`.sampledata-progress-${type}`).appendChild(list);

Expand All @@ -39,8 +38,8 @@ const sampledataAjax = (type, steps, step) => {
perform: true,
onSuccess: (resp) => {
// Remove loader image
const loader = list.querySelector('.loader-image');
loader.parentNode.removeChild(loader);
//const loader = list.querySelector('.loader-image');
//loader.parentNode.removeChild(loader);

let response = {};

Expand Down
98 changes: 45 additions & 53 deletions build/media_source/system/js/joomla-core-loader.w-c.es6.js
Original file line number Diff line number Diff line change
@@ -1,65 +1,57 @@
((customElements) => {
'strict';

/**
* Creates a custom element with the default spinner of the Joomla logo
*/
class JoomlaCoreLoader extends HTMLElement {
constructor() {
super();
/**
* Creates a custom element with the default spinner of the Joomla logo
*/
class JoomlaCoreLoader extends HTMLElement {
constructor() {
super();
}

const template = document.createElement('template');
template.innerHTML = `<style>{{CSS_CONTENTS_PLACEHOLDER}}</style>
<div>
<span class="yellow"></span>
<span class="red"></span>
<span class="blue"></span>
<span class="green"></span>
<p>&trade;</p>
</div>`;
connectedCallback() {
this.style.backgroundColor = this.color;

// Patch the shadow DOM
if (window.ShadyCSS) {
window.ShadyCSS.prepareTemplate(template, 'joomla-core-loader');
}
if (this.inline === 'false') {
this.classList.add('fullscreen');
}

this.attachShadow({ mode: 'open' });
this.shadowRoot.appendChild(template.content.cloneNode(true));
const template = document.createElement('template');
template.innerHTML = `
<style>{{CSS_CONTENTS_PLACEHOLDER}}</style>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 150 150" width="${this.size}" height="${this.size}">
<style>@keyframes joomla-spinner{0%,28%,to{opacity:.30}20%{opacity:1}}.joomla-spinner{animation:joomla-spinner 1.6s infinite cubic-bezier(0,.15,1,.75)}
</style>
<path d="m27 75.5-2.9-2.9c-8.9-8.9-11.7-21.7-8.3-33C6.9 37.6.2 29.6.2 20.1c0-11.1 9-20 20-20 10 0 18.2 7.3 19.8 16.8 10.8-2.5 22.6.4 31.1 8.8l1.2 1.2-14.9 14.7-1.1-1.2c-4.8-4.8-12.6-4.8-17.4 0-4.8 4.8-4.8 12.6 0 17.4l2.9 2.9 14.8 14.8 15.6 15.6-14.8 14.8-15.6-15.7L27 75.5z" class="joomla-spinner" style="animation-delay:-1.2s" fill="#f44321" />
<path d="m43.5 58.9 15.6-15.6 14.8-14.8 2.9-2.9c8.9-8.9 21.6-11.7 32.8-8.4C111 7.5 119.4 0 129.5 0c11.1 0 20 9 20 20 0 10.2-7.6 18.6-17.4 19.9 3.2 11.2.4 23.8-8.4 32.7l-1.2 1.2L107.7 59l1.1-1.1c4.8-4.8 4.8-12.6 0-17.4-4.8-4.8-12.5-4.8-17.4 0l-2.9 2.9-14.6 14.7-15.6 15.6-14.8-14.8z" class="joomla-spinner" style="animation-delay:-.8s" fill="#5091cd" />
<path d="M110.1 133.5c-11.4 3.5-24.2.7-33.2-8.3l-1.1-1.1 14.8-14.8 1.1 1.1c4.8 4.8 12.6 4.8 17.4 0 4.8-4.8 4.8-12.5 0-17.4l-2.9-2.9-14.9-14.6-15.6-15.7L90.5 45l15.6 15.6 14.8 14.8 2.9 2.9c8.5 8.5 11.4 20.5 8.8 31.3 9.7 1.4 17.2 9.7 17.2 19.8 0 11.1-9 20-20 20-9.8.2-17.9-6.7-19.7-15.9z" class="joomla-spinner" style="animation-delay:-.4s" fill="#7ac143" />
<path d="m104.3 92-15.6 15.6-14.8 14.8-2.9 2.9c-8.5 8.5-20.6 11.4-31.5 8.7-2 8.9-10 15.5-19.5 15.5-11.1 0-20-9-20-20 0-9.5 6.6-17.4 15.4-19.5-2.8-11 .1-23.1 8.7-31.7l1.1-1.1L40 92l-1.1 1.1c-4.8 4.8-4.8 12.6 0 17.4 4.8 4.8 12.6 4.8 17.4 0l2.9-2.9L74 92.8l15.6-15.6L104.3 92z" class="joomla-spinner" fill="#f9a541" />
</svg>`;

this.attachShadow({ mode: 'open' });
this.shadowRoot.appendChild(template.content.cloneNode(true));
}

// Patch the shadow DOM
if (window.ShadyCSS) {
window.ShadyCSS.styleElement(this);
}
}
static get observedAttributes() {
return ['color'];
}

connectedCallback() {
this.style.backgroundColor = this.color;
this.style.opacity = 0.8;
this.shadowRoot.querySelector('div').classList.add('box');
}
get inline() { return this.getAttribute('inline') || false; }

static get observedAttributes() {
return ['color'];
}
get size() { return this.getAttribute('size') || '345'; }

get color() { return this.getAttribute('color') || '#fff'; }
get color() { return this.getAttribute('color') || '#fff'; }

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

attributeChangedCallback(attr, oldValue, newValue) {
switch (attr) {
case 'color':
if (newValue && newValue !== oldValue) {
this.style.backgroundColor = this.color;
}
break;
default:
// Do nothing
}
attributeChangedCallback(attr, oldValue, newValue) {
switch (attr) {
case 'color':
if (newValue && newValue !== oldValue) {
this.style.backgroundColor = this.color;
}
break;
default:
// Do nothing
}
}
}

if (!customElements.get('joomla-core-loader')) {
customElements.define('joomla-core-loader', JoomlaCoreLoader);
}
})(customElements);
window.customElements.define('joomla-core-loader', JoomlaCoreLoader);
125 changes: 14 additions & 111 deletions build/media_source/system/scss/joomla-core-loader.scss
Original file line number Diff line number Diff line change
@@ -1,124 +1,27 @@
$theme-colours: ();
$theme-colours: map-merge((
"yellow" : #f9a541,
"red" : #f44321,
"blue" : #5091cd,
"green" : #7ac143,
), $theme-colours);

:host {
position: fixed;
top: 0;
left: 0;
z-index: 10000;
display: flex;
opacity: .8;
align-items: center;
width: 100%;
height: 100%;
display: flex;
overflow: hidden;
opacity: .8;
justify-content: center;
}

.box {
position: relative;
width: 345px;
height: 345px;
margin: 0 auto;

p {
float: right;
margin: 95px 0 0;
font: normal 1.25em/1em sans-serif;
color: #999;
}

> span {
animation: jspinner 2s infinite ease-in-out;
}

.red {
animation-delay: -1.5s;
}
.blue {
animation-delay: -1s;
}
.green {
animation-delay: -.5s;
}
}

@each $colour in $theme-colours {
$key: nth($colour, 1);
$value: nth($colour, 2);

.#{$key} {
position: absolute;
top: 0;
left: 0;
width: 90px;
height: 90px;
content: "";
background: $value;
border-radius: 90px;

&::before,
&::after {
position: absolute;
top: 0;
left: 0;
box-sizing: content-box;
width: 50px;
content: "";
background: transparent;
border: 50px solid $value;
}

&::before {
height: 35px;
margin: 60px 0 0 -30px;
border-width: 50px 50px 0;
border-radius: 75px 75px 0 0;
}

&::after {
height: 105px;
margin: 140px 0 0 -30px;
border-width: 0 0 0 50px;
}
}
}

.yellow {
margin: 0 0 0 255px;
transform: rotate(45deg);
}

.red {
margin: 255px 0 0 255px;
transform: rotate(135deg);
}

.blue {
margin: 255px 0 0;
transform: rotate(225deg);
}

.green {
transform: rotate(315deg);
}
:host(.fullscreen) {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;

@keyframes jspinner {
0%, 40%, 100% {
opacity: .3;
}
20% {
opacity: 1;
svg {
width: 345px;
height: 345px;
}
}


@media (prefers-reduced-motion: reduce) {
.box > span {
animation: none;
.joomla-spinner {
animation: none !important;
}
}

0 comments on commit 15d88f1

Please sign in to comment.