Attempting to replicate the functionality of Google Maps' addListener
using jQuery listeners for clicks, keypresses, etc.
In Moogle Maps, you can use
.event.addListener(map, 'click', function()...
or switch 'click' with 'drag', 'mouseover', etc. Similarly, in jQuery, there are equivalents like 'click', 'keypress', etc.
Struggling with the idea of passing the trigger type as a variable. I have managed to create separate wrapper listeners easily, such as
function addClickListener(id, fn) {
$(id).click(function() { fn(event); });
}
// and
function addKeyPressListener(id, fn) {
$(id).keypress(function() { fn(event); });
}
Having trouble implementing it with the below code snippet. Unsure how Google is able to pass a String like 'click' and execute a function. Possibly using eval
? shudder
function addListener(id, type, fn) {
typeFn = $.type;
$(id).typeFn(function() { fn(event); });
}
Check out this example: http://jsfiddle.net/YCVVL/