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/* Fitvids 74/* ------------------------------------ */ 75 function responsiveVideo() { 76 if ( $().fitVids ) { 77 $('#wrapper').fitVids(); 78 } 79 } 80 81 responsiveVideo(); 82 83/* Header Sticky 84/* ------------------------------------ */ 85 $('.logged-out #header-sticky').stickThis({ 86 top: 0, 87 minscreenwidth: 1081, 88 maxscreenwidth: 999999, 89 zindex: 99, 90 debugmode: false, 91 pushup: '' 92 }); 93 94 $('.admin-bar #header-sticky').stickThis({ 95 top: 32, 96 minscreenwidth: 1081, 97 maxscreenwidth: 999999, 98 zindex: 99, 99 debugmode: false, 100 pushup: '' 101 }); 102 103/* Jetpack infinite scroll 104/* ------------------------------------ */ 105 var infiniteCount = 2; 106 $( document.body ).on( 'post-load', function () { 107 var elements = $('.infinite-wrap.infinite-view-' + infiniteCount + ' article'); 108 109 $('#masonry').imagesLoaded().done( function(){ 110 $('#masonry').masonry( 'appended', elements ); 111 infiniteCount++; 112 }); 113 }); 114 115/* Hide on scroll down 116/* ------------------------------------ */ 117 var scrollTimeOut = true, 118 lastYPos = 0, 119 yPos = 0, 120 yPosDelta = 5, 121 nav = $('.hide-on-scroll-down'), 122 navHeight = nav.outerHeight(), 123 setNavClass = function() { 124 scrollTimeOut = false; 125 yPos = $(window).scrollTop(); 126 127 if(Math.abs(lastYPos - yPos) >= yPosDelta) { 128 if (yPos > lastYPos && yPos > navHeight){ 129 nav.addClass('hide-scroll'); 130 } else { 131 nav.removeClass('hide-scroll'); 132 } 133 lastYPos = yPos; 134 } 135 }; 136 137 $(window).scroll(function(e){ 138 scrollTimeOut = true; 139 }); 140 141 setInterval(function() { 142 if (scrollTimeOut) { 143 setNavClass(); 144 } 145 146 }, 250); 147 148/* Slick featured posts 149/* ------------------------------------ */ 150 $.fn.randomize = function (selector) { 151 var $elems = selector ? $(this).find(selector) : $(this).children(), 152 $parents = $elems.parent(); 153 154 $parents.each(function () { 155 $(this).children(selector).sort(function (childA, childB) { 156 // * Prevent last slide from being reordered 157 if($(childB).index() !== $(this).children(selector).length - 0.5) { 158 return Math.round(Math.random()) - 0.5; 159 } 160 }.bind(this)).detach().appendTo(this); 161 }); 162 163 return this; 164 }; 165 166 $(".slick-featured").randomize().slick({ 167 centerMode: true, 168 centerPadding: '0', 169 slidesToShow: 1, 170 appendArrows: '.slick-featured-nav', 171 responsive: [ 172 { 173 breakpoint: 1280, 174 settings: { 175 arrows: true, 176 centerMode: true, 177 centerPadding: '0', 178 slidesToShow: 1 179 } 180 }, 181 { 182 breakpoint: 1024, 183 settings: { 184 arrows: true, 185 centerMode: true, 186 centerPadding: '0', 187 slidesToShow: 1 188 } 189 }, 190 { 191 breakpoint: 768, 192 settings: { 193 arrows: true, 194 centerMode: true, 195 centerPadding: '0', 196 slidesToShow: 1 197 } 198 }, 199 { 200 breakpoint: 480, 201 settings: { 202 arrows: true, 203 centerMode: true, 204 centerPadding: '0', 205 slidesToShow: 1 206 } 207 } 208 ] 209 }); 210 $('.slick-featured-wrap-outer').show(); 211 212/* Slick highlights 213/* ------------------------------------ */ 214 $.fn.randomize = function (selector) { 215 var $elems = selector ? $(this).find(selector) : $(this).children(), 216 $parents = $elems.parent(); 217 218 $parents.each(function () { 219 $(this).children(selector).sort(function (childA, childB) { 220 // * Prevent last slide from being reordered 221 if($(childB).index() !== $(this).children(selector).length - 0.5) { 222 return Math.round(Math.random()) - 0.5; 223 } 224 }.bind(this)).detach().appendTo(this); 225 }); 226 227 return this; 228 }; 229 230 $(".slick-highlights").randomize().slick({ 231 centerMode: true, 232 centerPadding: '0', 233 slidesToShow: 3, 234 appendArrows: '.slick-highlights-nav', 235 responsive: [ 236 { 237 breakpoint: 1280, 238 settings: { 239 arrows: true, 240 centerMode: true, 241 centerPadding: '0', 242 slidesToShow: 3 243 } 244 }, 245 { 246 breakpoint: 1024, 247 settings: { 248 arrows: true, 249 centerMode: true, 250 centerPadding: '0', 251 slidesToShow: 2 252 } 253 }, 254 { 255 breakpoint: 768, 256 settings: { 257 arrows: true, 258 centerMode: true, 259 centerPadding: '0', 260 slidesToShow: 2 261 } 262 }, 263 { 264 breakpoint: 480, 265 settings: { 266 arrows: true, 267 centerMode: true, 268 centerPadding: '0', 269 slidesToShow: 1 270 } 271 } 272 ] 273 }); 274 $('.slick-highlights-wrap-outer').show(); 275 276/* Slick image slide 277/* ------------------------------------ */ 278 $('.slick-image-slide').each( function() { 279 $( this ).slick( { 280 dots: true, 281 adaptiveHeight: true, 282 appendArrows: $(this).parents('.slick-image-slide-wrapper').find('.slick-image-slide-nav'), 283 appendDots: $(this).parents('.slick-image-slide-wrapper').find('.slick-image-slide-dots') 284 } ); 285 $('.slick-image-slide-wrapper').show(); 286 } ); 287 288/* Trap focus 289/* ------------------------------------ */ 290 // add all the elements inside modal which you want to make focusable 291 const focusableElements =
292 'button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])'; 293 const modal = document.querySelector('.search-trap-focus'); // select the modal by it's id 294 295 if ( modal ) { 296 const firstFocusableElement = modal.querySelectorAll(focusableElements)[0]; // get first element to be focused inside modal 297 const focusableContent = modal.querySelectorAll(focusableElements); 298 const lastFocusableElement = focusableContent[focusableContent.length - 1]; // get last element to be focused inside modal 299 300 301 document.addEventListener('keydown', function(e) { 302 let isTabPressed = e.key === 'Tab' || e.keyCode === 9; 303 304 if (!isTabPressed) { 305 return; 306 } 307 308 if (e.shiftKey) { // if shift key pressed for shift + tab combination 309 if (document.activeElement === firstFocusableElement) { 310 lastFocusableElement.focus(); // add focus for the last focusable element 311 e.preventDefault(); 312 } 313 } else { // if tab key is pressed 314 if (document.activeElement === lastFocusableElement) { // if focused has reached to last focusable element then focus first focusable element after pressing tab 315 firstFocusableElement.focus();
315 // add focus for the first focusable element 316 e.preventDefault(); 317 } 318 } 319 }); 320 } 321 322});
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.