مدیاویکی:Gadget-AncreTitres.js: تفاوت میان نسخهها
ظاهر
imported>Dalba به علت طراحی بد Gadget-close.js امکان استفاده از mw-editsection وجود ندارد، مجبوریم استایلها را کپی کنیم، اگرنه تداخل پیدا میکند |
imported>Dalba fix a bug in the allowed characters in a wikilink + autocopy to clipboard |
||
| خط ۳: | خط ۳: | ||
/*global alert, jQuery, mediaWiki, window */ | /*global alert, jQuery, mediaWiki, window */ | ||
// <nowiki> | // <nowiki> | ||
(function(mw, $) { | (function (mw, $) { | ||
'use strict'; | |||
function toClipboard(what, text) { | |||
// https://stackoverflow.com/a/30810322/2705757 | |||
var textArea = document.createElement("textarea"); | |||
// Prevent scrolling to bottom of page in MS Edge/FF | |||
textArea.style.position = "fixed"; | |||
textArea.style.top = 0; | |||
textArea.style.left = 0; | |||
// Ensure it has a small width and height. Setting to 1px / 1em | |||
// doesn't work as this gives a negative w/h on some browsers. | |||
textArea.style.width = '2em'; | |||
textArea.style.height = '2em'; | |||
// We don't need padding, reducing the size if it does flash render. | |||
textArea.style.padding = 0; | |||
// Clean up any borders. | |||
textArea.style.border = 'none'; | |||
textArea.style.outline = 'none'; | |||
textArea.style.boxShadow = 'none'; | |||
// Avoid flash of white box if rendered for any reason. | |||
textArea.style.background = 'transparent'; | |||
textArea.value = text; | |||
document.body.appendChild(textArea); | |||
textArea.focus(); | |||
textArea.select(); | |||
try { | |||
document.execCommand('copy'); | |||
} catch (err) { | |||
mw.notify('امکان انتقال به بریدهدان نبود'); | |||
return; | |||
} | |||
finally { | |||
document.body.removeChild(textArea); | |||
} | |||
mw.notify(what + ' به بریدهدان منتقل شد'); | |||
} | |||
$(function () { | |||
var _option = { | |||
nom_permalink: 'پایاپیوند', | |||
nom_ancre: 'نشانی وب', | |||
nom_lien_interne: 'ویکیپیوند', | |||
description_pl: 'فرستادن پیوند پایدار به بریدهدان', | |||
description: 'انتقال نشانی وب ساده به بریدهدان', | |||
descinterne: 'انتقال ویکیپیوند به بریدهدان', | |||
}; | |||
if (typeof window.AncreTitres !== 'undefined') { | |||
$.extend(_option, window.AncreTitres); | |||
} | } | ||
| خط ۲۲: | خط ۵۶: | ||
var urlPrefix = 'https:' + mw.config.get('wgServer') + mw.config.get('wgScript') + '?title=' + mw.config.get('wgPageName'); | var urlPrefix = 'https:' + mw.config.get('wgServer') + mw.config.get('wgScript') + '?title=' + mw.config.get('wgPageName'); | ||
$('.mw-headline').each(function (_, headline) { | |||
var linksSection = $('<span> <span class="mw-editsection-bracket">[</span><span class="mw-editsection-bracket">]</span></span>'); | var linksSection = $('<span> <span class="mw-editsection-bracket">[</span><span class="mw-editsection-bracket">]</span></span>'); | ||
var lastBracket = linksSection.find('.mw-editsection-bracket').last(); | var lastBracket = linksSection.find('.mw-editsection-bracket').last(); | ||
linksSection.css({ | linksSection.css({ | ||
'-moz-user-select': 'none', | '-moz-user-select': 'none', | ||
'-ms-user-select': 'none', | '-ms-user-select': 'none', | ||
'-webkit-user-select': 'none', | '-webkit-user-select': 'none', | ||
'user-select': 'none', | 'user-select': 'none', | ||
'font-size': 'small', | 'font-size': 'small', | ||
| خط ۳۶: | خط ۷۰: | ||
if (headline.id) { | if (headline.id) { | ||
var anchor = '#' + headline.id; | var anchor = '#' + headline.id.replace(/\|/g, encodeURIComponent); | ||
} else { | } else { | ||
var anchor = ''; | var anchor = ''; | ||
} | } | ||
$('<a href="#" title="' + _option.description + '">' + _option.nom_ancre + '</a>').click(function() { | $('<a href="#" title="' + _option.description + '">' + _option.nom_ancre + '</a>').click(function () { | ||
toClipboard('نشانی وب معمولی', urlPrefix + anchor); | |||
return false; | return false; | ||
}).insertBefore(lastBracket); | }).insertBefore(lastBracket); | ||
if (permalink) { | |||
sep.clone().insertBefore(lastBracket); | sep.clone().insertBefore(lastBracket); | ||
$('<a href="#" title="' + _option.description_pl + '">' + _option.nom_permalink + '</a>').click(function() { | $('<a href="#" title="' + _option.description_pl + '">' + _option.nom_permalink + '</a>').click(function () { | ||
toClipboard('پایاپیوند', permalink + anchor); | |||
return false; | return false; | ||
}).insertBefore(lastBracket); | }).insertBefore(lastBracket); | ||
} | } | ||
sep.clone().insertBefore(lastBracket); | sep.clone().insertBefore(lastBracket); | ||
$('<a href="#" title="' + _option.descinterne + '">' + _option.nom_lien_interne + '</a>').click(function() { | $('<a href="#" title="' + _option.descinterne + '">' + _option.nom_lien_interne + '</a>').click(function () { | ||
toClipboard('ویکیپیوند', '[[' + mw.config.get('wgPageName') + anchor + ']]'); | |||
return false; | return false; | ||
}).insertBefore(lastBracket); | }).insertBefore(lastBracket); | ||
| خط ۶۶: | خط ۱۰۰: | ||
} | } | ||
}); | }); | ||
}); | |||
}(mediaWiki, jQuery)); | }(mediaWiki, jQuery)); | ||
// </nowiki> | // </nowiki> | ||
نسخهٔ ۱۹ اوت ۲۰۱۹، ساعت ۰۹:۳۷
/*jslint browser:true */
/*global $, wgServer, wgScript, wgPageName */
/*global alert, jQuery, mediaWiki, window */
// <nowiki>
(function (mw, $) {
'use strict';
function toClipboard(what, text) {
// https://stackoverflow.com/a/30810322/2705757
var textArea = document.createElement("textarea");
// Prevent scrolling to bottom of page in MS Edge/FF
textArea.style.position = "fixed";
textArea.style.top = 0;
textArea.style.left = 0;
// Ensure it has a small width and height. Setting to 1px / 1em
// doesn't work as this gives a negative w/h on some browsers.
textArea.style.width = '2em';
textArea.style.height = '2em';
// We don't need padding, reducing the size if it does flash render.
textArea.style.padding = 0;
// Clean up any borders.
textArea.style.border = 'none';
textArea.style.outline = 'none';
textArea.style.boxShadow = 'none';
// Avoid flash of white box if rendered for any reason.
textArea.style.background = 'transparent';
textArea.value = text;
document.body.appendChild(textArea);
textArea.focus();
textArea.select();
try {
document.execCommand('copy');
} catch (err) {
mw.notify('امکان انتقال به بریدهدان نبود');
return;
}
finally {
document.body.removeChild(textArea);
}
mw.notify(what + ' به بریدهدان منتقل شد');
}
$(function () {
var _option = {
nom_permalink: 'پایاپیوند',
nom_ancre: 'نشانی وب',
nom_lien_interne: 'ویکیپیوند',
description_pl: 'فرستادن پیوند پایدار به بریدهدان',
description: 'انتقال نشانی وب ساده به بریدهدان',
descinterne: 'انتقال ویکیپیوند به بریدهدان',
};
if (typeof window.AncreTitres !== 'undefined') {
$.extend(_option, window.AncreTitres);
}
var sep = $('<span> | </span>');
var permalink = $('#t-permalink a').length && $('#t-permalink a')[0].href;
var urlPrefix = 'https:' + mw.config.get('wgServer') + mw.config.get('wgScript') + '?title=' + mw.config.get('wgPageName');
$('.mw-headline').each(function (_, headline) {
var linksSection = $('<span> <span class="mw-editsection-bracket">[</span><span class="mw-editsection-bracket">]</span></span>');
var lastBracket = linksSection.find('.mw-editsection-bracket').last();
linksSection.css({
'-moz-user-select': 'none',
'-ms-user-select': 'none',
'-webkit-user-select': 'none',
'user-select': 'none',
'font-size': 'small',
'font-weight': 'normal',
'line-height': '1em'
});
if (headline.id) {
var anchor = '#' + headline.id.replace(/\|/g, encodeURIComponent);
} else {
var anchor = '';
}
$('<a href="#" title="' + _option.description + '">' + _option.nom_ancre + '</a>').click(function () {
toClipboard('نشانی وب معمولی', urlPrefix + anchor);
return false;
}).insertBefore(lastBracket);
if (permalink) {
sep.clone().insertBefore(lastBracket);
$('<a href="#" title="' + _option.description_pl + '">' + _option.nom_permalink + '</a>').click(function () {
toClipboard('پایاپیوند', permalink + anchor);
return false;
}).insertBefore(lastBracket);
}
sep.clone().insertBefore(lastBracket);
$('<a href="#" title="' + _option.descinterne + '">' + _option.nom_lien_interne + '</a>').click(function () {
toClipboard('ویکیپیوند', '[[' + mw.config.get('wgPageName') + anchor + ']]');
return false;
}).insertBefore(lastBracket);
if (headline.nextElementSibling && headline.nextElementSibling.className === 'mw-editsection') {
linksSection.appendTo(headline.nextElementSibling);
} else {
linksSection.appendTo(headline);
}
});
});
}(mediaWiki, jQuery));
// </nowiki>