|
1 | 1 | /** |
2 | 2 | * jquery-bootstrap-scrolling-tabs |
3 | | - * @version v2.1.0 |
| 3 | + * @version v2.1.1 |
4 | 4 | * @link https://github.com/mikejacobson/jquery-bootstrap-scrolling-tabs |
5 | 5 | * @author Mike Jacobson <michaeljjacobson1@gmail.com> |
6 | 6 | * @license MIT License, http://www.opensource.org/licenses/MIT |
|
152 | 152 | * right-to-left languages. If true, the plugin will |
153 | 153 | * check the page's <html> tag for attribute dir="rtl" |
154 | 154 | * and will adjust its behavior accordingly. |
| 155 | + * bootstrapVersion: |
| 156 | + * set to 4 if you're using Boostrap 4. Default is 3. |
| 157 | + * Bootstrap 4 handles some things differently than 3 |
| 158 | + * (e.g., the 'active' class gets applied to the tab's |
| 159 | + * 'li > a' element rather than the 'li' itself). |
155 | 160 | * |
156 | 161 | * |
157 | 162 | * On tabs data change: |
|
842 | 847 | stc = smv.stc, |
843 | 848 | RIGHT_OFFSET_BUFFER = 20, |
844 | 849 | $activeTab, |
| 850 | + $activeTabAnchor, |
845 | 851 | activeTabLeftPos, |
846 | 852 | activeTabRightPos, |
847 | 853 | rightArrowLeftPos, |
|
852 | 858 | return; |
853 | 859 | } |
854 | 860 |
|
855 | | - $activeTab = stc.$tabsUl.find('li.active'); |
| 861 | + if (stc.usingBootstrap4) { |
| 862 | + $activeTabAnchor = stc.$tabsUl.find('li > .nav-link.active'); |
| 863 | + if ($activeTabAnchor.length) { |
| 864 | + $activeTab = $activeTabAnchor.parent(); |
| 865 | + } |
| 866 | + } else { |
| 867 | + $activeTab = stc.$tabsUl.find('li.active'); |
| 868 | + } |
856 | 869 |
|
857 | | - if (!$activeTab.length) { |
| 870 | + if (!$activeTab || !$activeTab.length) { |
858 | 871 | return; |
859 | 872 | } |
860 | 873 |
|
|
867 | 880 |
|
868 | 881 | rightArrowLeftPos = stc.fixedContainerWidth - RIGHT_OFFSET_BUFFER; |
869 | 882 |
|
870 | | - if (activeTabRightPos > rightArrowLeftPos) { // active tab off right side |
871 | | - rightScrollArrowWidth = stc.$slideRightArrow.outerWidth(); |
872 | | - stc.movableContainerLeftPos -= (activeTabRightPos - rightArrowLeftPos + rightScrollArrowWidth); |
873 | | - smv.slideMovableContainerToLeftPos(); |
874 | | - return true; |
875 | | - } else { |
| 883 | + if (stc.rtl) { |
876 | 884 | leftScrollArrowWidth = stc.$slideLeftArrow.outerWidth(); |
877 | | - if (activeTabLeftPos < leftScrollArrowWidth) { // active tab off left side |
878 | | - stc.movableContainerLeftPos += leftScrollArrowWidth - activeTabLeftPos; |
| 885 | + |
| 886 | + if (activeTabLeftPos < 0) { // active tab off left side |
| 887 | + stc.movableContainerLeftPos += activeTabLeftPos; |
879 | 888 | smv.slideMovableContainerToLeftPos(); |
880 | 889 | return true; |
| 890 | + } else { // active tab off right side |
| 891 | + rightScrollArrowWidth = stc.$slideRightArrow.outerWidth(); |
| 892 | + if (activeTabRightPos > rightArrowLeftPos) { |
| 893 | + stc.movableContainerLeftPos += (activeTabRightPos - rightArrowLeftPos) + rightScrollArrowWidth + RIGHT_OFFSET_BUFFER; |
| 894 | + smv.slideMovableContainerToLeftPos(); |
| 895 | + return true; |
| 896 | + } |
| 897 | + } |
| 898 | + } else { |
| 899 | + if (activeTabRightPos > rightArrowLeftPos) { // active tab off right side |
| 900 | + rightScrollArrowWidth = stc.$slideRightArrow.outerWidth(); |
| 901 | + stc.movableContainerLeftPos -= (activeTabRightPos - rightArrowLeftPos + rightScrollArrowWidth); |
| 902 | + smv.slideMovableContainerToLeftPos(); |
| 903 | + return true; |
| 904 | + } else { |
| 905 | + leftScrollArrowWidth = stc.$slideLeftArrow.outerWidth(); |
| 906 | + if (activeTabLeftPos < leftScrollArrowWidth) { // active tab off left side |
| 907 | + stc.movableContainerLeftPos += leftScrollArrowWidth - activeTabLeftPos; |
| 908 | + smv.slideMovableContainerToLeftPos(); |
| 909 | + return true; |
| 910 | + } |
881 | 911 | } |
882 | 912 | } |
883 | 913 |
|
|
925 | 955 | smv.performingSlideAnim = true; |
926 | 956 |
|
927 | 957 | var targetPos = stc.rtl ? { right: leftOrRightVal } : { left: leftOrRightVal }; |
928 | | - |
| 958 | + |
929 | 959 | stc.$movableContainer.stop().animate(targetPos, 'slow', function __slideAnimComplete() { |
930 | 960 | var newMinPos = smv.getMinPos(); |
931 | 961 |
|
|
1001 | 1031 | } |
1002 | 1032 | } |
1003 | 1033 |
|
| 1034 | + if (options.bootstrapVersion.toString().charAt(0) === '4') { |
| 1035 | + stc.usingBootstrap4 = true; |
| 1036 | + } |
| 1037 | + |
1004 | 1038 | setTimeout(initTabsAfterTimeout, 100); |
1005 | 1039 |
|
1006 | 1040 | function initTabsAfterTimeout() { |
|
1810 | 1844 | leftArrowContent: '', |
1811 | 1845 | rightArrowContent: '', |
1812 | 1846 | enableSwiping: false, |
1813 | | - enableRtlSupport: false |
| 1847 | + enableRtlSupport: false, |
| 1848 | + bootstrapVersion: 3 |
1814 | 1849 | }; |
1815 | 1850 |
|
1816 | 1851 |
|
|
0 commit comments