1/* 2 scripts.js 3 4 License: GNU General Public License v3.0 5 License URI: http://www.gnu.org/licenses/gpl-3.0.html 6 7 Copyright: (c) 2013 Alexander "Alx" Agnarson, http://alx.media 8*/ 9 10"use strict"; 11 12jQuery(document).ready(function($) { 13 14/* Toggle header search 15/* ------------------------------------ */ 16 $('.toggle-search').on('click', function() { 17 $('.toggle-search').toggleClass('active'); 18 $('.search-expand').fadeToggle(250); 19 setTimeout(function(){ 20 $('.search-expand input').focus(); 21 }, 300); 22 }); 23 24/* Scroll to top 25/* ------------------------------------ */ 26 $('a#back-to-top').on('click', function() { 27 $('html, body').animate({scrollTop:0},'slow'); 28 return false; 29 }); 30 31/* Tabs widget 32/* ------------------------------------ */ 33 (function() { 34 var $tabsNav = $('.alx-tabs-nav'), 35 $tabsNavLis = $tabsNav.children('li'), 36 $tabsContainer = $('.alx-tabs-container'); 37 38 $tabsNav.each(function() { 39 var $this = $(this); 40 $this.next().children('.alx-tab').stop(true,true).hide() 41 .siblings( $this.find('a').attr('href') ).show(); 42 $this.children('li').first().addClass('active').stop(true,true).show(); 43 }); 44 45 $tabsNavLis.on('click', function(e) { 46 var $this = $(this); 47 48 $this.siblings().removeClass('active').end() 49 .addClass('active'); 50 51 $this.parent().next().children('.alx-tab').stop(true,true).hide() 52 .siblings( $this.find('a').attr('href') ).fadeIn(); 53 e.preventDefault(); 54 }).children( window.location.hash ? 'a[href="' + window.location.hash + '"]' : 'a:first' ).trigger('click'); 55 56 })(); 57 58/* Comments / pingbacks tabs 59/* ------------------------------------ */ 60 $('.comment-tabs li').on('click', function() { 61 $('.comment-tabs li').removeClass('active'); 62 $(this).addClass('active'); 63 $('.comment-tab').hide(); 64 var selected_tab = $(this).find('a').attr('href'); 65 $(selected_tab).fadeIn(); 66 return false; 67 }); 68 69/* Table odd row class 70/* ------------------------------------ */ 71 $('table tr:odd').addClass('alt'); 72 73/* Sidebar collapse 74/* ------------------------------------ */ 75 $('body').addClass('s1-collapse'); 76 $('body').addClass('s2-collapse'); 77 78 $('.s1 .sidebar-toggle').on('click', function() { 79 $('body').toggleClass('s1-collapse').toggleClass('s1-expand'); 80 if ($('body').is('.s2-expand')) { 81 $('body').toggleClass('s2-expand').toggleClass('s2-collapse'); 82 } 83 }); 84 $('.s2 .sidebar-toggle').on('click', function() { 85 $('body').toggleClass('s2-collapse').toggleClass('s2-expand'); 86 if ($('body').is('.s1-expand')) { 87 $('body').toggleClass('s1-expand').toggleClass('s1-collapse'); 88 } 89 }); 90 91/* Fitvids 92/* ------------------------------------ */ 93 function responsiveVideo() { 94 if ( $().fitVids ) { 95 $('#wrapper').fitVids(); 96 } 97 } 98 99 responsiveVideo(); 100 101/* Trap focus 102/* ------------------------------------ */ 103 // add all the elements inside modal which you want to make focusable 104 const focusableElements = 105 'button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])'; 106 const modal = document.querySelector('.search-trap-focus'); // select the modal by it's id 107 108 if ( modal ) { 109 const firstFocusableElement = modal.querySelectorAll(focusableElements)[0]; // get first element to be focused inside modal 110 const focusableContent = modal.querySelectorAll(focusableElements); 111 const lastFocusableElement = focusableContent[focusableContent.length - 1]; // get last element to be focused inside modal 112 113 114 document.addEventListener('keydown', function(e) { 115 let isTabPressed = e.key === 'Tab' || e.keyCode === 9; 116 117 if (!isTabPressed) { 118 return; 119 } 120 121 if (e.shiftKey) { // if shift key pressed for shift + tab combination 122 if (document.activeElement === firstFocusableElement) { 123 lastFocusableElement.focus();
123 // add focus for the last focusable element 124 e.preventDefault(); 125 } 126 } else { // if tab key is pressed 127 if (document.activeElement === lastFocusableElement) { // if focused has reached to last focusable element then focus first focusable element after pressing tab 128 firstFocusableElement.focus(); // add focus for the first focusable element 129 e.preventDefault(); 130 } 131 } 132 }); 133 } 134 135});
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.