MyBB Community Forums

Full Version: Help with MyAlerts active state/class
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi, I'd like some assistance in getting the 'Alerts' tab to be highlighted when clicked like so:

[Image: 13qRr.jpeg]

Currently it looks like this:

[Image: 13qRk.jpeg]

Thanks.
You'd have to edit the JS I'm afraid. Try the below script instead of the current myalerts.js and then you can use ".myalerts_dropdown_open".

jQuery.noConflict();

jQuery(document).ready(function($)
{
	$('body').on({
		click: function(event)
		{
			event.preventDefault();
			var popup_id = $(this).attr('id') + '_popup';

			$('#' + popup_id).attr('top', $(this).height() + 'px').slideToggle('fast', function() {
				var toMarkRead = [];
				$('[id^="alert_row_popup_"]').each(function() {
					toMarkRead.push($(this).attr('id').substr(16));
				});

				$.get('xmlhttp.php?action=markRead', {
					my_post_key: my_post_key,
					toMarkRead: toMarkRead
				}, function(data) {

				});
			});

			$(this).toggleClass('myalerts_dropdown_open');
			return false;
		}
	}, '.myalerts_popup_hook');

	$('.myalerts_popup *').on('click', function(event) {
		event.stopPropagation();
	});

	$("body:not('.myalerts_popup:visible')").on('click', function() {
        $('.myalerts_popup:visible').hide();
	});

	$('#getUnreadAlerts').on('click', function(event) {
		event.preventDefault();
		$.get('xmlhttp.php?action=getNewAlerts', function(data) {
			$('#latestAlertsListing').prepend(data);
		});
	});

	$('.deleteAlertButton').on('click', function(event) {
		event.preventDefault();
		var deleteButton = $(this);

		$.getJSON(deleteButton.attr('href'), {accessMethod: 'js'}, function(data) {
			if (data.success)
			{
				deleteButton.parents('tr').get(0).remove();
				if (data.template)
				{
					$('#latestAlertsListing').html(data.template);
				}
			}
			else
			{
				alert(data.error);
			}
		});
	});

	if (typeof myalerts_autorefresh !== 'undefined' && myalerts_autorefresh > 0)
	{
		window.setInterval(function() {
			$.get('xmlhttp.php?action=getNewAlerts', function(data) {
				$('#latestAlertsListing').prepend(data);
			});
		}, myalerts_autorefresh * 1000);
	}

	if (typeof unreadAlerts !== 'undefined' && unreadAlerts > 0)
	{
		document.title = document.title + ' (' + unreadAlerts + ')';
	}

});
(2013-04-20, 01:06 PM)Euan T Wrote: [ -> ]You'd have to edit the JS I'm afraid. Try the below script instead of the current myalerts.js and then you can use ".myalerts_dropdown_open".

jQuery.noConflict();

jQuery(document).ready(function($)
{
	$('body').on({
		click: function(event)
		{
			event.preventDefault();
			var popup_id = $(this).attr('id') + '_popup';

			$('#' + popup_id).attr('top', $(this).height() + 'px').slideToggle('fast', function() {
				var toMarkRead = [];
				$('[id^="alert_row_popup_"]').each(function() {
					toMarkRead.push($(this).attr('id').substr(16));
				});

				$.get('xmlhttp.php?action=markRead', {
					my_post_key: my_post_key,
					toMarkRead: toMarkRead
				}, function(data) {

				});
			});

			$(this).toggleClass('myalerts_dropdown_open');
			return false;
		}
	}, '.myalerts_popup_hook');

	$('.myalerts_popup *').on('click', function(event) {
		event.stopPropagation();
	});

	$("body:not('.myalerts_popup:visible')").on('click', function() {
        $('.myalerts_popup:visible').hide();
	});

	$('#getUnreadAlerts').on('click', function(event) {
		event.preventDefault();
		$.get('xmlhttp.php?action=getNewAlerts', function(data) {
			$('#latestAlertsListing').prepend(data);
		});
	});

	$('.deleteAlertButton').on('click', function(event) {
		event.preventDefault();
		var deleteButton = $(this);

		$.getJSON(deleteButton.attr('href'), {accessMethod: 'js'}, function(data) {
			if (data.success)
			{
				deleteButton.parents('tr').get(0).remove();
				if (data.template)
				{
					$('#latestAlertsListing').html(data.template);
				}
			}
			else
			{
				alert(data.error);
			}
		});
	});

	if (typeof myalerts_autorefresh !== 'undefined' && myalerts_autorefresh > 0)
	{
		window.setInterval(function() {
			$.get('xmlhttp.php?action=getNewAlerts', function(data) {
				$('#latestAlertsListing').prepend(data);
			});
		}, myalerts_autorefresh * 1000);
	}

	if (typeof unreadAlerts !== 'undefined' && unreadAlerts > 0)
	{
		document.title = document.title + ' (' + unreadAlerts + ')';
	}

});


Thanks, Euan, works like a charm. Smile