2019-08-11 11:08:52 +02:00
/ *
scripts . js
License : GNU General Public License v3 . 0
License URI : http : //www.gnu.org/licenses/gpl-3.0.html
2025-04-07 15:29:19 +02:00
Copyright : ( c ) 2013 Alexander "Alx" Agnarson , https : //agnarson.com
2019-08-11 11:08:52 +02:00
* /
"use strict" ;
jQuery ( document ) . ready ( function ( $ ) {
/ * T o g g l e h e a d e r s e a r c h
/* ------------------------------------ */
$ ( '.toggle-search' ) . on ( 'click' , function ( ) {
$ ( '.toggle-search' ) . toggleClass ( 'active' ) ;
$ ( '.search-expand' ) . fadeToggle ( 250 ) ;
setTimeout ( function ( ) {
$ ( '.search-expand input' ) . focus ( ) ;
} , 300 ) ;
} ) ;
/ * S c r o l l t o t o p
/* ------------------------------------ */
$ ( 'a#back-to-top' ) . on ( 'click' , function ( ) {
$ ( 'html, body' ) . animate ( { scrollTop : 0 } , 'slow' ) ;
return false ;
} ) ;
/ * T a b s w i d g e t
/* ------------------------------------ */
( function ( ) {
var $tabsNav = $ ( '.alx-tabs-nav' ) ,
$tabsNavLis = $tabsNav . children ( 'li' ) ,
$tabsContainer = $ ( '.alx-tabs-container' ) ;
$tabsNav . each ( function ( ) {
var $this = $ ( this ) ;
$this . next ( ) . children ( '.alx-tab' ) . stop ( true , true ) . hide ( )
. siblings ( $this . find ( 'a' ) . attr ( 'href' ) ) . show ( ) ;
$this . children ( 'li' ) . first ( ) . addClass ( 'active' ) . stop ( true , true ) . show ( ) ;
} ) ;
$tabsNavLis . on ( 'click' , function ( e ) {
var $this = $ ( this ) ;
$this . siblings ( ) . removeClass ( 'active' ) . end ( )
. addClass ( 'active' ) ;
$this . parent ( ) . next ( ) . children ( '.alx-tab' ) . stop ( true , true ) . hide ( )
. siblings ( $this . find ( 'a' ) . attr ( 'href' ) ) . fadeIn ( ) ;
e . preventDefault ( ) ;
} ) . children ( window . location . hash ? 'a[href="' + window . location . hash + '"]' : 'a:first' ) . trigger ( 'click' ) ;
} ) ( ) ;
/* Comments / pingbacks tabs
/* ------------------------------------ */
$ ( '.comment-tabs li' ) . on ( 'click' , function ( ) {
$ ( '.comment-tabs li' ) . removeClass ( 'active' ) ;
$ ( this ) . addClass ( 'active' ) ;
$ ( '.comment-tab' ) . hide ( ) ;
var selected _tab = $ ( this ) . find ( 'a' ) . attr ( 'href' ) ;
$ ( selected _tab ) . fadeIn ( ) ;
return false ;
} ) ;
/ * T a b l e o d d r o w c l a s s
/* ------------------------------------ */
$ ( 'table tr:odd' ) . addClass ( 'alt' ) ;
/ * D r o p d o w n m e n u a n i m a t i o n
/* ------------------------------------ */
$ ( '.nav ul.sub-menu' ) . hide ( ) ;
$ ( '.nav li' ) . hover (
function ( ) {
$ ( this ) . children ( 'ul.sub-menu' ) . slideDown ( 'fast' ) ;
} ,
function ( ) {
$ ( this ) . children ( 'ul.sub-menu' ) . hide ( ) ;
}
) ;
/ * F i t v i d s
/* ------------------------------------ */
function responsiveVideo ( ) {
if ( $ ( ) . fitVids ) {
$ ( '#wrapper' ) . fitVids ( ) ;
}
}
responsiveVideo ( ) ;
/ * M o b i l e m e n u s m o o t h t o g g l e h e i g h t
/* ------------------------------------ */
$ ( '.nav-toggle' ) . on ( 'click' , function ( ) {
slide ( $ ( '.nav-wrap .nav' , $ ( this ) . parent ( ) ) ) ;
} ) ;
function slide ( content ) {
var wrapper = content . parent ( ) ;
var contentHeight = content . outerHeight ( true ) ;
var wrapperHeight = wrapper . height ( ) ;
wrapper . toggleClass ( 'expand' ) ;
if ( wrapper . hasClass ( 'expand' ) ) {
setTimeout ( function ( ) {
wrapper . addClass ( 'transition' ) . css ( 'height' , contentHeight ) ;
} , 10 ) ;
}
else {
setTimeout ( function ( ) {
wrapper . css ( 'height' , wrapperHeight ) ;
setTimeout ( function ( ) {
wrapper . addClass ( 'transition' ) . css ( 'height' , 0 ) ;
} , 10 ) ;
} , 10 ) ;
}
wrapper . one ( 'transitionEnd webkitTransitionEnd transitionend oTransitionEnd msTransitionEnd' , function ( ) {
if ( wrapper . hasClass ( 'open' ) ) {
wrapper . removeClass ( 'transition' ) . css ( 'height' , 'auto' ) ;
}
} ) ;
}
/ * S l i c k i m a g e s l i d e
/* ------------------------------------ */
$ ( '.slick-image-slide' ) . each ( function ( ) {
$ ( this ) . slick ( {
dots : false ,
adaptiveHeight : true ,
appendArrows : $ ( this ) . parents ( '.slick-image-slide-wrapper' ) . find ( '.slick-image-slide-nav' ) ,
appendDots : $ ( this ) . parents ( '.slick-image-slide-wrapper' ) . find ( '.slick-image-slide-dots' )
} ) ;
} ) ;
/ * M o v e s i d e b a r
/* ------------------------------------ */
$ ( window ) . on ( 'load resize' , function ( ) {
if ( $ ( window ) . width ( ) < 960 ) {
$ ( ".sidebar.s1" ) . appendTo ( "#move-sidebar-content" ) ;
}
else {
$ ( ".sidebar.s1" ) . appendTo ( "#move-sidebar-header" ) ;
}
} ) ;
2021-03-03 11:35:45 +01:00
/ * T r a p f o c u s
/* ------------------------------------ */
// add all the elements inside modal which you want to make focusable
const focusableElements =
'button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])' ;
const modal = document . querySelector ( '.search-trap-focus' ) ; // select the modal by it's id
if ( modal ) {
const firstFocusableElement = modal . querySelectorAll ( focusableElements ) [ 0 ] ; // get first element to be focused inside modal
const focusableContent = modal . querySelectorAll ( focusableElements ) ;
const lastFocusableElement = focusableContent [ focusableContent . length - 1 ] ; // get last element to be focused inside modal
document . addEventListener ( 'keydown' , function ( e ) {
let isTabPressed = e . key === 'Tab' || e . keyCode === 9 ;
if ( ! isTabPressed ) {
return ;
}
if ( e . shiftKey ) { // if shift key pressed for shift + tab combination
if ( document . activeElement === firstFocusableElement ) {
lastFocusableElement . focus ( ) ; // add focus for the last focusable element
e . preventDefault ( ) ;
}
} else { // if tab key is pressed
if ( document . activeElement === lastFocusableElement ) { // if focused has reached to last focusable element then focus first focusable element after pressing tab
firstFocusableElement . focus ( ) ; // add focus for the first focusable element
e . preventDefault ( ) ;
}
}
} ) ;
}
2019-08-11 11:08:52 +02:00
} ) ;