Page 1 of 1

edit the title of specific block - custom.js

Posted: Tuesday 13 August 2019 21:51
by marmachine
Hi,

I have a block with wind data.
The block however has a title with too much information;

Code: Select all

<div data-id="88" class="mh transbg block_88 col-xs-3 hover" data-toggle="modal" data-target="#opengraph88">
  <div class="col-xs-4 col-icon">
  <em class="wi wi-wind-direction icon" style="-webkit-transform: rotate(410deg);-moz-transform: rotate(410deg);-ms-transform: rotate(410deg);-o-transform: rotate(410deg); transform: rotate(410deg);"></em>
  </div>
  <div class="col-xs-8 col-data"><strong class="title">0.7 m/s, 230° zuid-west</strong></div>
</div>
I wanted to remove a part from the title, so that 0.7 m/s, 230° zuid-west would become this: 0.7 m/s zuid-west
I had some trouble to find the right handles, but i think i already got this working and fixed with some custom js scripting, but is there an easier way to get such things done?

Code: Select all

$("div[data-id=88] div.col-data").each(function() {
            var orgtext = $("div[data-id=88] .col-data .title").text();
            var cuttext = orgtext.replace(/\,.*° /, '');
            $(this).html = $("div[data-id=88] .col-data .title").text(cuttext);
        });

Re: edit the title of specific block - custom.js

Posted: Tuesday 13 August 2019 22:55
by Lokonli
Maybe you can create a custom blocktype in the function getExtendedBlockTypes in custom.js.

See blocks.js how to define blocktypes.

Re: edit the title of specific block - custom.js

Posted: Wednesday 14 August 2019 19:46
by Lokonli
Lokonli wrote: Tuesday 13 August 2019 22:55 Maybe you can create a custom blocktype in the function getExtendedBlockTypes in custom.js.

See blocks.js how to define blocktypes.
hmm, I see my suggestion won't work: The title content for a wind device is created hard coded (function getStatusBlock in blocks.js)

Ideas how to make it configurable in Dashticz? What kind of parameter should we add to the block definition?

Your solution also works. An alternative could be to create a text device in Domoticz, and use some scripting to set it to the right text.