Utilisateur:Rical/common.js

La bibliothèque libre.

Note : après avoir enregistré vos modifications, il se peut que vous deviez forcer le rechargement complet du cache de votre navigateur pour voir les changements.

  • Firefox / Safari : Maintenez la touche Maj (Shift) en cliquant sur le bouton Actualiser ou pressez Ctrl-F5 ou Ctrl-R (⌘-R sur un Mac) ;
  • Google Chrome : Appuyez sur Ctrl-Maj-R (⌘-Shift-R sur un Mac) ;
  • Internet Explorer : Maintenez la touche Ctrl en cliquant sur le bouton Actualiser ou pressez Ctrl-F5 ;
  • Opera : Allez dans Menu → Settings (Opera → Préférences sur un Mac) et ensuite à Confidentialité & sécurité → Effacer les données d'exploration → Images et fichiers en cache.
/* Activate Test cases in Scribunto for Module:Central
UtilisateurRical.common.js on 20180806 0845
Goal : Try to activate Utilisateur:Rical/common.js to reuse it for function dropboxes.new(title, content)
Guideline :
* activate and update Utilisateur:Rical/common.js until OK
* buid a new Utilisateur:Rical/dropbox.js
* update until efficient
* optimise until OK

See: https://www.mediawiki.org/wiki/Extension:Scribunto/Lua_reference_manual#Test_cases
That is equivalent to
local testframework = require 'Module:TestFramework' 
class ClassNameTest extends Scribunto_LuaEngineTestBase {
    protected static $moduleName = 'ClassNameTest';
    function getTestModules() {
         return parent::getTestModules() + array(
             'ClassNameTest' => __DIR__ . '/ClassNameTests.lua';
         );
    }
}
That gives an error here, on 2017-08/01 Rical*/
/* === Projet de Worker HTML5 pour integrer du JS à toute page de wiki ===
voir : http://www.w3schools.com/html/html5_webworkers.asp
Pour des modèles ou des fonctions controlables selon ou par l'utilisateur.
Usages : adaptation aux navigateurs, infos ponctuelles, statistiques à jour à chaque affichage, fonctions pour modèles, formatage complexe, numéroter des vers...
Risques : surcharger les serveurs, un worker unique pour coordonner tous les workers ?
*/
/* Masquer ici le code HTML de base pour Worker, boutons et champ d'affichage
<!DOCTYPE html>
<html><body>
<p>Count numbers: <output id="result"></output></p>
<button onclick="startWorker()">Start Worker</button>
<button onclick="stopWorker()">Stop Worker</button><br>
<script>
*/
/*
var w;

function startWorker() {
  if(typeof(Worker)!=="undefined") {
    if(typeof(w)=="undefined") {
      w=new Worker("demo_workers.js");
    }
    w.onmessage = function (event) {
      document.getElementById("result").innerHTML=event.data;
    };
  } else {
    document.getElementById("result").innerHTML="Sorry, your browser does not support Web Workers...";
  }
}

function stopWorker() {
  w.terminate();
}
*/
/* Masquer ici la fin du code HTML de base pour Worker, boutons et champ d'affichage
</script>
</body></html>
*/

// === MathRoman : Conversion de nombre romain en decimal et vice-versa === */
// exemples d'appels : valeurDeRomain('MCXI'); testerDesRomains('span.vueromains');
/* */
function valeurDeRomain(r) {
	var v=0; var v1=0; var v2=0; var v3=0; // valeurs totale, derniere lettre et precedentes
	var x='-'; var i=0; // caractere courant et son numéro
	var e1=''; var e2=''; var e3=''; var lst='-MDCLXVIJ'; // erreur si hors lst
	while (x!='') {
		v3=v2; v2=v1; v1=0;
		x=r.substr(i,1);
		if ( x=='M' ) { v1=1000 };
		if ( x=='D' ) { v1=500 };
		if ( x=='C' ) { v1=100 };
		if ( x=='L' ) { v1=50 };
		if ( x=='X' ) { v1=10 };
		if ( x=='V' ) { v1=5 };
		if ( x=='I' ) { v1=1 };
		if ( x=='J' ) { v1=1; 
			if ( i < (r.length-1) ) {e3=' erreur caractere J avant la fin.';}
		};
		v+=v1;
		if ( (v1==5*v2) | (v1==10*v2) ) {v-=2*v2}; // pour ajuster 4, 9, 40, 90 ...
		if ( lst.indexOf(x) < 1 ) {e2=' erreur caractere '+x+' en '+(i+1)+'.';};
		if ( (v1>v2) & (v2>v3) ) {e1=' erreur caracteres croissants.';};
		if ( v>4999) {e1=' erreur > 4999.';};
		i+=1;
		x=r.substr(i,1);
	};
	// if ( lst.indexOf('J') < (lst.length-1) ) {e3=' erreur caractere J avant la fin.';};
	return ''+v+e1+e2+e3; // v+e1+e2 pour test des erreurs
}

