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/override/edit.php (#89)

* Remove inline Javascript for administrator/components/com_languages/tmpl/override/edit.php

* use slice in foreach

* deleted line

* wip

* use data attrib as it is a state specific behavior

* worked on the forgotton inline javascript

* worked on the forgotton inline javascript

* correction

* correction

* rename data attribute
  • Loading branch information
astridx authored and dneukirchen committed Mar 10, 2018
1 parent bbcc06b commit 7f2cbcf
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 19 deletions.
24 changes: 5 additions & 19 deletions administrator/components/com_languages/tmpl/override/edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

defined('_JEXEC') or die;

use Joomla\CMS\HTML\HTMLHelper;

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

JHtml::_('behavior.formvalidator');
Expand All @@ -22,23 +24,7 @@
JHtml::_('behavior.core');
JHtml::_('jquery.framework');
JHtml::_('script', 'com_languages/overrider.min.js', array('version' => 'auto', 'relative' => true));

JFactory::getDocument()->addScriptDeclaration('
jQuery(document).ready(function($) {
$("#jform_searchstring").on("focus", function() {
if (!Joomla.overrider.states.refreshed)
{
var expired = "' . $expired . '";
if (expired)
{
Joomla.overrider.refreshCache();
Joomla.overrider.states.refreshed = true;
}
}
$(this).removeClass("invalid");
});
});
');
HTMLHelper::_('script', 'com_languages/admin-override-edit-refresh-searchstring.js', ['relative' => true, 'version' => 'auto']);
?>

<form action="<?php echo JRoute::_('index.php?option=com_languages&id=' . $this->item->key); ?>" method="post" name="adminForm" id="override-form" class="form-validate">
Expand Down Expand Up @@ -138,9 +124,9 @@

<fieldset id="results-container" class="adminform">
<legend><?php echo JText::_('COM_LANGUAGES_VIEW_OVERRIDE_RESULTS_LEGEND'); ?></legend>
<div id="overrider-spinner" class="overrider-spinner text-center"><span class="fa fa-spinner fa-spin" aria-hidden="true"></span></div>
<div id="overrider-spinner" class="overrider-spinner text-center" data-search-string-expired="<?php echo $expired; ?>"><span class="fa fa-spinner fa-spin" aria-hidden="true"></span></div>
<span id="more-results" class="mt-2">
<a href="javascript:Joomla.overrider.searchStrings(Joomla.overrider.states.more);" class="btn btn-secondary">
<a id="more-results-button" class="btn btn-secondary">
<span id="overrider-spinner-btn" class="overrider-spinner-btn fa fa-spinner fa-spin" aria-hidden="true"></span>
<?php echo JText::_('COM_LANGUAGES_VIEW_OVERRIDE_MORE_RESULTS'); ?></a>
</span>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* @copyright Copyright (C) 2005 - 2017 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_searchstring').addEventListener('focus', (event) => {
if (!Joomla.overrider.states.refreshed) {
const expired = document.getElementById('overrider-spinner').getAttribute('data-search-string-expired');
if (expired) {
Joomla.overrider.refreshCache();
Joomla.overrider.states.refreshed = true;
}
}
event.currentTarget.classList.remove('invalid');
}, false);

document.getElementById('more-results-button').addEventListener('click', () => {
Joomla.overrider.searchStrings(Joomla.overrider.states.more);
}, false);
});

26 changes: 26 additions & 0 deletions media/com_languages/js/admin-override-edit-refresh-searchstring.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* 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 - 2017 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_searchstring').addEventListener('focus', function (event) {
if (!Joomla.overrider.states.refreshed) {
var expired = document.getElementById('overrider-spinner').getAttribute('data-search-string-expired');
if (expired) {
Joomla.overrider.refreshCache();
Joomla.overrider.states.refreshed = true;
}
}
event.currentTarget.classList.remove('invalid');
}, false);

document.getElementById('more-results-button').addEventListener('click', function () {
Joomla.overrider.searchStrings(Joomla.overrider.states.more);
}, false);
});

0 comments on commit 7f2cbcf

Please sign in to comment.