Беларускі вектар

Belarusian vector

When a widget preference == true (or false)

, , ,

I think this might be useful and save a bit of head scratching to somebody when working with opera widgets preferences.

So say if a checkbox is checked you want a preference value to be TRUE, otherwise FALSE. In my case the code looked like that:

var excludeSVGZ = false;

$('input#excludeSVGZ').change(function(e){
  excludeSVGZ = $(this).attr('checked'); // The value is either TRUE or FALSE
  widget.setPreferenceForKey(excludeSVGZ, 'excludeSVGZ');
});


And when you need to use the preference you could do something like that:

if (excludeSVGZ){
    // Do stuff
}

And this condition will always be TRUE. I've spent quite a bit of time to figure out what's the matter to find that everything was quite easy!

The value is saved as a string, so effectively when you check if (excludeSVGZ){...}, excludeSVGZ will be equal to strings 'true' or 'false' and not to boolean TRUE and FALSE, and thus the condition will always result in TRUE. So to know if a checkbox was checked use this:

if (excludeSVGZ === "true"){
    ...
}

Opera SVG viewer widget v0.3bHow to make widgets not move on click+drag

Write a comment

New comments have been disabled for this post.