Jump to content

User:Dlrohrer2003/validate-css.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Dlrohrer2003 (talk | contribs) at 00:19, 27 December 2011 (redefining default in switch statement). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
/** Validate CSS ***************************************************************
 *
 * Description: Add a tab to a CSS validation service on User and MediaMiki
 *              namespace CSS pages. This Script is inspired by and loosely
 *              based on a Wikimedia Commons gadget:
 *              [[Commons:MediaWiki:Gadget-CSSValidate.js]]
 *
 *      Author: [[User:Dlrohrer2003]]
 *
 *  Categories: [[Category:Wikipedia scripts]]
 */

// Global variables definable by the user.
if (!window.validateCssConfig) {var validateCssConfig = {};}

$( function() {

    if (wgPageName.match(/\.css/i) && (2 == wgNamespaceNumber || 8 == wgNamespaceNumber)) {

        var validatorProfile = "&profile=";

        switch(validateCssConfig.profile) {
        case 1:
        case "css1":
            validatorProfile += "css1";
            break;
        case 2:
        case "css2":
            validatorProfile += "css2";
            break;
        case 2.1:
        case "css21":
            validatorProfile += "css21";
            break;
        case 3:
        case "css3":
            validatorProfile += "css3";
            break;
        default:
            validatorProfile += "none";

        }

        var validator = "http://jigsaw.w3.org/css-validator/validator?uri=";
        var pageURL = window.location.protocol + wgServer + wgScript + "?title=" + wgPageName + "&action=raw&ctype=text/css";
        var options = validatorProfile;

        addPortletLink("p-cactions", validator + encodeURIComponent(pageURL) + options, "Validate CSS", "ca-validatecss" ,"Validate CSS" ,"" , null);

    }
});