Hide Legend Marker On Mouseout For Highmaps

PROBLEM
Hopefully this post will be the only time I need to share something I found with Highmaps/Highcharts… So what I was tasked to do was to remove this legend marker thing whenever the mouse was not over a US state or territory.

There’s a good demo of the issue here: http://www.highcharts.com/maps/demo/color-axis .

2015-05-08_170841As you can demo as well, when I mouse out, the gray arrow at the top of the legend still appears. This behavior may seem confusing to users so I was asked to remove it on mouse out.

SOLUTION
Ugh, after hours and hours of searching through Highcharts/Highmaps code, playing around with the different settings, I got no where. I started googling the dumbest things “highcharts legend mouse”, “highmaps legend cross crosshairs”, “how to jump out the window of an eleven story building”… I even tried to do it in JQuery which wasn’t working.

I then stumbled upon further customization on mouse actions. It turns out, in the options, series, events, you can add mouse options.

I got a simple JS alert to popup on mouse out. So when the user was not on a state, the alert would pop up. It was a start.

I then used JQuery to handle the rest… (It actually worked!)

series: [{
	...
	events: {
		mouseOut: function () {
			// when the mouse isn't over any of the states, hide the highcharts path
			$(".highcharts-legend-item > path").attr("visibility", "hidden");
		}
	}
}]

That successfully removes the arrow from the legend when the mouse is out.

I hope someone else can use this since you’d think this kind of option would be available easier than this way.

UPDATE: Get Default/Welcome Page Of A SharePoint 2010 Site

PROBLEM
I needed to find the default or “welcome page” of a SharePoint site. I needed this because I need to pass in a query string parameter to it. For example, if I passed in the string “http://www.mysite.com/staff”, it would give me “Pages/index.aspx”.

After surfing the net, the threads I read on Microsoft and other sites were not helpful at all. Most lead me to complex lines of code that used different utilities that I wasn’t familiar with. (I’m not that familiar with this stuff as it is.)

SOLUTION
I finally decided to ask the question on stackoverflow. My question was How do I get the default/welcome page of a SharePoint 2010 site?.

In a few minutes, a dude answered with a link to a thread on Microsoft. It was pretty helpful although it wasn’t complete as it gave me a few errors:

  • First it gave me an unrecognizable PublishingWeb. To solve that, I had to add the Microsoft.SharePoint.Publishing reference to the web part.
  • Second it gave me a cannot convert type SPFile to string. Trying .toString() didn’t work. Turns out SPFile has a Url function which returns a string.

The finished function is:

private string GetSPSiteUrl(string u) {
	string siteurl = "";

	using (SPSite site = new SPSite(u)) {
		using (SPWeb web = site.OpenWeb()) {

			if (PublishingWeb.IsPublishingWeb(web)) {
				siteurl = PublishingWeb.GetPublishingWeb(web).DefaultPage.Url;
			}
			else {
				siteurl = web.RootFolder.WelcomePage;
			}
		}
	}

	return siteurl;
}

UPDATE
As it turns out, this code works for sites that have permissions. Since our site is anonymous access, it gives an NT prompt.

The way to fix this issue is to add RunWithElevatedPrivileges.

private string GetSPSiteUrl(string u) {
	string siteurl = "";

	// run this code with elevated privileges
	SPSecurity.RunWithElevatedPrivileges(delegate() {

		using (SPSite site = new SPSite(u)) {
			using (SPWeb web = site.OpenWeb()) {

				// get the default page
                        	if (PublishingWeb.IsPublishingWeb(web)) {
					siteurl = PublishingWeb.GetPublishingWeb(web).DefaultPage.Url;
				}
				else {
					siteurl = web.RootFolder.WelcomePage;
				}
			}
		}
	});

	return siteurl;
}

Making A CheckBox In GridView 508 Compliant

ISSUE
Since all HHS government websites need to be 508 compliant by May 2013, my company has been running around trying to make them compliant now. We have quite a few old applications which are still being used. It’s my job to review them for compliancy and fix some of them.

The issue I had was with a .NET application. On a search page they’re using a asp:GridView control which gets the results. One of the results is put into a check box (an asp:CheckBox). 508 says there should be a label tag or a title attribute associated with any input form field (even disabled ones):

<asp:GridView ID=”GridView1″ OnSorting=”GridView_Sorting” AutoGenerateColumns=”False” runat=”server” CellPadding=”4″ GridLines=”None” AllowSorting=”True”>
<Columns>
<asp:TemplateField HeaderText=”Attending”>
<ItemTemplate>
<asp:CheckBox ID=”Attending” Checked='<%# GetCheckValue(Container.DataItem) %>’ Enabled='<%# GetCheckEnable(Container.DataItem) %>’ runat=”Server” />
</ItemTemplate>

</asp:TemplateField>

</Columns>
</asp:GridView>

The problem is we need to make sure the check box has either a label or a title associated with it.

In .NET you’re allowed to add a ToolTip (title attribute) to asp check boxes. However it added it to a <span> which it generates outside the actual <input type=”checkbox”> code.

FIX
After a little while googling around I wasn’t able to find anything that would let me either get the ID (which it generates) so I can put a label next to it or actually have the title IN the check box.

A shot in the dark made it work. I had to add an attribute Text to the asp:CheckBox . This generates a label next to the check box in the client side code.

Since the application I’m working on doesn’t need to display anything next to it, I put the text in a .hide class which hides it.

Text=”<span class=’hide’>Attending</span>”

Some cons are that its label is the same everywhere. I’m sure some mad .NET developer can whip up something that can change it.