User:Quiddity/common.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
![]() | The accompanying .css page for this skin is at User:Quiddity/common.css. |
importScript('User:Mvolz/veCiteFromURLLoader.js');
/* User:Zhaofeng Li/Reflinks.js */
importScript( 'User:Zhaofeng Li/Reflinks.js' );// Backlink: [[User:Zhaofeng Li/Reflinks.js]]
// Proof-of-concept of an "article map" sidebar for Wikipedia articles.
// Displays a scaled-down version of the page on the right side of the window.
// Doesn't work correctly on Chrome (and Chrome-like browsers) because of its
// numerous bugs, doesn't work on Internet Explorer because of its lack of
// support for advanced SVG features.
// Works on Firefox, mostly works on Opera 12.
// By Bartosz Dziewoński (Matma Rex), released under MIT license.
// Little attention was paid to details and code quality. Beware.
// version 1.0
/*global $ */
var sidebarWidth = 150;
$('#content')
.css('margin-right', sidebarWidth);
var contentWidth = $('#content').outerWidth();
var scale = sidebarWidth / contentWidth;
var contentHeight = $('#content').outerHeight();
var sidebarHeight = contentHeight * scale;
var windowHeight = $(window).height();
var contentTop = $('#content').offset().top;
var contentBottom = contentTop + contentHeight - windowHeight;
var $svg = $( '<div>' )
.css({
position: 'fixed',
overflow: 'hidden',
top: '0',
bottom: '0',
right: '0',
width: sidebarWidth
})
.insertAfter('#content')
.html(
'<svg width="'+sidebarWidth+'" height="'+sidebarHeight+'">' +
'<g transform="scale('+scale+')">' +
'<foreignObject width="'+contentWidth+'" height="'+contentHeight+'">' +
'</foreignObject>' +
'</g>' +
'</svg>'
);
$svg.find( 'foreignObject' ).append(
$('#content').clone().attr('id', '').css({
'margin-right': 0,
'margin-left': 0
})
);
// overlay to prevent clicking and hover effects
$svg.append( $('<div>')
.css({
position: 'absolute',
left: 0,
top: 0,
right: 0,
bottom: 0
}) );
var $indicator = $('<div>')
.css({
position: 'absolute',
background: 'rgba(0,0,0,0.3)',
left: 0,
top: 0,
width: sidebarWidth,
height: windowHeight * scale
});
$svg.append($indicator);
var maxContentScrollTop = document.documentElement.scrollHeight - windowHeight;
var needSidebarScrolling = sidebarHeight > windowHeight;
var maxSidebarScrollTop = sidebarHeight - windowHeight;
var state = 'top'; // || 'middle' || 'bottom'
var sidebarScrollTop = 0;
function scrollHandler() {
if(document.documentElement.scrollTop < contentTop) {
setTimeout( function () {
var top = Math.max(0, contentTop - document.documentElement.scrollTop);
$svg.css('top', top);
state = (top === 0 ? 'middle' : 'top');
}, 50 );
} else if(needSidebarScrolling && document.documentElement.scrollTop > contentBottom) {
setTimeout( function () {
var bottom = Math.max(0, document.documentElement.scrollTop - contentBottom);
$svg.css('bottom', bottom);
$svg.css('margin-top', -bottom);
state = (bottom === 0 ? 'middle' : 'bottom');
}, 50 );
} else {
if(state !== 'middle') {
$svg.css('top', 0);
$svg.css('bottom', 0);
$svg.css('margin-top', 0);
state = 'middle';
}
}
$indicator.css('top', document.documentElement.scrollTop * scale);
if(needSidebarScrolling) {
var scrollPercentage = document.documentElement.scrollTop / maxContentScrollTop;
sidebarScrollTop = scrollPercentage * maxSidebarScrollTop;
$svg.find('svg').css('margin-top', -sidebarScrollTop );
$indicator.css('margin-top', -sidebarScrollTop );
}
}
$(window).on('scroll', scrollHandler);
scrollHandler();
function clickHandler(e) {
e.stopPropagation();
e.preventDefault();
var ycoord = sidebarScrollTop + e.clientY;
var scrollTop = (ycoord / scale) - windowHeight/2;
$(document.documentElement).animate({ scrollTop: scrollTop }, 'fast');
scrollHandler();
}
$svg[0].addEventListener( 'click', clickHandler, true );