DropDown Default Value,write and read config.js

Post a reply

Smilies
:D :) :( :o :-? 8) :lol: :x :P :oops: :cry: :evil: :roll: :wink:

BBCode is ON
[img] is ON
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: DropDown Default Value,write and read config.js

Re: DropDown Default Value,write and read config.js

by Radon » Thu Oct 21, 2021 2:13 pm

Thank you for the quick answers.
This helps me well.

Re: DropDown Default Value,write and read config.js

by TIV73 » Thu Oct 21, 2021 9:46 am

In addition to the resources posted by drakinite you can also have a look at the dev branch in the code monkey repository for a full implementation. I recently finished adding the new color picker which also utilizes some things you asked about like reading and writing settings and less values.

Re: DropDown Default Value,write and read config.js

by drakinite » Thu Oct 21, 2021 9:20 am

Firstly: if you wish to set a dropdown's default value, the simplest way to do it is via the value property from JavaScript. (https://www.mediamonkey.com/docs/api/cl ... erty_value)

For example, if you wish to set the default value to 10, you would do either of the following:

Code: Select all

qid('SkinFontSize').controlClass.value = '10'
or

Code: Select all

var UI = getAllUIElements();
UI.SkinFontSize.controlClass.value = '10';
Secondly: If you wish for the value to be saved after the user changes their setting, you can use app.getValue and app.setValue. https://www.mediamonkey.com/docs/api/cl ... d_getValue There are plenty of addons that utilize this method for saving user preferences, including the Monkey Groove skin in recent beta builds.

Thirdly: To set LESS variables from JavaScript, there is a new method setLessValues in 5.0.2 beta builds which will let you do it: https://www.mediamonkey.com/docs/api/cl ... LessValues
The first argument to pass is an object with the variable names and values. The second argument is your skin's ID. In your case, that would be "DarkSilver". If you do NOT specify a skin ID, this will set LESS values for ALL skins.

So here's an example of how you could implement it, in your config file's save function:

Code: Select all

var UI = getAllUIElements();
var myFontSize = UI.SkinFontSize.controlClass.value + 'px';
setLessValues({ baseFontSize: myFontSize }, 'DarkSilver');
(P.S. Please note that there are future plans to make it easier for skin developers to make customizable settings, without having to create a config.js and config.html. However, I do not know when it will be ready.)

DropDown Default Value,write and read config.js

by Radon » Wed Oct 20, 2021 7:55 am

Hello, and please excuse me,
for my bad English, my native language is German.

I would like to add a font-size setting for my skin.
I would like to achieve this setting in MM5 under Options\Design.

I have already written or edited the corresponding file "config.html & config.js"
several times. I just can't get it to work.
The dropdown in config.html is created and also works.

Code: Select all

<div data-id="SkinFontSize" data-control-class="Dropdown" data-init-params="{readOnly: true,preload: true}" class="dropdown">
    <option>10</option>
    <option>11</option>
    <option>12</option>
</div>

Question, how do I set a default value, the dropdown menu is always empty ?
The entries are only displayed when you select them.

Question, how should I proceed in config.js to read the @baseFontSize variable,
and read the value from the dropdown menu and write it to the @baseFontSize variable.

I have searched all the MM5 help files and the forum, but have not found a solution.
An answer would be nice, thank you

Top