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