MediaWiki:Common.js: Difference between revisions
Appearance
Content deleted Content added
Caleb Cooper (talk | contribs) No edit summary |
Caleb Cooper (talk | contribs) No edit summary |
||
| Line 1: | Line 1: | ||
/* [[Category:AutoDumpContentFromCommons]] */ |
/* [[Category:AutoDumpContentFromCommons]] */ |
||
/* Any JavaScript here will be loaded for all users on every page load. */ |
/* Any JavaScript here will be loaded for all users on every page load. */ |
||
| ⚫ | |||
enhanceDomPre(); |
|||
$( document ).ready(function() { |
|||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
var boxes = []; |
|||
var pointersI = 0; |
|||
var boxesI = 0; |
|||
var thisparent = $(this).parent('div'); |
|||
| ⚫ | |||
var $this = $(this) |
|||
| ⚫ | |||
function returnBoxedText(match, p1) { return '<span class="temp-mw-box-anchor">' + p1 + '</span>'; } |
|||
function returnSpanPosStr(match, p1) { return '<span class="temp-mw-point-anchor" data-pos="' + p1 + '"></span>'; } |
|||
| ⚫ | |||
/* transform MW pointer anchors to full spans */ |
|||
var newText = thisorigtext.replace(/<point-here>/g, '<span class="temp-mw-point-anchor" data-pos="bl"></span>'); |
|||
| ⚫ | |||
/* transform MW box anchors to full spans */ |
|||
| ⚫ | |||
/* set new PRE text, including custom spans */ |
|||
| ⚫ | |||
| ⚫ | |||
function returnSpanPosStr(match, p1) { |
|||
var MarginTop = 0; |
|||
| ⚫ | |||
var Rotation = 0; |
|||
switch(p1) { |
|||
/* search for pointer anchors, add to pointers object */ |
|||
| ⚫ | |||
$(".temp-mw-point-anchor").each(function(){ pointers[ pointersI ] = $(this).position(); pointers[ pointersI ]["position"] = $(this).data('pos'); pointersI++; }); |
|||
MarginTop = 5; |
|||
MarginLeft = 5; |
|||
| ⚫ | |||
$(".temp-mw-box-anchor").each(function(){ boxes[ boxesI ] = $(this).position(); boxes[ boxesI ]["content"] = $(this)[0].outerText; boxesI++; }); |
|||
if (pointers.length > 0 || boxes.length > 0) { |
|||
| ⚫ | |||
/* Place back original text without key-text */ |
|||
var finalText = thisorigtext.replace(/<point-here>/g,''); |
|||
finalText = finalText.replace(/<point-here-\S{2}>/g,''); |
|||
finalText = finalText.replace(/<box>(.*)<\/box>/g,returnUnboxedText); |
|||
$(this).html(finalText); |
|||
/* append DOM pointer divs to PRE's parent DIV */ |
|||
if (pointers.length > 0) { |
|||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
data.left = data.rotation = 0; |
|||
switch($(this)[0].position) { |
|||
| ⚫ | |||
data.top = $(this)[0].top + 5; |
|||
| ⚫ | |||
| ⚫ | |||
break; |
break; |
||
case " |
case "-tr": |
||
MarginTop = 5; |
|||
MarginLeft = 5; |
|||
Rotation = 225; |
|||
break; |
break; |
||
case " |
case "-br": |
||
MarginTop = 20; |
|||
MarginLeft = 0; |
|||
Rotation = 315; |
|||
break; |
break; |
||
break; |
|||
case "-bl": |
|||
MarginTop = 10; |
|||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
break; |
break; |
||
} |
} |
||
| ⚫ | |||
}); |
|||
| ⚫ | |||
} |
|||
} |
|||
if (boxes.length > 0) { |
|||
| ⚫ | |||
$( boxes ).each(function(){ |
|||
| ⚫ | |||
thisparent.append( '<div class="pre-box-overlay" style="position: absolute; left: ' + ($(this)[0].left - 4) + 'px; top: ' + ($(this)[0].top - 4) + 'px;">' + $(this)[0].content + '</div>' ); |
|||
| ⚫ | |||
}); |
|||
} |
|||
} |
|||
| ⚫ | |||
}); |
|||
posTop = $(this).position().top - 3; |
|||
} |
|||
posLeft = $(this).position().left - 3; |
|||
boxWidth = $(this).width(); |
|||
| ⚫ | |||
$this.append( '<div style="padding:1px; padding-left:2px; border: 2px solid red; border-radius: 5px; box-shadow: 0.5px 0.5px 5px 0.5px red; position: absolute; left: ' + posLeft + 'px; top: ' + posTop + 'px; width:'+boxWidth+'px;"> </div>' ); |
|||
| ⚫ | |||
}); |
|||
}); |
|||
Revision as of 16:59, 2 February 2023
/* [[Category:AutoDumpContentFromCommons]] */
/* Any JavaScript here will be loaded for all users on every page load. */
$( document ).ready(function() {
$('pre').each(function(){
var $this = $(this)
var OriginalText = $this.html();
function returnBoxedText(match, p1) { return '<box>' + p1 + '</box>'; }
function returnSpanPosStr(match, p1) {
var MarginTop = 0;
var MarginLeft = 0;
var Rotation = 0;
switch(p1) {
case "":
MarginTop = 5;
MarginLeft = 5;
Rotation = 225;
break;
case "-tr":
MarginTop = 5;
MarginLeft = 5;
Rotation = 225;
break;
case "-br":
MarginTop = 20;
MarginLeft = 0;
Rotation = 315;
break;
break;
case "-bl":
MarginTop = 10;
MarginLeft = -5;
Rotation = 45;
break;
case "-tl":
MarginTop = 0;
MarginLeft = -5;
Rotation = 135;
break;
}
return '<point-here class="pre-arrow" orientation="' + p1 + '" style="position:absolute; maring-left: ' + MarginLeft + 'px; margin-top: ' + MarginTop + 'px; transform: rotate(' + Rotation + 'deg); transform-origin: 0% 0%;"> </point-here>';
}
var newText = OriginalText.replace(/<box>(.*)<\/box>/g,returnBoxedText);
newText = newText.replace(/<point-here(\S*)>/g, returnSpanPosStr);
$this.html(newText);
$this.find('box').each(function(){
posTop = $(this).position().top - 3;
posLeft = $(this).position().left - 3;
boxWidth = $(this).width();
$this.append( '<div style="padding:1px; padding-left:2px; border: 2px solid red; border-radius: 5px; box-shadow: 0.5px 0.5px 5px 0.5px red; position: absolute; left: ' + posLeft + 'px; top: ' + posTop + 'px; width:'+boxWidth+'px;"> </div>' );
});
});
});
/**
* @source https://www.mediawiki.org/wiki/Snippets/Open_specific_links_in_new_window
* @version 2018-09-15
*/
$( function () {
$( '#mw-content-text' ).on( 'click', '.newwin > a', function () {
var otherWindow = window.open();
otherWindow.opener = null;
otherWindow.location = this;
return false;
} );
} );