Difference between revisions of "MediaWiki:Common.js"

m (Testing.)
m
Line 30: Line 30:
 
     var itemImage = document.getElementById('itemImage');
 
     var itemImage = document.getElementById('itemImage');
 
     if (itemImage) {
 
     if (itemImage) {
 +
alert(itemImage);
 
         var image = new Image();
 
         var image = new Image();
 
         image.src = itemImage.getElementsByTagName('img')[0].src;
 
         image.src = itemImage.getElementsByTagName('img')[0].src;

Revision as of 14:29, 9 April 2011

/* Any JavaScript here will be loaded for all users on every page load. */

/**
 * Determines if a particular element possesses a class.
 */
var hasClass = (function () {
    var reCache = {};
    return function (element, className) {
        return (reCache[className] ? reCache[className] : (reCache[className] = new RegExp('(?:\\s|^)' + className + '(?:\\s|$)'))).test(element.className);
    };
})();

/**
 * Determines if a given value is a number.
 */
function isNumeric(value) {
    return new RegExp(/(^\d+$)|(^\d+\.\d+$)/).test(value);
}

/**
 * Removes all children from an element.
 */
function removeChildren(element) {
    while (element.hasChildNodes()) {
        element.removeChild(element.firstChild);
    }
}

function itemboxImageHeight() {
    var itemImage = document.getElementById('itemImage');
    if (itemImage) {
alert(itemImage);
        var image = new Image();
        image.src = itemImage.getElementsByTagName('img')[0].src;
        itemImage.style.marginTop = (-180 + (83 - (image.height / 2))) + 'px';
    }
}
addOnloadHook(itemboxImageHeight);

/**
 * Import more specific scripts.
 */
importScript('MediaWiki:Collapsible.js');
importScript('MediaWiki:Calculator.js');

if (wgAction == 'edit' || wgAction == 'submit')
{
    importScript('MediaWiki:Editbar.js');
}