Permalink
Browse files

Added on_before_hide callback. Tweaked hide and fadeOut.

  • Loading branch information...
1 parent cca5e91 commit e801f73a7e93e483a7868d73bb40dd2ff4b5f37b @christianhellsten committed Oct 26, 2009
Showing with 23 additions and 9 deletions.
  1. +9 −2 README.textile
  2. +14 −7 jquery.google-maps.tooltip.js
View
@@ -22,13 +22,20 @@ h3. JavaScript
<pre>
<code>
// Called right before tooltip is displayed
- var on_before_show = function(marker, tooltip) {
+ var before_show = function(marker, tooltip) {
// Set tooltip contents to the marker's title
// NOTE you could also attach JSON data to a marker and create more complex tooltips
tooltip.html(marker.title);
+ // NOTE you can also change the marker's icon
+ marker.setIcon('/images/hover.png');
};
+ // Called right before tooltip is hidden
+ var before_hide = function(marker, tooltip) {
+ marker.setIcon('/images/normal.png');
+ };
+
// Attach tooltip to the DIV element
- var tooltip = new MapTooltip($('#map-tooltip'), on_before_show);
+ var tooltip = new MapTooltip($('#map-tooltip'), before_show, before_hide);
// Add a marker to tooltip, see http://code.google.com/intl/sv-SE/apis/maps/documentation/v3/reference.html#Marker
tooltip.addMarker(marker); //
@@ -1,7 +1,7 @@
//
//
//
-function MapTooltip(tip, onBeforeShow) {
+function MapTooltip(tip, onBeforeShow, onBeforeHide) {
// Don't forget the tip
var $tooltip = tip;
// One timer
@@ -17,7 +17,7 @@ function MapTooltip(tip, onBeforeShow) {
// Mouse leave
$tooltip.bind('mouseleave.tooltip', function(e) {
- startTimer(function() { self.hide() }, 100);
+ startTimer(function() { self.hide(200) }, 100);
});
$tooltip.addClass('tooltip-enabled');
@@ -33,15 +33,17 @@ function MapTooltip(tip, onBeforeShow) {
}
this.show = function(marker) {
- var p = overlay.get_projection().fromLatLngToDivPixel(marker.get_position());
+ // Hide
+ self.hide(0);
- $tooltip.hide();
+ $tooltip.data('MapTooltips.marker', marker);
// Callback
onBeforeShow(marker, $tooltip);
// Map world relative to map container
// TODO This needs to be configurable and more exact
+ var p = overlay.get_projection().fromLatLngToDivPixel(marker.get_position());
var dragObject = overlay.get_panes().mapPane.parentNode;
var x = p.x + $tooltip.width(); // + parseInt(dragObject.style.left);
var y = p.y + $tooltip.height() / 2; // + parseInt(dragObject.style.top);
@@ -55,8 +57,13 @@ function MapTooltip(tip, onBeforeShow) {
$tooltip.animate({"top": "+=20px", "opacity": "toggle"}, 300);
}
- this.hide = function() {
- $tooltip.fadeOut(200);
+ this.hide = function(time) {
+ var marker = $tooltip.data('MapTooltips.marker');
+
+ if(marker && typeof onBeforeHide == 'function') {
+ onBeforeHide(marker, $tooltip);
+ }
+ $tooltip.fadeOut(time);
}
this.addMarker = function(marker) {
@@ -65,7 +72,7 @@ function MapTooltip(tip, onBeforeShow) {
});
google.maps.event.addListener(marker, 'mouseout', function(event) {
- startTimer(function() { self.hide() }, 500);
+ startTimer(function() { self.hide(200) }, 500);
});
}
};

0 comments on commit e801f73

Please sign in to comment.