[ label, type ] where type is toggle or level count. */ public static function modules() { $modules = array( 'text_size' => array( __( 'Text size', 'ariaccess' ), 'size' ), 'line_height' => array( __( 'Line spacing', 'ariaccess' ), 3 ), 'letter_spacing' => array( __( 'Letter spacing', 'ariaccess' ), 3 ), 'readable_font' => array( __( 'Readable font', 'ariaccess' ), 'toggle' ), 'dyslexia_font' => array( __( 'Dyslexia-friendly font', 'ariaccess' ), 'toggle' ), 'align_left' => array( __( 'Align text left', 'ariaccess' ), 'toggle' ), 'contrast_dark' => array( __( 'Dark high contrast', 'ariaccess' ), 'toggle' ), 'contrast_light' => array( __( 'Light high contrast', 'ariaccess' ), 'toggle' ), 'monochrome' => array( __( 'Greyscale', 'ariaccess' ), 'toggle' ), 'low_saturation' => array( __( 'Soft colours', 'ariaccess' ), 'toggle' ), 'highlight_links' => array( __( 'Highlight links', 'ariaccess' ), 'toggle' ), 'highlight_headings' => array( __( 'Highlight headings', 'ariaccess' ), 'toggle' ), 'stop_motion' => array( __( 'Stop animations', 'ariaccess' ), 'toggle' ), 'hide_images' => array( __( 'Hide images', 'ariaccess' ), 'toggle' ), 'big_cursor' => array( __( 'Big cursor', 'ariaccess' ), 'toggle' ), 'reading_guide' => array( __( 'Reading guide', 'ariaccess' ), 'toggle' ), 'reading_mask' => array( __( 'Reading mask', 'ariaccess' ), 'toggle' ), 'focus_ring' => array( __( 'Strong focus outline', 'ariaccess' ), 'toggle' ), 'read_aloud' => array( __( 'Read aloud on click', 'ariaccess' ), 'toggle' ), ); /** * Filter the display panel modules. * * @param array $modules key => [ label, type ]. */ return apply_filters( 'ariaccess_toolbar_modules', $modules ); } /** * Preset profiles. * * @return array key => [ label, description, modules ] */ public static function profiles() { return array( 'vision' => array( __( 'Low vision', 'ariaccess' ), __( 'Bigger text, clear links and focus', 'ariaccess' ), array( 'text_size' => 3, 'highlight_links' => 1, 'focus_ring' => 1, 'big_cursor' => 1, ), ), 'dyslexia' => array( __( 'Dyslexia', 'ariaccess' ), __( 'Friendly font, more space, reading guide', 'ariaccess' ), array( 'dyslexia_font' => 1, 'line_height' => 2, 'letter_spacing' => 1, 'align_left' => 1, 'reading_guide' => 1, ), ), 'focus' => array( __( 'Concentration', 'ariaccess' ), __( 'Fewer distractions, reading mask', 'ariaccess' ), array( 'stop_motion' => 1, 'reading_mask' => 1, 'highlight_headings' => 1, ), ), 'motion' => array( __( 'Motion sensitive', 'ariaccess' ), __( 'No animations, softer colours', 'ariaccess' ), array( 'stop_motion' => 1, 'low_saturation' => 1, ), ), 'keyboard' => array( __( 'Keyboard', 'ariaccess' ), __( 'Strong focus outline, visible links', 'ariaccess' ), array( 'focus_ring' => 1, 'highlight_links' => 1, ), ), ); } /** * Apply saved choices before the page paints, so there is no flash. */ public static function early_state() { if ( ! self::active() ) { return; } // Only class names are read from storage, checked against the modules the admin has enabled. $enabled = array_values( array_intersect( array_keys( self::modules() ), (array) AriAccess_Settings::get( 'toolbar', 'modules' ) ) ); $allowed = wp_json_encode( $enabled ); wp_print_inline_script_tag( "(function(){try{var s=JSON.parse(localStorage.getItem('ariaccess')||'{}'),m=s.m||{},a={$allowed},h=document.documentElement;for(var k in m){if(a.indexOf(k)>-1&&m[k]>0&&k!=='text_size'){h.classList.add('ariaccess-'+k.replace(/_/g,'-'));if(m[k]>1)h.classList.add('ariaccess-'+k.replace(/_/g,'-')+'-'+m[k]);}}}catch(e){}})();", array( 'id' => 'ariaccess-early' ) ); } /** * Enqueue the panel assets. */ public static function enqueue() { if ( ! self::active() ) { return; } $t = AriAccess_Settings::get( 'toolbar' ); wp_enqueue_style( 'ariaccess-toolbar', ARIACCESS_URL . 'assets/css/toolbar.css', array(), ARIACCESS_VERSION ); $fg = AriAccess_Color::ratio( '#ffffff', $t['color'] ) >= 4.5 ? '#ffffff' : '#000000'; $css = sprintf( '#ariaccess{--ariaccess-accent:%1$s;--ariaccess-on-accent:%2$s;--ariaccess-x:%3$dpx;--ariaccess-y:%4$dpx}@font-face{font-family:"AriAccess Readable";src:url(%5$s) format("woff2");font-weight:400;font-display:swap}@font-face{font-family:"AriAccess Readable";src:url(%6$s) format("woff2");font-weight:700;font-display:swap}@font-face{font-family:"AriAccess Dyslexic";src:url(%7$s) format("woff2");font-weight:400;font-display:swap}@font-face{font-family:"AriAccess Dyslexic";src:url(%8$s) format("woff2");font-weight:700;font-display:swap}', esc_attr( $t['color'] ), esc_attr( $fg ), (int) $t['offset_x'], (int) $t['offset_y'], esc_url( ARIACCESS_URL . 'assets/fonts/atkinson-hyperlegible-latin-400-normal.woff2' ), esc_url( ARIACCESS_URL . 'assets/fonts/atkinson-hyperlegible-latin-700-normal.woff2' ), esc_url( ARIACCESS_URL . 'assets/fonts/opendyslexic-latin-400-normal.woff2' ), esc_url( ARIACCESS_URL . 'assets/fonts/opendyslexic-latin-700-normal.woff2' ) ); if ( $t['hide_mobile'] ) { $css .= '@media (max-width:767px){#ariaccess .ariaccess-trigger{display:none}}'; } wp_add_inline_style( 'ariaccess-toolbar', $css ); wp_enqueue_script( 'ariaccess-toolbar', ARIACCESS_URL . 'assets/js/toolbar.js', array(), ARIACCESS_VERSION, array( 'strategy' => 'defer', 'in_footer' => true ) ); $profiles = array(); foreach ( self::profiles() as $key => $p ) { $profiles[ $key ] = array_intersect_key( $p[2], array_flip( $t['modules'] ) ); } wp_add_inline_script( 'ariaccess-toolbar', 'window.ariaccessToolbar=' . wp_json_encode( array( 'modules' => array_values( array_intersect( array_keys( self::modules() ), $t['modules'] ) ), 'all' => array_keys( self::modules() ), 'profiles' => $profiles, 'shortcut' => (bool) $t['shortcut'], 'lang' => str_replace( '_', '-', get_bloginfo( 'language' ) ), 'i18n' => array( 'on' => __( 'on', 'ariaccess' ), 'off' => __( 'off', 'ariaccess' ), /* translators: %s: percentage, e.g. 120%. */ 'textSize' => __( 'Text size %s', 'ariaccess' ), /* translators: 1: setting name, 2: level number, 3: number of levels. */ 'level' => __( '%1$s: level %2$d of %3$d', 'ariaccess' ), 'reset' => __( 'All display settings reset', 'ariaccess' ), /* translators: %s: profile name. */ 'profileOn' => __( 'Profile %s applied', 'ariaccess' ), 'readHint' => __( 'Click any paragraph to hear it. Press Escape to stop.', 'ariaccess' ), ), ) ) . ';', 'before' ); } /** * Icon SVG. * * @param string $icon Icon key. * @return string */ private static function icon( $icon ) { switch ( $icon ) { case 'eye': return ''; case 'sliders': return ''; default: return ''; } } /** * Print the panel. */ public static function render() { if ( ! self::active() ) { return; } $t = AriAccess_Settings::get( 'toolbar' ); $enabled = $t['modules']; $modules = self::modules(); $groups = array( 'text' => __( 'Text', 'ariaccess' ), 'colour' => __( 'Colour and contrast', 'ariaccess' ), 'focus' => __( 'Reading and motion', 'ariaccess' ), ); $statement = AriAccess_Statement::public_url(); $contact = AriAccess_Statement::contact_email(); ?>
__( 'Display settings', 'ariaccess' ) ), $atts, 'ariaccess_button' ); return ''; } }