מדיה ויקי:סקריפטים/48.js – הבדלי גרסאות

תוכן שנמחק תוכן שנוסף
hover is deprecated.
גרסה חדשה שיובאה מהמקור הצרפתי המעודכן של הסקריפט המקורי, תורגמה והותאמה לוויקיפדיה בעברית על ידי מש:חזרתי
שורה 1:
// הוספת כפתורים ליצירת קישורקישורים לסעיף כאשר מציפים את העכבר מעלליד כותרת הסעיף
// לקוח מ[[:arfr:mediawiki:Gadget-AncreTitres.js]] :מבוסס על
/* התאמה לעברית על ידי [[משתמש:חזרתי]] */
$(function() {
 
function createPromptButton(buttonText, hint, promptTitle, promptContent) {
/**
return $('<a>', {href: '#', title: hint})
* AncreTitres
.text(buttonText)
*
.css({verticalAlign: 'top', padding: '0 .4em 0 0', fontSize: '95%', fontWeight: 'bold'})
* Cette fonction fournit un lien vers une section de page en cliquant
.click(function(e) {
* sur le lien [URL] ou [[lien]] à droite du titre de section.
e.preventDefault();
*
window.prompt(promptTitle, promptContent);
* Auteurs : Pabix, Phe, Bayo, Chphe, Arkanosis, Mah3110, Ash_Crow
});
* {{Projet:JavaScript/Script|AncreTitres}}
}
*/
/* global $, mw */
$('span.mw-headline')
/* eslint-env browser */
.on('mouseenter', function () {
// <nowiki>
var $this = $(this),
mw.loader.using( [ 'mediawiki.util', 'user' ], function () {
span = $('<span>').appendTo($this),
'use strict';
anchor = $this.attr('id'),
 
sectionName = $this.text(),
$( function ( $ ) {
externalLink = 'https:' + mw.config.get('wgServer') + mw.util.getUrl() + '#' + anchor,
var pageNamelang = mw.config.get( 'wgPageNamewgUserLanguage' ).replace( /_/g, " " );
messages = {
internalLink = '[[' + pageName + '#' + sectionName + ']]';
en: {
span.append(createPromptButton('»', 'קישור פנימי לסעיף', 'העתיקו את הטקסט להלן, והדביקו בדף ויקיפדיה כדי ליצור קישור פנימי לסעיף', internalLink));
'ancretitres-anchor-name': '[URL]',
span.append(createPromptButton('›', 'קישור חיצוני לסעיף', 'העתיקו את הטקסט כדי לקבל את כתובת האינטרנט של הסעיף' , externalLink));
'ancretitres-internal-link-name': '[[Link]]',
}
'ancretitres-description': 'Get an URL to this section',
).on( 'mouseleave', function () {
'ancretitres-int-description': 'Get an internal link to this section',
$('span:last', this).remove();
'ancretitres-notif-title': 'Text copied to clipboard',
}
'ancretitres-notif-error': 'Could not copy to clipboard'
);
},
});
fr: {
'ancretitres-anchor-name': '[URL]',
'ancretitres-internal-link-name': '[[Lien]]',
'ancretitres-description': 'Obtenir une URL vers cette section',
'ancretitres-int-description': 'Obtenir un lien interne vers cette section',
'ancretitres-notif-title': 'Texte copié dans le presse-papiers',
'ancretitres-notif-error': 'Impossible de copier dans le presse-papiers'
},
he: {
'ancretitres-anchor-name': ' › ',
'ancretitres-internal-link-name': ' » ',
'ancretitres-internal-link-name-1': ' ၐ ',
'ancretitres-description': 'קישור חיצוני לפסקה זו',
'ancretitres-int-description': 'קישור פנימי לפסקה זו',
'ancretitres-int-description-1': 'קישור פנימי לפסקה זו עם כותרת שונה',
'ancretitres-notif-title': 'הקישור הועתק ללוח',
'ancretitres-notif-error': 'לא ניתן להעתיק ללוח'
}
},
options = {
afficheE: true,
afficheI: true,
afficheK: true
};
 
mw.messages.set( messages.en );
if ( lang !== 'en' && lang in messages ) {
mw.messages.set( messages[ lang ] );
}
 
// https://stackoverflow.com/questions/400212/how-do-i-copy-to-the-clipboard-in-javascript/30810322#30810322
function copyTextToClipboard( text ) {
var textArea = document.createElement( 'textarea' );
 
textArea.style.position = 'fixed';
textArea.style.top = 0;
textArea.style.left = 0;
 
textArea.style.width = '2em';
textArea.style.height = '2em';
textArea.style.padding = 0;
textArea.style.border = 'none';
textArea.style.outline = 'none';
textArea.style.boxShadow = 'none';
textArea.style.background = 'transparent';
 
textArea.value = text;
 
document.body.appendChild( textArea );
textArea.focus();
textArea.select();
 
var copySuccess;
try {
document.execCommand( 'copy' );
copySuccess = true;
} catch ( e ) {
copySuccess = false;
}
 
document.body.removeChild( textArea );
 
if ( copySuccess ) {
mw.notify( '', { title: mw.msg( 'ancretitres-notif-title' ), tag: 'ancretitres', type: 'info', autoHide: true } );
} else {
mw.notify( mw.msg( 'ancretitres-notif-error' ), { tag: 'ancretitres', type: 'error', autoHide: true } );
}
}
 
if ( typeof window.AncreTitres !== 'undefined' ) {
$.extend( options, window.AncreTitres );
}
 
if ( !options.afficheI && !options.afficheE && !options.afficheK ) {
return;
}
 
$( 'span.mw-headline' ).each( function ( _, headline ) {
var $span = $( '<span>' )
.addClass( 'noprint ancretitres' )
.css( {
'font-size': 'small',
'font-weight': 'normal',
'user-select': 'none' // jQuery se charge d'ajouter un vendor prefix si nécessaire
} );
 
if ( options.afficheK ) {
var $linkK = $( '<a href="#" title="' + mw.msg( 'ancretitres-int-description-1' ) + '">' + mw.msg( 'ancretitres-internal-link-name-1' ) + '</a>' ).click( function ( e ) {
e.preventDefault();
var escapedAnchor = headline.id
// escaping caractères spéciaux HTML
// (partiel, '"& ne sont pas escapés pour ne pas dégrader inutilement la lisibilité du lien)
.replace( /</g, '&lt;' )
.replace( />/g, '&gt;' )
// escaping caractères spéciaux MediaWiki
.replace( /\[/g, '&#91;' )
.replace( /\]/g, '&#93;' )
.replace( /\{/g, '&#123;' )
.replace( /\|/g, '&#124;' )
.replace( /\}/g, '&#125;' );
var outputText = '[[' + ( mw.config.get( 'wgPageName' ) + '#' + escapedAnchor ).replace( /_/g, ' ' ) + '|כותרת שונה]]';
copyTextToClipboard( outputText );
} );
$span.append( ' ', $linkK );
}
 
if ( options.afficheI ) {
var $linkI = $( '<a href="#" title="' + mw.msg( 'ancretitres-int-description' ) + '">' + mw.msg( 'ancretitres-internal-link-name' ) + '</a>' ).click( function ( e ) {
e.preventDefault();
var escapedAnchor = headline.id
// escaping caractères spéciaux HTML
// (partiel, '"& ne sont pas escapés pour ne pas dégrader inutilement la lisibilité du lien)
.replace( /</g, '&lt;' )
.replace( />/g, '&gt;' )
// escaping caractères spéciaux MediaWiki
.replace( /\[/g, '&#91;' )
.replace( /\]/g, '&#93;' )
.replace( /\{/g, '&#123;' )
.replace( /\|/g, '&#124;' )
.replace( /\}/g, '&#125;' );
var outputText = '[[' + ( mw.config.get( 'wgPageName' ) + '#' + escapedAnchor ).replace( /_/g, ' ' ) + ']]';
copyTextToClipboard( outputText );
} );
$span.append( ' ', $linkI );
}
if ( options.afficheE ) {
var $linkE = $( '<a href="#" title="' + mw.msg( 'ancretitres-description' ) + '">' + mw.msg( 'ancretitres-anchor-name' ) + '</a>' ).click( function ( e ) {
e.preventDefault();
var outputText = 'https:' + mw.config.get( 'wgServer' ) + mw.util.getUrl() + '#' + headline.id;
copyTextToClipboard( outputText );
} );
$span.append( ' ', $linkE );
}
 
$( headline ).parent().append( $span );
} );
 
} );
 
} );