Difference between revisions of "MediaWiki:Vector.js"

From Wikimedia District of Columbia
Jump to navigation Jump to search
(Removing code replaced by MediaWiki syntax)
 
(7 intermediate revisions by 3 users not shown)
Line 1: Line 1:
  +
/* For mobile devices */
/* Any JavaScript here will be loaded for users using the Vector skin */
 
   
 
var viewPortTag=document.createElement('meta');
// This script only works in Vector right now, but the banner should degrade gracefully.
 
  +
viewPortTag.id="viewport";
if (wgAction == 'view' && (wgPageName == 'Home' ||
 
  +
viewPortTag.name = "viewport";
wgPageName == 'Template:Main_Page_banner')) {
 
  +
viewPortTag.content = "width=device-width; initial-scale=1; maximum-scale=1;";
var randomImages = [{image: '//wikimediadc.org/w/images/8/81/Background_1.jpg',
 
 
document.getElementsByTagName('head')[0].appendChild(viewPortTag);
page: 'http://commons.wikimedia.org/wiki/File:President%27s_Park_with_White_House.jpg',
 
author: "Ad Meskens",
 
license: "CC-BY-SA 3.0"}];
 
 
var randomImage = randomImages[Math.floor(Math.random() * randomImages.length)];
 
 
var css = '#content {' +
 
' background-image: url(' + randomImage.image + ');' +
 
' background-size: 100%;' +
 
' background-repeat: no-repeat;' +
 
'}' +
 
'#main-page-banner {' +
 
' height: 12em;' +
 
' margin-bottom: 1em;' +
 
'}' +
 
'#main-page-welcome {' +
 
' text-shadow: #fff 0.3em 0.3em 1em, #fff -0.1em -0.1em 1em;' +
 
'}' +
 
'#main-page-credit {' +
 
' position: absolute; right: 0; top: 0; font-size: 0.5em' +
 
'}';
 
var head = document.getElementsByTagName('head')[0];
 
var style = document.createElement('style');
 
 
style.type = 'text/css';
 
if (style.styleSheet){
 
style.styleSheet.cssText = css;
 
} else {
 
style.appendChild(document.createTextNode(css));
 
}
 
 
addOnloadHook(function() {
 
var creditDiv = document.createElement('div');
 
creditDiv.id = 'main-page-credit';
 
var creditLink = document.createElement('a');
 
creditLink.href = randomImage.page;
 
creditLink.appendChild(document.createTextNode("Image: " + randomImage.author + ", " + randomImage.license));
 
creditDiv.appendChild(creditLink);
 
 
document.getElementById('mw-content-text').appendChild(creditDiv);
 
});
 
 
head.appendChild(style);
 
}
 

Latest revision as of 09:04, 17 August 2013

/* For mobile devices */

var viewPortTag=document.createElement('meta');
viewPortTag.id="viewport";
viewPortTag.name = "viewport";
viewPortTag.content = "width=device-width; initial-scale=1; maximum-scale=1;";
document.getElementsByTagName('head')[0].appendChild(viewPortTag);