- md5
- 79f1c6b0f740dc49511a5f0705186924
- sha1
- 56d1ea7ac6ba938988e2cb4f1bafd2d90100d10a
- sha256
- b23aba3578c674d4d872482709c17d0828e6816e57517e1569fe4969ade958a8
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
/**
* @copyright Copyright (C) 2005 - 2018 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
/**
* Some state variables for the overrider
*/
Joomla.overrider = {
states: {
refreshing : false,
refreshed : false,
counter : 0,
searchstring: '',
searchtype : 'value'
}
};
/**
* Method for refreshing the database cache of known language strings via Ajax
*
* @return void
*
* @since 2.5
*/
Joomla.overrider.refreshCache = function()
{
this.states.refreshing = true;
var self = this,
refreshStatus = document.getElementById('refresh-status');
refreshStatus.classList.add('show');
Joomla.request({
url: 'index.php?option=com_languages&task=strings.refresh&format=json',
method: 'POST',
headers: {'Content-Type': 'application/json'},
onSuccess: function(response) {
if (response.error && response.message) {
alert(response.message);
}
if (response.messages) {
Joomla.renderMessages(response.messages);
}
refreshStatus.classList.remove('show');
self.states.refreshing = false;
},
onError: function(xhr) {
alert(Joomla.JText._('COM_LANGUAGES_VIEW_OVERRIDE_REQUEST_ERROR'));
refreshStatus.classList.remove('show');
}
});
};
/**
* Method for searching known language strings via Ajax
*
* @param more Determines the limit start of the results
*
* @return void
*
* @since 2.5
*/
Joomla.overrider.searchStrings = function(more)
{
var self = this,
formSearchString = document.getElementById('jform_searchstring'),
formSearchType = document.getElementById('jform_searchtype'),
spinner = document.getElementById('overrider-spinner'),
spinnerBtn = document.getElementById('overrider-spinner-btn'),
moreResults = document.getElementById('more-results'),
resultsContainer = document.getElementById('results-container');
// Prevent searching if the cache is refreshed at the moment
if (this.states.refreshing) {
return;
}
// Only update the used searchstring and searchtype if the search button
// was used to start the search (that will be the case if 'more' is null)
if (!more) {
this.states.searchstring = formSearchString.value;
this.states.searchtype = formSearchType !== null ? formSearchType.value : 'value';
// Remove the old results
var oldResults = document.querySelectorAll('.language-results');
for (var i = 0, l = oldResults.length ; i < l; i++) {
oldResults[i].parentNode.removeChild(oldResults[i]);
}
}
if (!this.states.searchstring) {
formSearchString.classList.add('invalid');
return;
}
if (more) {
// If 'more' is greater than 0 we have already displayed some results for
// the current searchstring, so display the spinner at the more link
spinnerBtn.classList.add('show');
}
else {
// Otherwise it is a new searchstring and we have to remove all previous results first
moreResults.classList.remove('show');
var children = document.querySelectorAll('#results-container div.language-results');
for (var i = 0, l = children.length ; i < l; i++) {
children[i].parentNode.removeChild(children[i]);
}
resultsContainer.classList.add('show');
spinner.classList.add('show');
}
Joomla.request({
url: 'index.php?option=com_languages&task=strings.search&format=json&searchstring='
+ self.states.searchstring + '&searchtype=' + self.states.searchtype + '&more=' + more,
method: 'POST',
headers: {'Content-Type': 'application/json'},
onSuccess: function(response) {
var response = JSON.parse(response);
if (response.error && response.message) {
alert(response.message);
}
if (response.messages) {
Joomla.renderMessages(response.messages);
}
if (response.data) {
if (response.data.results) {
self.insertResults(response.data.results);
}
if (response.data.more) {
// If there are more results than the sent ones
// display the more link
self.states.more = response.data.more;
moreResults.classList.add('show');
}
}
spinnerBtn.classList.remove('show');
spinner.classList.remove('show');
},
onError: function(xhr) {
alert(Joomla.JText._('COM_LANGUAGES_VIEW_OVERRIDE_REQUEST_ERROR'));
moreResults.classList.remove('show');
resultsContainer.classList.remove('show');
}
});
};
/**
* Method inserting the received results into the results container
*
* @param results An array of search result objects
*
* @return void
*
* @since 2.5
*/
Joomla.overrider.insertResults = function(results)
{
var self = this;
// For creating an individual ID for each result we use a counter
this.states.counter = this.states.counter + 1;
// Create a container into which all the results will be inserted
var resultsDiv = document.createElement('div');
resultsDiv.setAttribute('id', 'language-results' + self.states.counter);
resultsDiv.classList.add('language-results');
resultsDiv.classList.add('list-group');
resultsDiv.classList.add('mb-2');
resultsDiv.classList.add('show');
// Create some elements for each result and insert it into the container
results.forEach(function(item, index) {
var a = document.createElement('a');
a.setAttribute('onclick', 'Joomla.overrider.selectString(' + self.states.counter + index + ');');
a.setAttribute('href', '#');
a.classList.add('list-group-item');
a.classList.add('list-group-item-action');
a.classList.add('flex-column');
a.classList.add('align-items-start');
var key = document.createElement('div');
key.setAttribute('id', 'override_key' + self.states.counter + index);
key.setAttribute('title', item.file);
key.classList.add('result-key');
key.innerHTML = item.constant;
var string = document.createElement('div');
string.setAttribute('id', 'override_string' + self.states.counter + index);
string.classList.add('result-string');
string.innerHTML = item.string;
a.appendChild(key);
a.appendChild(string);
resultsDiv.appendChild(a);
});
// If there aren't any results display an appropriate message
if (!results.length) {
var noresult = document.createElement('div');
noresult.innerHTML = Joomla.JText._('COM_LANGUAGES_VIEW_OVERRIDE_NO_RESULTS');
resultsDiv.appendChild(noresult);
}
// Finally insert the container before the "more" link
var moreResults = document.getElementById('more-results');
if (moreResults) {
moreResults.parentNode.insertBefore(resultsDiv, moreResults);
}
};
/**
* Inserts a specific constant/value pair into the form and scrolls the page back to the top
*
* @param id The ID of the element which was selected for insertion
*
* @return void
*
* @since 2.5
*/
Joomla.overrider.selectString = function(id)
{
document.getElementById('jform_key').value = document.getElementById('override_key' + id).innerHTML;
document.getElementById('jform_override').value = document.getElementById('override_string' + id).innerHTML;
};
No other release has this exact content. See every version of this file.