DropDown Default Value,write and read config.js

To discuss development of addons / skins / customization of MediaMonkey.

Moderators: jiri, drakinite, Addon Administrators

Radon
Posts: 17
Joined: Mon Jun 16, 2014 8:58 am

DropDown Default Value,write and read config.js

Post by Radon »

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
drakinite
Posts: 965
Joined: Tue May 12, 2020 10:06 am
Contact:

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

Post by drakinite »

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.)
Image
Student electrical-computer engineer, web programmer, part-time MediaMonkey developer, full-time MediaMonkey enthusiast
I uploaded many addons to MM's addon page, but not all of those were created by me. "By drakinite, Submitted by drakinite" means I made it on my own time. "By Ventis Media, Inc., Submitted by drakinite" means it may have been made by me or another MediaMonkey developer, so instead of crediting/thanking me, please thank the team. You can still ask me for support on any of our addons.
TIV73
Posts: 229
Joined: Sat Nov 12, 2011 1:31 pm

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

Post by TIV73 »

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.
Radon
Posts: 17
Joined: Mon Jun 16, 2014 8:58 am

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

Post by Radon »

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