function testerUnRomain(r1, vue) {
	$(vue).append(' '+r1+'='+valeurDeRomain(r1) ); 
}

function testerDesRomains(vue) {
    vue = '#vueRomains';
	testerUnRomain('XIJ', vue); 
	testerUnRomain('MCXI', vue); 
	testerUnRomain('MCDXLIV', vue); 
	testerUnRomain('MDCLXVI', vue); 
	testerUnRomain('MCMXCIX', vue); 
	testerUnRomain('MMCCXXII', vue); 
	testerUnRomain('MMMMCMXCIX', vue); 
	testerUnRomain('ERREURS', vue); 
	testerUnRomain('XIA', vue); 
	testerUnRomain('XJI', vue); 
	testerUnRomain('IXC', vue); 
	testerUnRomain('VLD', vue); 
	testerUnRomain('MMMMM', vue); 
	testerUnRomain('MMMMMYJXC', vue); 
}

// La function testerDesRomains(vue) ci-dessus donne le resultat suivant :
// [ bouton Calculs de romains ] Nombres romains : XIJ=12 MCXI=1111 MCDXLIV=1444 MDCLXVI=1666 MCMXCIX=1999 MMCCXXII=2222 MMMMCMXCIX=4999 ERREURS=0 erreur caractere S en 7. XIA=11 erreur caractere A en 3. XJI=12 erreur caractere J avant la fin. IXC=89 erreur caracteres croissants. VLD=445 erreur caracteres croissants. MMMMM=5000 erreur > 4999. MMMMMYJXC=5089 erreur > 4999. erreur caractere Y en 6. erreur caractere J avant la fin.

// === MathRoman : Creer des boutons pour tester la conversion de nombre romain ===
function razRomains() {
	
	$('#mw-content-text').attr('margin-left', '10em'); // #id
	$('#mw-content-text').attr('padding', '22px 22px 22px 22px'); // #id
	$('#mw-content-text').attr('background-color', '#bbddff'); // #id
	
	$('#flow-ui-load-overlay').attr('background-color', '#bbddff'); // #id
	$('#flow-ui-load-overlay').attr('width', '10em'); // #id
	$('#flow-ui-load-overlay').attr('padding', '22px 22px 22px 22px'); // #id

	$('flow-ui-load-overlay').attr('background-color', '#bbddff'); // <tag>
	$('flow-ui-load-overlay').attr('width', '10em'); // <tag>
	$('.flow-ui-load-overlay').attr('background-color', '#bbddff'); // .class
	$('.flow-ui-load-overlay').attr('width', '10em'); // .class

  $('#vueRomains').remove();
};
function initRomains() {
	
	$('#mw-content-text').attr('margin-left', '1em'); // #id
	$('#mw-content-text').attr('padding', '2px 2px 2px 2px'); // #id
	$('#mw-content-text').attr('background-color', '#ffddbb'); // #id
	
	$('#flow-ui-load-overlay').attr('background-color', '#ffddbb'); // #id
	$('#flow-ui-load-overlay').attr('width', '1em'); // #id
	$('#flow-ui-load-overlay').attr('padding', '2px 2px 2px 2px'); // #id

	$('flow-ui-load-overlay').attr('background-color', 'red'); // <tag>
	$('flow-ui-load-overlay').attr('width', '1em'); // <tag>
	$('.flow-ui-load-overlay').attr('background-color', '#ffddbb'); // .class
	$('.flow-ui-load-overlay').attr('width', '1em'); // .class

  $('#mw-content-text').prepend("<span id='vueRomains' > vueRomains : </span>");
  testerDesRomains('#vueRomains');
};
$('#p-personal').prepend('<button type="button" id="buttonRazromains" onclick="razRomains()" >razRomains</button>');
$('#p-personal').prepend('<button type="button" id="buttonvueromains" onclick="initRomains()" >calculsRomains</button>');
/* */
// === Gadget-ImgSynchro : Projet de gadget pour synchroniser l'image sur le texte dans Page: ===
/* Importer wikiEditor/contentCollector.js en mode debug=true pour Gadget-ImgSynchro.js */
/*
document.write('<script type="text/javascript" src="'
   + 'http://bits.wikimedia.org/fr.wikisource.org/load.php?debug=true&lang=fr'
   + '&modules=ext.gadget.CodeEditor%2CLeftText%2CTogglePanel%2CstockText%2C'
   + 'wikiEditor%7Cext.wikihiero%7Cmediawiki.legacy.commonPrint%2Cshared%7Cskins.vector&only=styles&skin=vector&*'
   + '"></script>');
// * /

// Importer Gadget-ImgSynchro comme simple script, le gadget Utilisateur:Rical/Gadget-ImgSynchro.js
document.write('<script type="text/javascript" src="' 
   + 'http://fr.wikisource.org/w/index.php?title=Utilisateur:Rical/Gadget-ImgSynchro.js'
   + '&debug=true&action=raw&ctype=text/javascript&dontcountme=s"></script>');
//