MediaWiki:Common.js: Difference between revisions

no edit summary
No edit summary
No edit summary
(25 intermediate revisions by 2 users not shown)
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 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 494: Line 516:
// Fix scripts literally disappearing when clicking "save changes" in VE
// Fix scripts literally disappearing when clicking "save changes" in VE
mw.hook('ve.activationComplete').add(function () {
mw.hook('ve.activationComplete').add(function () {
    var originalSaveComplete = ve.init.mw.ArticleTarget.prototype.saveComplete;
     ve.init.mw.ArticleTarget.prototype.saveComplete = function (data) {
     ve.init.mw.ArticleTarget.prototype.saveComplete = function (data) {
         this.editSummaryValue = null;
         // Calling the original implementation first
        this.initialEditSummary = null;
         originalSaveComplete.call(this, data);
        this.saveDeferred.resolve();
         // Custom things
        this.emit('save', data);
        var target = this;
         if (!this.pageExists || this.restoring) {
            this.teardown().then(function () {
                var newUrlParams = data.newrevid === undefined ? {} : {
                    venotify: target.restoring ? 'restored' : 'created'
                };
                if (data.isRedirect) {
                    newUrlParams.redirect = 'no';
                }
                location.href = target.viewUri.extend(newUrlParams);
            });
        } else {
            if (mw.loader.getState('mediawiki.page.watch.ajax') === 'ready') {
                mw.loader.using('mediawiki.page.watch.ajax', function () {
                    var watch = mw.libs['mediawiki.page.watch.ajax'];
                    if (watch) {
                        watch.updatePageWatchStatus(data.watched, data.watchlistexpiry);
                    }
                });
            }
            this.restoring = false;
            this.requestedRevId = undefined;
            if (data.newrevid !== undefined) {
                mw.config.set({
                    wgCurRevisionId: data.newrevid,
                    wgRevisionId: data.newrevid
                });
                this.revid = data.newrevid;
                this.currentRevisionId = data.newrevid;
            }
            mw.config.set(data.jsconfigvars);
            mw.loader.load(data.modules);
            mw.config.set({
                wgIsRedirect: !!data.isRedirect
            });
            if (this.saveDialog) {
                this.saveDialog.reset();
            }
            this.replacePageContent(data.content, data.categorieshtml, data.displayTitleHtml, data.lastModified, data.contentSub);
            this.tryTeardown(true);
         }
         doRoundEdges();
         doRoundEdges();
        performIE();
         enhancements();
         enhancements();
    }
});
// Now also fix the preview button
// 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();
        }
     }
     }
});
});
25,162

edits