/** * @package Joomla.Component.Builder * * @created 30th April, 2015 * @author Llewellyn van der Merwe * @git Joomla Component Builder * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ // Some Global Values jform_vvvvwcfvxj_required = false; // Initial Script document.addEventListener('DOMContentLoaded', function() { var extension_type_vvvvwcf = jQuery("#jform_extension_type").val(); vvvvwcf(extension_type_vvvvwcf); }); // the vvvvwcf function function vvvvwcf(extension_type_vvvvwcf) { if (isSet(extension_type_vvvvwcf) && extension_type_vvvvwcf.constructor !== Array) { var temp_vvvvwcf = extension_type_vvvvwcf; var extension_type_vvvvwcf = []; extension_type_vvvvwcf.push(temp_vvvvwcf); } else if (!isSet(extension_type_vvvvwcf)) { var extension_type_vvvvwcf = []; } var extension_type = extension_type_vvvvwcf.some(extension_type_vvvvwcf_SomeFunc); // set this function logic if (extension_type) { jQuery('#jform_joomla_plugin_group').closest('.control-group').show(); // add required attribute to joomla_plugin_group field if (jform_vvvvwcfvxj_required) { updateFieldRequired('joomla_plugin_group',0); jQuery('#jform_joomla_plugin_group').prop('required','required'); jQuery('#jform_joomla_plugin_group').attr('aria-required',true); jQuery('#jform_joomla_plugin_group').addClass('required'); jform_vvvvwcfvxj_required = false; } } else { jQuery('#jform_joomla_plugin_group').closest('.control-group').hide(); // remove required attribute from joomla_plugin_group field if (!jform_vvvvwcfvxj_required) { updateFieldRequired('joomla_plugin_group',1); jQuery('#jform_joomla_plugin_group').removeAttr('required'); jQuery('#jform_joomla_plugin_group').removeAttr('aria-required'); jQuery('#jform_joomla_plugin_group').removeClass('required'); jform_vvvvwcfvxj_required = true; } } } // the vvvvwcf Some function function extension_type_vvvvwcf_SomeFunc(extension_type_vvvvwcf) { // set the function logic if (extension_type_vvvvwcf == 'plugins' || extension_type_vvvvwcf == 'plugin') { return true; } return false; } // update fields required function updateFieldRequired(name, status) { // check if not_required exist if (document.getElementById('jform_not_required')) { var not_required = jQuery('#jform_not_required').val().split(","); if(status == 1) { not_required.push(name); } else { not_required = removeFieldFromNotRequired(not_required, name); } jQuery('#jform_not_required').val(fixNotRequiredArray(not_required).toString()); } } // remove field from not_required function removeFieldFromNotRequired(array, what) { return array.filter(function(element){ return element !== what; }); } // fix not required array function fixNotRequiredArray(array) { var seen = {}; return removeEmptyFromNotRequiredArray(array).filter(function(item) { return seen.hasOwnProperty(item) ? false : (seen[item] = true); }); } // remove empty from not_required array function removeEmptyFromNotRequiredArray(array) { return array.filter(function (el) { // remove ( 一_一) as well - lol return (el.length > 0 && '一_一' !== el); }); } // the isSet function function isSet(val) { if ((val != undefined) && (val != null) && 0 !== val.length){ return true; } return false; } jQuery(document).ready(function() { // load the used in div // jQuery('#usedin').show(); // check and load all the customcode edit buttons setTimeout(getEditCustomCodeButtons, 300); }); function getEditCustomCodeButtons_server(id) { var getUrl = JRouter("index.php?option=com_componentbuilder&task=ajax.getEditCustomCodeButtons&format=json&raw=true&vdm="+vastDevMod); let requestParams = ''; if (token.length > 0 && id > 0) { requestParams = token+'=1&id='+id+'&return_here='+return_here; } // Construct URL with parameters for GET request const urlWithParams = getUrl + '&' + requestParams; // Using the Fetch API for the GET request return fetch(urlWithParams, { method: 'GET', headers: { 'Content-Type': 'application/json' } }).then(response => { if (!response.ok) { throw new Error('Network response was not ok'); } return response.json(); }); } function getEditCustomCodeButtons() { // Get the id using pure JavaScript const id = document.querySelector("#jform_id").value; getEditCustomCodeButtons_server(id).then(function(result) { if (typeof result === 'object') { Object.entries(result).forEach(([field, buttons]) => { // Creating the div element for buttons const div = document.createElement('div'); div.className = 'control-group'; div.innerHTML = '
'; // Insert the div before .control-wrapper-{field} const insertBeforeElement = document.querySelector(".control-wrapper-"+field); insertBeforeElement.parentNode.insertBefore(div, insertBeforeElement); // Adding buttons to the div Object.entries(buttons).forEach(([name, button]) => { const controlsDiv = document.querySelector(".control-customcode-buttons-"+field); controlsDiv.innerHTML += button; }); }); } }).catch(error => { console.error('Error:', error); }); }