1// Easy Responsive Tabs Plugin 2// Author: Samson.Onna <Email : [email protected]> 3(function ($) { 4 $.fn.extend({ 5 easyResponsiveTabs: function (options) { 6 //Set the default values, use comma to separate the settings, example: 7 var defaults = { 8 type: 'default', //default, vertical, accordion; 9 width: 'auto', 10 fit: true, 11 closed: false, 12 tabidentify: '', 13 activetab_bg: 'white', 14 inactive_bg: '#F5F5F5', 15 active_border_color: '#c1c1c1', 16 active_content_border_color: '#c1c1c1', 17 activate: function () { 18 } 19 } 20 //Variables 21 var options = $.extend(defaults, options); 22 var opt = options, jtype = opt.type, jfit = opt.fit, jwidth = opt.width, vtabs = 'vertical', accord = 'accordion'; 23 var hash = window.location.hash; 24 var historyApi = !!(window.history && history.replaceState); 25 26 //Events 27 $(this).bind('tabactivate', function (e, currentTab) { 28 if (typeof options.activate === 'function') { 29 options.activate.call(currentTab, e) 30 } 31 }); 32 33 //Main function 34 this.each(function () { 35 var $respTabs = $(this); 36 var $respTabsList = $respTabs.find('ul.resp-tabs-list.' + options.tabidentify); 37 var respTabsId = $respTabs.attr('id'); 38 $respTabs.find('ul.resp-tabs-list.' + options.tabidentify + ' li').addClass('resp-tab-item').addClass(options.tabidentify); 39 $respTabs.css({ 40 'display': 'block', 41 'width': jwidth 42 }); 43 44 if (options.type == 'vertical') 45 $respTabsList.css('margin-top', '3px'); 46 47 $respTabs.find('.resp-tabs-container.' + options.tabidentify).css('border-color', options.active_content_border_color); 48 $respTabs.find('.resp-tabs-container.' + options.tabidentify + ' > div').addClass('resp-tab-content').addClass(options.tabidentify); 49 jtab_options(); 50 //Properties Function 51 function jtab_options() { 52 if (jtype == vtabs) { 53 $respTabs.addClass('resp-vtabs').addClass(options.tabidentify); 54 } 55 if (jfit == true) { 56 $respTabs.css({ width: '100%', margin: '0px' }); 57 } 58 if (jtype == accord) { 59 $respTabs.addClass('resp-easy-accordion').addClass(options.tabidentify); 60 $respTabs.find('.resp-tabs-list').css('display', 'none'); 61 } 62 } 63 64 //Assigning the h2 markup to accordion title 65 var $tabItemh2; 66 $respTabs.find('.resp-tab-content.' + options.tabidentify).before("<h2 class='resp-accordion " + options.tabidentify + "' role='tab'><span class='resp-arrow'></span></h2>"); 67 68 $respTabs.find('.resp-tab-content.' + options.tabidentify).prev("h2").css({ 69 'background-color': options.inactive_bg, 70 'border-color': options.active_border_color 71 }); 72 73 var itemCount = 0; 74 $respTabs.find('.resp-accordion').each(function () { 75 $tabItemh2 = $(this); 76 var $tabItem = $respTabs.find('.resp-tab-item:eq(' + itemCount + ')'); 77 var $accItem = $respTabs.find('.resp-accordion:eq(' + itemCount + ')'); 78 $accItem.append($tabItem.html()); 79 $accItem.data($tabItem.data()); 80 $tabItemh2.attr('aria-controls', options.tabidentify + '_tab_item-' + (itemCount)); 81 itemCount++; 82 }); 83 84 //Assigning the 'aria-controls' to Tab items 85 var count = 0, 86 $tabContent; 87 $respTabs.find('.resp-tab-item').each(function () { 88 $tabItem = $(this); 89 $tabItem.attr('aria-controls', options.tabidentify + '_tab_item-' + (count)); 90 $tabItem.attr('role', 'tab'); 91 $tabItem.css({ 92 'background-color': options.inactive_bg, 93 'border-color': 'none' 94 }); 95 96 //Assigning the 'aria-labelledby' attr to tab-content 97 var tabcount = 0; 98 $respTabs.find('.resp-tab-content.' + options.tabidentify).each(function () { 99 $tabContent = $(this); 100 $tabContent.attr('aria-labelledby', options.tabidentify + '_tab_item-' + (tabcount)).css({ 101 'border-color': options.active_border_color 102 }); 103 tabcount++; 104 }); 105 count++; 106 }); 107 108 // Show correct content area 109 var tabNum = 0; 110 if (hash != '') { 111 var matches = hash.match(new RegExp(respTabsId + "([0-9]+)")); 112 if (matches !== null && matches.length === 2) { 113 tabNum = parseInt(matches[1], 10) - 1; 114 if (tabNum > count) { 115 tabNum = 0; 116 } 117 } 118 } 119 120 //Active correct tab 121 $($respTabs.find('.resp-tab-item.' + options.tabidentify)[tabNum]).addClass('resp-tab-active').css({ 122 'background-color': options.activetab_bg, 123 'border-color': options.active_border_color 124 }); 125 126 //keep closed if option = 'closed' or option is 'accordion' and the element is in accordion mode 127 if (options.closed !== true && !(options.closed === 'accordion' && !$respTabsList.is(':visible')) && !(options.closed === 'tabs' && $respTabsList.is(':visible'))) { 128 $($respTabs.find('.resp-accordion.' + options.tabidentify)[tabNum]).addClass('resp-tab-active').css({ 129 'background-color': options.activetab_bg + ' !important', 130 'border-color': options.active_border_color, 131 'background': 'none' 132 }); 133 134 $($respTabs.find('.resp-tab-content.' + options.tabidentify)[tabNum]).addClass('resp-tab-content-active').addClass(options.tabidentify).attr('style', 'display:block'); 135 } 136 //assign proper classes for when tabs mode is activated before making a selection in accordion mode 137 else { 138 // $($respTabs.find('.resp-tab-content.' + options.tabidentify)[tabNum]).addClass('resp-accordion-closed'); //removed resp-tab-content-active 139 } 140 141 //Tab Click action function 142 $respTabs.find("[role=tab]").each(function () { 143 144 var $currentTab = $(this); 145 $currentTab.click(function () { 146 147 var $currentTab = $(this); 148 var $tabAria = $currentTab.attr('aria-controls'); 149 150 if ($currentTab.hasClass('resp-accordion') && $currentTab.hasClass('resp-tab-active')) { 151 $respTabs.find('.resp-tab-content-active.' + options.tabidentify).slideUp('', function () { 152 $(this).addClass('resp-accordion-closed'); 153 }); 154 $currentTab.removeClass('resp-tab-active').css({ 155 'background-color': options.inactive_bg, 156 'border-color': 'none' 157 }); 158 return false;
159 } 160 if (!$currentTab.hasClass('resp-tab-active') && $currentTab.hasClass('resp-accordion')) { 161 $respTabs.find('.resp-tab-active.' + options.tabidentify).removeClass('resp-tab-active').css({ 162 'background-color': options.inactive_bg, 163 'border-color': 'none' 164 }); 165 $respTabs.find('.resp-tab-content-active.' + options.tabidentify).slideUp().removeClass('resp-tab-content-active resp-accordion-closed'); 166 $respTabs.find("[aria-controls=" + $tabAria + "]").addClass('resp-tab-active').css({ 167 'background-color': options.activetab_bg, 168 'border-color': options.active_border_color 169 }); 170 171 $respTabs.find('.resp-tab-content[aria-labelledby = ' + $tabAria + '].' + options.tabidentify).slideDown().addClass('resp-tab-content-active'); 172 } else { 173 console.log('here'); 174 $respTabs.find('.resp-tab-active.' + options.tabidentify).removeClass('resp-tab-active').css({ 175 'background-color': options.inactive_bg, 176 'border-color': 'none' 177 }); 178 179 $respTabs.find('.resp-tab-content-active.' + options.tabidentify).removeAttr('style').removeClass('resp-tab-content-active').removeClass('resp-accordion-closed'); 180 181 $respTabs.find("[aria-controls=" + $tabAria + "]").addClass('resp-tab-active').css({ 182 'background-color': options.activetab_bg, 183 'border-color': options.active_border_color 184 }); 185 186 $respTabs.find('.resp-tab-content[aria-labelledby = ' + $tabAria + '].' + options.tabidentify).addClass('resp-tab-content-active').attr('style', 'display:block'); 187 } 188 //Trigger tab activation event 189 $currentTab.trigger('tabactivate', $currentTab); 190 191 //Update Browser History 192 if (historyApi) { 193 var currentHash = window.location.hash; 194 var tabAriaParts = $tabAria.split('tab_item-'); 195 // var newHash = respTabsId + (parseInt($tabAria.substring(9), 10) + 1).toString(); 196 var newHash = respTabsId + (parseInt(tabAriaParts[1], 10) + 1).toString(); 197 if (currentHash != "") { 198 var re = new RegExp(respTabsId + "[0-9]+"); 199 if (currentHash.match(re) != null) { 200 newHash = currentHash.replace(re, newHash); 201 } 202 else { 203 newHash = currentHash + "|" + newHash; 204 } 205 } 206 else { 207 newHash = '#' + newHash; 208 } 209 210 history.replaceState(null, null, newHash); 211 } 212 }); 213 214 }); 215 216 //Window resize function 217 $(window).resize(function () { 218 $respTabs.find('.resp-accordion-closed').removeAttr('style'); 219 }); 220 }); 221 } 222 }); 223})(jQuery);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.