tags:

views:

55

answers:

1

Hello, I've been trying to tackle this problem for a day and half now and I can't seem to figure out this strange behavior.

When I do that live.('click' fn) it behaves like a double click. Well no that's not the true, what happens is that if I click on it once it performs on action, then when I click on it again it files off the second action. Shouldn't a single click fire all the actions within the click function? And also tried the simple $.click(fn) but that didn't even work at all for a single click.

here is my code in quetion:

$('#details #map-home').live('click', function(){
    var name  = $('#dFname').text();
    ///////////////////////////////////////////////////////////////////
    ////////// Google Maps API Functions //////////////////////////////
    $(this).bind('cbox_complete', function(){
        var geocoder;
        var map;
        var a = $("span#address").text() + $("span#city").text() + $("span#state").text() + $("span#zip").text();
        //var image = 'http://code.google.com/apis/maps/documentation/javascript/examples/images/beachflag.png';
        var div = 
        geocoder = new google.maps.Geocoder();
        var latlng = new google.maps.LatLng(37.0625, -95.677068);
        var myOptions = {
            zoom: 19,
            center: latlng,
            disableDefaultUI: true,
            mapTypeId: google.maps.MapTypeId.HYBRID
        }
        map = new google.maps.Map(document.getElementById("map"), myOptions);

        geocoder.geocode( { 'address': a}, function(results, status) {
            if (status == google.maps.GeocoderStatus.OK) {
                map.setCenter(results[0].geometry.location);
                var infowindow = new google.maps.InfoWindow({
                    content: a
                });
                var marker = new google.maps.Marker({
                    map: map,
                    //draggable: true,
                    //icon: image,
                    position: results[0].geometry.location
                });
                google.maps.event.addListener(marker, 'click', function() {
                    infowindow.open(map, this);
                });
                infowindow.open(map, marker);
            } else {
                console.log("Geocode was not successful for the following reason: " + status);
            }
        });
    });
    ///////////////////////////////////////////////////////////////////
    $(this).colorbox({
        width:"650",
        inline: true,
        href:"#map",
        overlayClose: false
    });
    //$('#colorbox').draggable();
    return false
});

any ideas?

A: 

I don't think using live here makes sense as you are dealing with a unique element with an id so I changed it to click instead. Also moved the bind to cbox_complete out of your click function as this is probably in line with expected behaviour. Also removed some strange code. Try the below.

$("#map-home").bind('cbox_complete', function(){
    var geocoder;
    var map;
    var a = $("span#address").text() + $("span#city").text() + $("span#state").text() + $("span#zip").text();
    geocoder = new google.maps.Geocoder();
    var latlng = new google.maps.LatLng(37.0625, -95.677068);
    var myOptions = {
        zoom: 19,
        center: latlng,
        disableDefaultUI: true,
        mapTypeId: google.maps.MapTypeId.HYBRID
    }
    map = new google.maps.Map(document.getElementById("map"), myOptions);
    geocoder.geocode( { 'address': a}, function(results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
            map.setCenter(results[0].geometry.location);
            var infowindow = new google.maps.InfoWindow({
                content: a
            });
            var marker = new google.maps.Marker({
                map: map,
                position: results[0].geometry.location
            });
            google.maps.event.addListener(marker, 'click', function() {
                infowindow.open(map, this);
            });
            infowindow.open(map, marker);
        } else {
           console.log("Geocode was not successful for the following reason: " + status);
        }
    });
});
$("#map-home").click(function(){
    $(this).colorbox({
        width:"650",
        inline: true,
        href:"#map",
        overlayClose: false
    });
});
sunn0
i applied the changes sunn0, but I probably did something wrong because it doesn't seem to fire the .bind(). You had also accidentally deleted a }); after the closing bracket for the else statement. I can see that when the I click on map it should execute the code with-in the .bind()... you can test it out, I haven't made changes to the page so your modification still there ;-)
s2xi
you know I'm thinking that it has something to do with the `$(this).colorbox` because if i insert a simple alert with in the click function it does nothing, if i then use the live again with a click handler then it does fire whats in the handler when i click. so i'm not sure why the click isn't working here... also i should note that the page i'm using the link in isn't loaded with the DOM its loaded afterwards, maybe thats why the live is needed.
s2xi
but like my problem states, if i use live then it attaches the click to anything loaded after the dom. which i'm thinking is why i need to double click?
s2xi
Sorry but I can't even find a #map-home element in your code and no changes have been made using the link. What is the exact URL after logging in? And as Peter pointed out - when is cbox_complete fired? I thought it was something that the Google Maps API does for you? Fixed the closing });.
sunn0
the 'map' link the Home Address has an id of #map-home. Thats what is suppose to trigger the colorbox and load in the Maps API. www.helixagent.com/contacts.php. the link should look like this in Firebug: `<a id="map-home" href="#" title="Test lives here"> <p class="m1" style="position: relative; top: 3px; color: #74919b">map</p> </a>`
s2xi
Found it. Still don't understand how you cam up with the 'cbox_complete' event?
sunn0