Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bootstrap4 #52

Open
m-r-alizadeh opened this issue Jun 12, 2017 · 14 comments
Open

Bootstrap4 #52

m-r-alizadeh opened this issue Jun 12, 2017 · 14 comments

Comments

@m-r-alizadeh
Copy link

m-r-alizadeh commented Jun 12, 2017

Fix for bootstrap v4:

bootstrap: {
  'xs': $('<div class="device-xs hidden-sm-up">xs</div>'),
  'sm': $('<div class="device-sm hidden-xs-down hidden-md-up">sm</div>'),
  'md': $('<div class="device-md hidden-sm-down hidden-lg-up">md</div>'),
  'lg': $('<div class="device-lg hidden-xl-up hidden-md-down">lg</div>'),
  'xl': $('<div class="device-lg hidden-lg-down">xl</div>')
}

If you have better way please let us now.
thanks

@cmachanic
Copy link

Hello there!

How would you apply a fix for v4 Beta? Their previous display utility classes have been dropped.

@exreplay
Copy link

Hey,

i fixed it by changing it to the following:

var visibilityDivs = {
    'xs': $('<div class="device-xs d-block d-sm-none"></div>'),
    'sm': $('<div class="device-sm d-none d-sm-block d-md-none"></div>'),
    'md': $('<div class="device-md d-none d-sm-none d-md-block d-lg-none"></div>'),
    'lg': $('<div class="device-lg d-none d-sm-none d-md-none d-lg-block d-xl-none"></div>'),
    'xl': $('<div class="device-lg d-none d-sm-none d-md-none d-lg-none d-xl-block"></div>')
};

@cmachanic
Copy link

Great. Thanks, exreplay! I'll give it a shot!

@robcarey
Copy link

exreplay - changing "what" in particular to that? The source does not contain that var. Did you add it somewhere?

@cmachanic
Copy link

Hi robcarey,

I didn't take exreplay's var literally. Here's how I interpreted his solution, and it works perfectly:

detectionDivs: {
    // Bootstrap 4 beta
    bootstrap: {
        'xs': $('<div class="device-xs d-block d-sm-none"></div>'),
        'sm': $('<div class="device-sm d-none d-sm-block d-md-none"></div>'),
        'md': $('<div class="device-md d-none d-sm-none d-md-block d-lg-none"></div>'),
        'lg': $('<div class="device-lg d-none d-sm-none d-md-none d-lg-block d-xl-none"></div>'),
        'xl': $('<div class="device-lg d-none d-sm-none d-md-none d-lg-none d-xl-block"></div>')
    }
}

@robcarey
Copy link

Awesome thanks 36lpi ! I need to be more open minded I think :)

@sonnysavage
Copy link

sonnysavage commented Aug 23, 2017

It can be simplified further (with the correction of device-xl):

bootstrap: {
    'xs': $('<div class="device-xs d-block d-sm-none"></div>'),
    'sm': $('<div class="device-sm d-none d-sm-block d-md-none"></div>'),
    'md': $('<div class="device-md d-none d-md-block d-lg-none"></div>'),
    'lg': $('<div class="device-lg d-none d-lg-block d-xl-none"></div>'),
    'xl': $('<div class="device-xl d-none d-xl-block"></div>')
}

@ethanbeyer
Copy link

I'm having an issue with the following BS4 divs and their implementation:

(function($, viewport){

    // Bootstrap 4 Divs
    var bootstrapDivs = {
        'xs': $('<div class="device-xs d-block d-sm-none"></div>'),
        'sm': $('<div class="device-sm d-none d-sm-block d-md-none"></div>'),
        'md': $('<div class="device-md d-none d-md-block d-lg-none"></div>'),
        'lg': $('<div class="device-lg d-none d-lg-block d-xl-none"></div>'),
        'xl': $('<div class="device-xl d-none d-xl-block butts"></div>')
    };
    viewport.use('bs4', bootstrapDivs);

    // log
    var doSomething = function() {
        console.log('Current breakpoint: ', viewport.current());
    }

    // immediately
    doSomething();

    // on resize
    $(window).resize(
        viewport.changed(function() {
            doSomething();
        })
    );

})(jQuery, ResponsiveBootstrapToolkit);

This only happens on page load: Current breakpoint: unrecognized (that variable is being set here)

If the window changes size, it will print out the correct breakpoint: Current breakpoint: sm

Is this a a bug, a by-product of using custom visibility classes, or something I am just doing wrong?

@LazyRecon
Copy link

LazyRecon commented Nov 17, 2017

hi @ethanbeyer try to do call resize() function after have attached to window object like here

(function($, viewport){

    var visibilityDivs = {
        'xs': $('<div class="d-xs-block d-sm-none d-md-none d-lg-none d-xl-none"></div>'),
        'sm': $('<div class="d-none d-sm-block d-md-none d-lg-none d-xl-none"></div>'),
        'md': $('<div class="d-none d-md-block d-sm-none d-lg-none d-xl-none"></div>'),
        'lg': $('<div class="d-none d-lg-block d-sm-none d-md-none d-xl-none"></div>'),
        'xl': $('<div class="d-none d-xl-block d-sm-none d-md-none d-lg-none"></div>'),
    };

    viewport.use('custom', visibilityDivs);

    var doSomething = function() {
        console.log('Current breakpoint: ', viewport.current());
    }

    // on resize
    $(window).resize(
        viewport.changed(function() {
            doSomething();
        })
    ).resize();

})(jQuery, ResponsiveBootstrapToolkit);

@ethanbeyer
Copy link

@LazyRecon ah, thank you! That works perfectly. Better job of invoking the script at run, also.

Cheers!!

@dennisenderink
Copy link

dennisenderink commented May 31, 2018

It's sufficient to just add the following snippet before the DOM loaded callback (when required or imported for example):

viewport.breakpoints = {
    'xs': $('<div class="d-xs-block d-sm-none d-md-none d-lg-none d-xl-none"></div>'),
    'sm': $('<div class="d-none d-sm-block d-md-none d-lg-none d-xl-none"></div>'),
    'md': $('<div class="d-none d-md-block d-sm-none d-lg-none d-xl-none"></div>'),
    'lg': $('<div class="d-none d-lg-block d-sm-none d-md-none d-xl-none"></div>'),
    'xl': $('<div class="d-none d-xl-block d-sm-none d-md-none d-lg-none"></div>'),
};

@miksh7
Copy link

miksh7 commented Sep 24, 2018

Is there a benefit of testing media queries programmatically by window.matchMedia ?

@maciej-gurban
Copy link
Owner

@miksh7 If you're developing for modern browsers only you can manage perfectly well with matchMedia. If you're developing something modern though you're likely using a UI framework for React/Vue/Angular - most of which nowadays offer similar functionality by providing components like <Hidden xsDown> or <Grid xs={4}> etc.

If you need bulletproof older browser support, this lib would be the way to go. While the abstraction RBT provides is rather thin, it's still pretty useful if you don't want to write your own logic that does the .is('>=xs').

@wparad
Copy link

wparad commented May 31, 2020

And without jQuery
responsive-toolkit.js.txt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests