You will recieve your password to this address. Address is not made public.

Your preferred username that is used when logging in.

With dynamically changing Title attributes, how to change the tooltips? Created Aug 6, 2010

This thread is solved

Views: 1752     Replies: 3     Last reply Aug 23, 2010  
You must login first before you can use this feature

McCulloch

Posts: 7

Registered:
Aug 6, 2010

With dynamically changing Title attributes, how to change the tooltips?

Posted: Aug 6, 2010

I have a bilingual (English and French) page where the user can click a link to switch languages. The link dynamically changes the title attributes of many of the page's elements, but sadly the tooltips remain fixed in the language when the page was first loaded.

So something like this is triggered, after .tooltip():
$("#MyInputField").attr(
"title","Il s'agit d'un conseil utile pour l'utilisateur.")
The tooltip remains, "This is a helpful hint for the user." Do I have to re-execute tooltip for each changed element?

randyfyfe

Posts: 17

Registered:
Aug 17, 2010

» With dynamically changing Title attributes, how to change the tooltips?

Posted: Aug 17, 2010

Reply to: With dynamically changing Title attributes, how to change the tooltips? , from McCulloch
I believe a title based tooltip ends up creating a div just above the ending body tag.

you will need to edit the html in that div... however if you have multiple tooltips there is really no way of selecting those divs easily. try specifying a different "tipClass" for every tool tip, then run a jquery selction and html manipulation of:


$("#MyInputField").tooltip({tipClass: 'tipClassSpecified'});

$(".tipClassSpecified").text("Il s'agit d'un conseil utile pour l'utilisateur.")

McCulloch

Posts: 7

Registered:
Aug 6, 2010

» » With dynamically changing Title attributes, how to change the tooltips?

Posted: Aug 18, 2010

Reply to: » With dynamically changing Title attributes, how to change the tooltips? , from randyfyfe
Thanks. This is beginning to look really complicated. The tips themselves are created on the page from a user maintained data source, fed into the page with Ajax. So on the page, I don't know which fields may or may not have a tip defined.

Here's one of the functions that gets called when the user switches languages.
function getHints(language)
{
   var hintSelector = "HintEn";
   if (language == "fr") { hintSelector = "HintFr" };
   $.ajax({
      contentType: "application/xml; charset=UTF-8;",
      url: "webGetHints?OpenAgent",
      cache: true,
      dataType: "xml",
      type: "GET",
      success: function (data, textStatus, xmlRequest)
      {
         $("Results > Hint", data).each(function (index)
         {
            $("#" + $("> FieldId", this).text()).attr
               ("title", $("> " + hintSelector, this).text());
         })
      },
      beforeSend: function (data, textStatus, xmlRequest) { },
      complete: function (data, textStatus, xmlRequest) { },
      error: function (data, textStatus, xmlRequest) { }
   })
}
The webGetHints page returns something like this, which is pulled from a table of values maintained by the client.
<?xml version="1.0" encoding="utf-8" ?> 
<Results>
   <Hint>
      <FieldId>getUserLeft</FieldId> 
      <HintEn>Select items from this list for the "Authors" field and then click the move selected [>] button.</HintEn> 
      <HintFr>Sélectionnez les éléments de cette liste pour les «auteurs» des champs puis cliquez sur le mouvement sélectionné touche [>].</HintFr> 
   </Hint>
</Results>
I've left out the bit that handles updating the title attribute dynamically to classes as well as id's and the error handling and such. This all works rather well, but the client wants the tooltips style and functionality not just the browser's display of the title attribute.

randyfyfe

Posts: 17

Registered:
Aug 17, 2010

» » » With dynamically changing Title attributes, how to change the tooltips?

Posted: Aug 23, 2010

Reply to: » » With dynamically changing Title attributes, how to change the tooltips? , from McCulloch
hmm... well you can try this, but its ugly as sin...


function getHints(language)
{
   var hintSelector = "HintEn";
   if (language == "fr") { hintSelector = "HintFr" };
   $.ajax({
      contentType: "application/xml; charset=UTF-8;",
      url: "webGetHints?OpenAgent",
      cache: true,
      dataType: "xml",
      type: "GET",
      success: function (data, textStatus, xmlRequest)
      {
         $("Results > Hint", data).each(function (index)
         {
            $("#" + $("> FieldId", this).text()).attr
               ("title", $("> " + hintSelector, this).text());
            if (language == "fr") {$("div.tooltip:contains('HintEn')").text("HintFr");}
            else {$("div.tooltip:contains('HintFr')").text("HintEn")};

         })
      },
      beforeSend: function (data, textStatus, xmlRequest) { },
      complete: function (data, textStatus, xmlRequest) { },
      error: function (data, textStatus, xmlRequest) { }
   })
}


basically looks for a div with the class of tooltip (default tooltip class name) containing the old text, and replaces it with the new. Its really gross, and I'm not 100% if dropping that in will work, but give it a try and go from there :)