This repository has been archived by the owner on Aug 15, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 85
More accurate calculations on non-WebKit browsers #6
Open
rdebeasi
wants to merge
4
commits into
xoxco:master
Choose a base branch
from
352Media:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+41
−6
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
/* | ||
Breakpoints.js | ||
version 1.0 | ||
version 1.1 | ||
|
||
Creates handy events for your responsive design breakpoints | ||
|
||
Copyright 2011 XOXCO, Inc | ||
Copyright 2011-2012 XOXCO, Inc | ||
http://xoxco.com/ | ||
With contributions from 352 Media Group | ||
http://www.352media.com/ | ||
|
||
Documentation for this plugin lives here: | ||
http://xoxco.com/projects/code/breakpoints | ||
|
@@ -27,6 +29,32 @@ | |
lastSize = 0; | ||
}; | ||
|
||
var scrollbarWidth = 0; | ||
|
||
$.getScrollbarWidth = function() { | ||
/* Gets the width of the OS scrollbar | ||
https://github.com/brandonaaron/jquery-getscrollbarwidth/blob/master/jquery.getscrollbarwidth.js */ | ||
|
||
if ( !scrollbarWidth ) { | ||
if ( $.browser.msie ) { | ||
var $textarea1 = $('<textarea cols="10" rows="2"></textarea>') | ||
.css({ position: 'absolute', top: -1000, left: -1000 }).appendTo('body'), | ||
$textarea2 = $('<textarea cols="10" rows="2" style="overflow: hidden;"></textarea>') | ||
.css({ position: 'absolute', top: -1000, left: -1000 }).appendTo('body'); | ||
scrollbarWidth = $textarea1.width() - $textarea2.width(); | ||
$textarea1.add($textarea2).remove(); | ||
} else { | ||
var $div = $('<div />') | ||
.css({ width: 100, height: 100, overflow: 'auto', position: 'absolute', top: -1000, left: -1000 }) | ||
.prependTo('body').append('<div />').find('div') | ||
.css({ width: '100%', height: 200 }); | ||
scrollbarWidth = 100 - $div.width(); | ||
$div.parent().remove(); | ||
} | ||
} | ||
return scrollbarWidth; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. on this line, you assume that body height is bigger than window height and make calculation according to that. |
||
}; | ||
|
||
$.fn.setBreakpoints = function(settings) { | ||
var options = jQuery.extend({ | ||
distinct: true, | ||
|
@@ -36,7 +64,14 @@ | |
|
||
interval = setInterval(function() { | ||
|
||
var w = $(window).width(); | ||
var w; | ||
if ($.browser.webkit) { | ||
w = $(window).width(); | ||
} else { | ||
w = $(window).width() + $.getScrollbarWidth(); | ||
} | ||
|
||
// For continuous (i.e., most non-print) media, the width specified in a media query includes the scrollbar (if one exists). In WebKit, .width() includes the scrollbar. In other browsers, it does not, so we need to add the width of the scrollbar ourselves. | ||
var done = false; | ||
|
||
for (var bp in options.breakpoints.sort(function(a,b) { return (b-a) })) { | ||
|
@@ -87,4 +122,4 @@ | |
},250); | ||
}; | ||
|
||
})(jQuery); | ||
})(jQuery); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
jquery deprecated $.browser with version 1.9
Maybe we can define something like that instead of $.browser.msie:
var isMsie = /MSIE/gi.test(navigator.userAgent);