primo commit
This commit is contained in:
26
media/regularlabs/js/LICENCE
Normal file
26
media/regularlabs/js/LICENCE
Normal file
@ -0,0 +1,26 @@
|
||||
MIT License
|
||||
|
||||
Copyright 2021 Regular Labs <https://github.com/regularlabs/regularjs>
|
||||
|
||||
====
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
====
|
||||
436
media/regularlabs/js/README.md
Normal file
436
media/regularlabs/js/README.md
Normal file
@ -0,0 +1,436 @@
|
||||

|
||||
|
||||
### *A light and simple JavaScript Library*
|
||||
|
||||
[](https://github.com/regularlabs/regularjs/blob/master/LICENCE)
|
||||
[](https://github.com/regularlabs/regularjs/pulls)
|
||||
[](https://github.com/regularlabs)
|
||||
|
||||
Very small:  😮
|
||||
|
||||
---
|
||||
|
||||
This library contains a number of simple static javascript functions.
|
||||
|
||||
[hasClasses](#hasclasses)<br>
|
||||
[addClasses](#addclasses)<br>
|
||||
[removeClasses](#removeclasses)<br>
|
||||
[toggleClasses](#toggleclasses)<br>
|
||||
[show](#show)<br>
|
||||
[hide](#hide)<br>
|
||||
[fadeIn](#fadein)<br>
|
||||
[fadeOut](#fadeout)<br>
|
||||
[createElementFromHTML](#createelementfromhtml)<br>
|
||||
[onReady](#onready)<br>
|
||||
[loadUrl](#loadurl)<br>
|
||||
[alias](#alias)<br>
|
||||
<br>
|
||||
[Function Aliases](#function-aliases)
|
||||
|
||||
---
|
||||
|
||||
## hasClasses
|
||||
|
||||
Checks if the element contains one or more of the given class names.
|
||||
|
||||
#### Syntax
|
||||
|
||||
```javascript
|
||||
Regular.hasClasses(selector, classes, true)
|
||||
```
|
||||
|
||||
| Parameter | Description | Default |
|
||||
|------------|----------------------------------------------------------------------------------------------------|:-------:|
|
||||
| `selector` | A CSS selector string or a HTMLElement object. | |
|
||||
| `classes` | A string or array of class names. | |
|
||||
| `matchAll` | Optional boolean whether the element should have all given classes (true) or at least one (false). | `true` |
|
||||
|
||||
##### Returns
|
||||
|
||||
`boolean` true or false based on whether the element contains one or more of the given class names.
|
||||
|
||||
#### Examples
|
||||
|
||||
```html
|
||||
<div id="mydiv" class="foo bar">...</div>
|
||||
```
|
||||
|
||||
```javascript
|
||||
|
||||
Regular.hasClasses('#mydiv', 'foo');
|
||||
// => true
|
||||
|
||||
Regular.hasClasses('#mydiv', 'baz');
|
||||
// => false
|
||||
|
||||
Regular.hasClasses('#mydiv', 'bar baz');
|
||||
// => false
|
||||
|
||||
Regular.hasClasses('#mydiv', ['bar', 'baz']);
|
||||
// => false
|
||||
|
||||
const div = document.querySelector('#mydiv');
|
||||
Regular.hasClasses(div, ['bar', 'baz'], false);
|
||||
// => true
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## addClasses
|
||||
|
||||
Adds given class name(s) to the element.
|
||||
|
||||
#### Syntax
|
||||
|
||||
```javascript
|
||||
Regular.addClasses(selector, classes)
|
||||
```
|
||||
|
||||
| Parameter | Description |
|
||||
|------------|-------------------------------------------------------------------------------------|
|
||||
| `selector` | A CSS selector string, a HTMLElement object or a collection of HTMLElement objects. |
|
||||
| `classes` | A string or array of class names. |
|
||||
|
||||
#### Examples
|
||||
|
||||
```html
|
||||
<div id="mydiv" class="foo">...</div>
|
||||
```
|
||||
|
||||
```javascript
|
||||
Regular.addClasses('#mydiv', 'bar');
|
||||
// => class="foo bar"
|
||||
|
||||
Regular.addClasses('#mydiv', 'foo');
|
||||
// => class="foo"
|
||||
|
||||
Regular.addClasses('#mydiv', 'bar baz');
|
||||
// => class="foo bar baz"
|
||||
|
||||
const div = document.querySelector('#mydiv');
|
||||
Regular.addClasses(div, ['bar', 'baz']);
|
||||
// => class="foo bar baz"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## removeClasses
|
||||
|
||||
Removes given class name(s) from the element.
|
||||
|
||||
#### Syntax
|
||||
|
||||
```javascript
|
||||
Regular.removeClasses(selector, classes)
|
||||
```
|
||||
|
||||
| Parameter | Description |
|
||||
|------------|-------------------------------------------------------------------------------------|
|
||||
| `selector` | A CSS selector string, a HTMLElement object or a collection of HTMLElement objects. |
|
||||
| `classes` | A string or array of class names. |
|
||||
|
||||
#### Examples
|
||||
|
||||
```html
|
||||
<div id="mydiv" class="foo bar baz">...</div>
|
||||
```
|
||||
|
||||
```javascript
|
||||
Regular.removeClasses('#mydiv', 'bar');
|
||||
// => class="foo baz"
|
||||
|
||||
Regular.removeClasses('#mydiv', 'bar baz');
|
||||
// => class="foo"
|
||||
|
||||
Regular.removeClasses('#mydiv', ['bar', 'baz']);
|
||||
// => class="foo"
|
||||
|
||||
const div = document.querySelector('#mydiv');
|
||||
Regular.removeClasses(div, 'qux');
|
||||
// => class="foo bar baz"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## toggleClasses
|
||||
|
||||
Toggles given class name(s) of the element.
|
||||
|
||||
#### Syntax
|
||||
|
||||
```javascript
|
||||
Regular.toggleClasses(selector, classes)
|
||||
```
|
||||
|
||||
| Parameter | Description |
|
||||
|------------|-------------------------------------------------------------------------------------|
|
||||
| `selector` | A CSS selector string, a HTMLElement object or a collection of HTMLElement objects. |
|
||||
| `classes` | A string or array of class names. |
|
||||
|
||||
#### Examples
|
||||
|
||||
```html
|
||||
<div id="mydiv" class="foo bar baz">...</div>
|
||||
```
|
||||
|
||||
```javascript
|
||||
Regular.toggleClasses('#mydiv', 'bar');
|
||||
// => class="foo baz"
|
||||
|
||||
Regular.toggleClasses('#mydiv', 'bar baz');
|
||||
// => class="foo"
|
||||
|
||||
Regular.toggleClasses('#mydiv', ['bar', 'qux']);
|
||||
// => class="foo baz qux"
|
||||
|
||||
const div = document.querySelector('#mydiv');
|
||||
Regular.toggleClasses(div, 'qux');
|
||||
// => class="foo bar baz qux"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## show
|
||||
|
||||
Shows the given element (changes opacity and display attributes).
|
||||
|
||||
#### Syntax
|
||||
|
||||
```javascript
|
||||
Regular.show(el)
|
||||
```
|
||||
|
||||
| Parameter | Description |
|
||||
|------------|-------------------------------------------------------------------------------------|
|
||||
| `selector` | A CSS selector string, a HTMLElement object or a collection of HTMLElement objects. |
|
||||
|
||||
#### Examples
|
||||
|
||||
```html
|
||||
<div id="mydiv" style="display:none;">...</div>
|
||||
```
|
||||
|
||||
```javascript
|
||||
Regular.show('#mydiv');
|
||||
|
||||
const div = document.querySelector('#mydiv');
|
||||
Regular.show(div);
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## hide
|
||||
|
||||
Hides the given element (changes opacity and display attributes).
|
||||
|
||||
#### Syntax
|
||||
|
||||
```javascript
|
||||
Regular.hide(el)
|
||||
```
|
||||
|
||||
| Parameter | Description |
|
||||
|------------|-------------------------------------------------------------------------------------|
|
||||
| `selector` | A CSS selector string, a HTMLElement object or a collection of HTMLElement objects. |
|
||||
|
||||
#### Examples
|
||||
|
||||
```html
|
||||
<div id="mydiv">...</div>
|
||||
```
|
||||
|
||||
```javascript
|
||||
Regular.hide(div);
|
||||
|
||||
const div = document.querySelector('#mydiv');
|
||||
Regular.hide('#mydiv');
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## fadeIn
|
||||
|
||||
Fades in the the given element.
|
||||
|
||||
#### Syntax
|
||||
|
||||
```javascript
|
||||
Regular.fadeIn(selector, duration, oncomplete)
|
||||
```
|
||||
|
||||
| Parameter | Description | Default |
|
||||
|--------------|-------------------------------------------------------------------------------------|:-------:|
|
||||
| `selector` | A CSS selector string, a HTMLElement object or a collection of HTMLElement objects. | |
|
||||
| `duration` | Optional duration of the effect in milliseconds. | `250` |
|
||||
| `oncomplete` | Optional callback function to execute when effect is completed. | |
|
||||
|
||||
#### Examples
|
||||
|
||||
```html
|
||||
<div id="mydiv" style="display:none;">...</div>
|
||||
```
|
||||
|
||||
```javascript
|
||||
Regular.fadeIn('#mydiv');
|
||||
|
||||
const div = document.querySelector('#mydiv');
|
||||
Regular.fadeIn(div, 1000, () => console.log('Faded in'));
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## fadeOut
|
||||
|
||||
Fades out the the given element.
|
||||
|
||||
#### Syntax
|
||||
|
||||
```javascript
|
||||
Regular.fadeOut(selector, duration, oncomplete)
|
||||
```
|
||||
|
||||
| Parameter | Description | Default |
|
||||
|--------------|-------------------------------------------------------------------------------------|:-------:|
|
||||
| `selector` | A CSS selector string, a HTMLElement object or a collection of HTMLElement objects. | |
|
||||
| `duration` | Optional duration of the effect in milliseconds. | `250` |
|
||||
| `oncomplete` | Optional callback function to execute when effect is completed. | |
|
||||
|
||||
#### Examples
|
||||
|
||||
```html
|
||||
<div id="mydiv">...</div>
|
||||
```
|
||||
|
||||
```javascript
|
||||
Regular.fadeOut('#mydiv');
|
||||
|
||||
const div = document.querySelector('#mydiv');
|
||||
Regular.fadeOut(div, 1000, () => console.log('Faded out'));
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## createElementFromHTML
|
||||
|
||||
Converts a string with HTML code to a HTMLElement object.
|
||||
|
||||
#### Syntax
|
||||
|
||||
```javascript
|
||||
Regular.createElementFromHTML(html)
|
||||
```
|
||||
|
||||
| Parameter | Description |
|
||||
|-----------|------------------------|
|
||||
| `html` | String with HTML code. |
|
||||
|
||||
##### Returns
|
||||
|
||||
`HTMLElement` object based on the given string.
|
||||
|
||||
#### Example
|
||||
|
||||
```javascript
|
||||
const mydiv = Regular.createElementFromHTML(`<div id="mydiv" class="foo">My <strong>cool</strong> element!</div>`);
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## onReady
|
||||
|
||||
Runs a function when the document is loaded (on ready state).
|
||||
|
||||
#### Syntax
|
||||
|
||||
```javascript
|
||||
Regular.onReady(func)
|
||||
```
|
||||
|
||||
| Parameter | Description |
|
||||
|-----------|------------------------------------------------------|
|
||||
| `func` | Callback function to execute when document is ready. |
|
||||
|
||||
#### Example
|
||||
|
||||
```
|
||||
Regular.onReady(`console.log('Document is ready!')`);
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## loadUrl
|
||||
|
||||
Loads a url with optional POST data and optionally calls a function on success or fail.
|
||||
|
||||
#### Syntax
|
||||
|
||||
```javascript
|
||||
Regular.loadUrl(url, data, success, fail)
|
||||
```
|
||||
|
||||
| Parameter | Description |
|
||||
|-----------|-------------------------------------------------------------------------------------|
|
||||
| `url` | String containing the url to load. |
|
||||
| `data` | Optional string representing the POST data to send along. |
|
||||
| `success` | Optional callback function to execute when the url loads successfully (status 200). |
|
||||
| `fail` | Optional callback function to execute when the url fails to load. |
|
||||
|
||||
The result (responseText), status and the full XMLHttpRequest object will be passed to the callback functions.
|
||||
|
||||
#### Example
|
||||
|
||||
```javascript
|
||||
Regular.loadUrl('my/url.php');
|
||||
|
||||
Regular.loadUrl(
|
||||
'my/url.php',
|
||||
'id=123&format=ajax',
|
||||
(result) => {
|
||||
console.log('Yeah!');
|
||||
console.log(result);
|
||||
},
|
||||
(result, status) => console.log(`Oh no! Failed with status: ${status}`)
|
||||
);
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## alias
|
||||
|
||||
Sets a global alias for the Regular class.
|
||||
|
||||
#### Syntax
|
||||
|
||||
```javascript
|
||||
Regular.alias(word)
|
||||
```
|
||||
|
||||
| Parameter | Description |
|
||||
|-----------|----------------------------------------------------------------------------|
|
||||
| `word` | A string (character or word) representing the alias for the Regular class. |
|
||||
|
||||
##### Returns
|
||||
|
||||
`boolean` true if the alias is created, false if the given alias already exists as a global variable names.
|
||||
|
||||
#### Example
|
||||
|
||||
```javascript
|
||||
Regular.alias('$');
|
||||
|
||||
$.addClass('#myDiv', 'foo');
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Function Aliases
|
||||
|
||||
There are some aliases for some of the functions:
|
||||
|
||||
| Function | Alias for |
|
||||
|-------------|---------------|
|
||||
| hasClass | hasClasses |
|
||||
| addClass | addClasses |
|
||||
| removeClass | removeClasses |
|
||||
| toggleClass | toggleClasses |
|
||||
| as | alias |
|
||||
134
media/regularlabs/js/admin-form-descriptions.js
Normal file
134
media/regularlabs/js/admin-form-descriptions.js
Normal file
@ -0,0 +1,134 @@
|
||||
/**
|
||||
* @package Regular Labs Library
|
||||
* @version 24.11.1459
|
||||
*
|
||||
* @author Peter van Westen <info@regularlabs.com>
|
||||
* @link https://regularlabs.com
|
||||
* @copyright Copyright © 2024 Regular Labs All Rights Reserved
|
||||
* @license GNU General Public License version 2 or later
|
||||
*/
|
||||
|
||||
(function() {
|
||||
'use strict';
|
||||
|
||||
window.RegularLabs = window.RegularLabs || {};
|
||||
|
||||
window.RegularLabs.AdminFormDescriptions = window.RegularLabs.AdminFormDescriptions || {
|
||||
moveLabelDescriptions: function() {
|
||||
document.querySelectorAll('div[id$="-desc"]:not(.rl-moved)').forEach((description) => {
|
||||
const control_group = description.closest('.control-group');
|
||||
|
||||
if ( ! control_group) {
|
||||
return;
|
||||
}
|
||||
|
||||
const label = control_group.querySelector('label');
|
||||
|
||||
if ( ! label) {
|
||||
return;
|
||||
}
|
||||
|
||||
const controls = control_group.querySelector('.controls');
|
||||
|
||||
this.create(label, controls, description);
|
||||
});
|
||||
},
|
||||
|
||||
createFromClasses: function() {
|
||||
document.querySelectorAll('.rl-popover:not(.rl-moved)').forEach((description) => {
|
||||
const label = description.previousElementSibling;
|
||||
|
||||
if ( ! label) {
|
||||
return;
|
||||
}
|
||||
|
||||
let parent = description.closest('.rl-popover-parent');
|
||||
let position = 'after';
|
||||
|
||||
if ( ! parent) {
|
||||
parent = description.parentElement;
|
||||
position = 'end';
|
||||
}
|
||||
|
||||
this.create(label, parent, description, position);
|
||||
});
|
||||
},
|
||||
|
||||
create: function(label, controls, description, position = 'start') {
|
||||
if ( ! label) {
|
||||
return;
|
||||
}
|
||||
|
||||
description.classList.add('hidden');
|
||||
description.classList.add('rl-moved');
|
||||
|
||||
const popover = document.createElement('div');
|
||||
const popover_inner = document.createElement('div');
|
||||
|
||||
popover.classList.add('rl-admin-popover-container');
|
||||
|
||||
if (description.classList.contains('rl-popover-full')) {
|
||||
popover.classList.add('rl-admin-popover-full');
|
||||
}
|
||||
|
||||
popover_inner.classList.add('rl-admin-popover');
|
||||
popover_inner.innerHTML = description.querySelector('small').innerHTML;
|
||||
|
||||
popover.append(popover_inner);
|
||||
|
||||
const button = document.createElement('span');
|
||||
button.classList.add('icon-info-circle', 'text-muted', 'fs-6', 'ms-1', 'align-text-top');
|
||||
|
||||
label.setAttribute('role', 'button');
|
||||
label.setAttribute('tabindex', '0');
|
||||
|
||||
const action_show = function() {
|
||||
popover.classList.add('show');
|
||||
};
|
||||
const action_hide = function() {
|
||||
popover.classList.remove('show');
|
||||
};
|
||||
|
||||
label.addEventListener('mouseenter', action_show);
|
||||
label.addEventListener('mouseleave', action_hide);
|
||||
label.addEventListener('focus', action_show);
|
||||
label.addEventListener('blur', action_hide);
|
||||
|
||||
label.append(button);
|
||||
|
||||
switch (position) {
|
||||
case 'start':
|
||||
controls.prepend(popover);
|
||||
break;
|
||||
case 'end':
|
||||
controls.append(popover);
|
||||
break;
|
||||
case 'after':
|
||||
default:
|
||||
controls.parentNode.insertBefore(popover, controls.nextSibling);
|
||||
break;
|
||||
}
|
||||
},
|
||||
|
||||
removeInlineHelpToggleButton: function() {
|
||||
const toolbar_inlinehelp = document.getElementById('toolbar-inlinehelp');
|
||||
|
||||
if (toolbar_inlinehelp) {
|
||||
toolbar_inlinehelp.remove();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
RegularLabs.AdminFormDescriptions.removeInlineHelpToggleButton();
|
||||
RegularLabs.AdminFormDescriptions.moveLabelDescriptions();
|
||||
RegularLabs.AdminFormDescriptions.createFromClasses();
|
||||
|
||||
document.addEventListener('subform-row-add', () => {
|
||||
document.dispatchEvent(new Event('rl-update-form-descriptions'));
|
||||
});
|
||||
|
||||
document.addEventListener('rl-update-form-descriptions', () => {
|
||||
RegularLabs.AdminFormDescriptions.moveLabelDescriptions();
|
||||
RegularLabs.AdminFormDescriptions.createFromClasses();
|
||||
});
|
||||
})();
|
||||
11
media/regularlabs/js/admin-form-descriptions.min.js
vendored
Normal file
11
media/regularlabs/js/admin-form-descriptions.min.js
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
/*
|
||||
* Copyright © 2024 Regular Labs - All Rights Reserved
|
||||
* GNU General Public License version 2 or later
|
||||
*/
|
||||
(function(){'use strict';window.RegularLabs=window.RegularLabs||{};window.RegularLabs.AdminFormDescriptions=window.RegularLabs.AdminFormDescriptions||{moveLabelDescriptions:function(){document.querySelectorAll('div[id$="-desc"]:not(.rl-moved)').forEach((description)=>{const control_group=description.closest('.control-group');if(!control_group){return;}
|
||||
const label=control_group.querySelector('label');if(!label){return;}
|
||||
const controls=control_group.querySelector('.controls');this.create(label,controls,description);});},createFromClasses:function(){document.querySelectorAll('.rl-popover:not(.rl-moved)').forEach((description)=>{const label=description.previousElementSibling;if(!label){return;}
|
||||
let parent=description.closest('.rl-popover-parent');let position='after';if(!parent){parent=description.parentElement;position='end';}
|
||||
this.create(label,parent,description,position);});},create:function(label,controls,description,position='start'){if(!label){return;}
|
||||
description.classList.add('hidden');description.classList.add('rl-moved');const popover=document.createElement('div');const popover_inner=document.createElement('div');popover.classList.add('rl-admin-popover-container');if(description.classList.contains('rl-popover-full')){popover.classList.add('rl-admin-popover-full');}
|
||||
popover_inner.classList.add('rl-admin-popover');popover_inner.innerHTML=description.querySelector('small').innerHTML;popover.append(popover_inner);const button=document.createElement('span');button.classList.add('icon-info-circle','text-muted','fs-6','ms-1','align-text-top');label.setAttribute('role','button');label.setAttribute('tabindex','0');const action_show=function(){popover.classList.add('show');};const action_hide=function(){popover.classList.remove('show');};label.addEventListener('mouseenter',action_show);label.addEventListener('mouseleave',action_hide);label.addEventListener('focus',action_show);label.addEventListener('blur',action_hide);label.append(button);switch(position){case'start':controls.prepend(popover);break;case'end':controls.append(popover);break;case'after':default:controls.parentNode.insertBefore(popover,controls.nextSibling);break;}},removeInlineHelpToggleButton:function(){const toolbar_inlinehelp=document.getElementById('toolbar-inlinehelp');if(toolbar_inlinehelp){toolbar_inlinehelp.remove();}}};RegularLabs.AdminFormDescriptions.removeInlineHelpToggleButton();RegularLabs.AdminFormDescriptions.moveLabelDescriptions();RegularLabs.AdminFormDescriptions.createFromClasses();document.addEventListener('subform-row-add',()=>{document.dispatchEvent(new Event('rl-update-form-descriptions'));});document.addEventListener('rl-update-form-descriptions',()=>{RegularLabs.AdminFormDescriptions.moveLabelDescriptions();RegularLabs.AdminFormDescriptions.createFromClasses();});})();
|
||||
307
media/regularlabs/js/admin-form.js
Normal file
307
media/regularlabs/js/admin-form.js
Normal file
@ -0,0 +1,307 @@
|
||||
/**
|
||||
* @package Regular Labs Library
|
||||
* @version 24.11.1459
|
||||
*
|
||||
* @author Peter van Westen <info@regularlabs.com>
|
||||
* @link https://regularlabs.com
|
||||
* @copyright Copyright © 2024 Regular Labs All Rights Reserved
|
||||
* @license GNU General Public License version 2 or later
|
||||
*/
|
||||
|
||||
(function() {
|
||||
'use strict';
|
||||
|
||||
window.RegularLabs = window.RegularLabs || {};
|
||||
|
||||
window.RegularLabs.AdminForm = window.RegularLabs.AdminForm || {
|
||||
setToggleTitleClass: function(input, value) {
|
||||
const panel = input.closest('.rl-panel');
|
||||
|
||||
if ( ! panel) {
|
||||
return;
|
||||
}
|
||||
|
||||
panel.classList.remove('rl-panel-info');
|
||||
panel.classList.remove('rl-panel-success');
|
||||
panel.classList.remove('rl-panel-error');
|
||||
|
||||
switch (value) {
|
||||
case 2:
|
||||
panel.classList.add('rl-panel-error');
|
||||
break;
|
||||
case 1:
|
||||
panel.classList.add('rl-panel-success');
|
||||
break;
|
||||
default:
|
||||
panel.classList.add('rl-panel-info');
|
||||
break;
|
||||
}
|
||||
},
|
||||
|
||||
loadAjaxButton: function(id, url) {
|
||||
const button = document.querySelector(`#${id}`);
|
||||
const icon = button.querySelector("span:nth-child(1)");
|
||||
const message = document.querySelector(`#message_${id}`);
|
||||
|
||||
icon.className = "icon-refresh icon-spin";
|
||||
message.className = "";
|
||||
message.innerHTML = "";
|
||||
|
||||
const constants = `
|
||||
const button = document.querySelector("#${id}");
|
||||
const icon = button.querySelector("span:nth-child(1)");
|
||||
const message = document.querySelector("#message_${id}");
|
||||
`;
|
||||
|
||||
let success = `${constants}
|
||||
Regular.removeClass(button, "btn-warning");
|
||||
Regular.addClass(button, "btn-success");
|
||||
button.querySelector("span:nth-child(1)").className = "icon-ok";
|
||||
if (data) {
|
||||
Regular.addClass(message, "alert alert-success alert-noclose alert-inline");
|
||||
message.innerHTML = data;
|
||||
}
|
||||
`;
|
||||
|
||||
let error = `${constants}
|
||||
Regular.removeClass(button, "btn-success");
|
||||
Regular.addClass(button, "btn-warning");
|
||||
button.querySelector("span:nth-child(1)").className = "icon-warning";
|
||||
|
||||
if(data){
|
||||
let error = data;
|
||||
if(data.statusText) {
|
||||
error = data.statusText;
|
||||
if(data.responseText.test(/<blockquote>/)) {
|
||||
error = data.responseText.replace(/^[.\\s\\S]*?<blockquote>([.\\s\\S]*?)<\\/blockquote>[.\\s\\S]*$/gm, "$1");
|
||||
}
|
||||
}
|
||||
Regular.addClass(message, "alert alert-danger alert-noclose alert-inline");
|
||||
message.innerHTML = error;
|
||||
}
|
||||
`;
|
||||
|
||||
success = `
|
||||
if(data == "" || data.substring(0,1) == "+") {
|
||||
data = data.trim().replace(/^[+]/, "");
|
||||
${success}
|
||||
} else {
|
||||
data = data.trim().replace(/^[-]/, "");
|
||||
${error}
|
||||
}
|
||||
`;
|
||||
|
||||
RegularLabs.Scripts.loadAjax(url, success, error);
|
||||
},
|
||||
|
||||
loadAjaxFields: function() {
|
||||
if (typeof RegularLabs.Scripts === 'undefined') {
|
||||
return;
|
||||
}
|
||||
|
||||
document.querySelectorAll('textarea[data-rl-ajax]').forEach((el) => {
|
||||
this.loadAjaxField(el);
|
||||
});
|
||||
},
|
||||
|
||||
loadAjaxField: function(el) {
|
||||
if (el.dataset['rlAjaxDone']) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! this.isInView(el)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const wrapper = el.closest('.rl-ajax-wrapper');
|
||||
|
||||
if (wrapper) {
|
||||
wrapper.classList.add('loaded');
|
||||
}
|
||||
|
||||
let attributes = JSON.parse(el.dataset['rlAjax']);
|
||||
|
||||
attributes.id = el.id;
|
||||
attributes.name = el.name;
|
||||
|
||||
const query_attributes = createCompressedAttributes(attributes);
|
||||
|
||||
const url = `index.php?option=com_ajax&plugin=regularlabs&format=raw&fieldid=${el.id}&${query_attributes}`;
|
||||
|
||||
const set_field = `const field = document.querySelector("#${el.id}");`;
|
||||
const replace_field = `if(field && '${el.id}'.indexOf('X__') < 0){` + 'field.parentNode.replaceChild(' + 'Regular.createElementFromHTML(data),' + `document.querySelector("#${el.id}")` + ');' + '}';
|
||||
const remove_spinner = `if(field && '${el.id}'.indexOf('X__') < 0){` + 'field.parentNode.querySelectorAll(`.rl-spinner`).forEach((el) => {' + 'el.remove();' + '})' + '}';
|
||||
|
||||
let success = replace_field;
|
||||
|
||||
if (attributes.treeselect) {
|
||||
success += `if(data.indexOf('rl-treeselect-') > -1){RegularLabs.TreeSelect.init('${el.id}');}`;
|
||||
}
|
||||
|
||||
success += `RegularLabs.AdminForm.updateShowOn('${attributes.name}');`;
|
||||
|
||||
const error = `${set_field}${remove_spinner}`;
|
||||
success = `if(data){${set_field}${remove_spinner}${success}}`;
|
||||
|
||||
el.dataset['rlAjaxDone'] = 1;
|
||||
|
||||
RegularLabs.Scripts.addToLoadAjaxList(url, success, error);
|
||||
|
||||
function createCompressedAttributes(object) {
|
||||
const string = JSON.stringify(object);
|
||||
|
||||
const compressed = btoa(string);
|
||||
const chunk_length = Math.ceil(compressed.length / 10);
|
||||
const chunks = compressed.match(new RegExp('.{1,' + chunk_length + '}', 'g'));
|
||||
|
||||
const attributes = [];
|
||||
|
||||
chunks.forEach((chunk, i) => {
|
||||
attributes.push(`rlatt_${i}=${encodeURIComponent(chunk)}`);
|
||||
});
|
||||
|
||||
return attributes.join('&');
|
||||
}
|
||||
},
|
||||
|
||||
updateShowOn: function(fieldName) {
|
||||
fieldName = fieldName.replace(/\[\]$/g, '');
|
||||
const showonFields = document.querySelectorAll('[data-showon]');
|
||||
|
||||
showonFields.forEach(field => {
|
||||
if ( ! field.hasAttribute('data-showon-initialised')) {
|
||||
return;
|
||||
}
|
||||
|
||||
const jsonData = field.getAttribute('data-showon') || '';
|
||||
const showOnData = JSON.parse(jsonData);
|
||||
|
||||
showOnData.forEach((showOnItem) => {
|
||||
if (showOnItem.field !== fieldName) {
|
||||
return;
|
||||
}
|
||||
|
||||
field.removeAttribute('data-showon-initialised');
|
||||
Joomla.Showon.initialise(field.parentElement);
|
||||
});
|
||||
});
|
||||
|
||||
},
|
||||
|
||||
isInView: function(el) {
|
||||
const rect = el.getBoundingClientRect();
|
||||
const viewHeight = Math.max(document.documentElement.clientHeight, window.innerHeight);
|
||||
|
||||
if ((rect.bottom < 0 || rect.top - viewHeight >= 0)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// check if element is inside any hidden parents
|
||||
let parent = el.parentElement;
|
||||
|
||||
while (parent) {
|
||||
if (window.getComputedStyle(parent).display === 'none') {
|
||||
return false;
|
||||
}
|
||||
|
||||
parent = parent.parentElement;
|
||||
}
|
||||
|
||||
return true;
|
||||
},
|
||||
|
||||
removeEmptyControlGroups: function() {
|
||||
// remove all empty control groups
|
||||
document.querySelectorAll('div.control-group > div.control-label label').forEach((el) => {
|
||||
if (el.innerHTML.trim() === '') {
|
||||
el.remove();
|
||||
}
|
||||
});
|
||||
document.querySelectorAll('div.control-group > div.control-label,div.control-group > div.controls').forEach((el) => {
|
||||
if (el.innerHTML.trim() === '') {
|
||||
el.remove();
|
||||
}
|
||||
});
|
||||
document.querySelectorAll('div.control-group').forEach((el) => {
|
||||
if (el.innerHTML.trim() === '') {
|
||||
el.remove();
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
setParentClassOnCheckboxes: function() {
|
||||
document.querySelectorAll('fieldset.rl-form-checkboxes-set-parent-classes input').forEach((el) => {
|
||||
this.setParentClassOnCheckbox(el);
|
||||
document.addEventListener('change', (event) => {
|
||||
this.setParentClassOnCheckbox(el);
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
setParentClassOnCheckbox: function(el) {
|
||||
el.parentElement.classList.toggle('rl-checkbox-checked', el.checked);
|
||||
},
|
||||
|
||||
updateColoursOnSelectboxes: function() {
|
||||
document.querySelectorAll('[class*="rl-form-select-color"]').forEach((el) => {
|
||||
this.updateColoursOnSelectbox(el);
|
||||
document.addEventListener('change', (event) => {
|
||||
this.updateColoursOnSelectbox(el);
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
updateColoursOnSelectbox: function(el) {
|
||||
const value = parseInt(el.value, 10); // Add class on page load
|
||||
|
||||
el.classList.remove('form-select-success', 'form-select-danger', 'rl-form-select-info', 'rl-form-select-ghosted');
|
||||
|
||||
if (value === -1) {
|
||||
el.classList.add('rl-form-select-ghosted');
|
||||
return;
|
||||
}
|
||||
|
||||
if (el.classList.contains('rl-form-select-color-has-global') && value === -2) {
|
||||
el.classList.add('rl-form-select-info');
|
||||
}
|
||||
|
||||
if ( ! el.classList.contains('rl-form-select-color-has-states')) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (value === -2 || value === 0) {
|
||||
el.classList.add('form-select-danger');
|
||||
return;
|
||||
}
|
||||
|
||||
if (value === 1) {
|
||||
el.classList.add('form-select-success');
|
||||
return;
|
||||
}
|
||||
},
|
||||
|
||||
updateForm: function() {
|
||||
this.loadAjaxFields();
|
||||
this.removeEmptyControlGroups();
|
||||
}
|
||||
};
|
||||
|
||||
RegularLabs.AdminForm.updateForm();
|
||||
RegularLabs.AdminForm.setParentClassOnCheckboxes();
|
||||
RegularLabs.AdminForm.updateColoursOnSelectboxes();
|
||||
|
||||
document.addEventListener('joomla:showon-show', (event) => {
|
||||
event.target.querySelectorAll('.CodeMirror').forEach((editor) => {
|
||||
editor.CodeMirror.refresh();
|
||||
});
|
||||
});
|
||||
document.addEventListener('joomla.tab.show', (event) => {
|
||||
document.querySelectorAll('.CodeMirror').forEach((editor) => {
|
||||
editor.CodeMirror.refresh();
|
||||
});
|
||||
});
|
||||
|
||||
setInterval(() => {
|
||||
RegularLabs.AdminForm.updateForm();
|
||||
}, 1000);
|
||||
})();
|
||||
23
media/regularlabs/js/admin-form.min.js
vendored
Normal file
23
media/regularlabs/js/admin-form.min.js
vendored
Normal file
@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright © 2024 Regular Labs - All Rights Reserved
|
||||
* GNU General Public License version 2 or later
|
||||
*/
|
||||
(function(){'use strict';window.RegularLabs=window.RegularLabs||{};window.RegularLabs.AdminForm=window.RegularLabs.AdminForm||{setToggleTitleClass:function(input,value){const panel=input.closest('.rl-panel');if(!panel){return;}
|
||||
panel.classList.remove('rl-panel-info');panel.classList.remove('rl-panel-success');panel.classList.remove('rl-panel-error');switch(value){case 2:panel.classList.add('rl-panel-error');break;case 1:panel.classList.add('rl-panel-success');break;default:panel.classList.add('rl-panel-info');break;}},loadAjaxButton:function(id,url){const button=document.querySelector(`#${id}`);const icon=button.querySelector("span:nth-child(1)");const message=document.querySelector(`#message_${id}`);icon.className="icon-refresh icon-spin";message.className="";message.innerHTML="";const constants=`const button=document.querySelector("#${id}");const icon=button.querySelector("span:nth-child(1)");const message=document.querySelector("#message_${id}");`;let success=`${constants}
|
||||
Regular.removeClass(button,"btn-warning");Regular.addClass(button,"btn-success");button.querySelector("span:nth-child(1)").className="icon-ok";if(data){Regular.addClass(message,"alert alert-success alert-noclose alert-inline");message.innerHTML=data;}`;let error=`${constants}
|
||||
Regular.removeClass(button,"btn-success");Regular.addClass(button,"btn-warning");button.querySelector("span:nth-child(1)").className="icon-warning";if(data){let error=data;if(data.statusText){error=data.statusText;if(data.responseText.test(/<blockquote>/)){error=data.responseText.replace(/^[.\\s\\S]*?<blockquote>([.\\s\\S]*?)<\\/blockquote>[.\\s\\S]*$/gm,"$1");}}
|
||||
Regular.addClass(message,"alert alert-danger alert-noclose alert-inline");message.innerHTML=error;}`;success=`if(data==""||data.substring(0,1)=="+"){data=data.trim().replace(/^[+]/,"");${success}}else{data=data.trim().replace(/^[-]/,"");${error}}`;RegularLabs.Scripts.loadAjax(url,success,error);},loadAjaxFields:function(){if(typeof RegularLabs.Scripts==='undefined'){return;}
|
||||
document.querySelectorAll('textarea[data-rl-ajax]').forEach((el)=>{this.loadAjaxField(el);});},loadAjaxField:function(el){if(el.dataset['rlAjaxDone']){return;}
|
||||
if(!this.isInView(el)){return;}
|
||||
const wrapper=el.closest('.rl-ajax-wrapper');if(wrapper){wrapper.classList.add('loaded');}
|
||||
let attributes=JSON.parse(el.dataset['rlAjax']);attributes.id=el.id;attributes.name=el.name;const query_attributes=createCompressedAttributes(attributes);const url=`index.php?option=com_ajax&plugin=regularlabs&format=raw&fieldid=${el.id}&${query_attributes}`;const set_field=`const field=document.querySelector("#${el.id}");`;const replace_field=`if(field&&'${el.id}'.indexOf('X__')<0){`+'field.parentNode.replaceChild('+'Regular.createElementFromHTML(data),'+`document.querySelector("#${el.id}")`+');'+'}';const remove_spinner=`if(field&&'${el.id}'.indexOf('X__')<0){`+'field.parentNode.querySelectorAll(`.rl-spinner`).forEach((el) => {'+'el.remove();'+'})'+'}';let success=replace_field;if(attributes.treeselect){success+=`if(data.indexOf('rl-treeselect-')>-1){RegularLabs.TreeSelect.init('${el.id}');}`;}
|
||||
success+=`RegularLabs.AdminForm.updateShowOn('${attributes.name}');`;const error=`${set_field}${remove_spinner}`;success=`if(data){${set_field}${remove_spinner}${success}}`;el.dataset['rlAjaxDone']=1;RegularLabs.Scripts.addToLoadAjaxList(url,success,error);function createCompressedAttributes(object){const string=JSON.stringify(object);const compressed=btoa(string);const chunk_length=Math.ceil(compressed.length/10);const chunks=compressed.match(new RegExp('.{1,'+chunk_length+'}','g'));const attributes=[];chunks.forEach((chunk,i)=>{attributes.push(`rlatt_${i}=${encodeURIComponent(chunk)}`);});return attributes.join('&');}},updateShowOn:function(fieldName){fieldName=fieldName.replace(/\[\]$/g,'');const showonFields=document.querySelectorAll('[data-showon]');showonFields.forEach(field=>{if(!field.hasAttribute('data-showon-initialised')){return;}
|
||||
const jsonData=field.getAttribute('data-showon')||'';const showOnData=JSON.parse(jsonData);showOnData.forEach((showOnItem)=>{if(showOnItem.field!==fieldName){return;}
|
||||
field.removeAttribute('data-showon-initialised');Joomla.Showon.initialise(field.parentElement);});});},isInView:function(el){const rect=el.getBoundingClientRect();const viewHeight=Math.max(document.documentElement.clientHeight,window.innerHeight);if((rect.bottom<0||rect.top-viewHeight>=0)){return false;}
|
||||
let parent=el.parentElement;while(parent){if(window.getComputedStyle(parent).display==='none'){return false;}
|
||||
parent=parent.parentElement;}
|
||||
return true;},removeEmptyControlGroups:function(){document.querySelectorAll('div.control-group > div.control-label label').forEach((el)=>{if(el.innerHTML.trim()===''){el.remove();}});document.querySelectorAll('div.control-group > div.control-label,div.control-group > div.controls').forEach((el)=>{if(el.innerHTML.trim()===''){el.remove();}});document.querySelectorAll('div.control-group').forEach((el)=>{if(el.innerHTML.trim()===''){el.remove();}});},setParentClassOnCheckboxes:function(){document.querySelectorAll('fieldset.rl-form-checkboxes-set-parent-classes input').forEach((el)=>{this.setParentClassOnCheckbox(el);document.addEventListener('change',(event)=>{this.setParentClassOnCheckbox(el);});});},setParentClassOnCheckbox:function(el){el.parentElement.classList.toggle('rl-checkbox-checked',el.checked);},updateColoursOnSelectboxes:function(){document.querySelectorAll('[class*="rl-form-select-color"]').forEach((el)=>{this.updateColoursOnSelectbox(el);document.addEventListener('change',(event)=>{this.updateColoursOnSelectbox(el);});});},updateColoursOnSelectbox:function(el){const value=parseInt(el.value,10);el.classList.remove('form-select-success','form-select-danger','rl-form-select-info','rl-form-select-ghosted');if(value===-1){el.classList.add('rl-form-select-ghosted');return;}
|
||||
if(el.classList.contains('rl-form-select-color-has-global')&&value===-2){el.classList.add('rl-form-select-info');}
|
||||
if(!el.classList.contains('rl-form-select-color-has-states')){return;}
|
||||
if(value===-2||value===0){el.classList.add('form-select-danger');return;}
|
||||
if(value===1){el.classList.add('form-select-success');return;}},updateForm:function(){this.loadAjaxFields();this.removeEmptyControlGroups();}};RegularLabs.AdminForm.updateForm();RegularLabs.AdminForm.setParentClassOnCheckboxes();RegularLabs.AdminForm.updateColoursOnSelectboxes();document.addEventListener('joomla:showon-show',(event)=>{event.target.querySelectorAll('.CodeMirror').forEach((editor)=>{editor.CodeMirror.refresh();});});document.addEventListener('joomla.tab.show',(event)=>{document.querySelectorAll('.CodeMirror').forEach((editor)=>{editor.CodeMirror.refresh();});});setInterval(()=>{RegularLabs.AdminForm.updateForm();},1000);})();
|
||||
341
media/regularlabs/js/downloadkey.js
Normal file
341
media/regularlabs/js/downloadkey.js
Normal file
@ -0,0 +1,341 @@
|
||||
/**
|
||||
* @package Regular Labs Library
|
||||
* @version 24.11.1459
|
||||
*
|
||||
* @author Peter van Westen <info@regularlabs.com>
|
||||
* @link https://regularlabs.com
|
||||
* @copyright Copyright © 2024 Regular Labs All Rights Reserved
|
||||
* @license GNU General Public License version 2 or later
|
||||
*/
|
||||
|
||||
(function() {
|
||||
'use strict';
|
||||
|
||||
window.RegularLabs = window.RegularLabs || {};
|
||||
|
||||
window.RegularLabs.DownloadKey = window.RegularLabs.DownloadKey || {
|
||||
init: function() {
|
||||
const downloadKeys = document.querySelectorAll('div.rl-download-key');
|
||||
|
||||
downloadKeys.forEach((container) => {
|
||||
const spinner = container.querySelector('span.rl-spinner');
|
||||
const inputField = container.querySelector('input.rl-code-field');
|
||||
const editButton = container.querySelector('.button-edit');
|
||||
const applyButton = container.querySelector('.button-apply');
|
||||
const cancelButton = container.querySelector('.button-cancel');
|
||||
const emptyError = container.querySelector('.key-error-empty');
|
||||
const localError = container.querySelector('.key-error-local');
|
||||
const modal = container.querySelector(`#downloadKeyModal_${inputField.id}`);
|
||||
const extension = inputField.dataset['keyExtension'];
|
||||
|
||||
let key = '';
|
||||
|
||||
if (modal) {
|
||||
// Move modal to end of body, to prevent it getting hidden if inside hidden tab
|
||||
document.body.appendChild(modal);
|
||||
|
||||
modal.addEventListener('shown.bs.modal', () => {
|
||||
const modalInputField = modal.querySelector('input.rl-download-key-field');
|
||||
modalInputField.focus();
|
||||
});
|
||||
}
|
||||
|
||||
const getKey = async function() {
|
||||
const url = 'index.php?option=com_ajax&plugin=regularlabs&format=raw&getDownloadKey=1';
|
||||
|
||||
const response = await RegularLabs.Scripts.loadUrl(url);
|
||||
|
||||
if (response.status !== 200) {
|
||||
handleGetKeyFail();
|
||||
return;
|
||||
}
|
||||
|
||||
const responseText = response.responseText.trim();
|
||||
|
||||
handleGetKeySuccess(responseText);
|
||||
};
|
||||
|
||||
const handleGetKeySuccess = async function(data) {
|
||||
if ( ! data.match(/^[a-z0-9]*$/i)) {
|
||||
handleGetKeyFail();
|
||||
return;
|
||||
}
|
||||
|
||||
key = data;
|
||||
|
||||
await checkDownloadKey();
|
||||
|
||||
reset();
|
||||
|
||||
addListeners();
|
||||
};
|
||||
|
||||
const handleGetKeyFail = function() {
|
||||
localError.classList.remove('hidden');
|
||||
|
||||
showModal();
|
||||
};
|
||||
|
||||
const checkDownloadKey = async function() {
|
||||
const result = await RegularLabs.DownloadKey.check(extension, key, container, false);
|
||||
|
||||
if (['empty', 'invalid'].indexOf(result.error) > -1) {
|
||||
showModal();
|
||||
}
|
||||
};
|
||||
|
||||
const showModal = function() {
|
||||
if ( ! modal) {
|
||||
return;
|
||||
}
|
||||
|
||||
RegularLabs.DownloadKey.check(extension, key, modal);
|
||||
|
||||
if (window.bootstrap && window.bootstrap.Modal && ! window.bootstrap.Modal.getInstance(modal)) {
|
||||
Joomla.initialiseModal(modal, {
|
||||
isJoomla: true
|
||||
});
|
||||
}
|
||||
|
||||
window.bootstrap.Modal.getInstance(modal).show();
|
||||
};
|
||||
|
||||
const addListeners = function() {
|
||||
inputField.addEventListener('focus', selectField);
|
||||
inputField.addEventListener('keydown', handleKeyPressField);
|
||||
document.addEventListener('mousedown', deselectField);
|
||||
editButton.addEventListener('click', () => {
|
||||
inputField.focus();
|
||||
});
|
||||
applyButton.addEventListener('click', clickSave);
|
||||
cancelButton.addEventListener('click', clickCancel);
|
||||
};
|
||||
|
||||
const selectField = function() {
|
||||
inputField.value = '';
|
||||
inputField.classList.remove('inactive');
|
||||
editButton.classList.add('hidden');
|
||||
applyButton.classList.remove('hidden');
|
||||
cancelButton.classList.remove('hidden');
|
||||
};
|
||||
|
||||
const handleKeyPressField = function(event) {
|
||||
switch (event.keyCode) {
|
||||
case 13: // ENTER
|
||||
save();
|
||||
break;
|
||||
|
||||
case 27: // ESC
|
||||
cancel();
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
const deselectField = function(event) {
|
||||
if (event.target.closest('div.rl-download-key') === container) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (inputField.classList.contains('inactive')) {
|
||||
return;
|
||||
}
|
||||
|
||||
cancel();
|
||||
};
|
||||
|
||||
const clickSave = function(event) {
|
||||
event.preventDefault();
|
||||
save();
|
||||
};
|
||||
|
||||
const clickCancel = function(event) {
|
||||
event.preventDefault();
|
||||
cancel();
|
||||
};
|
||||
|
||||
const save = async function() {
|
||||
const saved = await RegularLabs.DownloadKey.save(extension, inputField.value, container);
|
||||
|
||||
if ( ! saved) {
|
||||
return;
|
||||
}
|
||||
|
||||
key = inputField.value;
|
||||
|
||||
container.dataset.callback && eval(`(() => {
|
||||
${container.dataset.callback}
|
||||
})()`);
|
||||
|
||||
reset();
|
||||
};
|
||||
|
||||
const cancel = async function() {
|
||||
reset();
|
||||
|
||||
RegularLabs.DownloadKey.resetErrors(container);
|
||||
RegularLabs.DownloadKey.check(extension, key, container);
|
||||
};
|
||||
|
||||
const reset = function() {
|
||||
inputField.value = cloak(key);
|
||||
|
||||
inputField.blur();
|
||||
spinner.classList.add('hidden');
|
||||
inputField.classList.remove('hidden');
|
||||
inputField.classList.add('inactive');
|
||||
editButton.classList.remove('hidden');
|
||||
applyButton.classList.add('hidden');
|
||||
cancelButton.classList.add('hidden');
|
||||
};
|
||||
|
||||
const cloak = function(string) {
|
||||
return RegularLabs.DownloadKey.cloak(string, inputField.dataset['keyCloakLength']);
|
||||
};
|
||||
|
||||
getKey();
|
||||
});
|
||||
},
|
||||
|
||||
cloak: function(string, cloakLength = 4) {
|
||||
if (string.length <= cloakLength) {
|
||||
return string;
|
||||
}
|
||||
|
||||
return "*".repeat(string.length - cloakLength) + string.substr(-cloakLength);
|
||||
},
|
||||
|
||||
showError: function(type, element, focus = true) {
|
||||
element.querySelector(`.key-error-${type}`) && element.querySelector(`.key-error-${type}`).classList.remove('hidden');
|
||||
|
||||
if (type === 'empty' || type === 'expired' || type === 'invalid') {
|
||||
element.querySelector('div.rl-download-key-wrapper') && element.querySelector('div.rl-download-key-wrapper').classList.remove('hidden');
|
||||
}
|
||||
|
||||
if ( ! focus) {
|
||||
return;
|
||||
}
|
||||
|
||||
const inputField = element.querySelector('input.rl-download-key-field');
|
||||
|
||||
inputField.classList.add('invalid');
|
||||
inputField.click();
|
||||
},
|
||||
|
||||
resetErrors: function(element) {
|
||||
const inputField = element.querySelector('input.rl-download-key-field');
|
||||
|
||||
inputField.classList.remove('invalid');
|
||||
|
||||
element.querySelectorAll('[class*="key-error-"]').forEach((error) => {
|
||||
error.classList.add('hidden');
|
||||
});
|
||||
},
|
||||
|
||||
save: function(extension, key, element) {
|
||||
return new Promise(async (resolve) => {
|
||||
|
||||
const result = await RegularLabs.DownloadKey.check(extension, key, element);
|
||||
|
||||
if ( ! result.pass) {
|
||||
resolve(false);
|
||||
return;
|
||||
}
|
||||
|
||||
await RegularLabs.DownloadKey.store(extension, key);
|
||||
|
||||
if (window.bootstrap.Modal && window.bootstrap.Modal.getInstance(element)) {
|
||||
const mainId = element.id.replace('downloadKeyModal_', 'downloadKeyWrapper_');
|
||||
const mainElement = document.querySelector(`#${mainId}`);
|
||||
RegularLabs.DownloadKey.resetErrors(mainElement);
|
||||
await RegularLabs.DownloadKey.check(extension, key, mainElement);
|
||||
window.bootstrap.Modal.getInstance(element).hide();
|
||||
} else {
|
||||
RegularLabs.DownloadKey.resetErrors(element);
|
||||
await RegularLabs.DownloadKey.check(extension, key, element);
|
||||
}
|
||||
|
||||
resolve(true);
|
||||
});
|
||||
},
|
||||
|
||||
check: function(extension, key, element, focus = true) {
|
||||
return new Promise(async (resolve) => {
|
||||
const url = `index.php?option=com_ajax&plugin=regularlabs&format=raw&checkDownloadKey=1&extension=${extension}&key=${key}`;
|
||||
const inputField = element.querySelector('input.rl-download-key-field');
|
||||
|
||||
RegularLabs.DownloadKey.resetErrors(element);
|
||||
|
||||
const result = {pass: false, error: ''};
|
||||
|
||||
if ( ! key) {
|
||||
result.error = 'empty';
|
||||
RegularLabs.DownloadKey.showError(result.error, element, focus);
|
||||
inputField.value = RegularLabs.DownloadKey.cloak(key);
|
||||
|
||||
result.pass = true;
|
||||
resolve(result);
|
||||
return;
|
||||
}
|
||||
|
||||
const response = await RegularLabs.Scripts.loadUrl(url);
|
||||
|
||||
if (response.status !== 200) {
|
||||
result.error = 'local';
|
||||
RegularLabs.DownloadKey.showError(result.error, element, false);
|
||||
|
||||
resolve(result);
|
||||
return;
|
||||
}
|
||||
|
||||
const responseText = response.responseText.trim();
|
||||
|
||||
if ( ! responseText || responseText.charAt(0) !== '{') {
|
||||
result.error = 'external';
|
||||
RegularLabs.DownloadKey.showError(result.error, element, false);
|
||||
|
||||
resolve(result);
|
||||
return;
|
||||
}
|
||||
|
||||
const data = JSON.parse(responseText);
|
||||
|
||||
if ( ! data.valid) {
|
||||
result.error = 'invalid';
|
||||
RegularLabs.DownloadKey.showError(result.error, element, focus);
|
||||
|
||||
resolve(result);
|
||||
return;
|
||||
}
|
||||
|
||||
const is_modal = element.id.indexOf('downloadKeyModal_') > -1;
|
||||
|
||||
if ( ! data.active && is_modal) {
|
||||
result.error = 'expired';
|
||||
RegularLabs.DownloadKey.showError(result.error, element, focus);
|
||||
|
||||
resolve(result);
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! data.active) {
|
||||
RegularLabs.DownloadKey.showError('expired', element, false);
|
||||
}
|
||||
|
||||
inputField.value = RegularLabs.DownloadKey.cloak(key);
|
||||
|
||||
result.pass = true;
|
||||
resolve(result);
|
||||
});
|
||||
},
|
||||
|
||||
store: function(extension, key) {
|
||||
const url = `index.php?option=com_ajax&plugin=regularlabs&format=raw&saveDownloadKey=1&key=${key}`;
|
||||
return RegularLabs.Scripts.loadUrl(url);
|
||||
},
|
||||
};
|
||||
|
||||
RegularLabs.DownloadKey.init();
|
||||
})();
|
||||
24
media/regularlabs/js/downloadkey.min.js
vendored
Normal file
24
media/regularlabs/js/downloadkey.min.js
vendored
Normal file
@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright © 2024 Regular Labs - All Rights Reserved
|
||||
* GNU General Public License version 2 or later
|
||||
*/
|
||||
(function(){'use strict';window.RegularLabs=window.RegularLabs||{};window.RegularLabs.DownloadKey=window.RegularLabs.DownloadKey||{init:function(){const downloadKeys=document.querySelectorAll('div.rl-download-key');downloadKeys.forEach((container)=>{const spinner=container.querySelector('span.rl-spinner');const inputField=container.querySelector('input.rl-code-field');const editButton=container.querySelector('.button-edit');const applyButton=container.querySelector('.button-apply');const cancelButton=container.querySelector('.button-cancel');const emptyError=container.querySelector('.key-error-empty');const localError=container.querySelector('.key-error-local');const modal=container.querySelector(`#downloadKeyModal_${inputField.id}`);const extension=inputField.dataset['keyExtension'];let key='';if(modal){document.body.appendChild(modal);modal.addEventListener('shown.bs.modal',()=>{const modalInputField=modal.querySelector('input.rl-download-key-field');modalInputField.focus();});}
|
||||
const getKey=async function(){const url='index.php?option=com_ajax&plugin=regularlabs&format=raw&getDownloadKey=1';const response=await RegularLabs.Scripts.loadUrl(url);if(response.status!==200){handleGetKeyFail();return;}
|
||||
const responseText=response.responseText.trim();handleGetKeySuccess(responseText);};const handleGetKeySuccess=async function(data){if(!data.match(/^[a-z0-9]*$/i)){handleGetKeyFail();return;}
|
||||
key=data;await checkDownloadKey();reset();addListeners();};const handleGetKeyFail=function(){localError.classList.remove('hidden');showModal();};const checkDownloadKey=async function(){const result=await RegularLabs.DownloadKey.check(extension,key,container,false);if(['empty','invalid'].indexOf(result.error)>-1){showModal();}};const showModal=function(){if(!modal){return;}
|
||||
RegularLabs.DownloadKey.check(extension,key,modal);if(window.bootstrap&&window.bootstrap.Modal&&!window.bootstrap.Modal.getInstance(modal)){Joomla.initialiseModal(modal,{isJoomla:true});}
|
||||
window.bootstrap.Modal.getInstance(modal).show();};const addListeners=function(){inputField.addEventListener('focus',selectField);inputField.addEventListener('keydown',handleKeyPressField);document.addEventListener('mousedown',deselectField);editButton.addEventListener('click',()=>{inputField.focus();});applyButton.addEventListener('click',clickSave);cancelButton.addEventListener('click',clickCancel);};const selectField=function(){inputField.value='';inputField.classList.remove('inactive');editButton.classList.add('hidden');applyButton.classList.remove('hidden');cancelButton.classList.remove('hidden');};const handleKeyPressField=function(event){switch(event.keyCode){case 13:save();break;case 27:cancel();break;default:break;}};const deselectField=function(event){if(event.target.closest('div.rl-download-key')===container){return;}
|
||||
if(inputField.classList.contains('inactive')){return;}
|
||||
cancel();};const clickSave=function(event){event.preventDefault();save();};const clickCancel=function(event){event.preventDefault();cancel();};const save=async function(){const saved=await RegularLabs.DownloadKey.save(extension,inputField.value,container);if(!saved){return;}
|
||||
key=inputField.value;container.dataset.callback&&eval(`(()=>{${container.dataset.callback}})()`);reset();};const cancel=async function(){reset();RegularLabs.DownloadKey.resetErrors(container);RegularLabs.DownloadKey.check(extension,key,container);};const reset=function(){inputField.value=cloak(key);inputField.blur();spinner.classList.add('hidden');inputField.classList.remove('hidden');inputField.classList.add('inactive');editButton.classList.remove('hidden');applyButton.classList.add('hidden');cancelButton.classList.add('hidden');};const cloak=function(string){return RegularLabs.DownloadKey.cloak(string,inputField.dataset['keyCloakLength']);};getKey();});},cloak:function(string,cloakLength=4){if(string.length<=cloakLength){return string;}
|
||||
return"*".repeat(string.length-cloakLength)+string.substr(-cloakLength);},showError:function(type,element,focus=true){element.querySelector(`.key-error-${type}`)&&element.querySelector(`.key-error-${type}`).classList.remove('hidden');if(type==='empty'||type==='expired'||type==='invalid'){element.querySelector('div.rl-download-key-wrapper')&&element.querySelector('div.rl-download-key-wrapper').classList.remove('hidden');}
|
||||
if(!focus){return;}
|
||||
const inputField=element.querySelector('input.rl-download-key-field');inputField.classList.add('invalid');inputField.click();},resetErrors:function(element){const inputField=element.querySelector('input.rl-download-key-field');inputField.classList.remove('invalid');element.querySelectorAll('[class*="key-error-"]').forEach((error)=>{error.classList.add('hidden');});},save:function(extension,key,element){return new Promise(async(resolve)=>{const result=await RegularLabs.DownloadKey.check(extension,key,element);if(!result.pass){resolve(false);return;}
|
||||
await RegularLabs.DownloadKey.store(extension,key);if(window.bootstrap.Modal&&window.bootstrap.Modal.getInstance(element)){const mainId=element.id.replace('downloadKeyModal_','downloadKeyWrapper_');const mainElement=document.querySelector(`#${mainId}`);RegularLabs.DownloadKey.resetErrors(mainElement);await RegularLabs.DownloadKey.check(extension,key,mainElement);window.bootstrap.Modal.getInstance(element).hide();}else{RegularLabs.DownloadKey.resetErrors(element);await RegularLabs.DownloadKey.check(extension,key,element);}
|
||||
resolve(true);});},check:function(extension,key,element,focus=true){return new Promise(async(resolve)=>{const url=`index.php?option=com_ajax&plugin=regularlabs&format=raw&checkDownloadKey=1&extension=${extension}&key=${key}`;const inputField=element.querySelector('input.rl-download-key-field');RegularLabs.DownloadKey.resetErrors(element);const result={pass:false,error:''};if(!key){result.error='empty';RegularLabs.DownloadKey.showError(result.error,element,focus);inputField.value=RegularLabs.DownloadKey.cloak(key);result.pass=true;resolve(result);return;}
|
||||
const response=await RegularLabs.Scripts.loadUrl(url);if(response.status!==200){result.error='local';RegularLabs.DownloadKey.showError(result.error,element,false);resolve(result);return;}
|
||||
const responseText=response.responseText.trim();if(!responseText||responseText.charAt(0)!=='{'){result.error='external';RegularLabs.DownloadKey.showError(result.error,element,false);resolve(result);return;}
|
||||
const data=JSON.parse(responseText);if(!data.valid){result.error='invalid';RegularLabs.DownloadKey.showError(result.error,element,focus);resolve(result);return;}
|
||||
const is_modal=element.id.indexOf('downloadKeyModal_')>-1;if(!data.active&&is_modal){result.error='expired';RegularLabs.DownloadKey.showError(result.error,element,focus);resolve(result);return;}
|
||||
if(!data.active){RegularLabs.DownloadKey.showError('expired',element,false);}
|
||||
inputField.value=RegularLabs.DownloadKey.cloak(key);result.pass=true;resolve(result);});},store:function(extension,key){const url=`index.php?option=com_ajax&plugin=regularlabs&format=raw&saveDownloadKey=1&key=${key}`;return RegularLabs.Scripts.loadUrl(url);},};RegularLabs.DownloadKey.init();})();
|
||||
498
media/regularlabs/js/mini-colors.js
Normal file
498
media/regularlabs/js/mini-colors.js
Normal file
@ -0,0 +1,498 @@
|
||||
/**
|
||||
* @package Regular Labs Library
|
||||
* @version 24.11.1459
|
||||
*
|
||||
* @author Peter van Westen <info@regularlabs.com>
|
||||
* @link https://regularlabs.com
|
||||
* @copyright Copyright © 2024 Regular Labs All Rights Reserved
|
||||
* @license GNU General Public License version 2 or later
|
||||
*/
|
||||
|
||||
(function(window, document, Math) {
|
||||
var picker, currentEl, oldColor;
|
||||
|
||||
// Default settings
|
||||
var settings = {
|
||||
el : '[data-rl-mini-colors]',
|
||||
parent : null,
|
||||
wrap : true,
|
||||
margin : 2,
|
||||
swatches : [],
|
||||
swatchesOnly: false,
|
||||
alpha : true,
|
||||
autoClose : false,
|
||||
|
||||
a11y: {
|
||||
open : 'Open color picker',
|
||||
swatch: 'Color swatch',
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Configure the color picker.
|
||||
* @param {object} options Configuration options.
|
||||
*/
|
||||
function configure(options) {
|
||||
if (typeof options !== 'object') {
|
||||
return;
|
||||
}
|
||||
|
||||
for (var key in options) {
|
||||
switch (key) {
|
||||
case 'el':
|
||||
bindFields(options.el);
|
||||
if (options.wrap !== false) {
|
||||
wrapFields(options.el);
|
||||
}
|
||||
break;
|
||||
case 'parent':
|
||||
settings.parent = document.querySelector(options.parent);
|
||||
if (settings.parent) {
|
||||
settings.parent.appendChild(picker);
|
||||
}
|
||||
break;
|
||||
case 'margin':
|
||||
options.margin *= 1;
|
||||
settings.margin = ! isNaN(options.margin) ? options.margin : settings.margin;
|
||||
break;
|
||||
case 'wrap':
|
||||
if (options.el && options.wrap) {
|
||||
wrapFields(options.el);
|
||||
}
|
||||
break;
|
||||
case 'swatches':
|
||||
if (Array.isArray(options.swatches)) {
|
||||
(function() {
|
||||
var swatches = [];
|
||||
|
||||
options.swatches.forEach(function(swatch, i) {
|
||||
swatches.push("<button id=\"rl-mini-colors-swatch-" + i + "\" class=\"rl-mini-colors-button\" aria-labelledby=\"rl-mini-colors-swatch-label rl-mini-colors-swatch-" + i + "\" style=\"color: " + swatch + ";\">" + swatch + "</button>");
|
||||
});
|
||||
|
||||
if (swatches.length) {
|
||||
getEl('rl-mini-colors-swatches').innerHTML = "<div>" + swatches.join('') + "</div>";
|
||||
}
|
||||
})();
|
||||
}
|
||||
break;
|
||||
case 'swatchesOnly':
|
||||
settings.swatchesOnly = !! options.swatchesOnly;
|
||||
picker.setAttribute('data-minimal', settings.swatchesOnly);
|
||||
|
||||
if (settings.swatchesOnly) {
|
||||
settings.autoClose = true;
|
||||
}
|
||||
break;
|
||||
case 'a11y':
|
||||
var labels = options.a11y;
|
||||
var update = false;
|
||||
|
||||
if (typeof labels === 'object') {
|
||||
for (var label in labels) {
|
||||
if (labels[label] && settings.a11y[label]) {
|
||||
settings.a11y[label] = labels[label];
|
||||
update = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (update) {
|
||||
var openLabel = getEl('rl-mini-colors-open-label');
|
||||
var swatchLabel = getEl('rl-mini-colors-swatch-label');
|
||||
|
||||
openLabel.innerHTML = settings.a11y.open;
|
||||
swatchLabel.innerHTML = settings.a11y.swatch;
|
||||
}
|
||||
default:
|
||||
settings[key] = options[key];
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Bind the color picker to input fields that match the selector.
|
||||
* @param {string} selector One or more selectors pointing to input fields.
|
||||
*/
|
||||
function bindFields(selector) {
|
||||
// Show the color picker on click on the input fields that match the selector
|
||||
addListener(document, 'click', selector, function(event) {
|
||||
|
||||
var parent = settings.parent;
|
||||
var coords = event.target.getBoundingClientRect();
|
||||
var scrollY = window.scrollY;
|
||||
var reposition = {left: false, top: false};
|
||||
var offset = {x: 0, y: 0};
|
||||
var left = coords.x;
|
||||
var top = scrollY + coords.y + coords.height + settings.margin;
|
||||
|
||||
currentEl = event.target;
|
||||
picker.classList.add('rl-mini-colors-open');
|
||||
|
||||
var pickerWidth = picker.offsetWidth;
|
||||
var pickerHeight = picker.offsetHeight;
|
||||
|
||||
// If the color picker is inside a custom container
|
||||
// set the position relative to it
|
||||
if (parent) {
|
||||
var style = window.getComputedStyle(parent);
|
||||
var marginTop = parseFloat(style.marginTop);
|
||||
var borderTop = parseFloat(style.borderTopWidth);
|
||||
|
||||
offset = parent.getBoundingClientRect();
|
||||
offset.y += borderTop + scrollY;
|
||||
left -= offset.x;
|
||||
top -= offset.y;
|
||||
|
||||
if (left + pickerWidth > parent.clientWidth) {
|
||||
left += coords.width - pickerWidth;
|
||||
reposition.left = true;
|
||||
}
|
||||
|
||||
if (top + pickerHeight > parent.clientHeight - marginTop) {
|
||||
top -= coords.height + pickerHeight + settings.margin * 2;
|
||||
reposition.top = true;
|
||||
}
|
||||
|
||||
top += parent.scrollTop;
|
||||
|
||||
// Otherwise set the position relative to the whole document
|
||||
} else {
|
||||
if (left + pickerWidth > document.documentElement.clientWidth) {
|
||||
left += coords.width - pickerWidth;
|
||||
reposition.left = true;
|
||||
}
|
||||
|
||||
if (top + pickerHeight - scrollY > document.documentElement.clientHeight) {
|
||||
top = scrollY + coords.y - pickerHeight - settings.margin;
|
||||
reposition.top = true;
|
||||
}
|
||||
}
|
||||
|
||||
picker.classList.toggle('rl-mini-colors-left', reposition.left);
|
||||
picker.classList.toggle('rl-mini-colors-top', reposition.top);
|
||||
picker.style.left = left + "px";
|
||||
picker.style.top = top + "px";
|
||||
|
||||
deselectRow(currentEl);
|
||||
});
|
||||
}
|
||||
|
||||
function deselectRow(el) {
|
||||
const tr = el.closest('tr');
|
||||
|
||||
if ( ! tr) {
|
||||
return;
|
||||
}
|
||||
|
||||
const input = tr.querySelector('.form-check-input');
|
||||
|
||||
if ( ! input) {
|
||||
return;
|
||||
}
|
||||
|
||||
input.checked = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrap the linked input fields in a div that adds a color preview.
|
||||
* @param {string} selector One or more selectors pointing to input fields.
|
||||
*/
|
||||
function wrapFields(selector) {
|
||||
document.querySelectorAll(selector).forEach(function(field) {
|
||||
var parentNode = field.parentNode;
|
||||
|
||||
if ( ! parentNode.classList.contains('rl-mini-colors-field')) {
|
||||
var wrapper = document.createElement('div');
|
||||
|
||||
wrapper.innerHTML = "<button class=\"rl-mini-colors-button\" aria-labelledby=\"rl-mini-colors-open-label\"></button>";
|
||||
parentNode.insertBefore(wrapper, field);
|
||||
wrapper.setAttribute('class', 'rl-mini-colors-field');
|
||||
wrapper.style.color = field.value;
|
||||
wrapper.appendChild(field);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Close the color picker.
|
||||
* @param {boolean} [revert] If true, revert the color to the original value.
|
||||
*/
|
||||
function closePicker(color) {
|
||||
if ( ! currentEl) {
|
||||
return;
|
||||
}
|
||||
|
||||
picker.classList.remove('rl-mini-colors-open');
|
||||
|
||||
currentEl = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy the active color to the linked input field.
|
||||
* @param {number} [color] Color value to override the active color.
|
||||
*/
|
||||
function pickColor(color) {
|
||||
if ( ! currentEl) {
|
||||
return;
|
||||
}
|
||||
currentEl.value = color;
|
||||
currentEl.dispatchEvent(new Event('input', {bubbles: true}));
|
||||
currentEl.dispatchEvent(new Event('change', {bubbles: true}));
|
||||
|
||||
const parent = currentEl.parentNode;
|
||||
|
||||
if (parent.classList.contains('rl-mini-colors-field')) {
|
||||
parent.style.color = color;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Init the color picker.
|
||||
*/
|
||||
function init() {
|
||||
// Render the UI
|
||||
picker = document.createElement('div');
|
||||
picker.setAttribute('id', 'rl-mini-colors-picker');
|
||||
picker.className = 'rl-mini-colors-picker';
|
||||
picker.innerHTML =
|
||||
'<div id="rl-mini-colors-swatches" class="rl-mini-colors-swatches"></div>'
|
||||
+ ("<span id=\"rl-mini-colors-open-label\" hidden>" + settings.a11y.open + "</span>")
|
||||
+ ("<span id=\"rl-mini-colors-swatch-label\" hidden>" + settings.a11y.swatch + "</span>");
|
||||
|
||||
// Append the color picker to the DOM
|
||||
document.body.appendChild(picker);
|
||||
|
||||
// Bind the picker to the default selector
|
||||
bindFields(settings.el);
|
||||
wrapFields(settings.el);
|
||||
|
||||
addListener(picker, 'click', '.rl-mini-colors-swatches .rl-mini-colors-button', (event) => {
|
||||
pickColor(event.target.textContent);
|
||||
closePicker(event.target.textContent);
|
||||
});
|
||||
|
||||
addListener(document, 'click', '.rl-mini-colors-field .rl-mini-colors-button', (event) => {
|
||||
event.target.nextElementSibling.dispatchEvent(new Event('click', {bubbles: true}));
|
||||
});
|
||||
|
||||
addListener(document, 'mousedown', (event) => {
|
||||
if (event.target.classList.contains('rl-mini-colors')
|
||||
|| event.target.classList.contains('rl-mini-colors-picker')
|
||||
|| event.target.closest('.rl-mini-colors-picker')) {
|
||||
return;
|
||||
}
|
||||
|
||||
closePicker();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Shortcut for getElementById to optimize the minified JS.
|
||||
* @param {string} id The element id.
|
||||
* @return {object} The DOM element with the provided id.
|
||||
*/
|
||||
function getEl(id) {
|
||||
return document.getElementById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shortcut for addEventListener to optimize the minified JS.
|
||||
* @param {object} context The context to which the listener is attached.
|
||||
* @param {string} type Event type.
|
||||
* @param {(string|function)} selector Event target if delegation is used, event handler if not.
|
||||
* @param {function} [fn] Event handler if delegation is used.
|
||||
*/
|
||||
function addListener(context, type, selector, fn) {
|
||||
var matches = Element.prototype.matches || Element.prototype.msMatchesSelector;
|
||||
|
||||
// Delegate event to the target of the selector
|
||||
if (typeof selector === 'string') {
|
||||
context.addEventListener(type, function(event) {
|
||||
if (matches.call(event.target, selector)) {
|
||||
fn.call(event.target, event);
|
||||
}
|
||||
});
|
||||
|
||||
// If the selector is not a string then it's a function
|
||||
// in which case we need regular event listener
|
||||
} else {
|
||||
fn = selector;
|
||||
context.addEventListener(type, fn);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Call a function only when the DOM is ready.
|
||||
* @param {function} fn The function to call.
|
||||
* @param {array} [args] Arguments to pass to the function.
|
||||
*/
|
||||
function DOMReady(fn, args) {
|
||||
args = args !== undefined ? args : [];
|
||||
|
||||
if (document.readyState !== 'loading') {
|
||||
fn.apply(void 0, args);
|
||||
} else {
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
fn.apply(void 0, args);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Polyfill for Nodelist.forEach
|
||||
if (NodeList !== undefined && NodeList.prototype && ! NodeList.prototype.forEach) {
|
||||
NodeList.prototype.forEach = Array.prototype.forEach;
|
||||
}
|
||||
|
||||
// Expose the color picker to the global scope
|
||||
window.RegularLabs_MiniColors = function() {
|
||||
var methods = {
|
||||
set : configure,
|
||||
wrap : wrapFields,
|
||||
close: closePicker
|
||||
};
|
||||
|
||||
function RegularLabs_MiniColors(options) {
|
||||
DOMReady(function() {
|
||||
if (options) {
|
||||
if (typeof options === 'string') {
|
||||
bindFields(options);
|
||||
} else {
|
||||
configure(options);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
var _loop = function _loop(key) {
|
||||
RegularLabs_MiniColors[key] = function() {
|
||||
for (var _len = arguments.length, args = new Array(_len), _key2 = 0; _key2 < _len; _key2++) {
|
||||
args[_key2] = arguments[_key2];
|
||||
}
|
||||
DOMReady(methods[key], args);
|
||||
};
|
||||
};
|
||||
for (var key in methods) {
|
||||
_loop(key);
|
||||
}
|
||||
|
||||
return RegularLabs_MiniColors;
|
||||
}();
|
||||
|
||||
// Init the color picker when the DOM is ready
|
||||
DOMReady(init);
|
||||
|
||||
})(window, document, Math);
|
||||
|
||||
(function() {
|
||||
'use strict';
|
||||
|
||||
window.RegularLabs = window.RegularLabs || {};
|
||||
|
||||
window.RegularLabs.MiniColors = window.RegularLabs.MiniColors || {
|
||||
init: function() {
|
||||
const minicolors = document.querySelectorAll('div.rl-mini-colors');
|
||||
const options = Joomla.getOptions ? Joomla.getOptions('rl_minicolors', {}) : Joomla.optionsStorage.rl_minicolors || {};
|
||||
|
||||
minicolors.forEach((minicolor) => {
|
||||
const field = minicolor.querySelector('input');
|
||||
RegularLabs_MiniColors({
|
||||
el : `#${field.id}`,
|
||||
theme : 'default',
|
||||
alpha : false,
|
||||
swatchesOnly: true,
|
||||
swatches : options.swatches
|
||||
});
|
||||
|
||||
if ( ! field.dataset['table'] || ! field.dataset['item_id']) {
|
||||
return;
|
||||
}
|
||||
|
||||
field.addEventListener('change', () => {
|
||||
RegularLabs.MiniColors.save(field.dataset['table'], field.dataset['item_id'], field.dataset['id_column'], field.value, field);
|
||||
});
|
||||
|
||||
RegularLabs.MiniColors.setTableRowBackground(field, field.value);
|
||||
});
|
||||
},
|
||||
|
||||
setTableRowBackground: async function(element, color, opacity = .1) {
|
||||
|
||||
if ( ! element) {
|
||||
return;
|
||||
}
|
||||
|
||||
const table_row = element.closest('tr');
|
||||
|
||||
if ( ! table_row) {
|
||||
return;
|
||||
}
|
||||
const table_cells = table_row.querySelectorAll('td, th');
|
||||
|
||||
if ( ! table_cells.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
const bg_color = RegularLabs.MiniColors.getColorWithOpacity(color, opacity);
|
||||
|
||||
if (color[0] === '#') {
|
||||
table_cells[0].style.borderLeft = `4px solid ${color}`;
|
||||
}
|
||||
|
||||
table_cells.forEach((table_cell) => {
|
||||
table_cell.style.backgroundColor = bg_color;
|
||||
});
|
||||
},
|
||||
|
||||
save: async function(table, item_id, id_column, color, element) {
|
||||
let spinner = null;
|
||||
id_column = id_column ? id_column : 'id';
|
||||
|
||||
if (element) {
|
||||
spinner = document.createElement('div');
|
||||
spinner.classList.add('rl-spinner');
|
||||
|
||||
element.closest('div.rl-mini-colors-field').append(spinner);
|
||||
|
||||
RegularLabs.MiniColors.setTableRowBackground(element, color);
|
||||
}
|
||||
|
||||
const url = 'index.php?option=com_ajax&plugin=regularlabs&format=raw&saveColor=1'
|
||||
+ '&table=' + table
|
||||
+ '&item_id=' + item_id
|
||||
+ '&id_column=' + id_column
|
||||
+ '&color=' + encodeURIComponent(color);
|
||||
|
||||
await RegularLabs.Scripts.loadUrl(url);
|
||||
|
||||
RegularLabs.MiniColors.saved(spinner);
|
||||
|
||||
},
|
||||
|
||||
saved: function(spinner = null) {
|
||||
if ( ! spinner) {
|
||||
return;
|
||||
}
|
||||
|
||||
spinner.remove();
|
||||
},
|
||||
|
||||
getColorWithOpacity: function(hex, opacity) {
|
||||
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
|
||||
|
||||
if ( ! result) {
|
||||
return 'var(--table-bg)';
|
||||
}
|
||||
|
||||
return 'rgba('
|
||||
+ parseInt(result[1], 16) + ','
|
||||
+ parseInt(result[2], 16) + ','
|
||||
+ parseInt(result[3], 16) + ','
|
||||
+ opacity
|
||||
+ ')';
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
RegularLabs.MiniColors.init();
|
||||
})();
|
||||
44
media/regularlabs/js/mini-colors.min.js
vendored
Normal file
44
media/regularlabs/js/mini-colors.min.js
vendored
Normal file
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright © 2024 Regular Labs - All Rights Reserved
|
||||
* GNU General Public License version 2 or later
|
||||
*/
|
||||
(function(window,document,Math){var picker,currentEl,oldColor;var settings={el:'[data-rl-mini-colors]',parent:null,wrap:true,margin:2,swatches:[],swatchesOnly:false,alpha:true,autoClose:false,a11y:{open:'Open color picker',swatch:'Color swatch',}};function configure(options){if(typeof options!=='object'){return;}
|
||||
for(var key in options){switch(key){case'el':bindFields(options.el);if(options.wrap!==false){wrapFields(options.el);}
|
||||
break;case'parent':settings.parent=document.querySelector(options.parent);if(settings.parent){settings.parent.appendChild(picker);}
|
||||
break;case'margin':options.margin*=1;settings.margin=!isNaN(options.margin)?options.margin:settings.margin;break;case'wrap':if(options.el&&options.wrap){wrapFields(options.el);}
|
||||
break;case'swatches':if(Array.isArray(options.swatches)){(function(){var swatches=[];options.swatches.forEach(function(swatch,i){swatches.push("<button id=\"rl-mini-colors-swatch-"+i+"\" class=\"rl-mini-colors-button\" aria-labelledby=\"rl-mini-colors-swatch-label rl-mini-colors-swatch-"+i+"\" style=\"color: "+swatch+";\">"+swatch+"</button>");});if(swatches.length){getEl('rl-mini-colors-swatches').innerHTML="<div>"+swatches.join('')+"</div>";}})();}
|
||||
break;case'swatchesOnly':settings.swatchesOnly=!!options.swatchesOnly;picker.setAttribute('data-minimal',settings.swatchesOnly);if(settings.swatchesOnly){settings.autoClose=true;}
|
||||
break;case'a11y':var labels=options.a11y;var update=false;if(typeof labels==='object'){for(var label in labels){if(labels[label]&&settings.a11y[label]){settings.a11y[label]=labels[label];update=true;}}}
|
||||
if(update){var openLabel=getEl('rl-mini-colors-open-label');var swatchLabel=getEl('rl-mini-colors-swatch-label');openLabel.innerHTML=settings.a11y.open;swatchLabel.innerHTML=settings.a11y.swatch;}
|
||||
default:settings[key]=options[key];}}}
|
||||
function bindFields(selector){addListener(document,'click',selector,function(event){var parent=settings.parent;var coords=event.target.getBoundingClientRect();var scrollY=window.scrollY;var reposition={left:false,top:false};var offset={x:0,y:0};var left=coords.x;var top=scrollY+coords.y+coords.height+settings.margin;currentEl=event.target;picker.classList.add('rl-mini-colors-open');var pickerWidth=picker.offsetWidth;var pickerHeight=picker.offsetHeight;if(parent){var style=window.getComputedStyle(parent);var marginTop=parseFloat(style.marginTop);var borderTop=parseFloat(style.borderTopWidth);offset=parent.getBoundingClientRect();offset.y+=borderTop+scrollY;left-=offset.x;top-=offset.y;if(left+pickerWidth>parent.clientWidth){left+=coords.width-pickerWidth;reposition.left=true;}
|
||||
if(top+pickerHeight>parent.clientHeight-marginTop){top-=coords.height+pickerHeight+settings.margin*2;reposition.top=true;}
|
||||
top+=parent.scrollTop;}else{if(left+pickerWidth>document.documentElement.clientWidth){left+=coords.width-pickerWidth;reposition.left=true;}
|
||||
if(top+pickerHeight-scrollY>document.documentElement.clientHeight){top=scrollY+coords.y-pickerHeight-settings.margin;reposition.top=true;}}
|
||||
picker.classList.toggle('rl-mini-colors-left',reposition.left);picker.classList.toggle('rl-mini-colors-top',reposition.top);picker.style.left=left+"px";picker.style.top=top+"px";deselectRow(currentEl);});}
|
||||
function deselectRow(el){const tr=el.closest('tr');if(!tr){return;}
|
||||
const input=tr.querySelector('.form-check-input');if(!input){return;}
|
||||
input.checked=false;}
|
||||
function wrapFields(selector){document.querySelectorAll(selector).forEach(function(field){var parentNode=field.parentNode;if(!parentNode.classList.contains('rl-mini-colors-field')){var wrapper=document.createElement('div');wrapper.innerHTML="<button class=\"rl-mini-colors-button\" aria-labelledby=\"rl-mini-colors-open-label\"></button>";parentNode.insertBefore(wrapper,field);wrapper.setAttribute('class','rl-mini-colors-field');wrapper.style.color=field.value;wrapper.appendChild(field);}});}
|
||||
function closePicker(color){if(!currentEl){return;}
|
||||
picker.classList.remove('rl-mini-colors-open');currentEl=null;}
|
||||
function pickColor(color){if(!currentEl){return;}
|
||||
currentEl.value=color;currentEl.dispatchEvent(new Event('input',{bubbles:true}));currentEl.dispatchEvent(new Event('change',{bubbles:true}));const parent=currentEl.parentNode;if(parent.classList.contains('rl-mini-colors-field')){parent.style.color=color;}}
|
||||
function init(){picker=document.createElement('div');picker.setAttribute('id','rl-mini-colors-picker');picker.className='rl-mini-colors-picker';picker.innerHTML='<div id="rl-mini-colors-swatches" class="rl-mini-colors-swatches"></div>'+("<span id=\"rl-mini-colors-open-label\" hidden>"+settings.a11y.open+"</span>")+("<span id=\"rl-mini-colors-swatch-label\" hidden>"+settings.a11y.swatch+"</span>");document.body.appendChild(picker);bindFields(settings.el);wrapFields(settings.el);addListener(picker,'click','.rl-mini-colors-swatches .rl-mini-colors-button',(event)=>{pickColor(event.target.textContent);closePicker(event.target.textContent);});addListener(document,'click','.rl-mini-colors-field .rl-mini-colors-button',(event)=>{event.target.nextElementSibling.dispatchEvent(new Event('click',{bubbles:true}));});addListener(document,'mousedown',(event)=>{if(event.target.classList.contains('rl-mini-colors')||event.target.classList.contains('rl-mini-colors-picker')||event.target.closest('.rl-mini-colors-picker')){return;}
|
||||
closePicker();});}
|
||||
function getEl(id){return document.getElementById(id);}
|
||||
function addListener(context,type,selector,fn){var matches=Element.prototype.matches||Element.prototype.msMatchesSelector;if(typeof selector==='string'){context.addEventListener(type,function(event){if(matches.call(event.target,selector)){fn.call(event.target,event);}});}else{fn=selector;context.addEventListener(type,fn);}}
|
||||
function DOMReady(fn,args){args=args!==undefined?args:[];if(document.readyState!=='loading'){fn.apply(void 0,args);}else{document.addEventListener('DOMContentLoaded',function(){fn.apply(void 0,args);});}}
|
||||
if(NodeList!==undefined&&NodeList.prototype&&!NodeList.prototype.forEach){NodeList.prototype.forEach=Array.prototype.forEach;}
|
||||
window.RegularLabs_MiniColors=function(){var methods={set:configure,wrap:wrapFields,close:closePicker};function RegularLabs_MiniColors(options){DOMReady(function(){if(options){if(typeof options==='string'){bindFields(options);}else{configure(options);}}});}
|
||||
var _loop=function _loop(key){RegularLabs_MiniColors[key]=function(){for(var _len=arguments.length,args=new Array(_len),_key2=0;_key2<_len;_key2++){args[_key2]=arguments[_key2];}
|
||||
DOMReady(methods[key],args);};};for(var key in methods){_loop(key);}
|
||||
return RegularLabs_MiniColors;}();DOMReady(init);})(window,document,Math);(function(){'use strict';window.RegularLabs=window.RegularLabs||{};window.RegularLabs.MiniColors=window.RegularLabs.MiniColors||{init:function(){const minicolors=document.querySelectorAll('div.rl-mini-colors');const options=Joomla.getOptions?Joomla.getOptions('rl_minicolors',{}):Joomla.optionsStorage.rl_minicolors||{};minicolors.forEach((minicolor)=>{const field=minicolor.querySelector('input');RegularLabs_MiniColors({el:`#${field.id}`,theme:'default',alpha:false,swatchesOnly:true,swatches:options.swatches});if(!field.dataset['table']||!field.dataset['item_id']){return;}
|
||||
field.addEventListener('change',()=>{RegularLabs.MiniColors.save(field.dataset['table'],field.dataset['item_id'],field.dataset['id_column'],field.value,field);});RegularLabs.MiniColors.setTableRowBackground(field,field.value);});},setTableRowBackground:async function(element,color,opacity=.1){if(!element){return;}
|
||||
const table_row=element.closest('tr');if(!table_row){return;}
|
||||
const table_cells=table_row.querySelectorAll('td, th');if(!table_cells.length){return;}
|
||||
const bg_color=RegularLabs.MiniColors.getColorWithOpacity(color,opacity);if(color[0]==='#'){table_cells[0].style.borderLeft=`4px solid ${color}`;}
|
||||
table_cells.forEach((table_cell)=>{table_cell.style.backgroundColor=bg_color;});},save:async function(table,item_id,id_column,color,element){let spinner=null;id_column=id_column?id_column:'id';if(element){spinner=document.createElement('div');spinner.classList.add('rl-spinner');element.closest('div.rl-mini-colors-field').append(spinner);RegularLabs.MiniColors.setTableRowBackground(element,color);}
|
||||
const url='index.php?option=com_ajax&plugin=regularlabs&format=raw&saveColor=1'+'&table='+table+'&item_id='+item_id+'&id_column='+id_column+'&color='+encodeURIComponent(color);await RegularLabs.Scripts.loadUrl(url);RegularLabs.MiniColors.saved(spinner);},saved:function(spinner=null){if(!spinner){return;}
|
||||
spinner.remove();},getColorWithOpacity:function(hex,opacity){const result=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);if(!result){return'var(--table-bg)';}
|
||||
return'rgba('+parseInt(result[1],16)+','+parseInt(result[2],16)+','+parseInt(result[3],16)+','+opacity+')';}};RegularLabs.MiniColors.init();})();
|
||||
627
media/regularlabs/js/regular.js
Normal file
627
media/regularlabs/js/regular.js
Normal file
@ -0,0 +1,627 @@
|
||||
/**
|
||||
* @package Regular.js
|
||||
* @description A light and simple JavaScript Library
|
||||
*
|
||||
* @author Peter van Westen <info@regularlabs.com>
|
||||
* @link https://github.com/regularlabs/regularjs
|
||||
* @copyright Copyright © 2024 Regular Labs - All Rights Reserved
|
||||
* @license https://github.com/regularlabs/regularjs/blob/master/LICENCE MIT
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
if (typeof window.Regular === 'undefined'
|
||||
|| typeof Regular.version === 'undefined'
|
||||
|| Regular.version < 1.5) {
|
||||
|
||||
window.Regular = new function() {
|
||||
/**
|
||||
*
|
||||
* PUBLIC PROPERTIES
|
||||
*
|
||||
*/
|
||||
|
||||
this.version = 1.5;
|
||||
|
||||
/**
|
||||
*
|
||||
* PUBLIC METHODS
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Sets a global alias for the Regular class.
|
||||
*
|
||||
* @param word A string (character or word) representing the alias for the Regular class.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
this.alias = function(word) {
|
||||
if (typeof window[word] !== 'undefined') {
|
||||
console.error(`Cannot set '${word}' as an alias of Regular, as it already exists.`);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
window[word] = $;
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns a boolean based on whether the element contains one or more of the given class names.
|
||||
*
|
||||
* @param selector A CSS selector string or a HTMLElement object.
|
||||
* @param classes A string or array of class names.
|
||||
* @param matchAll Optional boolean whether the element should have all given classes (true) or at least one (false).
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
this.hasClasses = function(selector, classes, matchAll = true) {
|
||||
if ( ! selector) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const element = typeof selector === 'string'
|
||||
? document.querySelector(selector)
|
||||
: selector;
|
||||
|
||||
if ( ! element) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (typeof classes === 'string') {
|
||||
classes = classes.split(' ');
|
||||
}
|
||||
|
||||
let hasClass = false;
|
||||
|
||||
for (const clss of classes) {
|
||||
hasClass = element.classList.contains(clss);
|
||||
|
||||
if (matchAll && ! hasClass) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ! matchAll && hasClass) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return hasClass;
|
||||
};
|
||||
|
||||
/**
|
||||
* Adds given class name(s) to the element(s).
|
||||
*
|
||||
* @param selector A CSS selector string, a HTMLElement object or a collection of HTMLElement objects.
|
||||
* @param classes A string or array of class names.
|
||||
*/
|
||||
this.addClasses = function(selector, classes) {
|
||||
doClasses('add', selector, classes);
|
||||
};
|
||||
|
||||
/**
|
||||
* Removes given class name(s) from the element(s).
|
||||
*
|
||||
* @param selector A CSS selector string, a HTMLElement object or a collection of HTMLElement objects.
|
||||
* @param classes A string or array of class names.
|
||||
*/
|
||||
this.removeClasses = function(selector, classes) {
|
||||
doClasses('remove', selector, classes);
|
||||
};
|
||||
|
||||
/**
|
||||
* Toggles given class name(s) of the element(s).
|
||||
*
|
||||
* @param selector A CSS selector string, a HTMLElement object or a collection of HTMLElement objects.
|
||||
* @param classes A string or array of class names.
|
||||
* @param force An optional boolean value that forces the class to be added or removed.
|
||||
*/
|
||||
this.toggleClasses = function(selector, classes, force) {
|
||||
switch (force) {
|
||||
case true:
|
||||
doClasses('add', selector, classes);
|
||||
break;
|
||||
|
||||
case false:
|
||||
doClasses('remove', selector, classes);
|
||||
break;
|
||||
|
||||
default:
|
||||
doClasses('toggle', selector, classes);
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Makes the given element(s) visible (changes visibility and display attributes).
|
||||
*
|
||||
* @param selector A CSS selector string, a HTMLElement object or a collection of HTMLElement objects.
|
||||
*/
|
||||
this.makeVisible = function(selector) {
|
||||
if ( ! selector) {
|
||||
return;
|
||||
}
|
||||
|
||||
const element = typeof selector === 'string'
|
||||
? document.querySelectorAll(selector)
|
||||
: selector;
|
||||
|
||||
if ('forEach' in element) {
|
||||
element.forEach(subElement => $.makeVisible(subElement));
|
||||
return;
|
||||
}
|
||||
|
||||
let computedDisplay = getComputedStyle(element, 'display');
|
||||
|
||||
if ( ! ('origDisplay' in element)) {
|
||||
element.origDisplay = computedDisplay === 'none'
|
||||
? getDefaultComputedStyle(element, 'display')
|
||||
: computedDisplay;
|
||||
}
|
||||
|
||||
if (computedDisplay === 'none') {
|
||||
element.style.display = ('origDisplay' in element) ? element.origDisplay : '';
|
||||
}
|
||||
|
||||
let elementType = element.nodeName.toLowerCase();
|
||||
|
||||
switch (elementType) {
|
||||
case 'tr':
|
||||
elementType = 'table-row';
|
||||
break;
|
||||
case 'td':
|
||||
case 'th':
|
||||
elementType = 'table-cell';
|
||||
break;
|
||||
case 'caption':
|
||||
elementType = 'table-caption';
|
||||
break;
|
||||
case 'col':
|
||||
elementType = 'table-column';
|
||||
break;
|
||||
case 'colgroup':
|
||||
elementType = 'table-column-group';
|
||||
break;
|
||||
case 'table':
|
||||
elementType = 'table';
|
||||
break;
|
||||
case 'thead':
|
||||
elementType = 'table-header-group';
|
||||
break;
|
||||
case 'tbody':
|
||||
elementType = 'table-row-group';
|
||||
break;
|
||||
case 'tfoot':
|
||||
elementType = 'table-footer-group';
|
||||
break;
|
||||
default:
|
||||
elementType = 'block';
|
||||
break;
|
||||
}
|
||||
|
||||
element.style.display = elementType;
|
||||
element.style.visibility = 'visible';
|
||||
};
|
||||
|
||||
/**
|
||||
* Shows the given element(s) (makes visible and changes opacity attribute).
|
||||
*
|
||||
* @param selector A CSS selector string, a HTMLElement object or a collection of HTMLElement objects.
|
||||
*/
|
||||
this.show = function(selector) {
|
||||
if ( ! selector) {
|
||||
return;
|
||||
}
|
||||
|
||||
const element = typeof selector === 'string'
|
||||
? document.querySelectorAll(selector)
|
||||
: selector;
|
||||
|
||||
if ('forEach' in element) {
|
||||
element.forEach(subElement => $.show(subElement));
|
||||
return;
|
||||
}
|
||||
|
||||
this.makeVisible(element);
|
||||
|
||||
element.style.opacity = 1;
|
||||
};
|
||||
|
||||
/**
|
||||
* Hides the given element(s) (changes opacity and display attributes).
|
||||
*
|
||||
* @param selector A CSS selector string, a HTMLElement object or a collection of HTMLElement objects.
|
||||
*/
|
||||
this.hide = function(selector) {
|
||||
if ( ! selector) {
|
||||
return;
|
||||
}
|
||||
|
||||
const element = typeof selector === 'string'
|
||||
? document.querySelectorAll(selector)
|
||||
: selector;
|
||||
|
||||
if ('forEach' in element) {
|
||||
element.forEach(subElement => $.hide(subElement));
|
||||
return;
|
||||
}
|
||||
|
||||
const computedDisplay = getComputedStyle(element, 'display');
|
||||
|
||||
if (computedDisplay !== 'none' && ! ('origDisplay' in element)) {
|
||||
element.origDisplay = computedDisplay;
|
||||
}
|
||||
|
||||
element.style.display = 'none';
|
||||
element.style.visibility = 'hidden';
|
||||
element.style.opacity = 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* Shows or hides the given element(s).
|
||||
*
|
||||
* @param selector A CSS selector string, a HTMLElement object or a collection of HTMLElement objects.
|
||||
* @param force An optional boolean value that forces the class to be added or removed.
|
||||
*/
|
||||
this.toggle = function(selector, force) {
|
||||
if ( ! selector) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (force) {
|
||||
case true:
|
||||
$.show(selector);
|
||||
break;
|
||||
|
||||
case false:
|
||||
$.hide(selector);
|
||||
break;
|
||||
|
||||
default:
|
||||
const element = typeof selector === 'string'
|
||||
? document.querySelectorAll(selector)
|
||||
: selector;
|
||||
|
||||
if ('forEach' in element) {
|
||||
element.forEach(subElement => $.toggle(subElement));
|
||||
return;
|
||||
}
|
||||
|
||||
element.style.display === 'none' ? $.show(selector) : $.hide(selector);
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Fades in the given element(s).
|
||||
*
|
||||
* @param selector A CSS selector string, a HTMLElement object or a collection of HTMLElement objects.
|
||||
* @param duration Optional duration of the effect in milliseconds.
|
||||
* @param oncomplete Optional callback function to execute when effect is completed.
|
||||
*/
|
||||
this.fadeIn = function(selector, duration = 250, oncomplete) {
|
||||
if ( ! selector) {
|
||||
return;
|
||||
}
|
||||
|
||||
const element = typeof selector === 'string'
|
||||
? document.querySelectorAll(selector)
|
||||
: selector;
|
||||
|
||||
this.makeVisible(element);
|
||||
|
||||
$.fadeTo(
|
||||
element,
|
||||
1,
|
||||
duration,
|
||||
() => {
|
||||
$.show(element);
|
||||
if (oncomplete) {
|
||||
oncomplete.call(element);
|
||||
}
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Fades out the given element(s).
|
||||
*
|
||||
* @param selector A CSS selector string, a HTMLElement object or a collection of HTMLElement objects.
|
||||
* @param duration Optional duration of the effect in milliseconds.
|
||||
* @param oncomplete Optional callback function to execute when effect is completed.
|
||||
*/
|
||||
this.fadeOut = function(selector, duration = 250, oncomplete) {
|
||||
if ( ! selector) {
|
||||
return;
|
||||
}
|
||||
|
||||
const element = typeof selector === 'string'
|
||||
? document.querySelectorAll(selector)
|
||||
: selector;
|
||||
|
||||
$.fadeTo(
|
||||
element,
|
||||
0,
|
||||
duration,
|
||||
() => {
|
||||
$.hide(element);
|
||||
if (oncomplete) {
|
||||
oncomplete.call(element);
|
||||
}
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Fades out the given element(s).
|
||||
*
|
||||
* @param selector A CSS selector string, a HTMLElement object or a collection of HTMLElement objects.
|
||||
* @param opacity Opacity Value to fade to
|
||||
* @param duration Optional duration of the effect in milliseconds.
|
||||
* @param oncomplete Optional callback function to execute when effect is completed.
|
||||
*/
|
||||
this.fadeTo = function(selector, opacity, duration = 250, oncomplete) {
|
||||
if ( ! selector) {
|
||||
return;
|
||||
}
|
||||
|
||||
const element = typeof selector === 'string'
|
||||
? document.querySelectorAll(selector)
|
||||
: selector;
|
||||
|
||||
if ('forEach' in element) {
|
||||
element.forEach(subElement => $.fadeTo(subElement, opacity, duration));
|
||||
return;
|
||||
}
|
||||
|
||||
const wait = 50; // amount of time between steps
|
||||
const nr_of_steps = duration / wait;
|
||||
const change = 1 / nr_of_steps; // time to wait before next step
|
||||
|
||||
element.style.opacity = getComputedStyle(element, 'opacity');
|
||||
|
||||
if (opacity === element.style.opacity) {
|
||||
element.setAttribute('data-fading', '');
|
||||
|
||||
if (oncomplete) {
|
||||
oncomplete.call(element);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
this.makeVisible(element);
|
||||
|
||||
const direction = opacity > element.style.opacity ? 'in' : 'out';
|
||||
|
||||
element.setAttribute('data-fading', direction);
|
||||
|
||||
(function fade() {
|
||||
if (element.getAttribute('data-fading')
|
||||
&& element.getAttribute('data-fading') !== direction
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
const new_opacity = direction === 'out'
|
||||
? parseFloat(element.style.opacity) - change
|
||||
: parseFloat(element.style.opacity) + change;
|
||||
|
||||
if ((direction === 'in' && new_opacity >= opacity)
|
||||
|| (direction === 'out' && new_opacity <= opacity)
|
||||
) {
|
||||
element.style.opacity = opacity;
|
||||
|
||||
element.setAttribute('data-fading', '');
|
||||
|
||||
if (oncomplete) {
|
||||
oncomplete.call(element);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
element.style.opacity = new_opacity;
|
||||
|
||||
setTimeout(() => {
|
||||
fade.call();
|
||||
}, wait);
|
||||
})();
|
||||
};
|
||||
|
||||
/**
|
||||
* Runs a function when the document is loaded (on ready state).
|
||||
*
|
||||
* @param func Callback function to execute when document is ready.
|
||||
*/
|
||||
this.onReady = function(func) {
|
||||
document.addEventListener('DOMContentLoaded', func);
|
||||
};
|
||||
|
||||
/**
|
||||
* Converts a string with HTML code to 'DOM' elements.
|
||||
*
|
||||
* @param html String with HTML code.
|
||||
*
|
||||
* @return element
|
||||
*/
|
||||
this.createElementFromHTML = function(html) {
|
||||
return document.createRange().createContextualFragment(html);
|
||||
};
|
||||
|
||||
/**
|
||||
* Loads a url with optional POST data and optionally calls a function on success or fail.
|
||||
*
|
||||
* @param url String containing the url to load.
|
||||
* @param data Optional string representing the POST data to send along.
|
||||
* @param success Optional callback function to execute when the url loads successfully (status 200).
|
||||
* @param fail Optional callback function to execute when the url fails to load.
|
||||
*/
|
||||
this.loadUrl = function(url, data, success, fail) {
|
||||
const request = new XMLHttpRequest();
|
||||
|
||||
request.open('POST', url, true);
|
||||
|
||||
request.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
|
||||
|
||||
request.onreadystatechange = function() {
|
||||
if (this.readyState !== 4) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.status === 200) {
|
||||
success && success.call(null, this.responseText, this.status, this);
|
||||
return;
|
||||
}
|
||||
|
||||
fail && fail.call(null, this.responseText, this.status, this);
|
||||
};
|
||||
|
||||
|
||||
request.send(this.toUrlQueryString(data));
|
||||
};
|
||||
|
||||
/**
|
||||
* Converts a data object (key, value) to a serialized query string.
|
||||
*
|
||||
* @param data The object with the data to serialize.
|
||||
* @param prefix An Optional prefix.
|
||||
*/
|
||||
this.toUrlQueryString = function(data, prefix) {
|
||||
if (typeof data !== 'object') {
|
||||
return data;
|
||||
}
|
||||
|
||||
const parts = [];
|
||||
|
||||
if ( ! (Symbol.iterator in Object(data))) {
|
||||
data = Object.entries(data);
|
||||
}
|
||||
|
||||
for (let i in data) {
|
||||
let value = data[i];
|
||||
let name = '';
|
||||
|
||||
if (value instanceof Array) {
|
||||
[name, value] = value;
|
||||
}
|
||||
|
||||
let key = name ? (prefix ? `${prefix}[${name}]` : name) : prefix;
|
||||
|
||||
if ( ! key) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (value !== null && typeof value === 'object') {
|
||||
if (value instanceof Array) {
|
||||
key += '[]';
|
||||
}
|
||||
|
||||
parts.push(this.toUrlQueryString(value, key));
|
||||
continue;
|
||||
}
|
||||
|
||||
parts.push(`${key}=${value}`);
|
||||
}
|
||||
|
||||
return parts.join('&');
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
* ALIASES
|
||||
*
|
||||
*/
|
||||
|
||||
this.as = this.alias;
|
||||
this.hasClass = this.hasClasses;
|
||||
this.addClass = this.addClasses;
|
||||
this.removeClass = this.removeClasses;
|
||||
this.toggleClass = this.toggleClasses;
|
||||
|
||||
/**
|
||||
*
|
||||
* PRIVATE FUNCTIONS
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Executes an action on the element(s) to add/remove/toggle classes.
|
||||
*
|
||||
* @param action A string that identifies the action: add|remove|toggle.
|
||||
* @param selector A CSS selector string, a HTMLElement object or a collection of HTMLElement objects.
|
||||
* @param classes A string or array of class names.
|
||||
*/
|
||||
const doClasses = function(action, selector, classes) {
|
||||
if ( ! selector) {
|
||||
return;
|
||||
}
|
||||
|
||||
const element = typeof selector === 'string'
|
||||
? document.querySelectorAll(selector)
|
||||
: selector;
|
||||
|
||||
if ('forEach' in element) {
|
||||
element.forEach(subElement => doClasses(action, subElement, classes));
|
||||
return;
|
||||
}
|
||||
|
||||
if (typeof classes === 'string') {
|
||||
classes = classes.split(' ');
|
||||
}
|
||||
|
||||
element.classList[action](...classes);
|
||||
};
|
||||
|
||||
/**
|
||||
* Finds the computed style of an element.
|
||||
*
|
||||
* @param element A HTMLElement object.
|
||||
* @param property The style property that needs to be returned.
|
||||
*
|
||||
* @returns mixed
|
||||
*/
|
||||
const getComputedStyle = function(element, property) {
|
||||
if ( ! element) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return window.getComputedStyle(element).getPropertyValue(property);
|
||||
};
|
||||
|
||||
/**
|
||||
* Finds the default computed style of an element by its type.
|
||||
*
|
||||
* @param element A HTMLElement object.
|
||||
* @param property The style property that needs to be returned.
|
||||
*
|
||||
* @returns mixed
|
||||
*/
|
||||
const getDefaultComputedStyle = function(element, property) {
|
||||
if ( ! element) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const defaultElement = document.createElement(element.nodeName);
|
||||
|
||||
document.body.append(defaultElement);
|
||||
let propertyValue = window.getComputedStyle(defaultElement).getPropertyValue(property);
|
||||
defaultElement.remove();
|
||||
|
||||
return propertyValue;
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
* PRIVATE VARIABLES
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @param $ internal shorthand for the 'this' keyword.
|
||||
*/
|
||||
const $ = this;
|
||||
};
|
||||
}
|
||||
47
media/regularlabs/js/regular.min.js
vendored
Normal file
47
media/regularlabs/js/regular.min.js
vendored
Normal file
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Regular.js - A light and simple JavaScript Library
|
||||
* Copyright © 2024 Regular Labs - All Rights Reserved
|
||||
* License https://github.com/regularlabs/regularjs/blob/master/LICENCE MIT
|
||||
*/
|
||||
"use strict";if(typeof window.Regular==='undefined'||typeof Regular.version==='undefined'||Regular.version<1.5){window.Regular=new function(){this.version=1.5;this.alias=function(word){if(typeof window[word]!=='undefined'){console.error(`Cannot set'${word}'as an alias of Regular,as it already exists.`);return false;}
|
||||
window[word]=$;return true;};this.hasClasses=function(selector,classes,matchAll=true){if(!selector){return false;}
|
||||
const element=typeof selector==='string'?document.querySelector(selector):selector;if(!element){return false;}
|
||||
if(typeof classes==='string'){classes=classes.split(' ');}
|
||||
let hasClass=false;for(const clss of classes){hasClass=element.classList.contains(clss);if(matchAll&&!hasClass){return false;}
|
||||
if(!matchAll&&hasClass){return true;}}
|
||||
return hasClass;};this.addClasses=function(selector,classes){doClasses('add',selector,classes);};this.removeClasses=function(selector,classes){doClasses('remove',selector,classes);};this.toggleClasses=function(selector,classes,force){switch(force){case true:doClasses('add',selector,classes);break;case false:doClasses('remove',selector,classes);break;default:doClasses('toggle',selector,classes);break;}};this.makeVisible=function(selector){if(!selector){return;}
|
||||
const element=typeof selector==='string'?document.querySelectorAll(selector):selector;if('forEach'in element){element.forEach(subElement=>$.makeVisible(subElement));return;}
|
||||
let computedDisplay=getComputedStyle(element,'display');if(!('origDisplay'in element)){element.origDisplay=computedDisplay==='none'?getDefaultComputedStyle(element,'display'):computedDisplay;}
|
||||
if(computedDisplay==='none'){element.style.display=('origDisplay'in element)?element.origDisplay:'';}
|
||||
let elementType=element.nodeName.toLowerCase();switch(elementType){case'tr':elementType='table-row';break;case'td':case'th':elementType='table-cell';break;case'caption':elementType='table-caption';break;case'col':elementType='table-column';break;case'colgroup':elementType='table-column-group';break;case'table':elementType='table';break;case'thead':elementType='table-header-group';break;case'tbody':elementType='table-row-group';break;case'tfoot':elementType='table-footer-group';break;default:elementType='block';break;}
|
||||
element.style.display=elementType;element.style.visibility='visible';};this.show=function(selector){if(!selector){return;}
|
||||
const element=typeof selector==='string'?document.querySelectorAll(selector):selector;if('forEach'in element){element.forEach(subElement=>$.show(subElement));return;}
|
||||
this.makeVisible(element);element.style.opacity=1;};this.hide=function(selector){if(!selector){return;}
|
||||
const element=typeof selector==='string'?document.querySelectorAll(selector):selector;if('forEach'in element){element.forEach(subElement=>$.hide(subElement));return;}
|
||||
const computedDisplay=getComputedStyle(element,'display');if(computedDisplay!=='none'&&!('origDisplay'in element)){element.origDisplay=computedDisplay;}
|
||||
element.style.display='none';element.style.visibility='hidden';element.style.opacity=0;};this.toggle=function(selector,force){if(!selector){return;}
|
||||
switch(force){case true:$.show(selector);break;case false:$.hide(selector);break;default:const element=typeof selector==='string'?document.querySelectorAll(selector):selector;if('forEach'in element){element.forEach(subElement=>$.toggle(subElement));return;}
|
||||
element.style.display==='none'?$.show(selector):$.hide(selector);break;}};this.fadeIn=function(selector,duration=250,oncomplete){if(!selector){return;}
|
||||
const element=typeof selector==='string'?document.querySelectorAll(selector):selector;this.makeVisible(element);$.fadeTo(element,1,duration,()=>{$.show(element);if(oncomplete){oncomplete.call(element);}});};this.fadeOut=function(selector,duration=250,oncomplete){if(!selector){return;}
|
||||
const element=typeof selector==='string'?document.querySelectorAll(selector):selector;$.fadeTo(element,0,duration,()=>{$.hide(element);if(oncomplete){oncomplete.call(element);}});};this.fadeTo=function(selector,opacity,duration=250,oncomplete){if(!selector){return;}
|
||||
const element=typeof selector==='string'?document.querySelectorAll(selector):selector;if('forEach'in element){element.forEach(subElement=>$.fadeTo(subElement,opacity,duration));return;}
|
||||
const wait=50;const nr_of_steps=duration/wait;const change=1/nr_of_steps;element.style.opacity=getComputedStyle(element,'opacity');if(opacity===element.style.opacity){element.setAttribute('data-fading','');if(oncomplete){oncomplete.call(element);}
|
||||
return;}
|
||||
this.makeVisible(element);const direction=opacity>element.style.opacity?'in':'out';element.setAttribute('data-fading',direction);(function fade(){if(element.getAttribute('data-fading')&&element.getAttribute('data-fading')!==direction){return;}
|
||||
const new_opacity=direction==='out'?parseFloat(element.style.opacity)-change:parseFloat(element.style.opacity)+change;if((direction==='in'&&new_opacity>=opacity)||(direction==='out'&&new_opacity<=opacity)){element.style.opacity=opacity;element.setAttribute('data-fading','');if(oncomplete){oncomplete.call(element);}
|
||||
return;}
|
||||
element.style.opacity=new_opacity;setTimeout(()=>{fade.call();},wait);})();};this.onReady=function(func){document.addEventListener('DOMContentLoaded',func);};this.createElementFromHTML=function(html){return document.createRange().createContextualFragment(html);};this.loadUrl=function(url,data,success,fail){const request=new XMLHttpRequest();request.open('POST',url,true);request.setRequestHeader('Content-type','application/x-www-form-urlencoded');request.onreadystatechange=function(){if(this.readyState!==4){return;}
|
||||
if(this.status===200){success&&success.call(null,this.responseText,this.status,this);return;}
|
||||
fail&&fail.call(null,this.responseText,this.status,this);};request.send(this.toUrlQueryString(data));};this.toUrlQueryString=function(data,prefix){if(typeof data!=='object'){return data;}
|
||||
const parts=[];if(!(Symbol.iterator in Object(data))){data=Object.entries(data);}
|
||||
for(let i in data){let value=data[i];let name='';if(value instanceof Array){[name,value]=value;}
|
||||
let key=name?(prefix?`${prefix}[${name}]`:name):prefix;if(!key){continue;}
|
||||
if(value!==null&&typeof value==='object'){if(value instanceof Array){key+='[]';}
|
||||
parts.push(this.toUrlQueryString(value,key));continue;}
|
||||
parts.push(`${key}=${value}`);}
|
||||
return parts.join('&');};this.as=this.alias;this.hasClass=this.hasClasses;this.addClass=this.addClasses;this.removeClass=this.removeClasses;this.toggleClass=this.toggleClasses;const doClasses=function(action,selector,classes){if(!selector){return;}
|
||||
const element=typeof selector==='string'?document.querySelectorAll(selector):selector;if('forEach'in element){element.forEach(subElement=>doClasses(action,subElement,classes));return;}
|
||||
if(typeof classes==='string'){classes=classes.split(' ');}
|
||||
element.classList[action](...classes);};const getComputedStyle=function(element,property){if(!element){return null;}
|
||||
return window.getComputedStyle(element).getPropertyValue(property);};const getDefaultComputedStyle=function(element,property){if(!element){return null;}
|
||||
const defaultElement=document.createElement(element.nodeName);document.body.append(defaultElement);let propertyValue=window.getComputedStyle(defaultElement).getPropertyValue(property);defaultElement.remove();return propertyValue;};const $=this;};}
|
||||
153
media/regularlabs/js/script.js
Normal file
153
media/regularlabs/js/script.js
Normal file
@ -0,0 +1,153 @@
|
||||
/**
|
||||
* @package Regular Labs Library
|
||||
* @version 24.11.1459
|
||||
*
|
||||
* @author Peter van Westen <info@regularlabs.com>
|
||||
* @link https://regularlabs.com
|
||||
* @copyright Copyright © 2024 Regular Labs All Rights Reserved
|
||||
* @license GNU General Public License version 2 or later
|
||||
*/
|
||||
|
||||
(function() {
|
||||
'use strict';
|
||||
|
||||
window.RegularLabs = window.RegularLabs || {};
|
||||
|
||||
window.RegularLabs.Scripts = window.RegularLabs.Scripts || {
|
||||
version: '24.11.1459',
|
||||
|
||||
ajax_list : [],
|
||||
started_ajax_list: false,
|
||||
ajax_list_timer : null,
|
||||
|
||||
loadAjax: function(url, success, fail, query, timeout, dataType, cache) {
|
||||
if (url.indexOf('index.php') !== 0 && url.indexOf('administrator/index.php') !== 0) {
|
||||
url = url.replace('http://', '');
|
||||
url = `index.php?rl_qp=1&url=${encodeURIComponent(url)}`;
|
||||
if (timeout) {
|
||||
url += `&timeout=${timeout}`;
|
||||
}
|
||||
if (cache) {
|
||||
url += `&cache=${cache}`;
|
||||
}
|
||||
}
|
||||
|
||||
let base = window.location.pathname;
|
||||
|
||||
base = base.substring(0, base.lastIndexOf('/'));
|
||||
|
||||
if (
|
||||
typeof Joomla !== 'undefined'
|
||||
&& typeof Joomla.getOptions !== 'undefined'
|
||||
&& Joomla.getOptions('system.paths')
|
||||
) {
|
||||
base = Joomla.getOptions('system.paths').base;
|
||||
}
|
||||
|
||||
// console.log(url);
|
||||
// console.log(`${base}/${url}`);
|
||||
|
||||
this.loadUrl(
|
||||
`${base}/${url}`,
|
||||
null,
|
||||
(function(data) {
|
||||
if (success) {
|
||||
success = `data = data ? data : ''; ${success};`.replace(/;\s*;/g, ';');
|
||||
eval(success);
|
||||
}
|
||||
}),
|
||||
(function(data) {
|
||||
if (fail) {
|
||||
fail = `data = data ? data : ''; ${fail};`.replace(/;\s*;/g, ';');
|
||||
eval(fail);
|
||||
}
|
||||
})
|
||||
);
|
||||
},
|
||||
|
||||
/**
|
||||
* Loads a url with optional POST data and optionally calls a function on success or fail.
|
||||
*
|
||||
* @param url String containing the url to load.
|
||||
* @param data Optional string representing the POST data to send along.
|
||||
* @param success Optional callback function to execute when the url loads successfully (status 200).
|
||||
* @param fail Optional callback function to execute when the url fails to load.
|
||||
*/
|
||||
loadUrl: function(url, data, success, fail) {
|
||||
return new Promise((resolve) => {
|
||||
const request = new XMLHttpRequest();
|
||||
|
||||
request.open("POST", url, true);
|
||||
|
||||
request.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
|
||||
|
||||
request.onreadystatechange = function() {
|
||||
if (this.readyState !== 4) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.status !== 200) {
|
||||
fail && fail.call(null, this.responseText, this.status, this);
|
||||
resolve(this);
|
||||
return;
|
||||
}
|
||||
|
||||
success && success.call(null, this.responseText, this.status, this);
|
||||
resolve(this);
|
||||
};
|
||||
|
||||
request.send(data);
|
||||
});
|
||||
},
|
||||
|
||||
addToLoadAjaxList: function(url, success, error) {
|
||||
// wrap inside the loadajax function (and escape string values)
|
||||
url = url.replace(/'/g, "\\'");
|
||||
success = success.replace(/'/g, "\\'");
|
||||
error = error.replace(/'/g, "\\'");
|
||||
|
||||
const action = `RegularLabs.Scripts.loadAjax(
|
||||
'${url}',
|
||||
'${success};RegularLabs.Scripts.ajaxRun();',
|
||||
'${error};RegularLabs.Scripts.ajaxRun();'
|
||||
)`;
|
||||
|
||||
this.addToAjaxList(action);
|
||||
},
|
||||
|
||||
addToAjaxList: function(action) {
|
||||
this.ajax_list.push(action);
|
||||
|
||||
if ( ! this.started_ajax_list) {
|
||||
this.ajaxRun();
|
||||
}
|
||||
},
|
||||
|
||||
ajaxRun: function() {
|
||||
if ( ! this.ajax_list.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
clearTimeout(this.ajax_list_timer);
|
||||
|
||||
this.started_ajax_list = true;
|
||||
|
||||
const action = this.ajax_list.shift();
|
||||
|
||||
eval(`${action};`);
|
||||
|
||||
if ( ! this.ajax_list.length) {
|
||||
this.started_ajax_list = false;
|
||||
return;
|
||||
}
|
||||
|
||||
// Re-trigger this ajaxRun function just in case it hangs somewhere
|
||||
this.ajax_list_timer = setTimeout(
|
||||
function() {
|
||||
RegularLabs.Scripts.ajaxRun();
|
||||
},
|
||||
5000
|
||||
);
|
||||
},
|
||||
};
|
||||
})();
|
||||
12
media/regularlabs/js/script.min.js
vendored
Normal file
12
media/regularlabs/js/script.min.js
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
/*
|
||||
* Copyright © 2024 Regular Labs - All Rights Reserved
|
||||
* GNU General Public License version 2 or later
|
||||
*/
|
||||
(function(){'use strict';window.RegularLabs=window.RegularLabs||{};window.RegularLabs.Scripts=window.RegularLabs.Scripts||{version:'24.11.1459',ajax_list:[],started_ajax_list:false,ajax_list_timer:null,loadAjax:function(url,success,fail,query,timeout,dataType,cache){if(url.indexOf('index.php')!==0&&url.indexOf('administrator/index.php')!==0){url=url.replace('http://','');url=`index.php?rl_qp=1&url=${encodeURIComponent(url)}`;if(timeout){url+=`&timeout=${timeout}`;}
|
||||
if(cache){url+=`&cache=${cache}`;}}
|
||||
let base=window.location.pathname;base=base.substring(0,base.lastIndexOf('/'));if(typeof Joomla!=='undefined'&&typeof Joomla.getOptions!=='undefined'&&Joomla.getOptions('system.paths')){base=Joomla.getOptions('system.paths').base;}
|
||||
this.loadUrl(`${base}/${url}`,null,(function(data){if(success){success=`data=data?data:'';${success};`.replace(/;\s*;/g,';');eval(success);}}),(function(data){if(fail){fail=`data=data?data:'';${fail};`.replace(/;\s*;/g,';');eval(fail);}}));},loadUrl:function(url,data,success,fail){return new Promise((resolve)=>{const request=new XMLHttpRequest();request.open("POST",url,true);request.setRequestHeader('Content-type','application/x-www-form-urlencoded');request.onreadystatechange=function(){if(this.readyState!==4){return;}
|
||||
if(this.status!==200){fail&&fail.call(null,this.responseText,this.status,this);resolve(this);return;}
|
||||
success&&success.call(null,this.responseText,this.status,this);resolve(this);};request.send(data);});},addToLoadAjaxList:function(url,success,error){url=url.replace(/'/g,"\\'");success=success.replace(/'/g,"\\'");error=error.replace(/'/g,"\\'");const action=`RegularLabs.Scripts.loadAjax('${url}','${success};RegularLabs.Scripts.ajaxRun();','${error};RegularLabs.Scripts.ajaxRun();')`;this.addToAjaxList(action);},addToAjaxList:function(action){this.ajax_list.push(action);if(!this.started_ajax_list){this.ajaxRun();}},ajaxRun:function(){if(!this.ajax_list.length){return;}
|
||||
clearTimeout(this.ajax_list_timer);this.started_ajax_list=true;const action=this.ajax_list.shift();eval(`${action};`);if(!this.ajax_list.length){this.started_ajax_list=false;return;}
|
||||
this.ajax_list_timer=setTimeout(function(){RegularLabs.Scripts.ajaxRun();},5000);},};})();
|
||||
65
media/regularlabs/js/simplecategory.js
Normal file
65
media/regularlabs/js/simplecategory.js
Normal file
@ -0,0 +1,65 @@
|
||||
/**
|
||||
* @package Regular Labs Library
|
||||
* @version 24.11.1459
|
||||
*
|
||||
* @author Peter van Westen <info@regularlabs.com>
|
||||
* @link https://regularlabs.com
|
||||
* @copyright Copyright © 2024 Regular Labs All Rights Reserved
|
||||
* @license GNU General Public License version 2 or later
|
||||
*/
|
||||
|
||||
(function() {
|
||||
'use strict';
|
||||
|
||||
document.querySelectorAll('rl-field-simple-category').forEach((simplecategory) => {
|
||||
const fancy_select = simplecategory.querySelector('joomla-field-fancy-select');
|
||||
const select = simplecategory.querySelector('select');
|
||||
const input = simplecategory.querySelector('input.choices__input');
|
||||
|
||||
if ( ! fancy_select || ! select || ! input) {
|
||||
return;
|
||||
}
|
||||
|
||||
const choices = fancy_select.choicesInstance;
|
||||
|
||||
// fancy_select.addEventListener('change', () => {
|
||||
// const new_category = input.value;
|
||||
// select.add(new Option(new_category, new_category));
|
||||
// select.value = new_category;
|
||||
// console.log('----');
|
||||
// console.log(select.value);
|
||||
// choices.clearInput();
|
||||
// });
|
||||
|
||||
input.addEventListener('change', (event) => {
|
||||
choices.clearInput();
|
||||
});
|
||||
|
||||
input.addEventListener('keyup', (event) => {
|
||||
if (event.keyCode !== 13) {
|
||||
return;
|
||||
}
|
||||
|
||||
choices.clearInput();
|
||||
});
|
||||
|
||||
const setNewCategory = (() => {
|
||||
const new_category = input.value;
|
||||
choices.clearInput();
|
||||
|
||||
if ( ! new_category.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
const new_option = new Option(new_category, new_category);
|
||||
|
||||
select.add(new_option);
|
||||
select.value = new_category;
|
||||
|
||||
choices._addChoice(new_option);
|
||||
choices._triggerChange(new_category);
|
||||
choices.setChoiceByValue(new_category);
|
||||
choices.clearInput();
|
||||
});
|
||||
});
|
||||
})();
|
||||
8
media/regularlabs/js/simplecategory.min.js
vendored
Normal file
8
media/regularlabs/js/simplecategory.min.js
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
/*
|
||||
* Copyright © 2024 Regular Labs - All Rights Reserved
|
||||
* GNU General Public License version 2 or later
|
||||
*/
|
||||
(function(){'use strict';document.querySelectorAll('rl-field-simple-category').forEach((simplecategory)=>{const fancy_select=simplecategory.querySelector('joomla-field-fancy-select');const select=simplecategory.querySelector('select');const input=simplecategory.querySelector('input.choices__input');if(!fancy_select||!select||!input){return;}
|
||||
const choices=fancy_select.choicesInstance;input.addEventListener('change',(event)=>{choices.clearInput();});input.addEventListener('keyup',(event)=>{if(event.keyCode!==13){return;}
|
||||
choices.clearInput();});const setNewCategory=(()=>{const new_category=input.value;choices.clearInput();if(!new_category.length){return;}
|
||||
const new_option=new Option(new_category,new_category);select.add(new_option);select.value=new_category;choices._addChoice(new_option);choices._triggerChange(new_category);choices.setChoiceByValue(new_category);choices.clearInput();});});})();
|
||||
50
media/regularlabs/js/textarea.js
Normal file
50
media/regularlabs/js/textarea.js
Normal file
@ -0,0 +1,50 @@
|
||||
/**
|
||||
* @package Regular Labs Library
|
||||
* @version 24.11.1459
|
||||
*
|
||||
* @author Peter van Westen <info@regularlabs.com>
|
||||
* @link https://regularlabs.com
|
||||
* @copyright Copyright © 2024 Regular Labs All Rights Reserved
|
||||
* @license GNU General Public License version 2 or later
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
(function() {
|
||||
'use strict';
|
||||
|
||||
window.RegularLabs = window.RegularLabs || {};
|
||||
|
||||
window.RegularLabs.TextArea = window.RegularLabs.TextArea || {
|
||||
prependTextarea: function(id, content, separator) {
|
||||
const textarea = $(`#${id}`);
|
||||
let originalContent = textarea.val().trim();
|
||||
|
||||
if (originalContent && separator) {
|
||||
separator = separator === 'none' ? '' : `\n\n${separator}`;
|
||||
originalContent = `${separator}\n\n${originalContent}`;
|
||||
}
|
||||
|
||||
textarea.val(`${content}${originalContent}`);
|
||||
this.moveCursorInTextareaTo(id, content.length);
|
||||
},
|
||||
|
||||
moveCursorInTextareaTo: function(id, position) {
|
||||
const textarea = document.getElementById(id);
|
||||
|
||||
if (textarea.setSelectionRange) {
|
||||
textarea.focus();
|
||||
textarea.setSelectionRange(position, position);
|
||||
textarea.scrollTop = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
if (textarea.createTextRange) {
|
||||
var range = textarea.createTextRange();
|
||||
range.moveStart('character', position);
|
||||
range.select();
|
||||
textarea.scrollTop = 0;
|
||||
}
|
||||
},
|
||||
};
|
||||
})();
|
||||
7
media/regularlabs/js/textarea.min.js
vendored
Normal file
7
media/regularlabs/js/textarea.min.js
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
/*
|
||||
* Copyright © 2024 Regular Labs - All Rights Reserved
|
||||
* GNU General Public License version 2 or later
|
||||
*/
|
||||
"use strict";(function(){'use strict';window.RegularLabs=window.RegularLabs||{};window.RegularLabs.TextArea=window.RegularLabs.TextArea||{prependTextarea:function(id,content,separator){const textarea=$(`#${id}`);let originalContent=textarea.val().trim();if(originalContent&&separator){separator=separator==='none'?'':`\n\n${separator}`;originalContent=`${separator}\n\n${originalContent}`;}
|
||||
textarea.val(`${content}${originalContent}`);this.moveCursorInTextareaTo(id,content.length);},moveCursorInTextareaTo:function(id,position){const textarea=document.getElementById(id);if(textarea.setSelectionRange){textarea.focus();textarea.setSelectionRange(position,position);textarea.scrollTop=0;return;}
|
||||
if(textarea.createTextRange){var range=textarea.createTextRange();range.moveStart('character',position);range.select();textarea.scrollTop=0;}},};})();
|
||||
233
media/regularlabs/js/treeselect.js
Normal file
233
media/regularlabs/js/treeselect.js
Normal file
@ -0,0 +1,233 @@
|
||||
/**
|
||||
* @package Regular Labs Library
|
||||
* @version 24.11.1459
|
||||
*
|
||||
* @author Peter van Westen <info@regularlabs.com>
|
||||
* @link https://regularlabs.com
|
||||
* @copyright Copyright © 2024 Regular Labs All Rights Reserved
|
||||
* @license GNU General Public License version 2 or later
|
||||
*/
|
||||
|
||||
(function() {
|
||||
'use strict';
|
||||
|
||||
window.RegularLabs = window.RegularLabs || {};
|
||||
|
||||
window.RegularLabs.TreeSelect = window.RegularLabs.TreeSelect || {
|
||||
direction: (document.dir !== undefined) ? document.dir : document.getElementsByTagName("html")[0].getAttribute("dir"),
|
||||
|
||||
init: function(id) {
|
||||
const menu = document.querySelector('div#rl-treeselect-' + id);
|
||||
|
||||
if ( ! menu) {
|
||||
return;
|
||||
}
|
||||
|
||||
const list = menu.querySelector('ul');
|
||||
const top_level_items = list.querySelectorAll(':scope > li');
|
||||
const items = list.querySelectorAll('li');
|
||||
const search_field = menu.querySelector('[name="treeselectfilter"]');
|
||||
const sub_tree_select = menu.querySelector('div.sub-tree-select > *');
|
||||
const no_results_found = menu.querySelector('joomla-alert');
|
||||
|
||||
items.forEach((item) => {
|
||||
// Store the innerText for filtering
|
||||
// because if done later, also the text from added menus and buttons is added
|
||||
item.text = item.innerText;
|
||||
});
|
||||
|
||||
items.forEach((item) => {
|
||||
const checkbox = item.querySelector(':scope > .treeselect-item > input');
|
||||
|
||||
if ( ! checkbox) {
|
||||
return;
|
||||
}
|
||||
|
||||
item.classList.toggle('rl-item-checked', checkbox.checked);
|
||||
|
||||
checkbox.addEventListener('change', () => {
|
||||
item.classList.toggle('rl-item-checked', checkbox.checked);
|
||||
});
|
||||
|
||||
const child_list = item.querySelector(':scope > ul.treeselect-sub');
|
||||
|
||||
if ( ! child_list) {
|
||||
return;
|
||||
}
|
||||
|
||||
const label = item.querySelector('label');
|
||||
|
||||
const sub_tree_select_el = sub_tree_select.cloneNode(true);
|
||||
|
||||
const sub_tree_expand = document.createElement('span');
|
||||
sub_tree_expand.className = 'treeselect-toggle icon-chevron-down';
|
||||
sub_tree_expand.collapsed = false;
|
||||
|
||||
sub_tree_expand.addEventListener('click', () => {
|
||||
this.expand(child_list, sub_tree_expand);
|
||||
});
|
||||
|
||||
sub_tree_select_el.querySelector('[data-action="checkNested"]').addEventListener('click', () => {
|
||||
this.check(child_list, true);
|
||||
});
|
||||
|
||||
sub_tree_select_el.querySelector('[data-action="uncheckNested"]').addEventListener('click', () => {
|
||||
this.check(child_list, false);
|
||||
});
|
||||
|
||||
sub_tree_select_el.querySelector('[data-action="toggleNested"]').addEventListener('click', () => {
|
||||
this.check(child_list, 'toggle');
|
||||
});
|
||||
|
||||
if (checkbox.dataset['rlTreeselectCollapseChildren']) {
|
||||
// Collapse children if top level parent is selected
|
||||
if (checkbox.checked) {
|
||||
sub_tree_expand.collapsed = false;
|
||||
this.expand(child_list, sub_tree_expand);
|
||||
this.check(child_list, false);
|
||||
}
|
||||
|
||||
// Add event when (un)checking top level parent
|
||||
checkbox.addEventListener('click', () => {
|
||||
sub_tree_expand.collapsed = ! checkbox.checked;
|
||||
this.expand(child_list, sub_tree_expand);
|
||||
this.check(child_list, false);
|
||||
});
|
||||
}
|
||||
|
||||
item.insertBefore(sub_tree_expand, item.firstChild);
|
||||
label.append(sub_tree_select_el);
|
||||
});
|
||||
|
||||
menu.querySelector('[data-action="checkAll"]').addEventListener('click', () => {
|
||||
this.check(menu, true);
|
||||
});
|
||||
menu.querySelector('[data-action="uncheckAll"]').addEventListener('click', () => {
|
||||
this.check(menu, false);
|
||||
});
|
||||
menu.querySelector('[data-action="toggleAll"]').addEventListener('click', () => {
|
||||
this.check(menu, 'toggle');
|
||||
});
|
||||
|
||||
menu.querySelector('[data-action="expandAll"]').addEventListener('click', () => {
|
||||
top_level_items.forEach((item) => {
|
||||
const child_list = item.querySelector('ul.treeselect-sub');
|
||||
const sub_tree_expand = item.querySelector('.treeselect-toggle');
|
||||
if ( ! child_list || ! sub_tree_expand) {
|
||||
return;
|
||||
}
|
||||
sub_tree_expand.collapsed = true;
|
||||
this.expand(child_list, sub_tree_expand);
|
||||
});
|
||||
});
|
||||
|
||||
menu.querySelector('[data-action="collapseAll"]').addEventListener('click', () => {
|
||||
top_level_items.forEach((item) => {
|
||||
const child_list = item.querySelector('ul.treeselect-sub');
|
||||
const sub_tree_expand = item.querySelector('.treeselect-toggle');
|
||||
if ( ! child_list || ! sub_tree_expand) {
|
||||
return;
|
||||
}
|
||||
sub_tree_expand.collapsed = false;
|
||||
this.expand(child_list, sub_tree_expand);
|
||||
});
|
||||
});
|
||||
menu.querySelector('[data-action="showAll"]').addEventListener('click', () => {
|
||||
this.resetSearch(items, search_field, no_results_found);
|
||||
});
|
||||
menu.querySelector('[data-action="showSelected"]').addEventListener('click', (e) => {
|
||||
this.resetSearch(items, search_field, no_results_found, true);
|
||||
});
|
||||
|
||||
// Takes care of the filtering
|
||||
search_field.addEventListener('keyup', () => {
|
||||
this.doSearch(items, search_field, no_results_found);
|
||||
});
|
||||
},
|
||||
|
||||
resetSearch: function(items, search_field, no_results_found, has_checked) {
|
||||
search_field.value = '';
|
||||
this.doSearch(items, search_field, no_results_found, has_checked);
|
||||
},
|
||||
|
||||
doSearch: function(items, search_field, no_results_found, has_checked) {
|
||||
const text = search_field.value.toLowerCase();
|
||||
|
||||
no_results_found.style.display = 'none';
|
||||
|
||||
let results_found = 0;
|
||||
|
||||
items.forEach((item) => {
|
||||
if (has_checked && ! item.querySelector('input:checked')) {
|
||||
item.style.display = 'none';
|
||||
return;
|
||||
}
|
||||
|
||||
if (text !== '') {
|
||||
let item_text = item.text.toLowerCase();
|
||||
item_text = item_text.replace(/\s+/g, ' ').trim();
|
||||
|
||||
if (item_text.indexOf(text) == -1) {
|
||||
item.style.display = 'none';
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
results_found++;
|
||||
item.style.display = 'block';
|
||||
});
|
||||
|
||||
if ( ! results_found) {
|
||||
no_results_found.style.display = 'block';
|
||||
}
|
||||
},
|
||||
|
||||
check: function(parent, checked) {
|
||||
const items = parent.querySelectorAll('li');
|
||||
|
||||
items.forEach((item) => {
|
||||
if (item.style.display === 'none') {
|
||||
return;
|
||||
}
|
||||
|
||||
const checkbox = item.querySelector(':scope > .treeselect-item input:enabled');
|
||||
|
||||
if ( ! checkbox) {
|
||||
return;
|
||||
}
|
||||
|
||||
checkbox.checked = checked === 'toggle' ? ! checkbox.checked : checked;
|
||||
|
||||
item.classList.toggle('rl-item-checked', checked);
|
||||
});
|
||||
},
|
||||
|
||||
expand: function(element, button) {
|
||||
const show = button.collapsed;
|
||||
|
||||
element.style.display = show ? 'block' : 'none';
|
||||
|
||||
button.classList.toggle('icon-chevron-down', show);
|
||||
button.classList.toggle(this.direction === 'rtl' ? 'icon-chevron-left' : 'icon-chevron-right', ! show);
|
||||
|
||||
button.collapsed = ! button.collapsed;
|
||||
|
||||
if ( ! show) {
|
||||
return;
|
||||
}
|
||||
|
||||
const child_lists = element.querySelectorAll(':scope > li > ul.treeselect-sub');
|
||||
|
||||
if ( ! child_lists.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
child_lists.forEach((child_list) => {
|
||||
const child_button = child_list.closest('li').querySelector('.treeselect-toggle');
|
||||
child_button.collapsed = true;
|
||||
this.expand(child_list, child_button);
|
||||
});
|
||||
|
||||
}
|
||||
};
|
||||
})();
|
||||
18
media/regularlabs/js/treeselect.min.js
vendored
Normal file
18
media/regularlabs/js/treeselect.min.js
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
/*
|
||||
* Copyright © 2024 Regular Labs - All Rights Reserved
|
||||
* GNU General Public License version 2 or later
|
||||
*/
|
||||
(function(){'use strict';window.RegularLabs=window.RegularLabs||{};window.RegularLabs.TreeSelect=window.RegularLabs.TreeSelect||{direction:(document.dir!==undefined)?document.dir:document.getElementsByTagName("html")[0].getAttribute("dir"),init:function(id){const menu=document.querySelector('div#rl-treeselect-'+id);if(!menu){return;}
|
||||
const list=menu.querySelector('ul');const top_level_items=list.querySelectorAll(':scope > li');const items=list.querySelectorAll('li');const search_field=menu.querySelector('[name="treeselectfilter"]');const sub_tree_select=menu.querySelector('div.sub-tree-select > *');const no_results_found=menu.querySelector('joomla-alert');items.forEach((item)=>{item.text=item.innerText;});items.forEach((item)=>{const checkbox=item.querySelector(':scope > .treeselect-item > input');if(!checkbox){return;}
|
||||
item.classList.toggle('rl-item-checked',checkbox.checked);checkbox.addEventListener('change',()=>{item.classList.toggle('rl-item-checked',checkbox.checked);});const child_list=item.querySelector(':scope > ul.treeselect-sub');if(!child_list){return;}
|
||||
const label=item.querySelector('label');const sub_tree_select_el=sub_tree_select.cloneNode(true);const sub_tree_expand=document.createElement('span');sub_tree_expand.className='treeselect-toggle icon-chevron-down';sub_tree_expand.collapsed=false;sub_tree_expand.addEventListener('click',()=>{this.expand(child_list,sub_tree_expand);});sub_tree_select_el.querySelector('[data-action="checkNested"]').addEventListener('click',()=>{this.check(child_list,true);});sub_tree_select_el.querySelector('[data-action="uncheckNested"]').addEventListener('click',()=>{this.check(child_list,false);});sub_tree_select_el.querySelector('[data-action="toggleNested"]').addEventListener('click',()=>{this.check(child_list,'toggle');});if(checkbox.dataset['rlTreeselectCollapseChildren']){if(checkbox.checked){sub_tree_expand.collapsed=false;this.expand(child_list,sub_tree_expand);this.check(child_list,false);}
|
||||
checkbox.addEventListener('click',()=>{sub_tree_expand.collapsed=!checkbox.checked;this.expand(child_list,sub_tree_expand);this.check(child_list,false);});}
|
||||
item.insertBefore(sub_tree_expand,item.firstChild);label.append(sub_tree_select_el);});menu.querySelector('[data-action="checkAll"]').addEventListener('click',()=>{this.check(menu,true);});menu.querySelector('[data-action="uncheckAll"]').addEventListener('click',()=>{this.check(menu,false);});menu.querySelector('[data-action="toggleAll"]').addEventListener('click',()=>{this.check(menu,'toggle');});menu.querySelector('[data-action="expandAll"]').addEventListener('click',()=>{top_level_items.forEach((item)=>{const child_list=item.querySelector('ul.treeselect-sub');const sub_tree_expand=item.querySelector('.treeselect-toggle');if(!child_list||!sub_tree_expand){return;}
|
||||
sub_tree_expand.collapsed=true;this.expand(child_list,sub_tree_expand);});});menu.querySelector('[data-action="collapseAll"]').addEventListener('click',()=>{top_level_items.forEach((item)=>{const child_list=item.querySelector('ul.treeselect-sub');const sub_tree_expand=item.querySelector('.treeselect-toggle');if(!child_list||!sub_tree_expand){return;}
|
||||
sub_tree_expand.collapsed=false;this.expand(child_list,sub_tree_expand);});});menu.querySelector('[data-action="showAll"]').addEventListener('click',()=>{this.resetSearch(items,search_field,no_results_found);});menu.querySelector('[data-action="showSelected"]').addEventListener('click',(e)=>{this.resetSearch(items,search_field,no_results_found,true);});search_field.addEventListener('keyup',()=>{this.doSearch(items,search_field,no_results_found);});},resetSearch:function(items,search_field,no_results_found,has_checked){search_field.value='';this.doSearch(items,search_field,no_results_found,has_checked);},doSearch:function(items,search_field,no_results_found,has_checked){const text=search_field.value.toLowerCase();no_results_found.style.display='none';let results_found=0;items.forEach((item)=>{if(has_checked&&!item.querySelector('input:checked')){item.style.display='none';return;}
|
||||
if(text!==''){let item_text=item.text.toLowerCase();item_text=item_text.replace(/\s+/g,' ').trim();if(item_text.indexOf(text)==-1){item.style.display='none';return;}}
|
||||
results_found++;item.style.display='block';});if(!results_found){no_results_found.style.display='block';}},check:function(parent,checked){const items=parent.querySelectorAll('li');items.forEach((item)=>{if(item.style.display==='none'){return;}
|
||||
const checkbox=item.querySelector(':scope > .treeselect-item input:enabled');if(!checkbox){return;}
|
||||
checkbox.checked=checked==='toggle'?!checkbox.checked:checked;item.classList.toggle('rl-item-checked',checked);});},expand:function(element,button){const show=button.collapsed;element.style.display=show?'block':'none';button.classList.toggle('icon-chevron-down',show);button.classList.toggle(this.direction==='rtl'?'icon-chevron-left':'icon-chevron-right',!show);button.collapsed=!button.collapsed;if(!show){return;}
|
||||
const child_lists=element.querySelectorAll(':scope > li > ul.treeselect-sub');if(!child_lists.length){return;}
|
||||
child_lists.forEach((child_list)=>{const child_button=child_list.closest('li').querySelector('.treeselect-toggle');child_button.collapsed=true;this.expand(child_list,child_button);});}};})();
|
||||
Reference in New Issue
Block a user