Resetting Cursor in Bing Maps – Support IE

August 10, 2015

I was having trouble resetting my Bing Maps implementation cursor back from a cross-hair (used when plotting a pin) to the default grab cursor.

I found that a slightly modified cursor url did the trick:

Old – _map.getRootElement().style.cursor =’url(https://ecn.dev.virtualearth.net/mapcontrol/v7.0/7.0.20150720111303.14/cursors/grabbing.cur) 10 9, move’;

New – _map.getRootElement().style.cursor =’url(https://ecn.dev.virtualearth.net/mapcontrol/v7.0/7.0.20150720111303.14/cursors/grab.cur), move’;


TagIt

April 2, 2015

TagIt! I have officially wrote the beginning of my first jQuery plugin.

I have been working on a much larger application and needed a lightweight tagging plugin for jQuery. I looked around but couldn’t find one that fit my needs. Lightweight, auto-complete, handles key/value pairs. I really wanted something that I could send some auto-complete values to that not only had a value, but a key.

I decided to take the plunge… and I thoroughly enjoyed it. The project is open-source and I hope someone can get some use out of it.
Your feedback is always welcomed.

Check out a demo on my website.


Formatting Javascript Date with Month Name

February 16, 2015

Oh the limitations of javascript… So I needed a way to produce a date/time string that would match the way I format my date/time strings in C# (MMMM dd, yyyy hh:mm:ss tt). As most know, javascript isn’t very nice when it comes to working with dates/times. My project had the added benefit of some special requirements. jQuery could be used, but no plug-ins are allowed.

After doing plenty of searching and posing a question on StackOverflow, I came up with this function. I sure wish the function could be shorter…


function getFormattedDateTime(dateTimeToFormat) {
dateTimeToFormat = new Date(dateTimeToFormat);

var zeroPad = function (val) {
return (val <= 9 ? '0' + val : '' + val);
};

var month = dateTimeToFormat.toLocaleString('en-us', {month: "long"});
var day = dateTimeToFormat.getDate();
var year = dateTimeToFormat.getFullYear();

var hour = ((dateTimeToFormat.getHours() + 11) % 12 + 1);
var minutes = dateTimeToFormat.getMinutes();
var seconds = dateTimeToFormat.getSeconds();
var suffix = (hour <= 12) ? 'AM' : 'PM';

return month + ' ' + zeroPad(day) + ', ' + year + ' ' + zeroPad(hour) + ':' + zeroPad(minutes) + ':' + zeroPad(seconds) + ' ' + suffix;
}

You can play with this function in action on JSFiddle


jQuery contains() – May not do what you think it does

May 10, 2014

As I was writing some javascript I needed to determine if a string was contained within the value of an element.

So, I started out with the following:

var myValue = $(“#myElement”).val();

The I proceed to check if my specific string was in fact part of myValue. So I kept coding:

if (myValue.contains(“magicString”)){

alert(“Test”);

}

But I never got my “Test” alert message. Why?

Because contains didn’t do what I thought it would. It’s meant to be used with DOM elements. Once I read the documentation it all became clear.

To start contains requires two arguments and looks like: $.contains(container, contained). It verifies if the second element (second parameter) is a descendant of the first element (first parameter). Since it’s looking for a descendant, location doesn’t matter. As long as the second element contains the first element somewhere it will return true.

So now I still needed a way to see if my string was contained in myValue… so I did some research this time and came up with the following:

if (myValue.indexOf(“magicString”) > -1) {

alert(“Test”);

}

This time I got my test message. This is the closest thing javascript has built in to verify if a string is contained within a value. If the string exists in the value, indexOf will return the index of that string (which will be greater than 1) and thus we have a work around.