I’ve found this blog where Matthias Burtscher converted the Marker Cluster (like the Phoogle2) for Google Maps API v.3. Since I’m starting to develop some v3 application, I’m very happy: http://blog.fusonic.net/archives/195
Nov 18 2009
Click links with JavaScript
If you want to click on objects, anchors, table cells or any other html element to emulate the javascript behaviour you can prototype the click function on the HTMLElement object. In the new method we fire the click event on the object. The click event is fired in two different ways (one for IE browser and one for Mozzilla-like browser).
I’ve used this code on a page that use a lightbox/shadowbox gallery. When the page is loaded I fire the click event on the first link of the lightbox gallery.
Watch a demo here.
HTMLElement.prototype.click = function() {
if (document.createEvent) {
var evt = this.ownerDocument.createEvent('MouseEvents');
evt.initMouseEvent('click', true, true, this.ownerDocument.defaultView, 1, 0, 0, 0, 0, false, false, false, false, 0, null);
this.dispatchEvent(evt);
} else if (this.fireEvent) {
this.fireEvent("onclick");
}
}
// usage
// <a href="http://www.barattalo.it" id="linktoclick">auto click</a>
document.getElementById("linktoclick").click();
Nov 17 2009
Set “write here” on input type text?
If you are using JQuery framework and you want to set up the default value of some text box in a form you can use this function that defines the onclick function, the onblur function and set the default value and css.
The configuration of the input type text box is defined into the rel attribute, here is the first part, the html code:
<style>
input.csson { color: red; }
input.cssoff { color: gray; }
</style>
<form>
<input id='author' type='text' value='' rel="writehere|type author|cssoff|csson"/><br/>
<input id='topic' type='text' value='' rel="writehere|type topic|cssoff|csson"/><br/>
</form>
and this is the javascript function that add events and styles when your document is ready:
function setWriteHere(search) {
/* add on click event handler */
$("input[rel^="+search+"]").click( function () {
var ar = $(this).attr('rel').split('|');
if($(this).val()==ar[1]) { $(this).val(""); $(this).attr('class',ar[3]); }
} );
/* add on blur event handler */
$("input[rel^="+search+"]").blur( function () {
var ar = $(this).attr('rel').split('|');
if($(this).val()=="") { $(this).val(ar[1]); $(this).attr('class',ar[2]); }
} );
/* trigger blur event */
$("input[rel^="+search+"]").each( function () { $(this).blur(); } );
}
$(document).ready(function() {
/* fix forms when ready */
setWriteHere("writehere");
}
);
« Previous Page — Next Page »
