abpetkov / switchery

iOS 7 style switches for your checkboxes
http://abpetkov.github.io/switchery/
2.06k stars 479 forks source link

Switch Checked + Modal Bootstrap #60

Open raphael22 opened 9 years ago

raphael22 commented 9 years ago

Hi,

got a issue with checked switch in a modal window,

computed width is "50px" not "20px" as usual.

I quick-fix it but it's not a solution

if(parseInt(window.getComputedStyle(switcher).width) - jack.offsetWidth > 20){
        jack.style.left = '20px';
}
abpetkov commented 9 years ago

@raphael22 can you provide a working example?

cardcc commented 8 years ago

Almost the same thing here... but it returns null...

It happened inside a modal with 2 iframes (tabs), one was hidden. It's due to known bug: https://bugzilla.mozilla.org/show_bug.cgi?id=548397

In these cases window.getComputedStyle returns null, so this code on line 1699 breaks:

if (window.getComputedStyle) 
  jack.style.left = parseInt(window.getComputedStyle(switcher).width) - parseInt(window.getComputedStyle(jack).width) + 'px';
else 
  jack.style.left = parseInt(switcher.currentStyle['width']) - parseInt(jack.currentStyle['width']) + 'px';

quick workaround:


if (window.getComputedStyle) {
    if ( ! window.getComputedStyle(switcher) ) {
       jack.style.left = '20px';
    } else {
       jack.style.left = parseInt(window.getComputedStyle(switcher).width) - parseInt(window.getComputedStyle(jack).width) + 'px';
    }
}

not pretty though