influxweb / cornerstoneUX.smartTabs

A jQuery plug-in to control tab/accordion functions primarily for responsive sites.
http://influxweb.github.io/cornerstoneUX.smartTabs/
MIT License
1 stars 0 forks source link

Unnecessarily re-initializing tabs on mobile devices #1

Open steveosoule opened 8 years ago

steveosoule commented 8 years ago

On some mobile devices, scrolling can a window resize event to fire. The plugin then responds and unnecessarily redraws the tabs. Then, when the tabs are redrawn, the original .current tab doesn't stay open.

Something like this could help the base.resize() function from unnecessarily re-initializing:

// ...
base.cachedViewport = 0;

base.resize = function () {
    base.viewport = $(window).outerWidth();

    if( base.viewport === base.cachedViewport ){
        return;
    }
    base.cachedViewport = base.viewport;

    if (base.viewport <= base.options.breakpoint && base.options.layout == 'auto') {
        base.$el.removeClass('tabs');
        base.$el.addClass('accordion');
    }
    else if (base.viewport > base.options.breakpoint && base.options.layout == 'auto') {
        base.$el.removeClass('accordion');
        base.$el.addClass('tabs');
    };
    base.init();
};

// Run Functions
base.init();
base.navigation();
$(window).on('resize', function () {
    base.resize();
});
// ...

I didn't really look at how to fix the part where when the tabs are re-initialized the .current tab changes.

influxweb commented 8 years ago

Thanks for the bug report and coding details; I'll take a look into it. I've been working on a rewrite of this script as well as a superceding version which doesn't require JavaScript.