MediaWiki:Mobile.js: Difference between revisions

Content deleted Content added
m 1 revision imported
No edit summary
 
(One intermediate revision by one other user not shown)
Line 1:
/* [[Category:AutoDumpContentFromCommons]] */
/* Any JavaScript here will be loaded for all users on every page load. */
$(function( $ ) {
 
enhanceDomPre();
 
$( document ).ready(function enhanceDomPre() {
$('pre').each(function(){
 
$('pre').each(function(){
var pointers = new Array();
var boxes = new Array();
var pointersI = boxesI = 0;
var thisparent = $(this).parent('div');
var thisorigtext = $(this).html();
 
function returnUnboxedText(match, p1) { return p1; }
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(/&lt;point-here&gt;/g, '<span class="temp-mw-point-anchor" data-pos="bl"></span>');
var newText = newText.replace(/&lt;point-here-(\S*)&gt;/g, returnSpanPosStr);
/* transform MW box anchors to full spans */
var newText = newText.replace(/&lt;box&gt;(.*)&lt;\/box&gt;/g,returnBoxedText);
/* set new PRE text, including custom spans */
$(this).html(newText);
 
var $this = $(this)
 
var OriginalText = $this.html();
/* 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++; });
/* search for box anchors, add to box object */
$(".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(/&lt;point-here&gt;/g,'');
finalText = finalText.replace(/&lt;point-here-\S{2}&gt;/g,'');
finalText = finalText.replace(/&lt;box&gt;(.*)&lt;\/box&gt;/g,returnUnboxedText);
$(this).html(finalText);
 
$this.parent(".mw-collapsible-content").show(); /// temporary show collapsible content to read its location....
/* append DOM pointer divs to PRE's parent DIV */
 
if (pointers.length > 0) {
function returnBoxedText(match, p1) { return '<box>' + p1 + '</box>'; }
$( pointers ).each(function(){
function returnSpanPosStr(match, p1) {
var data = new Object();
var MarginTop = 0;
data.top = $(this)[0].top;
data.left = data.rotation var MarginLeft = 0;
var Rotation = 0;
switch($(this)[0].position) {
switch(p1) {
case "tr":
 
data.top = $(this)[0].top + 5;
data.left = $(this)[0].left + 5;
case "": data.rotation = 225;
MarginTop = 5;
MarginLeft = 5;
Rotation = 0;
break;
case "br-tr":
data.topMarginTop = $(this)[0].top + 205;
data.leftMarginLeft = $(this)[0].left5;
data.rotationRotation = 315225;
break;
case "bl-br":
data.topMarginTop = $(this)[0].top + 1020;
data.leftMarginLeft = $(this)[0].left - 5;
data.rotationRotation = 45315;
break;
case "tl": break;
case data.left = $(this)[0].left "- 5;bl":
data.rotationMarginTop = 13510;
MarginLeft = -5;
Rotation = 45;
break;
case "-tl":
MarginTop = 0;
MarginLeft = -5;
Rotation = 135;
break;
}
 
thisparent.append( '<div class="pre-arrow" style="position: absolute; left: ' + data.left + 'px; top: ' + data.top + 'px; transform: rotate(' + data.rotation + 'deg); transform-origin: 0% 0%;">&nbsp</div>' );
 
});
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%;">&nbsp</point-here>';
}
}
 
if (boxes.length > 0) {
var newText = OriginalText.replace(/&lt;box&gt;(.*)&lt;\/box&gt;/g,returnBoxedText);
$( boxes ).each(function(){
newText = newText.replace(/&lt;point-here(\S*)&gt;/g, returnSpanPosStr);
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>' );
$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;">&nbsp</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;
} );
} );