Jump to content

MediaWiki:Common.js: Difference between revisions

From wikiNonStop
Content deleted Content added
m 1 revision imported: Initial Setup
No edit summary
 
(5 intermediate revisions by the same user not shown)
Line 51: Line 51:
}
}
});
});

// Mobil-Fix für Template-Tooltips mit title-Attribut
$(document).ready(function() {
if ('ontouchstart' in window || navigator.maxTouchPoints > 0) {
$('.custom-tooltip, abbr[title]').on('click', function(e) {
e.preventDefault();
var titleText = $(this).attr('title');
if (titleText) {
// Erstellt ein temporäres mobiles Mini-Popup über dem Element
alert(titleText); // Einfachste Variante.
// Alternativ kann hier ein schickeres div-Popup eingeblendet werden.
}
});
}
});

mw.hook('wikipage.content').add(function($content) {
// Erkennt mobile Touch-Gesten
if ('ontouchstart' in window || navigator.maxTouchPoints > 0) {
// Sucht nach Ihrer CSS-Klasse (z. B. .wiki-tooltip)
$content.find('.wiki-tooltip').on('click', function(e) {
e.preventDefault();
e.stopPropagation();
// Holt sich das versteckte Kind-Element (den Tooltip-Text)
var $tooltipContent = $(this).find('.tooltip-content');
// Wechselt die Sichtbarkeit bei jedem Klick/Tippen
$('.tooltip-content').not($tooltipContent).hide(); // Schließt andere offene Tooltips
$tooltipContent.toggle();
});

// Schließt das Tooltip-Fenster, wenn man irgendwo anders hinklickt
$(document).on('click', function() {
$('.tooltip-content').hide();
});
}
});

/**
* Fix für den Kartographer / Leaflet.draw Fehler querySelectorAll("*,:x")
* Dieser Fehler tritt in modernen Browsern auf, wenn veraltete Leaflet-Bibliotheken
* einen ungültigen CSS-Selector verwenden.
*/
(function() {
try {
// Testen, ob der Browser bei diesem Selector abstürzt
document.querySelectorAll("*,:x");
} catch (e) {
// Falls ja (Sicherheitsfehler), patchen wir die Methode global
var nativeQuerySelectorAll = Element.prototype.querySelectorAll;
Element.prototype.querySelectorAll = function(selectors) {
if (selectors === "*,:x") {
// Wir ersetzen den ungültigen Selector durch einen sicheren
return nativeQuerySelectorAll.call(this, "*");
}
return nativeQuerySelectorAll.call(this, selectors);
};
console.log("Kartographer-Fix: querySelectorAll('*,:x') wurde erfolgreich umgeleitet.");
}
})();

Latest revision as of 08:22, 20 September 2026

/*
 * This is the JS for all skins (for both mobile and desktop) on MediaWiki.org.
 * Consider whether you can use a gadget with one of the options set to limit
 * where it is loaded. See [[Extension:Gadgets#Options]].
 */
/* global mw, $ */
/**
 * Hide prefix in category
 *
 * @source https://www.mediawiki.org/wiki/Snippets/Hide_prefix_in_category
 * @rev 5
 */
var prefix = $.trim( $( '#mw-cat-hideprefix' ).text() ) || ( mw.config.get( 'wgTitle' ) + '/' );
$( '#mw-pages' ).find( 'a' ).text( function ( i, val ) {
    return val.slice( 0, prefix.length ) === prefix ? val.slice( prefix.length ) : val;
} );

/**
 * @source https://www.mediawiki.org/wiki/Snippets/Load_JS_and_CSS_by_URL
 * @revision 2017-05-16
 */
