Skip to content

Instantly share code, notes, and snippets.

@Morasta
Last active August 29, 2015 14:19
Show Gist options
  • Save Morasta/f55e2dbafb215c310b61 to your computer and use it in GitHub Desktop.
Save Morasta/f55e2dbafb215c310b61 to your computer and use it in GitHub Desktop.
Script to print current Bootstrap viewport breakpoint size
<script src="https://rawgit.com/maciej-gurban/responsive-bootstrap-toolkit/master/js/bootstrap-toolkit.min.js"></script>
<script>
function getCurrentVP(viewport) {
var currentViewport= 'n/a';
if( viewport.is('xs') ) {
currentViewport = 'xs';
}
else if( viewport.is('sm') ) {
currentViewport = 'sm';
}
else if( viewport.is('md') ) {
currentViewport = 'md';
}
else if( viewport.is('lg') ) {
currentViewport = 'lg';
}
return currentViewport;
}
(function($, viewport){
currentViewport = "";
// Initial load handling
$(document).ready(function() {
currentViewport = getCurrentVP(viewport);
console.log('current viewport: '+currentViewport);
});
// Window resize handling
$(window).bind('resize', function() {
viewport.changed(function(){
var newVp = getCurrentVP(viewport);
if (currentViewport != newVp) {
currentViewport = newVp;
console.log("viewport changed to: "+currentViewport);
}
});
});
})(jQuery, ResponsiveBootstrapToolkit);
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment