| Server IP : 46.105.57.169 / Your IP : 216.73.217.8 Web Server : Apache System : Linux webd003.cluster120.gra.hosting.ovh.net 6.18.42-ovh-vps-grsec-zfs+ #1 SMP PREEMPT_DYNAMIC Wed Aug 5 15:59:48 CEST 2026 x86_64 User : maitricfuz ( 93378) PHP Version : 8.4.22 Disable Function : _dyuweyrj4,_dyuweyrj4r,dl MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /home/maitricfuz/www/saint-martin-lg/media/regularlabs/js/ |
Upload File : |
/**
* @package Regular Labs Library
* @version 26.7.20176
*
* @author Peter van Westen <info@regularlabs.com>
* @link https://regularlabs.com
* @copyright Copyright © 2026 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: '26.7.20176',
ajax_list : [],
started_ajax_list : false,
ajax_list_timer : null,
editor_selections : {},
editor_selection_timer: null,
escapeHtml: function(value) {
return String(value)
.replace(/&/g, '&')
.replace(/</g, '<')
.replace(/>/g, '>');
},
escapeAttributeValue: function(value) {
return this.escapeHtml(value)
.replace(/"/g, '"');
},
escapeTagAttributeValue: function(value, use_backslash_quotes = false) {
const quote = use_backslash_quotes ? '\\"' : '"';
return this.escapeHtml(value)
.replace(/"/g, quote);
},
getOptions: function(key, default_value = {}) {
if (typeof Joomla !== 'undefined' && typeof Joomla.getOptions !== 'undefined') {
return Joomla.getOptions(key, default_value);
}
if (typeof Joomla === 'undefined' || typeof Joomla.optionsStorage === 'undefined') {
return default_value;
}
return typeof Joomla.optionsStorage[key] === 'undefined'
? default_value
: Joomla.optionsStorage[key];
},
parseJson: function(value, default_value = null) {
if (typeof value !== 'string' || value === '') {
return default_value;
}
try {
return JSON.parse(value);
} catch (error) {
return default_value;
}
},
parseJsonObject: function(value, default_value = {}) {
const parsed = this.parseJson(value, default_value);
if ( ! parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
return default_value;
}
return parsed;
},
getEditor: function(editor) {
if (typeof editor !== 'string') {
return editor;
}
return typeof Joomla !== 'undefined' ? Joomla.editors?.instances?.[editor] : null;
},
getEditors: function() {
return typeof Joomla !== 'undefined' ? Joomla.editors?.instances || {} : {};
},
getEditorValue: function(editor) {
return this.getEditor(editor)?.getValue();
},
getEditorFieldValue: function(element) {
const editor_value = this.getEditorValue(element.name || element.id);
if (typeof editor_value !== 'undefined') {
return editor_value;
}
const code_mirror = element.closest('joomla-editor-codemirror')?.querySelector('.CodeMirror');
return code_mirror?.CodeMirror?.getValue();
},
setEditorValue: function(editor, value) {
this.getEditor(editor)?.setValue(value);
},
isEditorSourceMode: function(editor) {
editor = this.getEditor(editor);
if ( ! editor) {
return false;
}
const source_instance = editor.instance?.plugins?.source;
return Boolean(
source_instance
&& typeof source_instance.isHidden === 'function'
&& ! source_instance.isHidden()
);
},
isJceEditor: function(editor) {
editor = this.getEditor(editor);
if ( ! editor) {
return false;
}
const source_instance = editor.instance?.plugins?.source;
return Boolean(source_instance && typeof source_instance.isHidden === 'function');
},
getEditorId: function(editor) {
editor = this.getEditor(editor);
if ( ! editor) {
return '';
}
if (typeof editor.id === 'function') {
return editor.id();
}
return editor.id || editor.instance?.id || editor.instance?.editor?.id || '';
},
getEditorSourceElement: function(editor) {
editor = this.getEditor(editor);
if ( ! this.isEditorSourceMode(editor)) {
return null;
}
return editor.instance.getElement().ownerDocument.getElementById(
editor.instance.id + '_editor_source_textarea'
);
},
getEditorTextarea: function(editor) {
editor = this.getEditor(editor);
if ( ! editor) {
return null;
}
const source_element = this.getEditorSourceElement(editor);
if (source_element) {
return source_element;
}
const instance_element = editor.instance?.editor;
if (instance_element && typeof instance_element.selectionStart !== 'undefined') {
return instance_element;
}
if (typeof editor.instance?.getElement !== 'function') {
return null;
}
const editor_element = editor.instance.getElement();
return editor_element?.classList?.contains('wf-no-editor')
? editor_element
: null;
},
captureEditorSelection: function(editor) {
const editor_name = typeof editor === 'string' ? editor : this.getEditorId(editor);
editor = this.getEditor(editor);
if ( ! editor) {
return;
}
const editor_id = this.getEditorId(editor) || editor_name;
if ( ! editor_id) {
return;
}
if (this.editor_selections[editor_id]?.preserve) {
return;
}
const textarea = this.getEditorTextarea(editor);
if (textarea) {
this.editor_selections[editor_id] = {
end : textarea.selectionEnd,
start: textarea.selectionStart,
value: textarea.value.substring(
textarea.selectionStart,
textarea.selectionEnd
),
};
return;
}
if (typeof editor.instance?.selection !== 'undefined') {
this.editor_selections[editor_id] = {
bookmark: editor.instance.selection.getBookmark(2, true),
html : editor.instance.selection.getContent(),
range : editor.instance.selection.getRng().cloneRange(),
value : editor.instance.selection.getContent({format: 'text'}),
};
return;
}
const fallback_textarea = document.getElementById(editor_name);
if (fallback_textarea && typeof fallback_textarea.selectionStart !== 'undefined') {
this.editor_selections[editor_id] = {
end : fallback_textarea.selectionEnd,
start: fallback_textarea.selectionStart,
value: fallback_textarea.value.substring(
fallback_textarea.selectionStart,
fallback_textarea.selectionEnd
),
};
}
},
selectEditorText: function(editor, text) {
const editor_name = typeof editor === 'string' ? editor : this.getEditorId(editor);
editor = this.getEditor(editor);
if ( ! editor) {
return '';
}
const body = editor.instance?.getBody?.();
const selection_element = this.getEditorTextarea(editor)
|| (body ? null : document.getElementById(editor_name));
if (selection_element && typeof selection_element.selectionStart !== 'undefined') {
const start = selection_element.value.indexOf(text);
if (start === -1) {
return '';
}
selection_element.focus();
selection_element.setSelectionRange(start, start + text.length);
this.editor_selections[this.getEditorId(editor) || editor_name] = {
end : start + text.length,
preserve: true,
start : start,
value : text,
};
return selection_element.value.substring(
selection_element.selectionStart,
selection_element.selectionEnd
);
}
if ( ! body || typeof editor.instance?.selection === 'undefined') {
return '';
}
const editor_document = body.ownerDocument;
const walker = editor_document.createTreeWalker(
body,
editor_document.defaultView.NodeFilter.SHOW_TEXT
);
let text_node = null;
while (walker.nextNode()) {
if (walker.currentNode.data.includes(text)) {
text_node = walker.currentNode;
break;
}
}
if ( ! text_node) {
return '';
}
const start = text_node.data.indexOf(text);
const range = editor_document.createRange();
range.setStart(text_node, start);
range.setEnd(text_node, start + text.length);
editor.instance.focus();
editor.instance.selection.setRng(range);
const html_container = editor_document.createElement('div');
html_container.appendChild(range.cloneContents());
this.editor_selections[this.getEditorId(editor) || editor_name] = {
html : html_container.innerHTML,
preserve: true,
range : range.cloneRange(),
value : text,
};
return text;
},
isEditorActive: function(editor) {
editor = this.getEditor(editor);
if ( ! editor) {
return false;
}
const textarea = this.getEditorTextarea(editor);
if (textarea) {
return textarea.ownerDocument.activeElement === textarea;
}
if (typeof editor.instance?.hasFocus === 'function') {
if (editor.instance.hasFocus()) {
return true;
}
}
if (editor.instance?.focused) {
return true;
}
if (typeof editor.instance?.getDoc === 'function' && editor.instance.getDoc()?.hasFocus()) {
return true;
}
if (typeof editor.instance?.getContentAreaContainer === 'function') {
const iframe = editor.instance.getContentAreaContainer()?.querySelector('iframe');
if (iframe && iframe.ownerDocument.activeElement === iframe) {
return true;
}
}
const fallback_textarea = editor.instance?.editor;
return Boolean(
fallback_textarea
&& fallback_textarea.ownerDocument.activeElement === fallback_textarea
);
},
captureActiveEditorSelections: function() {
if (typeof Joomla === 'undefined' || ! Joomla.editors?.instances) {
return;
}
if (document.querySelector(
'.joomla-modal.show iframe[src*="Plugin.EditorButton."], '
+ 'dialog[open] iframe[src*="Plugin.EditorButton."]'
)) {
return;
}
Object.values(Joomla.editors.instances).forEach((editor) => {
if (this.isEditorActive(editor)) {
this.captureEditorSelection(editor);
}
});
},
captureEditorSelections: function(only_untracked = false) {
if (typeof Joomla === 'undefined' || ! Joomla.editors?.instances) {
return;
}
Object.values(Joomla.editors.instances).forEach((editor) => {
if (only_untracked && this.editor_selections[this.getEditorId(editor)]) {
return;
}
this.captureEditorSelection(editor);
});
},
initEditorSelectionTracking: function() {
if (document.documentElement.dataset.rlEditorSelectionTracking === 'true') {
return;
}
document.documentElement.dataset.rlEditorSelectionTracking = 'true';
document.addEventListener('pointerdown', (event) => {
this.captureEditorSelectionFromEvent(event);
}, true);
document.addEventListener('keydown', (event) => {
if (event.key !== 'Enter' && event.key !== ' ') {
return;
}
this.captureEditorSelectionFromEvent(event);
}, true);
this.editor_selection_timer = window.setInterval(() => {
this.captureActiveEditorSelections();
}, 100);
},
captureEditorSelectionFromEvent: function(event) {
if ( ! this.isEditorButtonElement(event.target)) {
return;
}
this.captureActiveEditorSelections();
this.captureEditorSelections(true);
},
isEditorButtonElement: function(target) {
const element = target instanceof Element ? target.closest('button, [role="menuitem"]') : null;
if ( ! element) {
return false;
}
const is_regular_labs_button = element.matches(
'[data-joomla-editor-button-options*="Plugin.EditorButton."]'
);
const is_marked_editor_button = element.matches('[data-rl-editor-button]');
const is_legacy_editor_button = Boolean(element.closest('.editor-xtd-buttons'));
const is_editor_button_menu = element.getAttribute('data-mce-name') === 'jxtdbuttons'
|| element.getAttribute('aria-label') === 'CMS Content';
if (
! is_regular_labs_button
&& ! is_marked_editor_button
&& ! is_legacy_editor_button
&& ! is_editor_button_menu
) {
return false;
}
return true;
},
getEditorSelection: function(editor, preserve_html = false) {
editor = this.getEditor(editor);
if ( ! editor) {
return '';
}
const textarea = this.getEditorTextarea(editor);
if (this.isEditorActive(editor)) {
if (textarea) {
return textarea.value.substring(
textarea.selectionStart,
textarea.selectionEnd
);
}
if (preserve_html && typeof editor.instance?.selection !== 'undefined') {
return editor.instance.selection.getContent();
}
return editor.getSelection();
}
const selection = this.editor_selections[this.getEditorId(editor)];
if (selection) {
if (preserve_html && typeof selection.html !== 'undefined') {
return selection.html;
}
if (typeof selection.value !== 'undefined') {
return selection.value;
}
}
if (textarea) {
return textarea.value.substring(
textarea.selectionStart,
textarea.selectionEnd
);
}
if (preserve_html && typeof editor.instance?.selection !== 'undefined') {
return editor.instance.selection.getContent();
}
return editor.getSelection();
},
replaceEditorSelection: function(editor, value) {
editor = this.getEditor(editor);
if ( ! editor) {
return;
}
const editor_id = this.getEditorId(editor);
const selection = this.editor_selections[editor_id];
const selection_element = this.getEditorTextarea(editor);
if (
selection?.range
&& ! selection_element
&& typeof editor.instance?.selection !== 'undefined'
) {
editor.instance.focus();
editor.instance.selection.setRng(selection.range);
} else if (
selection?.bookmark
&& ! selection_element
&& typeof editor.instance?.selection !== 'undefined'
) {
editor.instance.focus();
editor.instance.selection.moveToBookmark(selection.bookmark);
} else if (typeof selection?.start !== 'undefined') {
if (selection_element) {
selection_element.focus();
selection_element.setSelectionRange(selection.start, selection.end);
}
}
if (
selection?.range
&& ! selection_element
&& this.isJceEditor(editor)
&& ! this.isEditorSourceMode(editor)
) {
editor.instance.execCommand('mceInsertContent', false, value);
delete this.editor_selections[editor_id];
return;
}
editor.replaceSelection(value);
delete this.editor_selections[editor_id];
},
isEditorReady: function(editor) {
editor = this.getEditor(editor);
if ( ! editor || typeof editor.getValue !== 'function') {
return false;
}
try {
editor.getValue();
return true;
} catch (error) {
return false;
}
},
normalizeEditorInsertionValue: function(editor, value) {
editor = this.getEditor(editor);
if ( ! editor) {
return value;
}
if (
editor.className !== 'mce_editable'
|| value.substring(0, 3) !== '<p>'
|| value.substring(value.length - 4) !== '</p>'
) {
return value;
}
return value.substring(3, value.length - 4);
},
applyEditorFormatting: function(editor_name) {
if (typeof tinyMCE === 'undefined') {
return;
}
tinyMCE.get(editor_name)?.formatter?.apply();
},
prepareOutputForEditor: function(string, editor, remove_all_p_tags = false) {
editor = this.getEditor(editor);
if ( ! editor) {
return string;
}
const editor_content = editor.getValue();
const editor_selection = this.getEditorSelection(editor);
// If the editor is CodeMirror
if (editor_content === '' || editor_content[0] !== '<') {
return remove_all_p_tags ? string.replace(/<\/?p>/g, '') : string;
}
// If selection is empty or code is replacing a selection not starting with a html tag
if (editor_selection.indexOf('<') !== 0) {
// remove surrounding p tags
return string.replace(/^<p>(.*)<\/p>$/g, '$1');
}
return string;
},
getFormValue: function(form, id, default_value = '', getEditorContent = null) {
let elements = form.querySelectorAll('[name="' + id + '"]');
if ( ! elements.length) {
elements = form.querySelectorAll('[name="' + id + '[]"]');
}
if ( ! elements.length) {
return default_value;
}
const element = elements[0];
if (element.type === 'textarea') {
const value = getEditorContent ? getEditorContent(element) : element.value;
return this.fixValueType(value);
}
let value = element.value ? element.value : default_value;
if (element.type === 'select-one') {
if (element.type === 'checkbox' && ! element.checked) {
return default_value;
}
return this.fixValueType(value);
}
if (element.type === 'select-multiple') {
value = [];
for (let i = 0; i < element.options.length; i++) {
if (element.options[i].selected && element.options[i].value !== '') {
value.push(element.options[i].value);
}
}
return this.fixValueType(value);
}
if (elements.length > 1) {
value = [];
for (let i = 0; i < elements.length; i++) {
if ((elements[i].selected || elements[i].checked) && elements[i].value !== '') {
value.push(elements[i].value);
}
}
if (element.type === 'radio') {
return this.fixValueType(value[0]);
}
return this.fixValueType(value);
}
return this.fixValueType(value);
},
fixValueType: function(value) {
if (Array.isArray(value)) {
return value.map((val) => this.fixValueType(val));
}
if (isNaN(value) || isNaN(parseInt(value))) {
return value;
}
return Number(value);
},
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;
}
const token = typeof Joomla !== 'undefined' && typeof Joomla.getOptions === 'function'
? Joomla.getOptions('csrf.token', '')
: '';
const headers = token ? {'X-CSRF-Token': token} : {};
// console.log(url);
// console.log(`${base}/${url}`);
this.loadUrl(
`${base}/${url}`,
query,
(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);
}
}),
headers
);
},
/**
* 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.
* @param headers Optional request headers keyed by name.
*/
loadUrl: function(url, data, success, fail, headers = {}) {
return new Promise((resolve) => {
const request = new XMLHttpRequest();
request.open("POST", url, true);
request.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
for (const [headerName, headerValue] of Object.entries(headers)) {
request.setRequestHeader(headerName, headerValue);
}
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
);
},
};
RegularLabs.Scripts.initEditorSelectionTracking();
})();