Skip to content

Commit 8ff9dfa

Browse files
authored
Merge pull request #29 from mikejacobson/custom-arrows
Add leftArrowContent, rightArrowContent options
2 parents a20f29d + 9a2e4e9 commit 8ff9dfa

17 files changed

+343
-37
lines changed

README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ There are also optional features available:
2929
* [Width Multiplier](#widthMultiplier)
3030
* [Tab Click Handler](#tabClickHandler)
3131
* [Custom Scroll Arrow classes](#cssClassArrows)
32+
* [Custom Scroll Arrow content](#customArrowsContent)
3233
* [Enable Horizontal Swiping for Touch Screens](#allowScrollbar)
3334

3435

@@ -397,6 +398,38 @@ $('#tabs-inside-here').scrollingTabs({
397398
});
398399
```
399400

401+
#### <a id="customArrowsContent"></a>Custom Scroll Arrow content
402+
403+
You can pass in custom values for the left- and right scroll arrow HTML using options `leftArrowContent` and `rightArrowContent`. This will override any custom `cssClassLeftArrow` and `cssClassRightArrow` settings.
404+
405+
For example, if you wanted to use svg icons, you could set them like so:
406+
407+
```javascript
408+
$('#tabs-inside-here').scrollingTabs({
409+
tabs: myTabs,
410+
leftArrowContent: [
411+
'<div class="custom-arrow">',
412+
' <svg class="icon icon-point-left">',
413+
' <use xlink:href="#icon-point-left"></use>',
414+
' </svg>',
415+
'</div>'
416+
].join(''),
417+
rightArrowContent: [
418+
'<div class="custom-arrow">',
419+
' <svg class="icon icon-point-right">',
420+
' <use xlink:href="#icon-point-right"></use>',
421+
' </svg>',
422+
'</div>'
423+
].join('')
424+
});
425+
```
426+
427+
You would then need to add some CSS to make them work correctly if you don't give them the default `scrtabs-tab-scroll-arrow` classes. This plunk shows it working with svg icons:
428+
http://plnkr.co/edit/2MdZCAnLyeU40shxaol3?p=preview
429+
430+
431+
432+
400433
#### <a id="allowScrollbar"></a>Enable Horizontal Swiping for Touch Screens
401434

402435
To enable horizontal swiping for touch screens, you need to enable horizontal scrolling&mdash;and therefore the horizontal scrollbar&mdash;for the tabs. For WebKit-based browsers, the scrollbar can then be hidden via CSS, but for browsers that don't support `::-webkit-scrollbar` (see [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/CSS/::-webkit-scrollbar) for details), the scrollbar will be visible (which is what this plugin was originally built to prevent).

bower.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": "1.1.0",
3+
"version": "1.2.0",
44
"main": [
55
"./dist/jquery.scrolling-tabs.js",
66
"./dist/jquery.scrolling-tabs.css"

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 v1.1.0
3+
* @version v1.2.0
44
* @link https://github.com/mikejacobson/jquery-bootstrap-scrolling-tabs
55
* @author Mike Jacobson <michaeljjacobson1@gmail.com>
66
* @license MIT License, http://www.opensource.org/licenses/MIT

dist/jquery.scrolling-tabs.js

Lines changed: 54 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* jquery-bootstrap-scrolling-tabs
3-
* @version v1.1.0
3+
* @version v1.2.0
44
* @link https://github.com/mikejacobson/jquery-bootstrap-scrolling-tabs
55
* @author Mike Jacobson <michaeljjacobson1@gmail.com>
66
* @license MIT License, http://www.opensource.org/licenses/MIT
@@ -118,6 +118,33 @@
118118
* .scrtabs-tab-scroll-arrow
119119
* .scrtabs-tab-scroll-arrow-left
120120
* .scrtabs-tab-scroll-arrow-right
121+
* leftArrowContent, rightArrowContent:
122+
* custom HTML string for the left and right scroll
123+
* arrows. This will override any custom cssClassLeftArrow
124+
* and cssClassRightArrow settings.
125+
* For example, if you wanted to use svg icons, you
126+
* could set them like so:
127+
128+
* leftArrowContent: [
129+
* '<div class="custom-arrow">',
130+
* ' <svg class="icon icon-point-left">',
131+
* ' <use xlink:href="#icon-point-left"></use>',
132+
* ' </svg>',
133+
* '</div>'
134+
* ].join(''),
135+
* rightArrowContent: [
136+
* '<div class="custom-arrow">',
137+
* ' <svg class="icon icon-point-right">',
138+
* ' <use xlink:href="#icon-point-right"></use>',
139+
* ' </svg>',
140+
* '</div>'
141+
* ].join('')
142+
*
143+
* You would then need to add some CSS to make them
144+
* work correctly if you don't give them the
145+
* default scrtabs-tab-scroll-arrow classes.
146+
* This plunk shows it working with svg icons:
147+
* http://plnkr.co/edit/2MdZCAnLyeU40shxaol3?p=preview
121148
*
122149
*
123150
* On tabs data change:
@@ -200,7 +227,6 @@
200227
CONTINUOUS_SCROLLING_TIMEOUT_INTERVAL: 50, // timeout interval for repeatedly moving the tabs container
201228
// by one increment while the mouse is held down--decrease to
202229
// make mousedown continous scrolling faster
203-
SCROLL_ARROW_WIDTH: 20,
204230
SCROLL_OFFSET_FRACTION: 6, // each click moves the container this fraction of the fixed container--decrease
205231
// to make the tabs scroll farther per click
206232

@@ -324,12 +350,15 @@
324350
var ehd = this,
325351
stc = ehd.stc,
326352
$tabsContainer = stc.$tabsContainer,
327-
$leftArrow = $tabsContainer.find('.scrtabs-tab-scroll-arrow-left'),
328-
$rightArrow = $tabsContainer.find('.scrtabs-tab-scroll-arrow-right');
353+
$leftArrow,
354+
$rightArrow;
329355

330356
stc.isNavPills = false;
331357

332358
stc.$fixedContainer = $tabsContainer.find('.scrtabs-tabs-fixed-container');
359+
$leftArrow = stc.$fixedContainer.prev();
360+
$rightArrow = stc.$fixedContainer.next();
361+
333362
stc.$movableContainer = $tabsContainer.find('.scrtabs-tabs-movable-container');
334363
stc.$tabsUl = $tabsContainer.find('.nav-tabs');
335364

@@ -734,7 +763,9 @@
734763
$activeTab,
735764
activeTabLeftPos,
736765
activeTabRightPos,
737-
rightArrowLeftPos;
766+
rightArrowLeftPos,
767+
leftScrollArrowWidth,
768+
rightScrollArrowWidth;
738769

739770
if (!stc.scrollArrowsVisible) {
740771
return;
@@ -756,13 +787,17 @@
756787
rightArrowLeftPos = stc.fixedContainerWidth - RIGHT_OFFSET_BUFFER;
757788

758789
if (activeTabRightPos > rightArrowLeftPos) { // active tab off right side
759-
stc.movableContainerLeftPos -= (activeTabRightPos - rightArrowLeftPos + CONSTANTS.SCROLL_ARROW_WIDTH);
760-
smv.slideMovableContainerToLeftPos();
761-
return true;
762-
} else if (activeTabLeftPos < CONSTANTS.SCROLL_ARROW_WIDTH) { // active tab off left side
763-
stc.movableContainerLeftPos += CONSTANTS.SCROLL_ARROW_WIDTH - activeTabLeftPos;
790+
rightScrollArrowWidth = stc.$slideRightArrow.outerWidth();
791+
stc.movableContainerLeftPos -= (activeTabRightPos - rightArrowLeftPos + rightScrollArrowWidth);
764792
smv.slideMovableContainerToLeftPos();
765793
return true;
794+
} else {
795+
leftScrollArrowWidth = stc.$slideLeftArrow.outerWidth();
796+
if (activeTabLeftPos < leftScrollArrowWidth) { // active tab off left side
797+
stc.movableContainerLeftPos += leftScrollArrowWidth - activeTabLeftPos;
798+
smv.slideMovableContainerToLeftPos();
799+
return true;
800+
}
766801
}
767802

768803
return false;
@@ -935,8 +970,10 @@
935970

936971
function getNewElScrollerElementWrappingNavTabsInstance($navTabsInstance, settings) {
937972
var $tabsContainer = $('<div class="scrtabs-tab-container"></div>'),
938-
$leftArrow = $('<div class="scrtabs-tab-scroll-arrow scrtabs-tab-scroll-arrow-left"><span class="' + settings.cssClassLeftArrow + '"></span></div>'),
939-
$rightArrow = $('<div class="scrtabs-tab-scroll-arrow scrtabs-tab-scroll-arrow-right"><span class="' + settings.cssClassRightArrow + '"></span></div>'),
973+
leftArrowContent = settings.leftArrowContent || '<div class="scrtabs-tab-scroll-arrow scrtabs-tab-scroll-arrow-left"><span class="' + settings.cssClassLeftArrow + '"></span></div>',
974+
$leftArrow = $(leftArrowContent),
975+
rightArrowContent = settings.rightArrowContent || '<div class="scrtabs-tab-scroll-arrow scrtabs-tab-scroll-arrow-right"><span class="' + settings.cssClassRightArrow + '"></span></div>',
976+
$rightArrow = $(rightArrowContent),
940977
$fixedContainer = $('<div class="scrtabs-tabs-fixed-container"></div>'),
941978
$movableContainer = $('<div class="scrtabs-tabs-movable-container"></div>');
942979

@@ -1158,7 +1195,7 @@
11581195

11591196
$scroller.initTabs();
11601197

1161-
listenForDropdownMenuTabs($scroller);
1198+
listenForDropdownMenuTabs($scroller, scrollingTabsControl);
11621199

11631200
return $scroller;
11641201
}
@@ -1357,7 +1394,7 @@
13571394
return isInitTabsRequired;
13581395
}
13591396

1360-
function listenForDropdownMenuTabs($scroller) {
1397+
function listenForDropdownMenuTabs($scroller, stc) {
13611398
var $ddMenu;
13621399

13631400
// for dropdown menus to show, we need to move them out of the
@@ -1398,7 +1435,7 @@
13981435

13991436
// make sure the menu doesn't go off the right side of the page
14001437
ddMenuRightX = $ddMenu.width() + ddLiOffset.left;
1401-
tabsContainerMaxX = $scroller.width() - (CONSTANTS.SCROLL_ARROW_WIDTH + 1);
1438+
tabsContainerMaxX = $scroller.width() - (stc.$slideRightArrow.outerWidth() + 1);
14021439
ddMenuTargetLeft = ddLiOffset.left;
14031440

14041441
if (ddMenuRightX > tabsContainerMaxX) {
@@ -1661,6 +1698,8 @@
16611698
tabClickHandler: null,
16621699
cssClassLeftArrow: 'glyphicon glyphicon-chevron-left',
16631700
cssClassRightArrow: 'glyphicon glyphicon-chevron-right',
1701+
leftArrowContent: '',
1702+
rightArrowContent: '',
16641703
enableSwiping: false
16651704
};
16661705

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": "1.1.0",
3+
"version": "1.2.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",

run/index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@
3232

3333
<ul>
3434
<li><a href="markup-only.html">Markup-only Tabs</a></li>
35-
<li><a href="data-driven.html">Data-driven Tabs</a></li>
35+
<li><a href="data-driven.html">Data-driven Tabs</a></li>
36+
<li><a href="markup-only-svg.html">Markup-only Tabs with SVG Arrows</a></li>
3637
</ul>
3738

3839
</body>

0 commit comments

Comments
 (0)