Skip to content
This repository has been archived by the owner on Aug 15, 2019. It is now read-only.

Bootstrap default breakpoints #17

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 37 additions & 6 deletions breakpoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,44 @@
$.fn.setBreakpoints = function(settings) {
var options = jQuery.extend({
distinct: true,
breakpoints: new Array(320,480,768,1024)
breakpoints: new Array(320,480,768,992,1200), //Bootstrap default sizes
debounceTimeout: 300
},settings);

// Debounce function for better performace of this plugin
var debounce = function(a,b,c){var d;return function(){var e=this,f=arguments;clearTimeout(d),d=setTimeout(function(){d=null,c||a.apply(e,f)},b),c&&!d&&a.apply(e,f)}}

interval = setInterval(function() {

var w = $(window).width();

var onResize = debounce(function() {

var viewportwidth;

// the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
if (typeof window.innerWidth != 'undefined')
{
viewportwidth = window.innerWidth
}

// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
else if (typeof document.documentElement != 'undefined'
&& typeof document.documentElement.clientWidth !=
'undefined' && document.documentElement.clientWidth != 0)
{
viewportwidth = document.documentElement.clientWidth
}

// older versions of IE
else
{
viewportwidth = document.getElementsByTagName('body')[0].clientWidth
}


var w = viewportwidth;
var done = false;

for (var bp in options.breakpoints.sort(function(a,b) { return (b-a) })) {

// fire onEnter when a browser expands into a new breakpoint
// if in distinct mode, remove all other breakpoints first.
if (!done && w >= options.breakpoints[bp] && lastSize < options.breakpoints[bp]) {
Expand Down Expand Up @@ -84,7 +111,11 @@
if (lastSize != w) {
lastSize = w;
}
},250);
}, options.debounceTimeout);

$(window).on("resize", onResize);
onResize();

};

})(jQuery);