From 7f64427fe52622f37d2fec3916381e61439b6517 Mon Sep 17 00:00:00 2001 From: mateuswetah Date: Mon, 26 Sep 2022 20:59:32 -0300 Subject: [PATCH] Lint check for version 0.1.1. --- blocks/a11y-button/save.js | 3 +-- build/frontend/frontend.asset.php | 2 +- build/frontend/frontend.js | 2 +- frontend/frontend.js | 31 +++++++++++++++++-------------- frontend/high-contrast.scss | 2 +- webpack.config.js | 28 +++++++++++++++++++++++----- 6 files changed, 44 insertions(+), 24 deletions(-) diff --git a/blocks/a11y-button/save.js b/blocks/a11y-button/save.js index dd25bef..4b07b9f 100644 --- a/blocks/a11y-button/save.js +++ b/blocks/a11y-button/save.js @@ -85,8 +85,7 @@ export default function Save( { attributes, className } ) { } return ( -
  • +
  • { attributes.action === 'skip-to-content' ? ( array(), 'version' => '8ed04bd2e9a8266e99de'); + array(), 'version' => '65a0f97b27bca61a44a2'); diff --git a/build/frontend/frontend.js b/build/frontend/frontend.js index 3a3f71d..a4b666c 100644 --- a/build/frontend/frontend.js +++ b/build/frontend/frontend.js @@ -1 +1 @@ -!function(){"use strict";function t(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"increase",e=arguments.length>1?arguments[1]:void 0;const s=document.getElementsByTagName("html")[0];if("reset"===t)return s.style.fontSize="",void window.sessionStorage.removeItem("a11y-buttons-font-size");if("set"===t&&e)return void(s.style.fontSize=e);const n=window.getComputedStyle(s).fontSize,o=/[\d]*/gm,i=n.match(o);let a=i.length&&!isNaN(i[0])?Number(i[0]):16;if("increase"===t&&a<=64)a+=4;else{if(!("decrease"===t&&a>=8))return;a-=4}const c=i.length&&!isNaN(i[0])&&n.split(i[0])&&isNaN(n.split(i[0])[1])?n.split(i[0])[1]:"px",d=a+c;s.style.fontSize=d,window.sessionStorage.setItem("a11y-buttons-font-size",d)}function e(){var t,e;t="frontend/high-contrast.css",t=a11yButtonSettings.pluginBuildPath+t,(e=document.createElement("link")).setAttribute("rel","stylesheet"),e.setAttribute("type","text/css"),e.setAttribute("href",t),document.getElementsByTagName("head")[0].appendChild(e);const s=document.getElementsByTagName("html")[0].classList.toggle("a11y-buttons-high-contrast-mode");window.sessionStorage.setItem("a11y-buttons-high-contrast-mode",s)}var s;s=()=>{!function(){const s=window.sessionStorage.getItem("a11y-buttons-font-size");s&&t("set",s),"true"===window.sessionStorage.getItem("a11y-buttons-high-contrast-mode")&&e()}(),function(){const s=document.getElementsByClassName("wp-block-a11y-buttons-a11y-button");if(!s||!s.length)return;const n=[];for(const t of s)t.childNodes&&t.childNodes[0]&&"BUTTON"===t.childNodes[0].tagName&&t.childNodes[0].dataset.action&&n.push(t.childNodes[0]);for(const s of n)s.addEventListener("click",(()=>{switch(s.dataset.action){case"increase-font-size":t("increase");break;case"decrease-font-size":t("decrease");break;case"reset-font-size":t("reset");break;case"toggle-high-contrast":e()}}))}()},/comp|inter|loaded/.test(document.readyState)?s():document.addEventListener("DOMContentLoaded",s,!1)}(); \ No newline at end of file +!function(){"use strict";function t(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"increase",e=arguments.length>1?arguments[1]:void 0;const s=document.getElementsByTagName("html")[0];if("reset"===t)return s.style.fontSize="",void window.sessionStorage.removeItem("a11y-buttons-font-size");if("set"===t&&e)return void(s.style.fontSize=e);const n=window.getComputedStyle(s).fontSize,o=/[\d]*/gm,i=n.match(o);let a=i.length&&!isNaN(i[0])?Number(i[0]):16;if("increase"===t&&a<=64)a+=4;else{if(!("decrease"===t&&a>=8))return;a-=4}const c=i.length&&!isNaN(i[0])&&n.split(i[0])&&isNaN(n.split(i[0])[1])?n.split(i[0])[1]:"px",d=a+c;s.style.fontSize=d,window.sessionStorage.setItem("a11y-buttons-font-size",d)}function e(){!function(t,e){t=(window.a11ButtonSettings?window.a11yButtonSettings.pluginBuildPath:"")+t;{const e=document.createElement("link");e.setAttribute("rel","stylesheet"),e.setAttribute("type","text/css"),e.setAttribute("href",t),document.getElementsByTagName("head")[0].appendChild(e)}}("frontend/high-contrast.css");const t=document.getElementsByTagName("html")[0].classList.toggle("a11y-buttons-high-contrast-mode");window.sessionStorage.setItem("a11y-buttons-high-contrast-mode",t)}var s;s=()=>{!function(){const s=window.sessionStorage.getItem("a11y-buttons-font-size");s&&t("set",s),"true"===window.sessionStorage.getItem("a11y-buttons-high-contrast-mode")&&e()}(),function(){const s=document.getElementsByClassName("wp-block-a11y-buttons-a11y-button");if(!s||!s.length)return;const n=[];for(const t of s)t.childNodes&&t.childNodes[0]&&"BUTTON"===t.childNodes[0].tagName&&t.childNodes[0].dataset.action&&n.push(t.childNodes[0]);for(const s of n)s.addEventListener("click",(()=>{switch(s.dataset.action){case"increase-font-size":t("increase");break;case"decrease-font-size":t("decrease");break;case"reset-font-size":t("reset");break;case"toggle-high-contrast":e()}}))}()},/comp|inter|loaded/.test(document.readyState)?s():document.addEventListener("DOMContentLoaded",s,!1)}(); \ No newline at end of file diff --git a/frontend/frontend.js b/frontend/frontend.js index a936dfb..1f69e1d 100644 --- a/frontend/frontend.js +++ b/frontend/frontend.js @@ -65,7 +65,7 @@ function updateFontSize( action = 'increase', setValue ) { * elements based on our high contrast stylesheet. */ function toggleHighContrast() { - loadFile('frontend/high-contrast.css', 'css'); + loadFile( 'frontend/high-contrast.css', 'css' ); const htmlElement = document.getElementsByTagName( 'html' )[ 0 ]; const isContrastModeEnabled = htmlElement.classList.toggle( @@ -137,22 +137,25 @@ function addActionsToButtons() { } } -function loadFile(path, type) { - const pluginPath = a11yButtonSettings['pluginBuildPath']; +function loadFile( path, type ) { + const pluginPath = window.a11ButtonSettings + ? window.a11yButtonSettings.pluginBuildPath + : ''; path = pluginPath + path; - if (type == "js") { - var fileref = document.createElement("script"); - fileref.setAttribute("type", "text/javascript"); - fileref.setAttribute("src", path); - } else if (type == "css") { - var fileref = document.createElement("link"); - fileref.setAttribute("rel", "stylesheet"); - fileref.setAttribute("type", "text/css"); - fileref.setAttribute("href", path); + if ( type === 'js' ) { + const fileref = document.createElement( 'script' ); + fileref.setAttribute( 'type', 'text/javascript' ); + fileref.setAttribute( 'src', path ); + document.getElementsByTagName( 'head' )[ 0 ].appendChild( fileref ); + } else if ( type === 'css' ) { + const fileref = document.createElement( 'link' ); + fileref.setAttribute( 'rel', 'stylesheet' ); + fileref.setAttribute( 'type', 'text/css' ); + fileref.setAttribute( 'href', path ); + document.getElementsByTagName( 'head' )[ 0 ].appendChild( fileref ); } - document.getElementsByTagName("head")[0].appendChild(fileref); - } +} /* * Waiting the page to be loaded to initialize things diff --git a/frontend/high-contrast.scss b/frontend/high-contrast.scss index c1a3d38..8306727 100644 --- a/frontend/high-contrast.scss +++ b/frontend/high-contrast.scss @@ -3,7 +3,7 @@ /* This file holds the styling made by the plugin * on the site css for some states. */ - .a11y-buttons-high-contrast-mode { +.a11y-buttons-high-contrast-mode { *, *.has-background, diff --git a/webpack.config.js b/webpack.config.js index 6e46237..407e4dc 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -2,10 +2,28 @@ const path = require( 'path' ); const config = require( '@wordpress/scripts/config/webpack.config.js' ); config.entry = { - 'a11y-buttons/index': path.resolve( process.cwd(), 'blocks', 'a11y-buttons', 'index.js' ), - 'a11y-button/index': path.resolve( process.cwd(), 'blocks', 'a11y-button', 'index.js' ), - 'frontend/frontend': path.resolve( process.cwd(), 'frontend', 'frontend.js' ), - 'frontend/high-contrast': path.resolve( process.cwd(), 'frontend', 'high-contrast.scss' ) + 'a11y-buttons/index': path.resolve( + process.cwd(), + 'blocks', + 'a11y-buttons', + 'index.js' + ), + 'a11y-button/index': path.resolve( + process.cwd(), + 'blocks', + 'a11y-button', + 'index.js' + ), + 'frontend/frontend': path.resolve( + process.cwd(), + 'frontend', + 'frontend.js' + ), + 'frontend/high-contrast': path.resolve( + process.cwd(), + 'frontend', + 'high-contrast.scss' + ), }; -module.exports = config; \ No newline at end of file +module.exports = config;