Skip to content

Commit 3665133

Browse files
authored
Merge pull request #61 from mikejacobson/check-for-wrapped-right-arrow
Add handleDelayedScrollbar option
2 parents 983c0fc + de52d35 commit 3665133

10 files changed

+109
-8
lines changed

README.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ There are also optional features available:
2626
* [Reverse Scroll](#reverseScroll)
2727
* [Force Scroll to Tab Edge](#scrollToTabEdge)
2828
* [Disable Scroll Arrows on Fully Scrolled](#disableScrollArrowsOnFullyScrolled)
29+
* [Handle Delayed Scrollbar](#handleDelayedScrollbar)
2930
* [Width Multiplier](#widthMultiplier)
3031
* [Tab Click Handler](#tabClickHandler)
3132
* [Custom Scroll Arrow classes](#cssClassArrows)
@@ -140,7 +141,6 @@ If you're using the default scroll setting, this will cause the left scroll arro
140141
If you have the `reverseScroll` option set to `true`, the opposite arrows will disable.
141142

142143

143-
144144
##### widthMultiplier Option
145145

146146
You can also pass in the `widthMultiplier` option:
@@ -367,6 +367,22 @@ $('#tabs-inside-here').scrollingTabs({
367367
Note that if you have the `reverseScroll` option set to `true`, the opposite arrows will disable.
368368

369369

370+
#### <a id="handleDelayedScrollbar"></a>Handle Delayed Scrollbar
371+
372+
If you experience a situation where the right scroll arrow wraps to the next line due to a vertical scrollbar coming into existence on the page *after* the plugin already calculated its width without a scrollbar present, pass in option `handleDelayedScrollbar: true`:
373+
374+
```javascript
375+
$('.nav-tabs').scrollingTabs({
376+
handleDelayedScrollbar: true
377+
});
378+
```
379+
380+
This would occur if, for example, the bulk of the page's content loaded after a delay, and only then did a vertical scrollbar become necessary.
381+
382+
It would also occur if a vertical scrollbar only appeared on selection of a particular tab that had more content than the default tab.
383+
384+
This is not enabled by default because, since a window resize event is not triggered by a vertical scrollbar appearing, it requires adding an iframe to the page that listens for resize events because a scrollbar appearing in the parent window *does* trigger a resize event in the iframe, which then dispatches a resize event to the parent, triggering the plugin to recalculate its width.
385+
370386

371387
#### <a id="widthMultiplier"></a>Width Multiplier
372388

@@ -546,6 +562,7 @@ $.fn.scrollingTabs.defaults.tabs = myTabs;
546562
$.fn.scrollingTabs.defaults.forceActiveTab = true;
547563
$.fn.scrollingTabs.defaults.scrollToTabEdge = true;
548564
$.fn.scrollingTabs.defaults.disableScrollArrowsOnFullyScrolled = true;
565+
$.fn.scrollingTabs.defaults.handleDelayedScrollbar = true;
549566
$.fn.scrollingTabs.defaults.reverseScroll = true;
550567
$.fn.scrollingTabs.defaults.widthMultiplier = 0.5;
551568
$.fn.scrollingTabs.defaults.enableSwiping = true;

dist/jquery.scrolling-tabs.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* jquery-bootstrap-scrolling-tabs
3-
* @version v2.4.0
3+
* @version v2.6.0
44
* @link https://github.com/mikejacobson/jquery-bootstrap-scrolling-tabs
55
* @author Mike Jacobson <[email protected]>
66
* @license MIT License, http://www.opensource.org/licenses/MIT

dist/jquery.scrolling-tabs.js

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* jquery-bootstrap-scrolling-tabs
3-
* @version v2.4.0
3+
* @version v2.6.0
44
* @link https://github.com/mikejacobson/jquery-bootstrap-scrolling-tabs
55
* @author Mike Jacobson <[email protected]>
66
* @license MIT License, http://www.opensource.org/licenses/MIT
@@ -204,6 +204,17 @@
204204
* right-to-left languages. If true, the plugin will
205205
* check the page's <html> tag for attribute dir="rtl"
206206
* and will adjust its behavior accordingly.
207+
* handleDelayedScrollbar:
208+
* set to true if you experience a situation where the
209+
* right scroll arrow wraps to the next line due to a
210+
* vertical scrollbar coming into existence on the page
211+
* after the plugin already calculated its width without
212+
* a scrollbar present. This would occur if, for example,
213+
* the bulk of the page's content loaded after a delay,
214+
* and only then did a vertical scrollbar become necessary.
215+
* It would also occur if a vertical scrollbar only appeared
216+
* on selection of a particular tab that had more content
217+
* than the default tab.
207218
* bootstrapVersion:
208219
* set to 4 if you're using Boostrap 4. Default is 3.
209220
* Bootstrap 4 handles some things differently than 3
@@ -584,13 +595,43 @@
584595
.on(ev.CLICK, stc.tabClickHandler);
585596
}
586597

598+
if (settings.handleDelayedScrollbar) {
599+
ehd.listenForDelayedScrollbar();
600+
}
601+
587602
stc.$win
588603
.off(resizeEventName)
589604
.smartresizeScrtabs(function (e) { evh.handleWindowResize.call(evh, e); }, resizeEventName);
590605

591606
$('body').on(CONSTANTS.EVENTS.FORCE_REFRESH, stc.elementsHandler.refreshAllElementSizes.bind(stc.elementsHandler));
592607
};
593608

609+
p.listenForDelayedScrollbar = function () {
610+
var iframe = document.createElement('iframe');
611+
iframe.id = "scrtabs-scrollbar-resize-listener";
612+
iframe.style.cssText = 'height: 0; background-color: transparent; margin: 0; padding: 0; overflow: hidden; border-width: 0; position: absolute; width: 100%;';
613+
iframe.onload = function() {
614+
var timeout;
615+
616+
function handleResize() {
617+
try {
618+
$(window).trigger('resize');
619+
timeout = null;
620+
} catch(e) {}
621+
}
622+
623+
iframe.contentWindow.addEventListener('resize', function() {
624+
if (timeout) {
625+
clearTimeout(timeout);
626+
}
627+
628+
timeout = setTimeout(handleResize, 100);
629+
});
630+
};
631+
632+
document.body.appendChild(iframe);
633+
};
634+
594635
p.setFixedContainerWidth = function () {
595636
var ehd = this,
596637
stc = ehd.stc,
@@ -1955,6 +1996,7 @@
19551996
tabsPostProcessors: null,
19561997
enableSwiping: false,
19571998
enableRtlSupport: false,
1999+
handleDelayedScrollbar: false,
19582000
bootstrapVersion: 3
19592001
};
19602002

dist/jquery.scrolling-tabs.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/jquery.scrolling-tabs.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jquery-bootstrap-scrolling-tabs",
3-
"version": "2.5.0",
3+
"version": "2.6.0",
44
"description": "jQuery plugin for scrollable Bootstrap Tabs",
55
"homepage": "https://github.com/mikejacobson/jquery-bootstrap-scrolling-tabs",
66
"bugs": "https://github.com/mikejacobson/jquery-bootstrap-scrolling-tabs/issues",

src/js/api.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,5 +156,6 @@ $.fn.scrollingTabs.defaults = {
156156
tabsPostProcessors: null,
157157
enableSwiping: false,
158158
enableRtlSupport: false,
159+
handleDelayedScrollbar: false,
159160
bootstrapVersion: 3
160161
};

src/js/elementsHandler.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,13 +225,43 @@ function ElementsHandler(scrollingTabsControl) {
225225
.on(ev.CLICK, stc.tabClickHandler);
226226
}
227227

228+
if (settings.handleDelayedScrollbar) {
229+
ehd.listenForDelayedScrollbar();
230+
}
231+
228232
stc.$win
229233
.off(resizeEventName)
230234
.smartresizeScrtabs(function (e) { evh.handleWindowResize.call(evh, e); }, resizeEventName);
231235

232236
$('body').on(CONSTANTS.EVENTS.FORCE_REFRESH, stc.elementsHandler.refreshAllElementSizes.bind(stc.elementsHandler));
233237
};
234238

239+
p.listenForDelayedScrollbar = function () {
240+
var iframe = document.createElement('iframe');
241+
iframe.id = "scrtabs-scrollbar-resize-listener";
242+
iframe.style.cssText = 'height: 0; background-color: transparent; margin: 0; padding: 0; overflow: hidden; border-width: 0; position: absolute; width: 100%;';
243+
iframe.onload = function() {
244+
var timeout;
245+
246+
function handleResize() {
247+
try {
248+
$(window).trigger('resize');
249+
timeout = null;
250+
} catch(e) {}
251+
}
252+
253+
iframe.contentWindow.addEventListener('resize', function() {
254+
if (timeout) {
255+
clearTimeout(timeout);
256+
}
257+
258+
timeout = setTimeout(handleResize, 100);
259+
});
260+
};
261+
262+
document.body.appendChild(iframe);
263+
};
264+
235265
p.setFixedContainerWidth = function () {
236266
var ehd = this,
237267
stc = ehd.stc,

src/js/header.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* jquery-bootstrap-scrolling-tabs
3-
* @version v2.4.0
3+
* @version v2.6.0
44
* @link https://github.com/mikejacobson/jquery-bootstrap-scrolling-tabs
55
* @author Mike Jacobson <[email protected]>
66
* @license MIT License, http://www.opensource.org/licenses/MIT

src/js/usage.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,17 @@
197197
* right-to-left languages. If true, the plugin will
198198
* check the page's <html> tag for attribute dir="rtl"
199199
* and will adjust its behavior accordingly.
200+
* handleDelayedScrollbar:
201+
* set to true if you experience a situation where the
202+
* right scroll arrow wraps to the next line due to a
203+
* vertical scrollbar coming into existence on the page
204+
* after the plugin already calculated its width without
205+
* a scrollbar present. This would occur if, for example,
206+
* the bulk of the page's content loaded after a delay,
207+
* and only then did a vertical scrollbar become necessary.
208+
* It would also occur if a vertical scrollbar only appeared
209+
* on selection of a particular tab that had more content
210+
* than the default tab.
200211
* bootstrapVersion:
201212
* set to 4 if you're using Boostrap 4. Default is 3.
202213
* Bootstrap 4 handles some things differently than 3

0 commit comments

Comments
 (0)