Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions administrator/components/com_content/tmpl/articles/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,21 @@
HTMLHelper::_('draggablelist.draggable');
}

$js = "
;(function($)
{
$(function()
{
$('.article-status').on('click', function(e)
{
e.stopPropagation();
});
$js = <<<JS
(function() {
document.addEventListener('DOMContentLoaded', function() {
var elements = [].slice.call(document.querySelectorAll('.article-status'));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove whitespace.

elements.forEach(function (element) {
element.addEventListener('click', function(event) {
event.stopPropagation();
});
})(jQuery);
";
});
});
})();
JS;

// @todo move the script to a file
Factory::getDocument()->addScriptDeclaration($js);

$assoc = Associations::isEnabled();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,24 @@
use Joomla\CMS\Language\Text;
use Joomla\CMS\HTML\HTMLHelper;

JFactory::getDocument()->addScriptDeclaration("
jQuery('#exampleModal').on('hide.bs.modal', function (e) {
$js = <<<JS
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can actually just remove all this JS. exampleModal isn't the name of an ID in Joomla

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are you sure?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code gone

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exampleModal is a copy/paste error from whatever boilerplate code was used

(function() {
var element = document.getElementById('exampleModal');
if (element) {
element.addEventListener('hide.bs.modal', function() {
document.getElementById('batch-category-id').value = '';
document.getElementById('batch-access').value = '';
document.getElementById('batch-language-id').value = '';
document.getElementById('batch-user-id').value = '';
document.getElementById('batch-tag-id').value = '';
document.getElementById('batch-workflowstage-id').value = '';
});
");
}
})();
JS;

// @todo move the script to a file
JFactory::getDocument()->addScriptDeclaration($js);

HTMLHelper::_('script', 'com_content/admin-articles-default-batch-footer.js', ['relative' => true, 'version' => 'auto']);
?>
Expand Down
26 changes: 14 additions & 12 deletions administrator/components/com_content/tmpl/featured/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,22 @@
HTMLHelper::_('sortablelist.sortable', 'articleList', 'adminForm', strtolower($listDirn), $saveOrderingUrl);
}

$js = "
;(function($)
{
$(function()
{
$('.article-status').on('click', function(e)
{
e.stopPropagation();
});
$js = <<<JS
(function() {
document.addEventListener('DOMContentLoaded', function() {
var elements = [].slice.call(document.querySelectorAll('.article-status'));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove whitespace.

elements.forEach(function (element) {
element.addEventListener('click', function(event) {
event.stopPropagation();
});
})(jQuery);
";
});
});
})();
JS;

\Joomla\CMS\Factory::getDocument()->addScriptDeclaration($js);
// @todo mode the script to a file
Factory::getDocument()->addScriptDeclaration($js);

?>

Expand Down
52 changes: 31 additions & 21 deletions administrator/components/com_fields/Field/Modal/FieldField.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,48 +50,58 @@ protected function getInput ()
// Load language
Factory::getLanguage()->load('com_fields', JPATH_ADMINISTRATOR);

// Build the script.
$script = array();
$jsId = $this->id;

// Build the script.
// Select button script
$script[] = ' function jSelectCategory_' . $this->id . '(id, title, object) {';
$script[] = ' document.getElementById("' . $this->id . '_id").value = id;';
$script[] = ' document.getElementById("' . $this->id . '_name").value = title;';
$script = <<<JS1
function jSelectCategory_$jsId(id, title, object) {
document.getElementById("$jsId" + "_id").value = id;
document.getElementById("$jsId" + "_name").value = title;
JS1;

if ($allowEdit)
{
$script[] = ' document.getElementById("' . $this->id . '_edit").classList.remove("hidden");';
$script += <<<JS2
document.getElementById("$jsId" + "_edit").classList.remove("hidden");
JS2;
}

if ($allowClear)
{
$script[] = ' document.getElementById("' . $this->id . '_clear").classList.remove("hidden");';
$script += <<<JS3
document.getElementById("$jsId" + "_clear").classList.remove("hidden");
JS3;
}

$script[] = ' Joomla.Modal.getCurrent().close()';
$script[] = ' }';
$script += <<<JS4
Joomla.Modal.getCurrent().close();
}
JS4;

// Clear button script
static $scriptClear;

if ($allowClear && !$scriptClear)
{
$scriptClear = true;

$script[] = ' function jClearCategory(id) {';
$script[] = ' document.getElementById(id + "_id").value = "";';
$script[] = ' document.getElementById(id + "_name").value = "' .
htmlspecialchars(Text::_('COM_FIELDS_SELECT_A_FIELD', true), ENT_COMPAT, 'UTF-8') . '";';
$script[] = ' document.getElementById(id + "_clear").classList.add("hidden");';
$script[] = ' if (document.getElementById(id + "_edit")) {';
$script[] = ' document.getElementById(id + "_edit").classList.add("hidden");';
$script[] = ' }';
$script[] = ' return false;';
$script[] = ' }';
$jsValue = htmlspecialchars(Text::_('COM_FIELDS_SELECT_A_FIELD', true), ENT_COMPAT, 'UTF-8');
$script += <<<JS5
function jClearCategory(id) {
document.getElementById(id + "_id").value = "";
document.getElementById(id + "_name").value = "$jsValue";
document.getElementById(id + "_clear").classList.add("hidden");
if (document.getElementById(id + "_edit")) {
document.getElementById(id + "_edit").classList.add("hidden");
}
return false;
}
JS5;
}

// @todo move the script to a file
// Add the script to the document head.
Factory::getDocument()->addScriptDeclaration(implode("\n", $script));
Factory::getDocument()->addScriptDeclaration($script);

// Setup variables for display.
$html = array();
Expand Down
28 changes: 16 additions & 12 deletions administrator/components/com_fields/Field/TypeField.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,22 @@ function ($a, $b)
}
);

Factory::getDocument()->addScriptDeclaration("
jQuery( document ).ready(function() {
Joomla.loadingLayer('load');
});
function typeHasChanged(element){
Joomla.loadingLayer('show');
var cat = jQuery(element);
jQuery('input[name=task]').val('field.reload');
element.form.submit();
}
"
);
$js = <<<JS
(function () {
window.typeHasChanged = function(element) {
Joomla.loadingLayer('show');
document.querySelector('input[name=task]').value = 'field.reload';
element.form.submit();
};

document.addEventListener('DOMContentLaoded', function() {
Joomla.loadingLayer('load');
});
})();
JS;

// @todo move the script to a file
Factory::getDocument()->addScriptDeclaration($js);

return $options;
}
Expand Down
37 changes: 24 additions & 13 deletions administrator/components/com_fields/helpers/fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -327,20 +327,31 @@ public static function prepareForm($context, JForm $form, $data)
*/
$form->setFieldAttribute('catid', 'onchange', 'categoryHasChanged(this);');

$formControl = $form->getFormControl();

// @todo move the script to a file
// Preload spindle-wheel when we need to submit form due to category selector changed
Factory::getDocument()->addScriptDeclaration("
function categoryHasChanged(element) {
var cat = jQuery(element);
if (cat.val() == '" . $assignedCatids . "')return;
Joomla.loadingLayer('show');
jQuery('input[name=task]').val('" . $section . ".reload');
element.form.submit();
}
jQuery( document ).ready(function() {
Joomla.loadingLayer('load');
var formControl = '#" . $form->getFormControl() . "_catid';
if (!jQuery(formControl).val() != '" . $assignedCatids . "'){jQuery(formControl).val('" . $assignedCatids . "');}
});"
Factory::getDocument()->addScriptDeclaration(
<<<JS
function categoryHasChanged(element) {
if (cat.value === '$assignedCatids') {
return;
}

Joomla.loadingLayer('show');
document.querySelector('input[name=task]').value = "$section.reload";
element.form.submit();
}

document.addEventListener('DOMContentLoaded', function() {
Joomla.loadingLayer('load');

var element = document.getElementById("$formControl" + "_catid")
if (!element.val() !== "$assignedCatids") {
element.value = "$assignedCatids";
}
});
JS
);
}

Expand Down
44 changes: 29 additions & 15 deletions components/com_content/tmpl/categories/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,36 @@
Text::script('JGLOBAL_EXPAND_CATEGORIES');
Text::script('JGLOBAL_COLLAPSE_CATEGORIES');

Factory::getDocument()->addScriptDeclaration("
jQuery(function($) {
$('.categories-list').find('[id^=category-btn-]').each(function(index, btn) {
var btn = $(btn);
btn.on('click', function() {
btn.find('span').toggleClass('icon-plus');
btn.find('span').toggleClass('icon-minus');
if (btn.attr('aria-label') === Joomla.JText._('JGLOBAL_EXPAND_CATEGORIES'))
{
btn.attr('aria-label', Joomla.JText._('JGLOBAL_COLLAPSE_CATEGORIES'));
} else {
btn.attr('aria-label', Joomla.JText._('JGLOBAL_EXPAND_CATEGORIES'));
}
});
$js = <<<JS
(function() {
document.addEventListener('DOMContentLoaded', function() {
var categories = [].slice.call(document.querySelectorAll('.categories-list'));
categories.forEach(function(category) {
var buttons = [].slice.call(document.querySelectorAll('.categories-list'));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove space

buttons.forEach(function(button) {
var span = button.querySelector('span');
if(span) {
span.classList.toggle('icon-plus')
span.classList.toggle('icon-minus')
}
if (button.getAttribute('aria-label') === Joomla.JText._('JGLOBAL_EXPAND_CATEGORIES'))
{
button.setAttribute('aria-label', Joomla.JText._('JGLOBAL_COLLAPSE_CATEGORIES'));
} else {
button.setAttribute('aria-label', Joomla.JText._('JGLOBAL_EXPAND_CATEGORIES'));
}
})
})
});
});");
})();
JS;

// @todo move script to a file
Factory::getDocument()->addScriptDeclaration($js);
?>
<div class="com-content-categories categories-list">
<?php
Expand Down