Change gadget title dynamically

Christian_Schönert January 14, 2019

Hello,

so I implemented a gadget that shows information based on filters that users can configure. Currently I am having a static title defined in the ModulePrefs in gadget.xml title="__MSG_gadget.title__" which refers to the gadget.title in messages.xml. This all works fine and well, but how do I implement a dynamic title?

Or more precise: How can I set the title to the name of the current filter in use? A generic method of dynamically setting the title would be perfect for future use.

 

Regards

Chris

1 answer

0 votes
Albrit Bendo July 2, 2019

You need to identify the gadget:

var gadget = [
{
id:
title:
}]

and then add the function.

if(text)
text.title = item.title;

Hope this helps a bit.

Christian_Schönert July 3, 2019

Hi Albrit,

it looks like something of the right direction, although I seem to be missing where and what to put.

'identifiy the gadget':

Do you mean, find the gadget in a javascript context and then change its value? Im not sure where this happens. Also I am wondering about the code you posted. Either I'm stuck with my thoughts, or there is some information missing.

Or is this inside the gadget.xml where you put the javascript code? Can you give me some more information?

Albrit Bendo August 21, 2019

Hi @Christian_Schönert

"How can I set the title to the name of the current filter in use?"

On gadget.xml you need to define your UserPref:

<UserPref name="name" display_name="Title:" datatype="string"/>

 On myPlugin.js (which is your JavaScript file) you write the function:

var gadget = [
{
id:"gadget-key",
title: "" // Empty
}];

gadget.forEach(function(item) {
var element = parent.document.getElementById(item.id) // where element is the title
if (element) { // if there is an input for title
item.title = prefs.getString("name"); // here you can use some JavaScript API
}
});

And that should be all. 

 

If this does the trick you are looking for, please accept my answer for future use.

Suggest an answer

Log in or Sign up to answer