MediaWiki:Common.js: Difference between revisions

no edit summary
No edit summary
No edit summary
(28 intermediate revisions by 2 users not shown)
Line 24: Line 24:
}
}


var loadJS = function(url, implementationCode, location){
var loadJS = function (url, implementationCode, location) {
     var scriptTag = document.createElement('script');
     var scriptTag = document.createElement('script');
     scriptTag.src = url;
     scriptTag.src = url;
Line 31: Line 31:
     location.appendChild(scriptTag);
     location.appendChild(scriptTag);
};
};
var popperLoaded = function() {
var popperLoaded = function () {
     var tippyLoaded = function() {
     var tippyLoaded = function () {
         tippy('.tippy-btn', {
         tippy('.tippy-btn', {
             interactive: true,
             interactive: true,
Line 69: Line 69:
         var rows = $('[class^="colortable-"] td b:contains("' + rowContent + '")');
         var rows = $('[class^="colortable-"] td b:contains("' + rowContent + '")');
         rows.each(function () {
         rows.each(function () {
             if ($(this).text() == rowContent) $(this).parent().addClass('tone-4');
             const textContent = $(this).parents('td')[0].textContent.trim();
            if (textContent == rowContent) $(this).parent().addClass('tone-4');
         })
         })
     })
     })
Line 180: Line 181:
             setCookie('elwiki-dark-mode', 'true');
             setCookie('elwiki-dark-mode', 'true');
         }
         }
         setTimeout(function(){
         setTimeout(function () {
             window.location.reload(1);
             window.location.reload(1);
         }, 50)
         }, 50)
Line 187: Line 188:
     if (getCookie('elwiki-dark-mode') == 'true') $('body').addClass('dark-mode');
     if (getCookie('elwiki-dark-mode') == 'true') $('body').addClass('dark-mode');
     if (getCookie('not-new') == null) $('#dark-mode-switch').addClass('new');
     if (getCookie('not-new') == null) $('#dark-mode-switch').addClass('new');
    // This is pretty cringe, tabs don't load sometimes
    if (!$('.tabber-new.loaded').length) mw.loader.load('https://elwiki.net/wiki/index.php?title=MediaWiki:Gadget-Tabs.js&action=raw&ctype=text/javascript')
}
}


Line 193: Line 197:
     performIE();
     performIE();
     enhancements();
     enhancements();
    // Fix the preview button losing custom script output
    // This is a complete ChatGPT moment, I couldn't be arsed to debug on my own
    $(document).on('DOMNodeInserted', function (event) {
        var element = event.target;
        if ($(element).hasClass('previewnote')) {
            var previewLoaded = $(element).find('.previewloading').length == 0;
            if (previewLoaded && !$(element).hasClass('custom-preview-run')) {
                $(element).addClass('custom-preview-run');
                enhancements();
            }
        }
    });
});
});


Line 483: Line 500:
     }
     }
}
}
//Fix height issue with ads
var HeightFix = $("#mw-content-block");
//$("#mw-related-navigation").css("min-height", HeightFix.height());
$("#mw-related-navigation").attr("style", "min-height: " + HeightFix.height() + "px !important");


//Get Ad Dart Number
//Get Ad Dart Number
Line 491: Line 513:
}
}
genSetRandDARTNumber();
genSetRandDARTNumber();
// Fix scripts literally disappearing when clicking "save changes" in VE
mw.hook('ve.activationComplete').add(function () {
    var originalSaveComplete = ve.init.mw.ArticleTarget.prototype.saveComplete;
    ve.init.mw.ArticleTarget.prototype.saveComplete = function (data) {
        // Calling the original implementation first
        originalSaveComplete.call(this, data);
        // Custom things
        doRoundEdges();
        enhancements();
    }
});
25,162

edits