Benutzer:Netaction/WikiCite.js
aus Wikipedia, der freien Enzyklopädie
< Benutzer:Netaction
Dies ist die aktuelle Version dieser Seite, zuletzt bearbeitet am 8. Juli 2011 um 13:37 Uhr durch imported>Netaction(181765).
Hinweis: Leere nach dem Veröffentlichen den Browser-Cache, um die Änderungen sehen zu können.
- Firefox/Safari: Umschalttaste drücken und gleichzeitig Aktualisieren anklicken oder entweder Strg+F5 oder Strg+R (⌘+R auf dem Mac) drücken
- Google Chrome: Umschalttaste+Strg+R (⌘+Umschalttaste+R auf dem Mac) drücken
- Internet Explorer/Edge: Strg+F5 drücken oder Strg drücken und gleichzeitig Aktualisieren anklicken
- Opera: Strg+F5
// WikiCite helps if you want to cite parts of an article.
// Thomas Schmidt 2011 netAction.de
// The strings for every user's language:
const WikiCiteLangMsgs = {
'en': {
BubbleHeadline:'Copy selection',
BubbleText:'Create a citation with all necessary information, ready for copy&paste to your blog or web site!',
ButtonHighlight:'Highlight to copy',
ButtonCancel:'Cancel',
BubbleCopyHint:'Please copy the HTML into your clipboard now.',
SourceText1:'From the page',
SourceText2:'on Wikipedia, the Free Encyclopedia.'
},
'de': {
BubbleHeadline:'Text kopieren',
BubbleText:'Erstelle ein Zitat mit allen nötigen Informationen, fertig zum Kopieren in den Blog oder die Webseite!',
ButtonHighlight:'Markieren zum Kopieren',
ButtonCancel:'Abbrechen',
BubbleCopyHint:'Bitte kopiere das HTML jetzt in die Zwischenablage.',
SourceText1:'Aus dem Artikel',
SourceText2:'auf Wikipedia, der freien Enzyklopädie.'
}
}
function WCgetMsg(msg) {
var lang = window.mediaWiki.user.options.values.language;
if (!(lang in WikiCiteLangMsgs)) lang = 'en';
if (!(msg in WikiCiteLangMsgs[lang])) lang = 'en';
return WikiCiteLangMsgs[lang][msg];
}
$(function() {
if ((!wgCurRevisionId)||(!wgTitle)) return;
// first we need some nice CSS:
$("head").append('<style type="text/css" charset="utf-8">'+
'#WikiCiteSelectionBubble { position:absolute; width:130px; background-color:#E5E9EA; box-shadow:3px 3px 8px #666; border:1px solid #93B5C0; z-index:200; padding:3px; text-align:center; left:10px; font-size:70%; }'+
'.skin-monobook #WikiCiteSelectionBubble { font-size:110% }'+
'#WikiCiteSelectionBubble h3 { text-decoration:underline; cursor:pointer; }'+
'#WikiCiteSelectionBubble p { padding:0 4px; }'+
'#WikiCiteSelectionBubble h3:hover { background-color:#BCCCD0; }'+
'#WikiCiteSelectionBubble.active { width:600px; background-color:##BCCCD0; }'+
'#WikiCiteSelectionBubble.active h3 { text-decoration:none; cursor:default; }'+
'#WikiCiteSelectionBubbleClose { position:absolute; top:2px; right:2px; cursor:pointer; }'+
'#WikiCiteSelectionBubbleClose:hover { background-color:#BCCCD0; }'+
'#WikiCiteSelectionBubble.active h3:hover { background-color:transparent; }'+
'#WikiCiteSelectionBubble.active #WikiCiteSelectionBubbleClose { font-size:1.4em; }'+
'#WikiCiteSelectionBox { margin:10px 0; padding:5px; }'+
'#WikiCiteSelectionBox textarea { height:200px; width:100%; margin-left:-5px;}'+
'#WikiCiteSelectionBox input { cursor:pointer; }'+
'</style>'
);
// Add the HTML elements for our Script:
$('<div id="WikiCiteSelectionBubble">'+
'<div id="WikiCiteSelectionBubbleClose">⨯</div>'+
'<h3>'+WCgetMsg('BubbleHeadline')+'</h3>'+
'<p>'+WCgetMsg('BubbleText')+'</p>'+
'<div id="WikiCiteSelectionBox">'+
'<textarea></textarea>'+
'<p><input type="button" value="'+WCgetMsg('ButtonHighlight')+'" id="WikiCiteBoxHighlight"> '+
'<input type="button" value="'+WCgetMsg('ButtonCancel')+'" id="WikiCiteBoxCancel"></p>'+
'</div>'+
'</div>').appendTo('body').hide();
$('#WikiCiteSelectionBox').hide();
// Check every second if there is a selection and show bubble:
setInterval(function(){
// Is the bubble already in usage?
if ($('#WikiCiteSelectionBubble').hasClass('active')) return;
// get html of selection:
var html;
var userSelection;
userSelection = window.getSelection();
if (userSelection.rangeCount>0) {
var range = userSelection.getRangeAt(0);
var clonedSelection = range.cloneContents();
var div = document.createElement ('div');
div.appendChild (clonedSelection);
html = div.innerHTML;
} else html="";
if (html) { // the user selected some text
var position = $(userSelection.getRangeAt(0).startContainer.parentNode).offset();
if ($('#WikiCiteSelectionBubble').is(":visible")) // Bubble already there?
// move bubble in position:
$('#WikiCiteSelectionBubble').stop(true,true).animate({top:position.top},'fast','linear');
// show bubble:
else $('#WikiCiteSelectionBubble').stop(true,true).fadeIn().css({top:position.top});
// save selected html in bubble element:
$('#WikiCiteSelectionBubble').data('selection',html);
} else { // nothing selected
// hide bubble:
$('#WikiCiteSelectionBubble').stop(true,true).fadeOut();
$('#WikiCiteSelectionBubble').removeClass('active');
}
},1000);
// The bubble is clicked:
$('#WikiCiteSelectionBubble h3').click(function(){
window.getSelection().removeAllRanges();
$('#WikiCiteSelectionBubble').addClass('active').stop(true,true).show();
// Clean up the HTML:
// TODO
// Prepare copyright
if ($('#copyright').html()) var copyright = $('#copyright').html(); // Monobook
else if ($('#footer-info-copyright').html()) var copyright = $('#footer-info-copyright').html(); // Vector
copyright=copyright.replace(/\<br\>/g,"");
// add HTML to textarea:
$('#WikiCiteSelectionBox textarea').val($('#WikiCiteSelectionBubble').data('selection')+
'\n\n<p>'+WCgetMsg('SourceText1')+' '+
'<a href="http://'+window.mediaWiki.user.options.values.variant+'.wikipedia.org/w/index.php?'+
'title='+encodeURIComponent(wgTitle)+'&oldid='+wgCurRevisionId+'">'+
wgTitle+'</a> '+WCgetMsg('SourceText2')+' '+
copyright+'</p>'
);
// Show the big box with textarea:
$('#WikiCiteSelectionBox').stop(true,true).fadeIn();
});
// X clicked:
$('#WikiCiteSelectionBubbleClose').click(function(){
window.getSelection().removeAllRanges();
$('#WikiCiteSelectionBox').stop(true,true).hide();
$('#WikiCiteSelectionBubble').removeClass('active').hide();
return false;
});
// Highlight button:
$('#WikiCiteBoxHighlight').click(function() {
$('#WikiCiteSelectionBox textarea').select();
$('<p>'+WCgetMsg('BubbleCopyHint')+'</p>').appendTo($('#WikiCiteSelectionBox')).delay(2000).fadeOut();
});
// Cancel button:
$('#WikiCiteBoxCancel').click(function() { $('#WikiCiteSelectionBubbleClose').click(); });
});