Utilisateur:Zebulon84a/common.js
Note : après avoir enregistré la page, vous devrez forcer le rechargement complet du cache de votre navigateur pour voir les changements.
Mozilla / Firefox / Konqueror / Safari : maintenez la touche Majuscule (Shift) en cliquant sur le bouton Actualiser (Reload) ou pressez Maj-Ctrl-R (Cmd-R sur Apple Mac) ;
Firefox (sur GNU/Linux) / Chrome / Internet Explorer / Opera : maintenez la touche Ctrl en cliquant sur le bouton Actualiser ou pressez Ctrl-F5.//obtenir('Toolbar2017');
$( function ( $ ) {
//console.log( 'création boutons' );
if ( typeof( gadgetToolbar2017 ) !== "undefined" ) {
gadgetToolbar2017.fonctions.CreateButton("//upload.wikimedia.org/wikipedia/commons/thumb/c/c1/Gnome-edit-redo.svg/45px-Gnome-edit-redo.svg.png", "Notif", '{{Notif|', '}}', "Pseudo", "mw-editbutton-notif");
gadgetToolbar2017.fonctions.CreateButton("//upload.wikimedia.org/wikipedia/commons/4/4a/1328102008_Redo.png", "Notif discret", '{{Notif discret|', '}}', "Pseudo", "mw-editbutton-notifdiscret");
gadgetToolbar2017.fonctions.CreateButton("//upload.wikimedia.org/wikipedia/commons/thumb/8/88/At_sign.svg/45px-At_sign.svg.png", "Mention", '{{Mention|', '}}', "Pseudo", "mw-editbutton-mention");
gadgetToolbar2017.fonctions.CreateButton("//upload.wikimedia.org/wikipedia/commons/f/f8/Waving.png", "Bonjour", '{{Bonjour|', '}}', "Pseudo", "mw-editbutton-bonjour");
gadgetToolbar2017.fonctions.CreateButton("//upload.wikimedia.org/wikipedia/commons/thumb/b/b3/Happy_face_ball.png/45px-Happy_face_ball.png", "Bonsoir", '{{Bonsoir|', '}}', "Pseudo", "mw-editbutton-bonsoir");
gadgetToolbar2017.fonctions.CreateButton("//upload.wikimedia.org/wikipedia/commons/thumb/6/68/Orange_Icon_User.svg/45px-Orange_Icon_User.svg.png", "Utilisateur", '{{u-|', '}}', "Pseudo", "mw-editbutton-user");
gadgetToolbar2017.fonctions.CreateButton("//upload.wikimedia.org/wikipedia/commons/thumb/5/57/Face-wink.svg/45px-Face-wink.svg.png", "Merci", '{{Merci|', '}}', "Pseudo", "mw-editbutton-merci");
} // Fin test anti-double inclusion
} );
// {{Catégorisation JS|dictionaryLookupHover}}
try { // containerize gadget, to protect other gadgets if this one goes wrong
/*****************
If you wish to use this elsewhere, please do not copy it, but instead hotlink it.
This is still undergoing active development, and you will miss out if you just statically copy it.
To hotlink, copy only the following line:
mw.loader.load( '//en.wikinews.org/w/index.php?title=MediaWiki:Gadget-dictionaryLookupHover.js&action=raw&ctype=text/javascript' );
[[Image:Wikinews-breaking-news.svg|x15px|top-left|]]
See //en.wikinews.org/wiki/WN:WiktLookup#Wiktionary_lookup_gadget_.28Hover_box_variety.29
for details on this script, and how to use it on your own site.
*****************/
/*** This is the stable version of the gadget js.***/
/*****************
If you wish to use this elsewhere, please do not copy it, but instead hotlink it.
This is still undergoing active development, and you will miss out if you just statically copy it.
To hotlink, copy only the following line:
mw.loader.load( '//en.wikinews.org/w/index.php?title=MediaWiki:Gadget-dictionaryLookupHover.js&action=raw&ctype=text/javascript' );
See //en.wikinews.org/wiki/WN:WiktLookup#Wiktionary_lookup_gadget_.28Hover_box_variety.29
for details on this script, and how to use it on your own site.
Note this script can take a number of parameters. Parameters are stored in the wiktLookup object.
Generally its a good idea to set parameters before the onload event is fired (some parameters it matters, others it doesn't).
An example of parameters would be using the following js code
(don't feel like you have to set all of them, they all have defaults ; this is just an example):
if ( !window.wiktLookup ) {
wiktLookup = {};
}
wiktLookup.count = 1; //number of defn to return.
wiktLookup.showWord = bold; // to show what word we're looking up. one of bold, none, link
wiktLookup.noRedir = false;// true to stop magic (not mediawiki)-redirection. unrecomended
wiktLookup.audio = true;// true, false, autoplay. NOT IMPLEMENTED
wiktLookup.width = 500; // width of box. make sure number not string. in units of pixels.
wiktLookup.height = 400; //- height of box
wiktLookup.key = 'w';// - ctrl+shift+key makes box popup (should be lowercase. default is 'l')
wiktLookup.reverseShift = false; // - if set, requires shift+double click to lookup a word.
wiktLookup.mode = context; // - context, bottom. default to context. to display as tooltip, or at bottom
wiktLookup.definitionBegin = 'Definition ('; // - for i18n. in english it is 'Definition ('. used in mode='bottom'
wiktLookup.definitionEnd = '):'; // - for i18n. in English it is '):' used in bottom mode
wiktLookup.hideText = 'hide'; //- for i18n. in English it is 'hide'. used in bottom mode.
wiktLookup.exit = true; //have a hide link.
wiktLookup.disableByDefault = true; //enable only in <span class="wiktLookup-enable">blah</span> sections.
*****************/
/*** This is the stable version of the gadget js.***/
/*
Stolen from fr wikinews, and than subsequently heavily modified by Bawolff.
This script is based on the french one created by [[:en:wiktionary:User:Bequw]] and [[en:wiktionary:User:Conrad.Irwin]].
The bottom mode is heavily based on work done by [[:fr:wikt:user:Darkdadaah]].
Special thanks for [[wikinews:User:Amgine]], [[:fr:Wikinews:User:Otourly]], [[:fr:wikinews:user:Sniff]],
[[:fr:Wikinews:User:JackPotte]], [[:en:wikibooks:user:TestPilot]], and many others for support and assistance.
The current version of this is maintained by Bawolff. please don't hesitate to contact me
(bawolff - //en.wikinews.org/wiki/user_talk:Bawolff ) if you have any issues, comments, bugs, need help, or whatever.
*/
/*global window, $, XSLTProcessor*/
/*jslint strict:false */
//set wiktLookup.useNewWindow to true to force new window.
if ( !window.wiktLookup ) {
var wiktLookup = {};
}
wiktLookup.key = wiktLookup.key ? wiktLookup.key : 'l';
/*
Options:
count - numb results to return
showWord - bold, none, link
noRedir - true to stop redirection
audio - true, false, autoplay
width - width of box
height - height of box
key - ctrl+shift+key makes box popup (should be lowercase)
reverseShift - if set, requires shift+double click to lookup a word.
mode - context, bottom. default to context
definitionBegin - for i18n. in english it is 'Definition ('
definitionEnd - for i18n. in English it is '):'
hideText - for i18n. in English it is 'hide';
exit - X in corner to hide.
disableByDefault - only enable in specially marked sections.
*/
var userLanguage = mw.config.get( 'wgUserLanguage' );
var contentLanguage = mw.config.get( "wgContentLanguage" );
wiktLookup.validLangs = { en: "en", fr: "fr", frc: "fr", fra: "fr", fre: "fr", nl: "nl", es: 'es', it: 'it', ja: 'ja', pt: 'pt', ru: 'ru' };
wiktLookup.wiktDomain = 'en'; //default
wiktLookup.stripAfterDash = /-.*$/;
if ( wiktLookup.validLangs[ userLanguage ] ) {
wiktLookup.wiktDomain = wiktLookup.validLangs[ userLanguage ];
} else if ( wiktLookup.validLangs[ userLanguage.replace( wiktLookup.stripAfterDash ) ] ) {
wiktLookup.wiktDomain = wiktLookup.validLangs[ userLanguage.replace( wiktLookup.stripAfterDash ) ];
} else if ( wiktLookup.validLangs[ contentLanguage ] ) {
wiktLookup.wiktDomain = wiktLookup.validLangs[ contentLanguage ];
} else if ( wiktLookup.validLangs[contentLanguage.replace( wiktLookup.stripAfterDash ) ] ) {
wiktLookup.wiktDomain = wiktLookup.validLangs[ contentLanguage.replace( wiktLookup.stripAfterDash ) ];
}
if ( !wiktLookup.preferLang ) {
wiktLookup.preferLang = contentLanguage || wiktLookup.wiktDomain;
}
if ( wiktLookup.disableByDefault === undefined ) {
wiktLookup.disableByDefault = false;
}
wiktLookup.getOptions = function () {
var opt = '';
if ( wiktLookup.count ) {
opt += '&count=' + wiktLookup.count;
}
if ( wiktLookup.showWord ) {
opt += '&showWord=' + wiktLookup.showWord;
}
if ( wiktLookup.audio ) {
opt += '&audio=' + wiktLookup.audio;
}
if ( wiktLookup.noRedir ) {
opt += '&rd=500';
}
if ( wiktLookup.exit ) {
opt += '&exit=true';
}
return opt;
};
wiktLookup.rangeToWord = function ( selection ) {
//includes apostraphes
//fixme: if at begin of container.
var finalText = selection.toString();
try {
var expandWord = /['\-]/; //list of chars that are not actual word boundries.
var textNode, i;
var range = selection.getRangeAt( 0 );
var rangeBefore = range.cloneRange();
if ( rangeBefore.startOffset !== 0 ) {
rangeBefore.setStart( rangeBefore.startContainer, rangeBefore.startOffset - 1 );
textNode = rangeBefore.cloneContents().firstChild;
if ( textNode.nodeType === 3 && expandWord.test( textNode.data.charAt( 0 ) ) ) {
for ( i = 0; i < 30 /*to stop run-away*/; i++ ) {
rangeBefore.setStart( rangeBefore.startContainer, rangeBefore.startOffset - 1 );
textNode = rangeBefore.cloneContents().firstChild;
if ( ( textNode.nodeType !== 3 ) || ( textNode.nodeType === 3 && textNode.data.match( /^\s/ ) ) ) {
rangeBefore.setStart( rangeBefore.startContainer, rangeBefore.startOffset + 1 );
finalText = rangeBefore.toString();
rangeBefore.detach();
range.detach();
return finalText;
}
else if ( rangeBefore.startOffset === 0 ) {
//at the end of the range. this might add periods, which are stripped later.
finalText = rangeBefore.toString();
rangeBefore.detach();
range.detach();
return finalText;
}
}
}
}
rangeBefore.detach(); //done with it.
var rangeAfter = range.cloneRange();
rangeAfter.setEnd( rangeAfter.endContainer, rangeAfter.endOffset + 1 );
textNode = rangeAfter.cloneContents().firstChild; //double var...
if ( textNode.nodeType === 3 && expandWord.test( textNode.data.charAt( textNode.data.length - 1 ) ) ) {
for ( i = 0; i < 30 /*to stop run-away*/; i++ ) {
rangeAfter.setEnd( rangeAfter.endContainer, rangeAfter.endOffset + 1 );
textNode = rangeAfter.cloneContents().firstChild;
if ( ( textNode.nodeType !== 3 ) || ( textNode.nodeType === 3 && textNode.data.match( /\s$/ ) ) ) {
rangeAfter.setEnd( rangeAfter.endContainer, rangeAfter.endOffset - 1 );
finalText = rangeAfter.toString();
rangeAfter.detach();
range.detach();
return finalText;
} else if ( rangeAfter.endOffset - rangeAfter.endContainer.data.length === 0 ) {
// this assumes this is a text node... this might add periods, which are stripped later.
finalText = rangeAfter.toString();
rangeAfter.detach();
range.detach();
return finalText;
}
}
}
rangeAfter.detach(); //no match, and done with this range.
} catch ( e ) {
if ( window.range ) {
range.detach();
}
return finalText;
}
return finalText;
};
wiktLookup.findWord = function ( e ) {
if ( !e ) {
e = window.event;
}
if ( e.shiftKey && e.type === 'dblclick' && !wiktLookup.reverseShift ) {
return true; //don't do anything if shift is pressed down. for compat with other things.
}
if ( !e.shiftKey && e.type === 'dblclick' && wiktLookup.reverseShift ) {
return true; //if reverse shift is on, require shift key for double click.
}
var clientX, clientY, coordsAbs, langOverride;
if ( e.clientX ) { //this implies has Y as well
clientX = e.clientX;
clientY = e.clientY;
}
// stolen from http://www.codetoad.com/javascript_get_selected_text.asp
var text;
if ( window.getSelection ) {
text = wiktLookup.rangeToWord( window.getSelection() );
if ( !clientX ) {
try {
//mostly for from keyboard requests
var parent = window.getSelection().anchorNode.parentNode;
clientX = parent.offsetLeft + 7*window.getSelection().anchorOffset; //this is very rough
clientY = parent.offsetTop + parent.offsetHeight; //at bottom of elm
coordsAbs = true;
parent = parent.offsetParent;
while ( parent ) {
clientX += parent.offsetLeft;
clientY += parent.offsetTop;
parent = parent.offsetParent;
}
} catch ( e ) {}
}
try { //figure out what language the current node is.
//and determine if we're in an enabled section
// aka <span class="wiktLookup-enable">blah</span>
//wiktLookup.disableByDefault
var enabled = !wiktLookup.disableByDefault;
var foundAnEnableSection = false;
var foundLangSection = false;
var cur = window.getSelection().anchorNode.parentNode;
for ( var i = 0; i < 9; i++ ) {
if ( !foundAnEnableSection && cur.className.indexOf( 'wiktLookup-disable' ) !== -1 ) {
return; //die
}
if ( !foundAnEnableSection && cur.className.indexOf( 'wiktLookup-enable' ) !== -1 ) {
enabled = true;
foundAnEnableSection = true;
if ( foundLangSection ) {
break;
}
}
if ( !foundLangSection && cur.lang ) {
langOverride = cur.lang.replace( wiktLookup.stripAfterDash );
if ( foundAnEnableSection ) break;
} else {
if ( cur.parentNode ) {
cur = cur.parentNode;
} else {
break;
}
}
}
if ( !enabled ) {
return; //die
}
}
catch ( e ) {
/*ignore error*/
if ( !enabled ) {
return; //die
}
}
}
else if ( document.getSelection ) {
text = wiktLookup.rangeToWord( document.getSelection() );
}
if ( !clientX ) {
clientX = 400;
clientY = 200;
//good as numbers as any...
}
if ( text && text.length < 32 ) {
//If we have the text. we be done.
return wiktLookup.lookupWord( text, clientX, clientY, coordsAbs, langOverride );
}
// seems to work somewhat on moz. Hopefully moz will be picked up above. So this shouldn't be neccesary.
if ( e.rangeParent && e.rangeParent.nodeType === document.TEXT_NODE ) {
//mozilla part
var rangeOffset = e.rangeOffset;
var my_rangestr = e.rangeParent.data; //the event is dynamic!
// which word the rangeOffset is in
var wordlist1 = my_rangestr.substring( 0, rangeOffset ).split( /\s+/ );
var wordlist2 = my_rangestr.substring( rangeOffset, my_rangestr.length ).split( /\s+/ );
if ( my_rangestr.length > 0 ) {
wiktLookup.lookupWord(
wordlist1[ wordlist1.length - 1 ] + wordlist2[ 0 ],
clientX,
clientY,
coordsAbs,
langOverride
);
}
e.preventDefault();
e.stopPropagation();
}
//IE specific stuff. Try this as a last resort.
else {
try {
if ( document.readyState !== "complete" ) {
return false;
}
//IE
var my_range = document.selection.createRange();
my_range.collapse();
my_range.expand( "word" );
wiktLookup.lookupWord( my_range.text, clientX, clientY, coordsAbs, langOverride );
e.returnValue = false;
return false;
} catch ( err ) {
/*ignore*/
}
}
};
wiktLookup.getScrollX = function () {
return window.pageXOffset;
};
wiktLookup.getScrollY = function () {
return window.pageYOffset;
};
wiktLookup.getInnerWidth = function () {
return window.innerWidth;
};
wiktLookup.lookupWord = function ( word, x, y, absCoords,langOveride ) {
var word2;
if ( !word.match( /(?:^[\wa-zA-Zа-яА-Яà-žÀ-ŽΑ-ῥԱ-ևぁ-ヶ促-杁ㄱ-하ⁿßſ]|[\wa-zA-Zа-яА-Яà-žÀ-ŽΑ-ῥԱ-ևぁ-ヶ促-杁ㄱ-하ⁿßſ]\s?$)/ ) ) {
//this regex doesn't work if word starts or ends with accents.
//is this regex even needed?
word2 = word.match( /\b(?:[\S]|(?!\.\s)\.)*\b/ ); //strip quotation marks
}
var s = word2 ? word2[0] : word; //if regex failed, fall back to word
if ( !s ) { // test if null or empty.
return false;
}
s = encodeURIComponent( s );
if ( !wiktLookup.supported() ) {
//This includes IE, which doesn't recognize the mime type mediawiki uses.
// in future this could put the window where user clicked.
var newwin = window.open(
'//' + wiktLookup.wiktDomain + '.wiktionary.org/wiki/' + s + '?uselang=' + wiktLookup.preferLang,
'temp',
'height=450,width=800,location,menubar,toolbar,status,resizable,scrollbars'
);
if ( newwin ) {
newwin.focus();
}
return true;
}
var frame = document.getElementById( 'dict-popup-frame' );
frame.src = 'about:blank'; //don't display old results.
frame.style.display = 'block';
frame.src = '//'
+ wiktLookup.wiktDomain
+ '.wiktionary.org/w/api.php?action=parse&redirects&prop=text&format=xml&xslt=MediaWiki:extractFirst.xsl&page='
+ s
+ '&lang='
+ ( langOveride ? langOveride : wiktLookup.preferLang )
+ wiktLookup.getOptions();
var left, top;
if ( !absCoords ) {
left = x + wiktLookup.getScrollX();
if ( left + ( wiktLookup.width || 420 ) > wiktLookup.getInnerWidth() &&
left - ( wiktLookup.width || 420 ) > 0
) {
left -= ( wiktLookup.width || 420 );
}
top = ( y + wiktLookup.getScrollY() + 10 );
}
else {
top = y + 10;
left = x;
if ( x + ( wiktLookup.width || 420 ) > wiktLookup.getInnerWidth() ) {
left = wiktLookup.getInnerWidth() - ( wiktLookup.width || 420 );
}
}
frame.style.top = top +'px';
frame.style.left= left +'px';
document.getElementById( 'dict-popup-container' ).style.display = 'block';
};
wiktLookup.setup = function () {
document.addEventListener( "dblclick", wiktLookup.findWord, true ); //capture
$( window ).keypress( function ( event ) {
if ( !( event.ctrlKey && event.shiftKey ) ) {
return;
}
var key = event.which;
if ( key &&
( String.fromCharCode( key ) === wiktLookup.key ||
String.fromCharCode( key ) === wiktLookup.key.toUpperCase() )
) {
wiktLookup.findWord( event );
event.preventDefault();
}
} );
};
wiktLookup.supported = function () {
if ( navigator &&
navigator.userAgent &&
navigator.userAgent.indexOf( 'Gecko' ) !== -1 &&
navigator.productSub &&
navigator.productSub <= 20090823 &&
navigator.productSub > 2000000
) {
//old moz has broken support for html entities.
//FIXME: figure out exact date when gecko was fixed.
return false;
}
if ( wiktLookup.useNewWindow ) {
return false;
}
if ( window.XSLTProcessor || document.selectNodes ) {
return true; //note: second part for IE
}
return false;
};
$( wiktLookup.setup );
$( function () {
if ( !wiktLookup.definitionBegin ) {
wiktLookup.definitionBegin = 'Definition (';
}
if ( !wiktLookup.definitionEnd ) {
wiktLookup.definitionEnd = '):';
}
if ( !wiktLookup.hideText ) {
wiktLookup.hideText = 'hide';
}
var div = document.createElement( 'div' );
div.id = 'dict-popup-container';
var frame = document.createElement( 'iframe' );
frame.style.border = 'none';
if ( wiktLookup.mode !== 'bottom' ) {
frame.style.position = 'absolute';
}
frame.style.display = 'none';
frame.style.zIndex = '102';
if ( wiktLookup.mode === 'bottom' ) {
frame.style.width = '98%';
}
else {
frame.style.width = ( wiktLookup.width ? wiktLookup.width + 'px' : '420px' ); //default 300 if unset
}
frame.style.height = ( wiktLookup.height ? wiktLookup.height + 'px' : '180px' ); //default 150 if unset.
frame.id = 'dict-popup-frame';
frame.src = 'about:blank';
if ( wiktLookup.mode === 'bottom' ) {
div.style.padding = '0.3em';
div.style.display = 'none';
div.style.position = 'fixed';
div.style.margin = '0';
div.style.bottom = '0';
div.style.zIndex = '50';
div.style.background = 'url(//upload.wikimedia.org/wikipedia/commons/thumb/e/ec/Wiktionary-logo.svg/840px-Wiktionary-logo.svg.png) white no-repeat 30%';
div.style.borderTop = 'solid thin black';
div.style.width = '100%';
div.appendChild( document.createTextNode( wiktLookup.definitionBegin ) );
var link = document.createElement( 'a' );
link.href = '#';
link.onclick = wiktLookup.hide;
link.appendChild( document.createTextNode( wiktLookup.hideText ) );
div.appendChild( link );
div.appendChild( document.createTextNode( wiktLookup.definitionEnd ) );
}
div.appendChild( frame );
document.body.appendChild( div );
} );
wiktLookup.hide = function () {
try {
var frame = document.getElementById( 'dict-popup-frame' );
if ( frame.src !== 'javascript:%22%20%22' ) {
frame.src = 'javascript:%22%20%22'; //transparent
}
//not using about:blank due to bug with font re-sizing on firefox.
frame.style.display = 'none';
document.getElementById( 'dict-popup-container' ).style.display = 'none';
} catch( e ) {
/*ignore*/
}
};
$( window ).click( wiktLookup.hide );
} catch ( e ) { // containerize gadget, to protect other gadgets if this one goes wrong
// ignore
}