Is it possible to override default tooltips?

9811
28
04-02-2014 09:35 AM
RobertKirkwood
Occasional Contributor III
I would like to be able to override the default tooltips for the Homebutton, Simple Slider, and the Locate buttons.  I have other tooltips in the map and i want the tooltips to all look the same.
0 Kudos
28 Replies
KellyHutchins
Esri Frequent Contributor
Hi Robert,

Here's a link to a help topic that explains how to override the default strings in the JSAPI.

https://developers.arcgis.com/javascript/jshelp/inside_bundle.html
RobertKirkwood
Occasional Contributor III
Hi Robert,

Here's a link to a help topic that explains how to override the default strings in the JSAPI.

https://developers.arcgis.com/javascript/jshelp/inside_bundle.html


Thanks. I have looked and can't seem to find anything that talks about the default tootip being overwritten specifically. I have tried the code below for the Homebutton and the Locate button, but it doesn't seem to work. I have even put in the variable map.

require(["dijit/Tooltip", "dojo/domReady!"], function(Tooltip){
 
 new Tooltip({
        connectId: ["HomeButton"],
        label: "Home",
  orient: ['before'],
    });
 


I have also tried this in my .css file:

.HomeButton .tooltip {
    font-family: Arial !important;
    font-size: 11px !important;
    font-weight: bold !important;
    
    background-color: white !important;
    
}


I am not sure what i am missing here? Thanks for the help!
0 Kudos
KellyHutchins
Esri Frequent Contributor
The link I posted shows how to change the default text for the tooltip. Are you trying to change the text or do you want to modify the appearance of the tooltip?
RobertKirkwood
Occasional Contributor III
The link I posted shows how to change the default text for the tooltip. Are you trying to change the text or do you want to modify the appearance of the tooltip?


I am trying to change the default style. I have a white box with a border around the rest of the tooltips in the map. here are the examples:

[ATTACH=CONFIG]32743[/ATTACH]

[ATTACH=CONFIG]32744[/ATTACH]
0 Kudos
RobertKirkwood
Occasional Contributor III
I would also like to change the position of the tooltip...
0 Kudos
KellyHutchins
Esri Frequent Contributor
Ok so the current tooltip for the Home Button is generated using the HTML title attribute Basically when you add the title attribute to an HTML tag the browser will display a tooltip. The style is browser dependent and I don't know of a way to modify the style.

One approach might be to remove the title attribute then add a new one - maybe data-title and then use the mechanism you are using to generate the other tooltips to generate that one.  Here's a sample that show hiding the existing tooltip and creating a new one using css.

<!DOCTYPE HTML>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">
  <title>Home Extent</title>
  <link rel="stylesheet" type="text/css" href="http://js.arcgis.com/3.8/js/esri/css/esri.css">
  <style>
    html, body, #map {
      padding:0;
      margin:0;
      height:100%;
    }
    #HomeButton {
      position: absolute;
      top: 95px;
      left: 20px;
      z-index: 50;
    }
[data-title]:hover:after {
  content: attr(data-title);
  padding: 4px 8px;
  color: #333;
  position: absolute;
  left: 0;
  top: 100%;
  white-space: nowrap;
  z-index: 20px;
  -moz-border-radius: 5px;
  -webkit-border-radius: 5px;
  border-radius: 5px;
  -moz-box-shadow: 0px 0px 4px #222;
  -webkit-box-shadow: 0px 0px 4px #222;
  box-shadow: 0px 0px 4px #222;
  background-image: -moz-linear-gradient(top, #eeeeee, #cccccc);
  background-image: -webkit-gradient(linear,left top,left bottom,color-stop(0, #eeeeee),color-stop(1, #cccccc));
  background-image: -webkit-linear-gradient(top, #eeeeee, #cccccc);
  background-image: -moz-linear-gradient(top, #eeeeee, #cccccc);
  background-image: -ms-linear-gradient(top, #eeeeee, #cccccc);
  background-image: -o-linear-gradient(top, #eeeeee, #cccccc);
}
  </style>
  <script src="//js.arcgis.com/3.8/"></script>
  <script>

    require([
      "esri/map", 
      "esri/dijit/HomeButton",
      "dojo/i18n!esri/nls/jsapi",
      "dojo/query",
      "dojo/dom-attr",
      "dojo/domReady!"
    ], function(
      Map, HomeButton,esriBundle, query, domAttr
    )  {




      var map = new Map("map", {
        center: [-56.049, 38.485],
        zoom: 3,
        basemap: "streets"
      });
            
      var home = new HomeButton({
        map: map
      }, "HomeButton");
      home.startup();

      query(".home").forEach(function(node){
        //remove the title attribute 
        //Get the title attribute 
        if(domAttr.get(node, "title") === esriBundle.widgets.homeButton.home.title){
          //replace the title attribute with data-title
          domAttr.remove(node, "title");
          domAttr.set(node, "data-title", esriBundle.widgets.homeButton.home.title )
        }

      });


    });
  </script>
</head>
<body>
  <div id="map" class="map">
    <div id="HomeButton"></div>
  </div>
</body>
</html>

RobertKirkwood
Occasional Contributor III
Excellent! Wow, nice work and thanks so much!

[ATTACH=CONFIG]32747[/ATTACH]

So, now i can do the same thing for the Locate button? I will test that out and see if it works for that too...
0 Kudos
RobertKirkwood
Occasional Contributor III
Ok so the current tooltip for the Home Button is generated using the HTML title attribute Basically when you add the title attribute to an HTML tag the browser will display a tooltip. The style is browser dependent and I don't know of a way to modify the style.

One approach might be to remove the title attribute then add a new one - maybe data-title and then use the mechanism you are using to generate the other tooltips to generate that one.  Here's a sample that show hiding the existing tooltip and creating a new one using css.


one more question: what is the format for the Locate button widget? i.e. for the Homebutton its  "esriBundle.widgets.homeButton.home.title"

Thanks again!
0 Kudos
KenBuja
MVP Esteemed Contributor
If you're using an IDE that has debugging, you can pause it and examine esriBundle. That's how I was able to find the right property in this thread.