Difference between revisions of "User:James Hare/vector.js"

From Wikimedia District of Columbia
Jump to navigation Jump to search
(And so.)
m (Trying something)
Line 37: Line 37:
 
var creditLink = document.createElement('a');
 
var creditLink = document.createElement('a');
 
creditLink.href = randomImage.page;
 
creditLink.href = randomImage.page;
creditLink.appendChild(document.createTextNode("Image: " + randomImage.author + ", " + randomImage.license));
+
creditLink.appendChild(document.createTextNode("<br />" + "Image: " + randomImage.author + ", " + randomImage.license));
 
creditDiv.appendChild(creditLink);
 
creditDiv.appendChild(creditLink);
   

Revision as of 07:06, 19 May 2013

if (wgAction == 'view' && (wgPageName == 'User:James_Hare/Main_Page_redesign')) {
  var randomImages = [{image: '//wikimediadc.org/w/images/a/a3/Background_2.jpg',
                       page: 'http://commons.wikimedia.org/wiki/File:LOC_Main_Reading_Room_Highsmith.jpg',
                       author: "Carol M. Highsmith",
                       license: "Public Domain"}];

  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 {' +
            '  color:#fff; text-shadow: #000 0.3em 0.3em 1em, #000 -0.1em -0.1em 1em;' +
            '}' +
            '#main-page-credit {' +
            '  position: absolute; right: 0; top: -1em; 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("<br />" + "Image: " + randomImage.author + ", " + randomImage.license));
    creditDiv.appendChild(creditLink);

    document.getElementById('mw-content-text').appendChild(creditDiv);
  });

  head.appendChild(style);

  document.getElementById("firstHeading").className += " nodisplay";
  document.getElementById("contentSub").className += " nodisplay";

  addOnloadHook(removeFirstHeading);

}