Jump to content

User:Writ Keeper/Scripts/monobookEchoFix.js

From Wikipedia, the free encyclopedia
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.
$(document).ready(function()
{
	if($("body.skin-monobook.skin--responsive").length === 1)
	{
		var theEye = new MutationObserver(function(recordedEvent)
		{
			if($(".mw-echo-ui-notificationBadgeButtonPopupWidget-popup .oo-ui-popupWidget-body").length > 0)
			{
				theEye.disconnect();
				resizeNotificationDropdown();
			}
		});
		theEye.observe(document,{"subtree":true,"childList":true});
	}
	function resizeNotificationDropdown()
	{
		var ceaselessWatcher = new MutationObserver(function(recordedEvent)
		{
			var windowWidth = $(window).width();
			if(windowWidth < 535)
			{
				$(".oo-ui-popupWidget-anchor").css({"left":"auto","right":"22px"});
				$(".mw-echo-ui-notificationBadgeButtonPopupWidget-popup").css({"left":"auto","right":"10px"});
				var interiorWidth=windowWidth<520?""+(windowWidth-20)+"px":"500px";
				$(".mw-echo-ui-notificationBadgeButtonPopupWidget-popup .oo-ui-popupWidget-popup").css("width",interiorWidth);
				$(".mw-echo-ui-notificationBadgeButtonPopupWidget-popup .oo-ui-popupWidget-body").css("max-width",interiorWidth);
			}
		});
		$(".mw-echo-ui-notificationBadgeButtonPopupWidget-popup .oo-ui-popupWidget-body").each(function(ind, el){ceaselessWatcher.observe(el,{"attributes":true})});
	}
});