obihill / restive.js

a designer-friendly jQuery toolkit for responsive Web design
http://www.restivejs.com
MIT License
513 stars 113 forks source link

onAddClass fires on every resize event #14

Closed morganwdavis closed 10 years ago

morganwdavis commented 10 years ago

onAddClass fires on every resize event even if the class has already been added:

$('body').restive({
                        breakpoints:[ '480', '640',  '768',  '960', '100000' ],
                        classes:    [ 'R S', 'R ML', 'R MP', 'R L', 'MAX' ],
                        force_dip: true,
                        onAddClass: function(name) { $('body').trigger('restiveAddClass', name); }
                    });

...elsewhere...

    $('body').on('restiveAddClass', function(e, name) {
        console.log('restiveAddClass = ' + name);
    });

I would expect the onAddClass event to occur only if the class is truly added (meaning: it wasn't there before -- I only want to be notified once, otherwise I'd just use onResize). The only way to work around this is to keep track of the last class name and only trigger my event listener if there was a change. I think the plugin should take care of that.

If it is too late to change this behavior, I would welcome an onChangeClass event that is only called once if jQuery addClass or removeClass executed, and it would pass the class name with a Boolean indicating the add or remove state.

obihill commented 10 years ago

Hi Morgan,

I'm looking into this for you. I'll update you ASAP.

obihill commented 10 years ago

Please see the current version update - 1.3.1. The issue is fixed. Kindly confirm and advise.

morganwdavis commented 10 years ago

Confirmed fixed. Thank you!