From b7e9a22912834b0259229c18bef7a773acdc4019 Mon Sep 17 00:00:00 2001 From: Andrew Luetgers Date: Wed, 5 Nov 2014 17:24:30 -0600 Subject: [PATCH 1/2] Support for a short circuiting Added support via the new option allowOverlayBars to disable the plugin when OS bars overlay the content. This corresponds with how most modern browsers handle scrollbars, it is often the effect you are going for when you use this plugin and if its already acceptable why run this code. Now you don't have to. --- jquery.scrollbar.js | 50 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 47 insertions(+), 3 deletions(-) diff --git a/jquery.scrollbar.js b/jquery.scrollbar.js index f09975d..3b74982 100644 --- a/jquery.scrollbar.js +++ b/jquery.scrollbar.js @@ -19,13 +19,33 @@ var debug = false; var lmb = 1, px = "px"; + // do scrollbars displace content + function hasOverlayScrollBars() { + // Create the measurement node + var scrollDiv = $("
").css({ + width: "100px", + height: "100px", + overflow: "scroll", + position: "absolute", + top: "-9999px" + })[0]; + + // Get the scroll bar width + document.body.appendChild(scrollDiv); + var scrollBarWidth = scrollDiv.offsetWidth - scrollDiv.clientWidth; + + // Delete the measurement div + document.body.removeChild(scrollDiv); + return !scrollBarWidth; + } + var browser = { "data": {}, - "macosx": win.navigator.platform.toLowerCase().indexOf('mac') !== -1, "mobile": /Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(win.navigator.userAgent), "scroll": null, "scrolls": [], "webkit": win.WebKitPoint ? true : false, + "scrollBarsOverlay": hasOverlayScrollBars(), "log": debug ? function(data, toString){ var output = data; @@ -45,6 +65,30 @@ } }; + + // do scrollbars displace content + function hasOverlayScrollBars() { + // Create the measurement node + var scrollDiv = $("
").css({ + width: "100px", + height: "100px", + overflow: "scroll", + position: "absolute", + top: "-9999px" + })[0]; + + // Get the scroll bar width + document.body.appendChild(scrollDiv); + var scrollBarWidth = scrollDiv.offsetWidth - scrollDiv.clientWidth; + + // Delete the measurement div + document.body.removeChild(scrollDiv); + scrollBarsMeasured = true; + scrollBarsOverlay = !scrollBarWidth; + return scrollBarsOverlay; + } + + var scrollbarsOverlay = hasOverlayScrollBars(); var defaults = { "autoScrollSize": true, // automatically calculate scrollsize @@ -586,7 +630,7 @@ browser.scrolls.splice($.inArray(instance, browser.scrolls), 1); } } else { - if(typeof options != "string"){ + if(typeof options != "string" && !(options && options.allowOverlayBars && browser.scrollBarsOverlay)){ instance = new customScrollbar(container, options); container.data("scrollbar", instance); browser.scrolls.push(instance); @@ -738,4 +782,4 @@ return true; } -})(jQuery, document, window); \ No newline at end of file +})(jQuery, document, window); From 39c4e120e40f1bc8b25c6d0e90d34dd4dc8ff1af Mon Sep 17 00:00:00 2001 From: Andrew Luetgers Date: Wed, 5 Nov 2014 17:30:03 -0600 Subject: [PATCH 2/2] cleanup from prior changes --- jquery.scrollbar.js | 62 ++++++++++++++------------------------------- 1 file changed, 19 insertions(+), 43 deletions(-) diff --git a/jquery.scrollbar.js b/jquery.scrollbar.js index 3b74982..2d56152 100644 --- a/jquery.scrollbar.js +++ b/jquery.scrollbar.js @@ -19,25 +19,25 @@ var debug = false; var lmb = 1, px = "px"; - // do scrollbars displace content - function hasOverlayScrollBars() { - // Create the measurement node - var scrollDiv = $("
").css({ - width: "100px", - height: "100px", - overflow: "scroll", - position: "absolute", - top: "-9999px" - })[0]; - - // Get the scroll bar width - document.body.appendChild(scrollDiv); - var scrollBarWidth = scrollDiv.offsetWidth - scrollDiv.clientWidth; - - // Delete the measurement div - document.body.removeChild(scrollDiv); - return !scrollBarWidth; - } + // do scrollbars displace content + function hasOverlayScrollBars() { + // Create the measurement node + var scrollDiv = $("
").css({ + width: "100px", + height: "100px", + overflow: "scroll", + position: "absolute", + top: "-9999px" + })[0]; + + // Get the scroll bar width + document.body.appendChild(scrollDiv); + var scrollBarWidth = scrollDiv.offsetWidth - scrollDiv.clientWidth; + + // Delete the measurement div + document.body.removeChild(scrollDiv); + return !scrollBarWidth; + } var browser = { "data": {}, @@ -66,30 +66,6 @@ } }; - // do scrollbars displace content - function hasOverlayScrollBars() { - // Create the measurement node - var scrollDiv = $("
").css({ - width: "100px", - height: "100px", - overflow: "scroll", - position: "absolute", - top: "-9999px" - })[0]; - - // Get the scroll bar width - document.body.appendChild(scrollDiv); - var scrollBarWidth = scrollDiv.offsetWidth - scrollDiv.clientWidth; - - // Delete the measurement div - document.body.removeChild(scrollDiv); - scrollBarsMeasured = true; - scrollBarsOverlay = !scrollBarWidth; - return scrollBarsOverlay; - } - - var scrollbarsOverlay = hasOverlayScrollBars(); - var defaults = { "autoScrollSize": true, // automatically calculate scrollsize "autoUpdate": true, // update scrollbar if content/container size changed