[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 (function () { 2 'use strict'; 3 4 /** 5 * @copyright (C) 2018 Open Source Matters, Inc. <https://www.joomla.org> 6 * @license GNU General Public License version 2 or later; see LICENSE.txt 7 */ 8 (function (Joomla, document) { 9 var Overrider = /*#__PURE__*/function () { 10 function Overrider() { 11 this.states = { 12 refreshing: false, 13 refreshed: false, 14 counter: 0, 15 searchString: '', 16 searchType: 'value' 17 }; 18 this.spinner = document.getElementById('overrider-spinner'); 19 this.spinnerBtn = document.getElementById('overrider-spinner-btn'); 20 this.moreResults = document.getElementById('more-results'); 21 this.moreResultsButton = document.getElementById('more-results-button'); 22 this.resultsContainer = document.getElementById('results-container'); 23 this.refreshStatus = document.getElementById('refresh-status'); 24 } 25 /** 26 * Method for refreshing the database cache of known language strings via Ajax 27 * 28 * @return void 29 * 30 * @since 2.5 31 */ 32 33 34 var _proto = Overrider.prototype; 35 36 _proto.refreshCache = function refreshCache() { 37 var _this = this; 38 39 this.states.refreshing = true; 40 this.refreshStatus.classList.add('show'); 41 Joomla.request({ 42 url: 'index.php?option=com_languages&task=strings.refresh&format=json', 43 method: 'POST', 44 headers: { 45 'Content-Type': 'application/json' 46 }, 47 onSuccess: function onSuccess(response) { 48 if (response.error && response.message) { 49 alert(response.message); 50 } 51 52 if (response.messages) { 53 Joomla.renderMessages(response.messages); 54 } 55 56 _this.refreshStatus.classList.remove('show'); 57 58 _this.states.refreshing = false; 59 }, 60 onError: function onError() { 61 alert(Joomla.Text._('COM_LANGUAGES_VIEW_OVERRIDE_REQUEST_ERROR')); 62 63 _this.refreshStatus.classList.remove('show'); 64 } 65 }); 66 } 67 /** 68 * Method for searching known language strings via Ajax 69 * 70 * @param more Determines the limit start of the results 71 * 72 * @return void 73 * 74 * @since 2.5 75 */ 76 ; 77 78 _proto.searchStrings = function searchStrings(more) { 79 var _this2 = this; 80 81 // Prevent searching if the cache is refreshed at the moment 82 if (this.states.refreshing) { 83 return; 84 } 85 86 var formSearchString = document.getElementById('jform_searchstring'); 87 var formSearchType = document.getElementById('jform_searchtype'); // Only update the used searchstring and searchtype if the search button 88 // was used to start the search (that will be the case if 'more' is null) 89 90 if (!more) { 91 this.states.searchString = formSearchString.value; 92 this.states.searchType = formSearchType.value || 'value'; // Remove the old results 93 94 var oldResults = [].slice.call(document.querySelectorAll('.language-results')); 95 oldResults.forEach(function (result) { 96 result.parentNode.removeChild(result); 97 }); 98 } 99 100 if (!this.states.searchString) { 101 formSearchString.classList.add('invalid'); 102 return; 103 } 104 105 if (more) { 106 // If 'more' is greater than 0 we have already displayed some results for 107 // the current searchstring, so display the spinner at the more link 108 this.spinnerBtn.classList.add('show'); 109 } else { 110 // Otherwise it is a new searchstring and we have to remove all previous results first 111 this.moreResults.classList.remove('show'); 112 var childs = [].slice.call(document.querySelectorAll('#results-container div.language-results')); 113 childs.forEach(function (child) { 114 child.parentNode.removeChild(child); 115 }); 116 this.resultsContainer.classList.add('show'); 117 this.spinner.classList.add('show'); 118 } 119 120 Joomla.request({ 121 url: "index.php?option=com_languages&task=strings.search&format=json&searchstring=" + this.states.searchString + "&searchtype=" + this.states.searchType + "&more=" + more, 122 method: 'POST', 123 headers: { 124 'Content-Type': 'application/json' 125 }, 126 onSuccess: function onSuccess(resp) { 127 var response = JSON.parse(resp); 128 129 if (response.error && response.message) { 130 alert(response.message); 131 } 132 133 if (response.messages) { 134 Joomla.renderMessages(response.messages); 135 } 136 137 if (response.data) { 138 if (response.data.results) { 139 Joomla.overrider.insertResults(response.data.results); 140 } 141 142 if (response.data.more) { 143 // If there are more results than the sent ones 144 // display the more link 145 _this2.states.more = response.data.more; 146 _this2.moreResultsButton.disabled = false; 147 148 _this2.moreResults.classList.add('show'); 149 } else { 150 _this2.moreResultsButton.disabled = true; 151 152 _this2.moreResults.classList.remove('show'); 153 } 154 } 155 156 _this2.spinnerBtn.classList.remove('show'); 157 158 _this2.spinner.classList.remove('show'); 159 }, 160 onError: function onError() { 161 alert(Joomla.Text._('COM_LANGUAGES_VIEW_OVERRIDE_REQUEST_ERROR')); 162 _this2.moreResultsButton.disabled = true; 163 164 _this2.moreResults.classList.remove('show'); 165 166 _this2.resultsContainer.classList.remove('show'); 167 } 168 }); 169 } 170 /** 171 * Method inserting the received results into the results container 172 * 173 * @param results An array of search result objects 174 * 175 * @return void 176 * 177 * @since 2.5 178 */ 179 ; 180 181 _proto.insertResults = function insertResults(results) { 182 var _this3 = this; 183 184 // For creating an individual ID for each result we use a counter 185 this.states.counter += 1; // Create a container into which all the results will be inserted 186 187 var resultsDiv = document.createElement('div'); 188 resultsDiv.setAttribute('id', "language-results" + this.states.counter); 189 resultsDiv.classList.add('language-results'); 190 resultsDiv.classList.add('list-group'); 191 resultsDiv.classList.add('mb-2'); 192 resultsDiv.classList.add('show'); // Create some elements for each result and insert it into the container 193 194 results.forEach(function (item, index) { 195 var a = document.createElement('a'); 196 a.setAttribute('onclick', "Joomla.overrider.selectString(" + _this3.states.counter + index + ");"); 197 a.setAttribute('href', '#'); 198 a.classList.add('list-group-item'); 199 a.classList.add('list-group-item-action'); 200 a.classList.add('flex-column'); 201 a.classList.add('align-items-start'); 202 var key = document.createElement('div'); 203 key.setAttribute('id', "override_key" + _this3.states.counter + index); 204 key.setAttribute('title', item.file); 205 key.classList.add('result-key'); 206 key.innerHTML = Joomla.sanitizeHtml(item.constant); 207 var string = document.createElement('div'); 208 string.setAttribute('id', "override_string" + _this3.states.counter + index); 209 string.classList.add('result-string'); 210 string.innerHTML = Joomla.sanitizeHtml(item.string); 211 a.appendChild(key); 212 a.appendChild(string); 213 resultsDiv.appendChild(a); 214 }); // If there aren't any results display an appropriate message 215 216 if (!results.length) { 217 var noresult = document.createElement('div'); 218 noresult.innerText = Joomla.Text._('COM_LANGUAGES_VIEW_OVERRIDE_NO_RESULTS'); 219 resultsDiv.appendChild(noresult); 220 } 221 222 if (this.moreResults) { 223 this.moreResults.parentNode.insertBefore(resultsDiv, this.moreResults); 224 } 225 } 226 /** 227 * Inserts a specific constant/value pair into the form and scrolls the page back to the top 228 * 229 * @param id The ID of the element which was selected for insertion 230 * 231 * @return void 232 * 233 * @since 2.5 234 */ 235 // eslint-disable-next-line class-methods-use-this 236 ; 237 238 _proto.selectString = function selectString(id) { 239 document.getElementById('jform_key').value = document.getElementById("override_key" + id).innerHTML; 240 document.getElementById('jform_override').value = document.getElementById("override_string" + id).innerHTML; 241 }; 242 243 return Overrider; 244 }(); 245 246 document.addEventListener('DOMContentLoaded', function () { 247 Joomla.overrider = new Overrider(); 248 }); 249 })(Joomla, document); 250 251 })();
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Sep 7 05:41:13 2022 | Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer |