MediaWiki:Gadget-DotsSyntaxHighlighter.js: Difference between revisions

no edit summary
mNo edit summary
No edit summary
 
(5 intermediate revisions by 2 users not shown)
Line 1: Line 1:
$(function() {
$(function() {
    //enable the highlighter only when editing wikitext pages
    //in the future a separate parser could be added for CSS and JS pages
    //blacklist Internet Explorer and Edge, they're just too broken
    var wgAction = mw.config.get("wgAction");
    var layoutEngine = $.client.profile().layout;
    if ((wgAction == "edit" || wgAction == "submit") && mw.config.get("wgPageContentModel") == "wikitext" && layoutEngine != "trident" && layoutEngine != "edge")
    {
        setup();
    }
    else
    {
        return;
    }
     //variables that are preserved between function calls
     //variables that are preserved between function calls
     var wpTextbox0;
     var wpTextbox0;
Line 556: Line 542:
         window.syntaxHighlighterSiteConfig = window.syntaxHighlighterSiteConfig || {};
         window.syntaxHighlighterSiteConfig = window.syntaxHighlighterSiteConfig || {};
         window.syntaxHighlighterConfig = window.syntaxHighlighterConfig || {};
         window.syntaxHighlighterConfig = window.syntaxHighlighterConfig || {};
        var tone6 = getComputedStyle(document.body).getPropertyValue('--theme-tone-6');


         //use 3-digit colors instead of 6-digit colors for performance
         //use 3-digit colors instead of 6-digit colors for performance
         configureColor("backgroundColor",    "#FFF",  false); //white
         if ($('body').hasClass('dark-mode')) {
        configureColor("foregroundColor",    "#000",  false); //black
            configureColor("backgroundColor",    tone6,  false); //white
        configureColor("boldOrItalicColor",  "#EEE",  true);  //gray
            configureColor("foregroundColor",    "#FFF",  false); //black
        configureColor("commentColor",      "#EFE",  true);  //green
            configureColor("boldOrItalicColor",  "#444",  true);  //gray
        configureColor("entityColor",        "#DFD",  true);  //green
            configureColor("commentColor",      "#4d745d",  true);  //green
        configureColor("externalLinkColor",  "#EFF",  true);  //cyan
            configureColor("entityColor",        "#556c55",  true);  //green
        configureColor("headingColor",      "#EEE",  true);  //gray
            configureColor("externalLinkColor",  "#485959",  true);  //cyan
        configureColor("hrColor",            "#EEE",  true);  //gray
            configureColor("headingColor",      "#444",  true);  //gray
        configureColor("listOrIndentColor",  "#EFE",  true);  //green
            configureColor("hrColor",            "#444",  true);  //gray
        configureColor("parameterColor",    "#FC6",  true);  //orange
            configureColor("listOrIndentColor",  "#4d745d",  true);  //green
        configureColor("signatureColor",    "#FC6",  true);  //orange
            configureColor("parameterColor",    "#6e5e36",  true);  //orange
        configureColor("tagColor",          "#FEF",  true);  //pink
            configureColor("signatureColor",    "#6e5e36",  true);  //orange
        configureColor("tableColor",        "#FFC",  true);  //yellow
            configureColor("tagColor",          "#4f364f",  true);  //pink
        configureColor("templateColor",      "#FFC",  true);  //yellow
            configureColor("tableColor",        "#3f3f31",  true);  //yellow
        configureColor("wikilinkColor",      "#EEF",  true);  //blue
            configureColor("templateColor",      "#3f3f31",  true);  //yellow
            configureColor("wikilinkColor",      "#5d5d6c",  true);  //blue
        } else {
            configureColor("backgroundColor",    "#FFF",  false); //white
            configureColor("foregroundColor",    "#000",  false); //black
            configureColor("boldOrItalicColor",  "#EEE",  true);  //gray
            configureColor("commentColor",      "#EFE",  true);  //green
            configureColor("entityColor",        "#DFD",  true);  //green
            configureColor("externalLinkColor",  "#EFF",  true);  //cyan
            configureColor("headingColor",      "#EEE",  true);  //gray
            configureColor("hrColor",            "#EEE",  true);  //gray
            configureColor("listOrIndentColor",  "#EFE",  true);  //green
            configureColor("parameterColor",    "#FC6",  true);  //orange
            configureColor("signatureColor",    "#FC6",  true);  //orange
            configureColor("tagColor",          "#FEF",  true);  //pink
            configureColor("tableColor",        "#FFC",  true);  //yellow
            configureColor("templateColor",      "#FFC",  true);  //yellow
            configureColor("wikilinkColor",      "#EEF",  true);  //blue
        }
       


         //tag lists are ordered from most common to least common
         //tag lists are ordered from most common to least common
Line 605: Line 612:
         wpTextbox0.style.fontFamily      = wpTextbox1Style.fontFamily;
         wpTextbox0.style.fontFamily      = wpTextbox1Style.fontFamily;
         wpTextbox0.style.fontSize        = wpTextbox1Style.fontSize;
         wpTextbox0.style.fontSize        = wpTextbox1Style.fontSize;
         wpTextbox0.style.lineHeight      = "1.3em";
         wpTextbox0.style.lineHeight      = "normal";
         wpTextbox0.style.marginBottom    = "0";
         wpTextbox0.style.marginBottom    = "0";
         wpTextbox0.style.marginLeft      = "0";
         wpTextbox0.style.marginLeft      = "0";
Line 623: Line 630:
         wpTextbox1.style.color          = syntaxHighlighterConfig.foregroundColor;
         wpTextbox1.style.color          = syntaxHighlighterConfig.foregroundColor;
         wpTextbox1.style.fontSize        = wpTextbox1Style.fontSize; //resolves alignment problems on mobile chrome
         wpTextbox1.style.fontSize        = wpTextbox1Style.fontSize; //resolves alignment problems on mobile chrome
         wpTextbox1.style.lineHeight      = "1.3em";
         wpTextbox1.style.lineHeight      = "normal";
         wpTextbox1.style.marginBottom    = wpTextbox1Style.marginBottom; //lock to pixel value because the top margin was also locked to a pixel value when it was moved to wpTextbox0
         wpTextbox1.style.marginBottom    = wpTextbox1Style.marginBottom; //lock to pixel value because the top margin was also locked to a pixel value when it was moved to wpTextbox0
         wpTextbox1.style.marginLeft      = "0";
         wpTextbox1.style.marginLeft      = "0";
Line 652: Line 659:
         highlightSyntaxIfNeededIntervalID = setInterval(highlightSyntaxIfNeeded, 500);
         highlightSyntaxIfNeededIntervalID = setInterval(highlightSyntaxIfNeeded, 500);
         highlightSyntax();
         highlightSyntax();
    }
    //enable the highlighter only when editing wikitext pages
    //in the future a separate parser could be added for CSS and JS pages
    //blacklist Internet Explorer and Edge, they're just too broken
    var wgAction = mw.config.get("wgAction");
    var layoutEngine = $.client.profile().layout;
    if ((wgAction == "edit" || wgAction == "submit") && mw.config.get("wgPageContentModel") == "wikitext" && layoutEngine != "trident" && layoutEngine != "edge")
    {
        setup();
    }
    else
    {
        return;
     }
     }
});
});