views:

48

answers:

3

So im using jquery to search and replace certain text in my html page. Which is:

function offon(){
  $("#sidebar li").each(function(){
     $(this).html($(this).html().replace(/Off Premise/, "Liquor Store"));
     $(this).html($(this).html().replace(/On Premise/, "Bar/Restaurant"));
  });
}

This is the createmarker function, it uses a 3rd part tooltip the div is "simple_example_window" that contains all the html. I tried using simple_example_window for the div in the offon function but it did not do anything.

http://gmaps-utility-library-dev.googlecode.com/svn/trunk/extinfowindow/docs/examples.html is the plugin.

function createMarker(point, name, address, type) {
var marker = new GMarker(point, customIcons[type]);
  markerGroups[type].push(marker);
var html = '<span class="name"><b>' + name + '</b></span> <br/>' + address + '<br/>' +     type;
GEvent.addListener(marker, 'click', function() {
    marker.openExtInfoWindow(
      map,
      "simple_example_window",
     html,
      {beakOffset: 2}
    );

It works like a charm. The only problem now is my tooltips in google maps are not changing.

Any ideas?

+1  A: 

You need to do the same text replace before you attach the data to the google map. Or when you attach the data to the google map.

Boushley
How do I get multiple .replace() strings for one variable? ie: var newstring = type.replace(/Off Premise/, "Liquor Store"); var newstring = type.replace(/On Premise/, "Bar/Restaurant");
Robert
I figured it out thanks guys!
Robert
For future reference of anyone out there that comes across this, you could do this with var newstring = type.replace(/Off Premise/, "Liquor Store").replace(/On Premise/, "Bar/Restraunt");
Boushley
A: 

We might need to see more markup to make sure the selector is correct. As well, as Boushley mentions, the timing might be such that the tooltips are generated (or added) after your jQuery executes.

madjester
Ya, it looks like a timing issue since he's looping the #sidebar li elements... You need to do the same replace as you are creating the markers on the map.
Boushley
I tried putting the function in the load function of google maps. still no change.
Robert
A: 

I see from the comments you figured this out, just a bit of an optimized version here:

function offon(){
  $("#sidebar li").html(function(i, h){
     return h.replace(/Off Premise/, "Liquor Store")
             .replace(/On Premise/, "Bar/Restaurant");
  });
}

You can test it here

.html() can take a function, and doesn't need to create unnecessary jQuery objects (and .html() calls) along the way, this will result in a lot of saved CPU cycles all around.

Nick Craver