/*******************************************************************************
* (en)
* Various utility functions personal scripts.
*******************************************************************************
* (fr)
* Différentes fonctions utiles pour scripts personnels.
*******************************************************************************
* ]
*******************************************************************************/
/**
* Computes the sort key for the given word.
* French words only need to take apostrophies into account.
* @param word {string} The word.
* @return {string} The sort key.
* @deprecated Use `sortKey()` function from ]
*/
function CommonWikt_CleTri(word) {
let key = word;
key = key.replaceAll("ĉ", "cx");
key = key.replaceAll("ĝ", "gx");
key = key.replaceAll("ĥ", "hx");
key = key.replaceAll("ĵ", "jx");
key = key.replaceAll("ŝ", "sx");
key = key.replaceAll("ŭ", "ux");
key = key.replaceAll(//g, "");
key = key.replaceAll(//g, " ");
return key;
}
/**
* Ajoute un menu dans les onglets.
* @param link {string} L’URL.
* @param title {string} Le titre de la page.
* @deprecated Préférer utiliser mw.util.addPortletLink()
* (cf. ])
*/
function CommonWikt_AddTabMenu(link, title) {
$(() => {
const cactionsTab = document.getElementById("p-cactions");
if (cactionsTab) {
const tabList = cactionsTab.getElementsByTagName("ul");
tabList.innerHTML += '<li><a href="' + link + '">' + title + '</a></li>';
if (cactionsTab.className)
cactionsTab.className = cactionsTab.className.replace(/\s*emptyPortlet\s*/, " ");
}
});
}
/*
* AJAX
*/
/**
* @typedef {{
* method?: "GET" | "POST",
* url: string,
* headers: Record<string, string>,
* data: any,
* onSuccess?: (XMLHttpRequest, AjaxBundle) => void,
* onFailure?: (XMLHttpRequest, AjaxBundle) => void,
* : any,
* }} AjaxBundle
*/
/**
* Objet permettant d’envoyer une requête AJAX aux serveurs WikiMedia.
* - soit via l’interface standard (index.php)
* - soit via l’API (api.php)
* - soit via les requêtes POST et GET
* @deprecated Utiliser $.ajax() à la place.
*/
var CommonWikt_ajax = {
/**
* @param bundle {AjaxBundle}
* @return {XMLHttpRequest}
*/
http: (bundle) => {
const xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = () => {
if (xmlhttp.readyState === 4)
CommonWikt_ajax.httpComplete(xmlhttp, bundle);
};
xmlhttp.open(bundle.method ? bundle.method : "GET", bundle.url);
if (bundle.headers)
for (const of Object.entries(bundle.headers))
xmlhttp.setRequestHeader(field, value);
xmlhttp.send(bundle.data || null);
return xmlhttp;
},
/**
* @param xmlhttp {XMLHttpRequest}
* @param bundle {AjaxBundle}
*/
httpComplete: (xmlhttp, bundle) => {
if (xmlhttp.status === 200 || xmlhttp.status === 302) {
if (bundle.onSuccess)
bundle.onSuccess(xmlhttp, bundle);
} else if (bundle.onFailure)
bundle.onFailure(xmlhttp, bundle);
}
};