@ -3,52 +3,53 @@ import * as Cookies from 'js-cookie';
export default {
export default {
init ( ) {
init ( ) {
// JavaScript to be fired on all pages
// JavaScript to be fired on all pages
jQuery ( $ => {
// JavaScript to be fired on all pages
$ ( 'body' )
document . body . classList . remove ( 'no-js' ) ;
. removeClass ( 'no-js' )
document . body . classList . add ( 'js' ) ;
. addClass ( 'js' ) ;
$ ( document ) . ready ( function ( ) {
// Font Size handler
// Fontsize handler
( function ( ) {
const fontSizeButton = document . querySelector ( '.a11y-fontsize' ) ;
if ( Cookies . get ( 'a11y-root-larger-fontsize' ) === '1' ) {
if ( Cookies . get ( 'a11y-root-larger-fontsize' ) === '1' ) {
$ ( 'html' ) . addClass ( 'fontsize' ) ;
document . documentElement . classList . add ( 'fontsize' ) ;
$ ( '#is_normal_fontsize' )
fontSizeButton . setAttribute ( 'aria-pressed' , true ) ;
. attr ( 'id' , 'is_large_fontsize' )
fontSizeButton . textContent = pressbooksBook . decrease _label ;
. attr ( 'aria-checked' , true )
. addClass ( 'active' )
. text ( PB _A11y . decrease _label )
. attr ( 'title' , PB _A11y . decrease _label ) ;
}
}
$ ( '.toggle-fontsize' ) . on ( 'click' , function ( ) {
fontSizeButton . onclick = ( ) => {
if ( $ ( this ) . attr ( 'id' ) === 'is_normal_fontsize' ) {
// Cast the state as a boolean
$ ( 'html' ) . addClass ( 'fontsize' ) ;
let pressed = fontSizeButton . getAttribute ( 'aria-pressed' ) === 'true' || false ;
$ ( this )
. attr ( 'id' , 'is_large_fontsize' )
// Switch the state
. attr ( 'aria-checked' , true )
fontSizeButton . setAttribute ( 'aria-pressed' , ! pressed ) ;
. addClass ( 'active' )
. text ( PB _A11y . decrease _label )
if ( ! pressed ) {
. attr ( 'title' , PB _A11y . decrease _label ) ;
document . documentElement . classList . add ( 'fontsize' ) ;
fontSizeButton . setAttribute ( 'title' , pressbooksBook . decrease _label ) ;
fontSizeButton . textContent = pressbooksBook . decrease _label ;
document . querySelector ( '.nav-reading' ) . setAttribute ( 'style' , '' ) ;
Cookies . set ( 'a11y-root-larger-fontsize' , '1' , {
Cookies . set ( 'a11y-root-larger-fontsize' , '1' , {
expires : 365 ,
expires : 365 ,
path : '/' ,
path : '/' ,
} ) ;
} ) ;
return false ;
return false ;
} else {
} else {
$ ( 'html' ) . removeClass ( 'fontsize' ) ;
document . documentElement . classList . remove ( 'fontsize' ) ;
$ ( this )
fontSizeButton . setAttribute ( 'title' , pressbooksBook . increase _label ) ;
. attr ( 'id' , 'is_normal_fontsize' )
fontSizeButton . textContent = pressbooksBook . increase _label ;
. removeAttr ( 'aria-checked' )
document . querySelector ( '.nav-reading' ) . setAttribute ( 'style' , '' ) ;
. removeClass ( 'active' )
. text ( PB _A11y . increase _label )
. attr ( 'title' , PB _A11y . increase _label ) ;
Cookies . set ( 'a11y-root-larger-fontsize' , '0' , {
Cookies . set ( 'a11y-root-larger-fontsize' , '0' , {
expires : 365 ,
expires : 365 ,
path : '/' ,
path : '/' ,
} ) ;
} ) ;
return false ;
return false ;
}
}
} ) ;
} ;
} ) ( ) ;
jQuery ( $ => {
$ ( document ) . ready ( function ( ) {
// Sets a -1 tabindex to ALL sections for .focus()-ing
// Sets a -1 tabindex to ALL sections for .focus()-ing
let sections = document . getElementsByTagName ( 'section' ) ;
let sections = document . getElementsByTagName ( 'section' ) ;
for ( let i = 0 , max = sections . length ; i < max ; i ++ ) {
for ( let i = 0 , max = sections . length ; i < max ; i ++ ) {