Skip to content
This repository has been archived by the owner on May 26, 2020. It is now read-only.

Commit

Permalink
Remove inline Javascript for administrator/components/com_languages/t…
Browse files Browse the repository at this point in the history
…mpl/language/edit.php (#94)

* Jquery es6 remove inline

* corrections

* easier way

* dont use script options

* Revert "dont use script options"

This reverts commit 80fcd898d0ea862c806fe32dc6adda0cde925930.

* use global script option as discussed in glip

* use global script option as discussed in glip
  • Loading branch information
astridx authored and dneukirchen committed Mar 9, 2018
1 parent c0bdb92 commit 28f2ab0
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 15 deletions.
18 changes: 3 additions & 15 deletions administrator/components/com_languages/tmpl/language/edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,14 @@

defined('_JEXEC') or die;

use Joomla\CMS\HTML\HTMLHelper;

JHtml::addIncludePath(JPATH_COMPONENT . '/helpers/html');

JHtml::_('behavior.formvalidator');
JHtml::_('behavior.tabstate');

JFactory::getDocument()->addScriptDeclaration(
'
jQuery(document).ready(function() {
jQuery("#jform_image").on("change", function() {
var flag = this.value;
if (flag) {
jQuery("#flag img").attr("src", "' . JUri::root(true) . '" + "/media/mod_languages/images/" + flag + ".gif").attr("alt", flag);
}
else
{
jQuery("#flag img").removeAttr("src").removeAttr("alt");
}
});
});'
);
HTMLHelper::_('script', 'com_languages/admin-language-edit-change-flag.js', ['relative' => true, 'version' => 'auto']);
?>

<form action="<?php echo JRoute::_('index.php?option=com_languages&view=language&layout=edit&lang_id=' . (int) $this->item->lang_id); ?>" method="post" name="adminForm" id="language-form" class="form-validate">
Expand Down
19 changes: 19 additions & 0 deletions media/com_languages/js/admin-language-edit-change-flag.es6.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* @copyright Copyright (C) 2005 - 2018 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
document.addEventListener('DOMContentLoaded', () => {
document.getElementById('jform_image').addEventListener('change', (event) => {
const flagSelectedValue = event.currentTarget.value;
const flagimage = document.getElementById('flag').querySelector('img');
const src = `${Joomla.getOptions('system.paths').rootFull}/media/mod_languages/images/${flagSelectedValue}.gif`;

if (flagSelectedValue) {
flagimage.setAttribute('src', src);
flagimage.setAttribute('alt', flagSelectedValue);
} else {
flagimage.removeAttribute('src');
flagimage.setAttribute('alt', '');
}
}, false);
});
24 changes: 24 additions & 0 deletions media/com_languages/js/admin-language-edit-change-flag.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* PLEASE DO NOT MODIFY THIS FILE. WORK ON THE ES6 VERSION.
* OTHERWISE YOUR CHANGES WILL BE REPLACED ON THE NEXT BUILD.
**/

/**
* @copyright Copyright (C) 2005 - 2018 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
document.addEventListener('DOMContentLoaded', function () {
document.getElementById('jform_image').addEventListener('change', function (event) {
var flagSelectedValue = event.currentTarget.value;
var flagimage = document.getElementById('flag').querySelector('img');
var src = Joomla.getOptions('system.paths').rootFull + '/media/mod_languages/images/' + flagSelectedValue + '.gif';

if (flagSelectedValue) {
flagimage.setAttribute('src', src);
flagimage.setAttribute('alt', flagSelectedValue);
} else {
flagimage.removeAttribute('src');
flagimage.setAttribute('alt', '');
}
}, false);
});

0 comments on commit 28f2ab0

Please sign in to comment.