mw.loader.using( ['mediawiki.util'], function () {
	var extraCSS = mw.util.getParamValue( 'withCSS' ),
		extraJS = mw.util.getParamValue( 'withJS' ),
		extraModule = mw.util.getParamValue( 'withModule' );

	if ( extraCSS ) {
		// WARNING: DO NOT REMOVE THIS "IF" - REQUIRED FOR SECURITY (against XSS/CSRF attacks)
		if ( /^MediaWiki:[^&<>=%#]*\.css$/.test( extraCSS ) ) {
			mw.loader.load( '/w/index.php?title=' + encodeURIComponent( extraCSS ) + '&action=raw&ctype=text/css', 'text/css' );
		} else {
			mw.notify( 'Only pages from the MediaWiki namespace are allowed.', { title: 'Invalid withCSS value' } );
		}
	}

	if ( extraJS ) {
		// WARNING: DO NOT REMOVE THIS "IF" - REQUIRED FOR SECURITY (against XSS/CSRF attacks)
		if ( /^MediaWiki:[^&<>=%#]*\.js$/.test( extraJS ) ) {
			mw.loader.load( '/w/index.php?title=' + encodeURIComponent( extraJS ) + '&action=raw&ctype=text/javascript' );
		} else {
			mw.notify( 'Only pages from the MediaWiki namespace are allowed.', { title: 'Invalid withJS value' } );
		}
	}

	if ( extraModule ) {
		if ( /^ext\.gadget\.[^,\|]+$/.test( extraModule ) ) {
			mw.loader.load( extraModule );
		} else {
			mw.notify( 'Only gadget modules are allowed.', { title: 'Invalid withModule value' } );
		}
	}
});

// Mobil-Fix für Template-Tooltips mit title-Attribut
$(document).ready(function() {
    if ('ontouchstart' in window || navigator.maxTouchPoints > 0) {
        $('.custom-tooltip, abbr[title]').on('click', function(e) {
            e.preventDefault();
            var titleText = $(this).attr('title');
            if (titleText) {
                // Erstellt ein temporäres mobiles Mini-Popup über dem Element
                alert(titleText); // Einfachste Variante. 
                // Alternativ kann hier ein schickeres div-Popup eingeblendet werden.
            }
        });
    }
});

mw.hook('wikipage.content').add(function($content) {
    // Erkennt mobile Touch-Gesten
    if ('ontouchstart' in window || navigator.maxTouchPoints > 0) {
        // Sucht nach Ihrer CSS-Klasse (z. B. .wiki-tooltip)
        $content.find('.wiki-tooltip').on('click', function(e) {
            e.preventDefault();
            e.stopPropagation();
            
            // Holt sich das versteckte Kind-Element (den Tooltip-Text)
            var $tooltipContent = $(this).find('.tooltip-content');
            
            // Wechselt die Sichtbarkeit bei jedem Klick/Tippen
            $('.tooltip-content').not($tooltipContent).hide(); // Schließt andere offene Tooltips
            $tooltipContent.toggle();
        });

        // Schließt das Tooltip-Fenster, wenn man irgendwo anders hinklickt
        $(document).on('click', function() {
            $('.tooltip-content').hide();
        });
    }
});

/**
 * Fix für den Kartographer / Leaflet.draw Fehler querySelectorAll("*,:x")
 * Dieser Fehler tritt in modernen Browsern auf, wenn veraltete Leaflet-Bibliotheken
 * einen ungültigen CSS-Selector verwenden.
 */
(function() {
    try {
        // Testen, ob der Browser bei diesem Selector abstürzt
        document.querySelectorAll("*,:x");
    } catch (e) {
        // Falls ja (Sicherheitsfehler), patchen wir die Methode global
        var nativeQuerySelectorAll = Element.prototype.querySelectorAll;
        Element.prototype.querySelectorAll = function(selectors) {
            if (selectors === "*,:x") {
                // Wir ersetzen den ungültigen Selector durch einen sicheren
                return nativeQuerySelectorAll.call(this, "*");
            }
            return nativeQuerySelectorAll.call(this, selectors);
        };
        console.log("Kartographer-Fix: querySelectorAll('*,:x') wurde erfolgreich umgeleitet.");
    }
})();