<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <title>Code Red Blog</title>
	<subtitle>A feed of the latest posts from our blog.</subtitle>
	<link href="https://code-red.uk/feed.xml" rel="self"/>
	<link href="https://code-red.uk/"/>
	<updated>2026-01-23T16:29:22Z</updated>
	<id>https://code-red.uk</id>
	<author>
    <name>Code Red Digital</name>
    <email>hello@code-red.uk</email>
	</author>
	
    
    <entry>
      <title>Future Post that will be removed</title>
      <link href="https://code-red.uk/blog/future-post-that-will-be-removed/"/>
      <updated>2500-01-01T00:00:00Z</updated>
      <id>https://code-red.uk/blog/future-post-that-will-be-removed/</id>
      <content type="html"><![CDATA[
        <section>
    <h2>Hello Mike, from the future</h2>
    <p>This is not really a post from the future, but it is used to solve a problem.</p>
</section>
<section>
    <h2>The Problem</h2>
    <p>On the blog listing, I wanted to show a different number of posts on the first page (8) than the rest of the pages (9). <a href="https://www.11ty.dev/">Eleventy</a>, the Static Site Generator I used to build this site, doesn't have a nice way to do this.</p>
</section>
<section>
    <h2>The solution</h2>
    <h3>Future Post (aka this one)</h3>
    <p>I created a post that has a future date, of 1st January 2500.</p>
    <pre>
---
title: 'Future Post that will be removed'
date: '2500-01-01'
tags: ['Future', 'Eleventy']
description: 'If you are seeing this, …
---
    </pre>
    <h3>Filter out the future post</h3>
    <p>In order to do this I check if the posts date is <em>not</em> 1st January 2500.</p>
    <pre>
&lcub;&percnt; if item.data.date != "2500-01-01" &percnt;&rcub;
  code that I want goes here
&lcub;&percnt; endif &percnt;&rcub;
    </pre>
    <h3>Set a reminder to update in 2500</h3>
    <p>As I may want to post an article on 1st January 2500, I have set a calender reminder to fix this hack in the future.</p>
</section>
<section>
    <h2>Why 'Hello Mike…'</h2>
    <p>Well it was my good friend Mike that came up with the original idea for solving this:</p>
    <blockquote>
        <p>I would approach this by having a dummy entry in whatever data you're paginating, either at the start or at the end, which has a property set to say that it should not be displayed. <a href="https://twitter.com/hashtag/hack?src=hashtag_click">#hack</a> <a href="https://twitter.com/eleven_ty">@eleven_ty</a></p>
        <cite>Quote Source <a href="https://twitter.com/PermittedSoc/status/1358798855358316545">@PermittedSoc - Twitter</a></cite>
    </blockquote>
</section>
      ]]></content>
    </entry>
	
    
    <entry>
      <title>Array.some()</title>
      <link href="https://code-red.uk/blog/array-dot-some/"/>
      <updated>2021-09-29T10:00:00Z</updated>
      <id>https://code-red.uk/blog/array-dot-some/</id>
      <content type="html"><![CDATA[
        <section>
  <p>As I learn more and more about JavaScript I realise that there is more and more that I don't know and I have realised that a great deal of what I am doing with JavaScript is examining data and doing stuff with that data. A great deal of that data is a list of things or an array.</p>
  <p>In JavaScript there are methods, which are prebuilt bits of code for working with data, whether that data be:</p>
  <ul>
    <li>Strings - words and numbers for example a person's name</li>
    <li>Numbers - for example the cost of something</li>
    <li>Boolean - true or false value for example an option is selected or not</li>
    <li>Array - a list of things for example a list of peoples names.</li>
    <li>Object -  a complex bit of related data for example a person, their first/last names, age, date of birth, etc.</li>
  </ul>
  <p> An array can be a list of strings, numbers, booleans, arrays, objects or a mixture of all of these.</p>
</section>
<section>
  <h2>Array.some()</h2>
  <p>This method allows you to check that a value appears in an array and will return <code>true</code> or <code>false</code>.</p>
  <p>Here I have a simple array of numbers.</p>
  <pre>
let simpleArray = [1, 2, 3, 4, 5, 6]
  </pre>
  <p>I can use the <code>.some()</code> method to check if a value appears in the array.</p>
  <pre>
simpleArray.some(2)
// returns true as 2 is in the array
simpleArray.some(7)
// returns false as 7 is not in the array
  </pre>
  <h3>If a value in an array is an object</h3>
  <p>Real life is usually a little more complex so let me explain why I am using this to give more context</p>
  <h4>Use Case</h4>
  <p>I have an id which I have got from the url:</p>
  <p><code>https://mysite.com/user/<strong>abc123</strong></code> id = abc123</p>
  <p>I have an array of users, my data:</p>
  <pre>
const users = [
  {
    id: "abc123",
    name: "Dave",
    age: 52
  },
  {
    id: "def456",
    name: "Tom",
    age: 36
  },
  {
    id: "ghi789",
    name: "Dick",
    age: 27
  }
]
  </pre>
  <p>Now I want to check to see if the id appears in the users array</p>
  <h4>Solution</h4>
  <pre>
users.some(user => user.id.includes(id))
  </pre>
  <p>This uses the <code>.some()</code> method and inside we have an arrow function that breaks each object in the array into a user.</p>
  <p>Then it looks in that user for an <code>id</code> (or <code>object key</code>) and then uses the <code>.includes()</code> string method to see if the <code>id</code> I got from the url is in the current user object that is being inspected.</p>
  <h4>How I am using this</h4>
  <p>So I am checking to see if the user exists in my array and if it is I am loading that into the page, if not I make an <code>API</code> call to get the user.</p>
  <pre>
if (users.some(user => user.id.includes(id))) {
  // load the user into the page
} else {
  // call function to get the user
  getUser(id);
  // load user into the page
}
  </pre>
  <h3>Further reading</h3>
  <ul>
    <li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some"><code>.some()</code> array method MDN</a></li>
    <li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes"><code>.includes()</code> string method MDN</a></li>
    <li><a href="https://caniuse.com/mdn-javascript_builtins_array_some"><code>.some()</code> array method can I use</a></li>
    <li><a href="https://caniuse.com/es6-string-includes"><code>.includes()</code> string method can I use</a></li>
  </ul>
      ]]></content>
    </entry>
	
    
    <entry>
      <title>Money is not the only form of Reward</title>
      <link href="https://code-red.uk/blog/money-is-not-the-only-form-of-reward/"/>
      <updated>2021-05-14T16:00:00Z</updated>
      <id>https://code-red.uk/blog/money-is-not-the-only-form-of-reward/</id>
      <content type="html"><![CDATA[
        <section>
    <p>Last week I had some downtime from client work and my partner who is working for a local charity <a href="https://bonnydowns.org/">Bonny Downs Community Association (BDCA)</a> was experiencing some technical issues with a method of getting referrals to their Foodbank.</p>
    <p>So we offered our services to help with this and build them an online form to solve this process.</p>
</section>
<section>
    <h2>Solution</h2>
    <p>So their Content Management System (CMS) is <a href="https://wordpress.org/">Wordpress</a>, which is an Open Source CMS that powers almost <a href="https://www.searchenginejournal.com/wordpress-powers-39-5-of-all-websites/391647">40% of all the websites in the world</a>. Although there was no form functionality in the CMS.</p>
    <p>There are a number of <em>Form Plugins</em> for Wordpress. The requirements that I had for this were:</p>
    <ul>
        <li>Free, to save on extra expense</li>
        <li>Full control of the code generated on the frontend</li>
        <li>Simple to use and embed in a page</li>
    </ul>
    <h3>Contact Form 7</h3>
    <p>The solution I opted for was <a href="https://contactform7.com/">Contact Form 7</a> as it met all the requirements, mostly.</p>
    <p>It is not like many other form builders drag and drop, which can be easy for some users although you still need to know what you are dragging and dropping. It has fantastic documentation and gave me full control over the frontend HTML. this meant that I could make sure taht I was using the input elements that I wanted and make sure the from was easy to use and accessible.</p>
    <p>The only downside to Contact Form 7 is that it does not store the form submission in the Wordpress Database. This may not be an issue if you just want the form to send emails. If however you do want to collect the data, then there is another plugin for use with Contact Form 7 that does exactly that, called <a href="https://contactform7.com/save-submitted-messages-with-flamingo/">Flamingo</a>.</p>
    <p>You can see the code I used to build the form on my github account.</p>
    <ul>
        <li><a href="https://github.com/CodeRedDigital/Bonny-Downs-Food-Bank-Referral/blob/main/Forms/food-bank-referral.html">Contact Form</a></li>
        <li><a href="https://github.com/CodeRedDigital/Bonny-Downs-Food-Bank-Referral/blob/main/Forms/message-body.html">Email content</a></li>
    </ul>
</section>
      ]]></content>
    </entry>
	
    
    <entry>
      <title>Daft Punk of the Web</title>
      <link href="https://code-red.uk/blog/daft-punk-of-the-web/"/>
      <updated>2021-02-26T12:00:00Z</updated>
      <id>https://code-red.uk/blog/daft-punk-of-the-web/</id>
      <content type="html"><![CDATA[
        <section>
    <p>This week <a href="https://en.wikipedia.org/wiki/Daft_Punk" title="Daft Punk's wikipedia page">Daft Punk</a>, the French electronic music duo, announced that after 28 years in the music industry they were to split.</p>
    <p>They did this via <a href="https://www.youtube.com/watch?v=DuDX6wNfjqc" title="Daft Punk's Epilogue video">a video called Epilogue</a> on their YouTube channel.</p>
    <p>But how does Daft Punk relate to the Web?</p>
</section>
<section>
    <h2>Robots rock</h2>
    <p>Daft Punk, were commonly known via their Robot personas. Similarly websites also need a Robot to be discoverable.</p>
    <p>To be more precise a <code>robots.txt</code>. This is a text file that lives at the root of a website that tells machines what to look for on  the site and what not to look for.</p>
    <p>In this file we tell the bots of the web what they are <em>allowed</em> and <em>disallowed</em> from seeing or indexing (storing for them to display).</p>
    <p>By default with no settings the bots will just look at everything in your site. For areas you don't want them to go add a <code>Disallow</code> rule and then for other bots you can then <code>Allow</code> those areas back, see my example below. <sup><a href="#thanks" title="attribution to Alistair Shepherd">†</a></sup></p>
    <p>These bots are referred to as <strong>User-Agents</strong> and we can target all of them together with a wildcard <code>* (asterisk)</code>, or naming them individually.</p>
    <p>Here is the <a href="/robots.txt">robots.txt</a> for this site, below I shall explain what is going on.</p>
    <pre>
User-agent: Twitterbot
Allow: /images/

User-agent: facebookexternalhit
Allow: /images/

User-agent: *
Sitemap: https://code-red.uk/sitemap.xml
Disallow: /images/
    </pre>
    <p>First of all I am telling the Twitter and Facebook's bot that it is OK to go ahead and look at all the files in the <code>/images/</code> folder.</p>
    <p>Secondly I m using the <code>*</code> (wildcard) to target every bot and tell them where my <a href="/sitemap.xml"><code>sitemap.xml</code></a> is located. I then <code>Disallow</code> them all from indexing all files in the <code>/images/</code> folder. A sitemap is just a list of all the pages, in your site, you want the bots to look at.</p>
</section>
<section>
    <h2>Humans after all</h2>
    <p>Daft Punk, were of course not robots, they were Humans after all. Just like websites are not created by robots they are created by humans.</p>
    <p>We can add a <code>humans.txt</code> file to the root to show who are the real people that have worked on, contributed or helped on a site.</p>
    <p>While there is no requirement or standard for creating a <code>humans.txt</code>, <a href="http://humanstxt.org/">http://humanstxt.org/</a> has some guidelines on what you might include. For example:</p>
    <ul>
        <li>Team</li>
        <li>Technologies</li>
        <li>Thanks</li>
    </ul>
    <p>Some companies will use it to advertise jobs too.</p>
    <p>Below you can see the <a href="/humans.txt">humans.txt</a> file for this site.</p>
    <pre>
# humanstxt.org
/* OWNER & DEVELOPER */

    Name:    Dave Letorey
    Email:   dave@code-red.uk
    GitHub:  https://github.com/dletorey
    Twitter: https://twitter.com/dletorey

/* SITE */

    URL:           https://code-red.uk
    Language:      en
    Doctype:       HTML5
    Fonts:         Helvetica Neue, Georgia, Lucida Console
    Compiled with: Eleventy
    IDE:           VS Code

/* LANGUAGES */

    HTML
    CSS (SCSS)
    JavaScript
    JSON
    Nunjucks
    XML
    YAML


                                
/* THANKS */
            
    CSS Skills: Chris Burnell
    URL: https://chrisburnell.com 
    Twitter: @iamchrisburnell

    Eleventy From Scratch: Andy Bell
    URL: https://piccalil.li
    Course URL: https://piccalil.li/course/learn-eleventy-from-scratch
    Twitter: @piccalilli_
    </pre>
</section>
<section>
    <h2>Conclusion</h2>
    <p>Daft Punk were an amazing part of music history and their music has not gone away, they just won't be making anymore. I don't think this is that bad a thing as they'd been dormant for a while and perhaps now they will make more music on solo projects.</p> 
    <p>In order to make your site discoverable, you'll need a <code>robots.txt</code> file.</p>
    <p>The bots/user-agents that I've been talking about are Search Engines (<a href="https://www.google.com/">https://www.google.com/</a>, <a href="https://duckduckgo.com/">DuckDuckGo</a>, <a href="https://uk.yahoo.com/">Yahoo</a>, etc) or Social Networks. These are the most common, but there are more too.</p>
    <p>In order to show appreciation for those working on your site you should include a <code>humans.txt</code> file.</p>
    <h3>Listen to the tracks that inspired this article</h3>
    <ul>
        <li><a href="https://www.youtube.com/watch?v=DuDX6wNfjqc">Epilogue - Daft Punk</a></li>
        <li><a href="https://www.youtube.com/watch?v=HdeYwObD-j4">Robot Rock - Daft Punk</a></li>
        <li><a href="https://www.youtube.com/watch?v=PXYeARRyDWk">Human After All - Daft Punk</a></li>
    </ul>
</section>
<section>
    <h2 id="thanks">† Thanks</h2>
    <p>Thanks to <a href="https://twitter.com/Accudio" title="Alistair Shepherd on twitter">Alistair Shepherd</a> for helping me clarify the default behaviour.</p>
</section>

      ]]></content>
    </entry>
	
    
    <entry>
      <title>I have a problem, an HTML problem</title>
      <link href="https://code-red.uk/blog/i-have-a-problem-an-html-problem/"/>
      <updated>2021-02-23T00:00:00Z</updated>
      <id>https://code-red.uk/blog/i-have-a-problem-an-html-problem/</id>
      <content type="html"><![CDATA[
        <section>
    <p>The term <em>HTML-aholic</em> was coined by <a href="https://twitter.com/brucel/" title="Bruce on Twitter">Bruce Lawson</a> during his talk “<a href="https://youtu.be/T2CjuAwrAq8?t=29" title="Watch Bruce's talk">Accessibility, Back to the Future</a>” at <a href="https://monkigras.com/" title="Monkigras Conference">Monkigras 2019</a>.</p>
    <blockquote>I'm Bruce and I’m an HTML-aholic. … I've been an HTML-aholic for 20 years now. <cite><a href="https://www.brucelawson.co.uk/" title="Bruce’s site">Bruce Lawson</a> - Monkigras 2019</cite></blockquote>
    <p>In my <a href="/ethos">ethos</a> my first point is HTML First, I hope this goes some way to explaining that.</p>
</section>
<section>
    <h2>What is HTML</h2>
    <p>HTML, or Hyper Text Markup Language, is the language of the World Wide Web.</p>
    <p>Without HTML there would be no Social Media, there would be no online stores, there would be no Web.</p>
    <p>In short HTML is the web.</p>
</section>
<section>
    <h2>Why HTML first?</h2>
    <p>Many of these modern platforms and sites are now built with JavaScript Libraries, so much so that Facebook built their own JavaScript Library called <a href="https://reactjs.org/" title="React JS Library">React</a>. All of these Libraries, though, in the end output HTML.</p>
    <p>Done correctly using these Libraries is not an issue. Although done wrongly a user could just be left staring at a blank screen.</p>
    <figure>
        <img src="/images/posts/social-no-JavaScript.png" alt="Social networks with JavaScript disabled">
        <figcaption>Facebook, Instagram and Twitter with JavaScript disabled</figcaption>
    </figure>
    <p>This is a terrible situation, if you are building sites with content, such as a blog, recipe site, a store. You want these things to be discovered.</p>
    <p>A search engine or spider will crawl the web, that's why it's called a spider. When it does this it will look at the HTML on your site and the content within that HTML. It will <strong>not</strong> run any JavaScript that is on your site, that's not what it's looking for. So if the HTML and content on your site is built with JavaScript the spider will not discover it. This is the worst SEO you could possibly have: <em>no content</em>.</p>
    <p>This does not mean don’t use JavaScript, it means use JavaScript at the right time and for the right purpose, I shall write about this in the future.</p>
</section>
<section>
    <h2>HTML has meaning</h2>
    <p>In HTML there are things called elements, for example <code>&lt;p&gt;</code> represents a <em>paragraph</em> and <code>&lt;address&gt;</code> is used to display an address for a person or organisation. At the time of writing <abbr title="Mozilla Developer Network">MDN</abbr> says there are <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element">142 different HTML elements</a>.</p>
    <p>Using the correct <em>element</em> tells the Browser, Search Engine, Assistive Technology (such as a screen reader), etc what the content really is and giving it meaning.</p>
    <p>These meanings are what we call semantics of the information on web pages or web applications. Without using these elements you would then need to teach the Browser, Search Engine, Assistive Technology, what various parts of your content are for.</p>
    <p>If you look at the code (right click and select <em>View Source</em>) behind many of the largest sites you’d be forgiven for not even realising that HTML has more than just <code>&lt;div&gt;</code> and <code>&lt;span&gt;</code> elements.</p>
    <figure>
        <img src="/images/posts/tweet-code.png" alt="Social networks with JavaScript disabled">
        <figcaption>Some of the code behind a single tweet on twitter.com</figcaption>
    </figure>
    <p>In this example, from twitter, we can gain absolutely no meaning at all and would need to start explaining to the tools what each bit is for.</p>
    <p>By the way a <code>&lt;div&gt;</code> element is a block-level generic element that has no meaning. A <code>&lt;span&gt;</code> element is a inline-level generic element that has no meaning.</p>
    <p>Developers give them meaning by applying classes or ids, such as:</p>
    <pre>&lt;div class="header"&gt;</pre>
    <p>This is the whole reason <a href="https://en.wikipedia.org/wiki/HTML5" title="HTML5 entry on wikipedia">HTML5</a> was developed during 2004-2008.</p>
    <h3>How HTML5 gives meaning</h3>
    <pre>
&lt;header&gt;
    &lt;a href=".."&gt;
      &lt;strong&gt;Code Red Digital&lt;/strong&gt;
      &lt;time&gt;
        Feb 23
      &lt;/time&gt;
    &lt;/a&gt;
&lt;/header&gt;
&lt;section&gt;
    &lt;p&gt;Content of my tweet…&lt;/p&gt;
&lt;/section&gt;
&lt;footer&gt;
    Comment, Retweet, Like 
&lt;/footer&gt;
    </pre>
    <p>Here I have simply refactored the code of a tweet to give it meaning, which means there is some basic understanding. What you can see here is:</p>
    <ul>
        <li>A <code>&lt;header&gt;</code> that contains the users name and date of the tweet</li>
        <li>A <code>&lt;section&gt;</code> that contains the contents of the tweet</li>
        <li>A <code>&lt;footer&gt;</code> that contains the comment, like and share functions</li>
    </ul>
    <p>All of these sections now have a meaning.</p>
</section>
<section>
    <h2>HTML is Dumb/Smart</h2>
    <h3>Why Dumb</h3>
    <p>It is often said that HTML is a dumb language, what this means is that if a tool looking at the HTML code (such as a browser) doesn't understand it, it just moves on.</p>
    <p>Although more importantly does not break.</p>
    <h3>Why Smart</h3>
    <p>Alternatively it is also said that HTML is a smart language.</p>
    <p>If a developer misses something out in HTML, for example a closing tag, unlike most other programming languages it does not care and just carries on.</p>
    <p>If a user is using an old device, or browser they have no control over and that browser does not recognise a new HTML element it just moves on. Pretty smart eh?</p>
</section>
<section>
    <h2>HTML is Accessible</h2>
    <p>Semantic HTML is accessible out of the box. For example if on our web page or web app we create a button, like so:</p>
    <pre>&lt;button&gt;Click Me&lt;/button&gt;</pre>
    <p>A screen-reader or other assistive technology will instantly know what it is and what it does.</p>
    <p>If however we don't use semantics and create a button like this:</p>
    <pre>&lt;div class="button"&gt;Click Me&lt;/div&gt;</pre>
    <p>We then need to teach that assistive technology that this is a button and not some random HTML element.</p>
    <p>I call this, <strong>Using the right tool for the right job</strong>. Creating a button from a <code>&lt;div&gt;</code> is like a builder using a screwdriver to cut a piece of wood.</p>
</section>
<section>
    <h2>HTML is Responsive</h2>
    <p>Again, out of the box, HTML is responsive. What this means is that the content of a  web page will flow to fit the size of the device displaying it.</p>
    <p>It is only when we start adding CSS and sizes that we break that inherent responsiveness.</p>
</section>
<section>
    <h2>Conclusion</h2>
    <p>Many thought leaders in the web industry will say, build with Mobile first philosophy and then build up.</p> 
    <p>I would take this further and build HTML First, there are still browsers out there that do not understand CSS and then build for mobile and then progressively add more features for more capable devices (this is called progressive enhancement, but I'll talk about that in a future post).</p>
    <p>I also believe that the more that we use other new devices, such as smart speakers then HTML will again need to be front and center.</p>
</section>

      ]]></content>
    </entry>
	
    
    <entry>
      <title>A11y isn’t Just…</title>
      <link href="https://code-red.uk/blog/a11y-isnt-just/"/>
      <updated>2021-02-19T00:00:00Z</updated>
      <id>https://code-red.uk/blog/a11y-isnt-just/</id>
      <content type="html"><![CDATA[
        
<section><p>
  Why a11y? A11y is a numeronym, presenting "accessibility" as "a" followed by
  11 more letters, followed by "y".
</p>
</section>
<section>
<h2>… Screen Readers</h2>
<p>
  For a great many people when you talk about accessibility, they instantly
  think about Screen Readers. While Screen Readers are an important tool for
  those that have an impairment there are many other ways a user can be
  affected.
</p>
<h3>Hearing</h3>
<p>
  You might think that reading a web page isn't going to affect hearing, but in
  today's modern web has rich media including video and audio. Subtitles and
  Captioning can help with this, I believe this should be mandatory. If
  Subtitles or Captions are not possible or appropriate a Text Description can
  help, this will also help with those on slow networks or less with data.
</p>
<h3>Visual</h3>
<p>
  The majority of people think that Screen Reader users are blind. This is just
  not true, in fact the majority of blind people actually have some sight. The
  best thing that we can do for Screen Readers are:
</p>
<ul>
  <li>Use the correct <acronym title="Hyper Text Markup Language">HTML</acronym> elements</li>
  <li>Write semantic HTML</li>
  <li>Use <a href="https://www.w3.org/TR/2017/NOTE-wai-aria-practices-1.1-20171214/examples/landmarks/index.html" title="W3C Aria Landmark Roles examples">Aria Landmark Roles</a></li>
  <li>Use large text</li>
  <li>Consider contrast ratios of text and background</li>
</ul>
<h4>Colour Blindness</h4>
<p>
  Colour Blindness affects about 8% of all men and 0.6% of women and comes in many different types, the 3 main ones are:
</p>
<ul>
  <li>Deuteranopia (common)</li>
  <li>Protanopia (Rare)</li>
  <li>Tritanopia (Very Rare)</li>
</ul>
<p>
  I use a tool called
  <a href="https://colororacle.org/" title="Color Oracle App">Color Oracle</a>
  for testing my web pages for colour blind users, you should consider looking
  at what your site looks like for user with Colour Blindness. You can also get contrast score in the browsers dev tools.
</p>
<h3>Dexterity</h3>
<p>
  Not all of our users have the ability to use a mouse to navigate a web page,
  some of them have fat fingers. While not actually a disability it does make it
  difficult to hit small targets close together on touch devices.
</p>
<p>
  Dexterity is about making your site easy to use for those with accuracy
  problems. Having small buttons makes it difficult to target with a mouse,
  especially if the elements are not laid out semantically.
</p>
<p>
  At work I use a mouse as little as possible, opting for Keyboard Shortcuts and
  tabbing through forms and I’m frequently disappointed.
</p>
<p>The best things we can do for users with dexterity problems are:</p>
<ul>
  <li>Use <code>:focus</code> styles - this is not hard and you probably already have <code>:hover</code> styles, although these may not be appropriate</li>
  <li>Use the correct HTML elements</li>
  <li>Write semantic HTML</li>
  <li>Don't re-order elements with <acronym title="Cascading Style Sheets">CSS</acronym></li>
  <li>Never mess with <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/tabindex" title="Mozilla Developer Network article on tabindex">tabindex</a></li>
</ul>
<h3>Cognitive</h3>
<p>
  This affects a user's ability to understand. The issue most associated with
  this is dyslexia. Making the content easy to read and understand, without
  using complex terms. Using sans serif fonts are easier to read, users who have
  severe dyslexia will often override your stylesheets with their own. The
  British Dyslexia Association has a fantastic
  <a href="https://www.bdadyslexia.org.uk/common/ckeditor/filemanager/userfiles/About_Us/policies/Dyslexia_Style_Guide.pdf" title="BDA Style Guide">Dyslexia Style Guide (PDF)</a>.
</p>
</section>
<section>
<h2>… Guidelines</h2>
<p>
  There are guidelines that help us to check our sites for accessibility issues.
  These, as the name suggest, are a guide and only following a set of predefined
  checkpoints doesn't mean that your site is truly accessible, it means that you
  passed those checkpoints.
</p>
<p>
  Saying that, they can still be a good guide. There is a great tool called <a href="https://www.deque.com/axe/">axe</a>, that I use regularly.
</p>
<h3>Section508 (1194.22)</h3>
<p>
  While this standard covers all areas of a11y there is a section of it,
  <a
    href="https://www.access-board.gov/guidelines-and-standards/communications-and-it/about-the-section-508-standards/guide-to-the-section-508-standards/web-based-intranet-and-internet-information-and-applications-1194-22"
    title="section508 1194.22"
    >1194.22</a
  >, which covers Web-based Intranet and Internet Information and Applications.
  The rest of the standard covers areas such as:
</p>
<ul>
  <li>Software Applications &amp; Operating Systems (1194.21)</li>
  <li>Telecommunication Products (1194.23)</li>
  <li>Video &amp; Multi-media Products (1194.24)</li>
  <li>Self-Contained, Closed Products (1194.25)</li>
  <li>Desktop &amp; Portable Computers (1194.26)</li>
  <li>Functional Performance Criteria (1194.31)</li>
  <li>Information Documentation &amp; Support (1194.41)</li>
</ul>
<p>
  The bulk of 1194.22 has not been updated since 2001, a time when the web we
  created was a very different beast. In fact, some of the recommendations I
  looked at talk specifically about table-based layouts. This got me thinking
  about perhaps it’s about time that the US should consider using, WCAG, the
  same standard used by the rest of the world and recommended by W3C. Further
  reading/research led me to discover that the United States Access Board, 18
  January 2017, published a
  <a
    href="https://www.access-board.gov/guidelines-and-standards/communications-and-it/about-the-ict-refresh/overview-of-the-final-rule"
    title="Overview of section508 final Rule"
    >Final Rule</a
  >.
</p>
<p>
  The Final Rule, outlined the changes that were to be made to section508. The
  main one, affect those who build websites and web-based applications, is
  Incorporation of the Web Content Accessibility Guidelines (WCAG). This came
  into effect as of 18 January 2018. This is a great leap forward for a11y in
  the US, many of the sites that I tested last week, using HTML CodeSniffer, for
  section508 would highlight the occasion error or warning. When testing the
  same sites against WCAG AA, they would highlight considerably more errors or
  warnings.
</p>
<h3>WCAG</h3>
<p>
  <a href="https://www.w3.org/WAI/intro/wcag" title="Introduction to WCAG"
    >WCAG</a
  >
  is a more universal standard, created by the W3C's WAI (Web Accessibility
  Initiative). WCAG is a standard that originates from 1999 (WCAG 1.0), the WAI
  have just released the <a href="https://www.w3.org/TR/wcag-3.0/" title="Candidate Release for WCAG 2.1">First Public Working Draft for WCAG 3.0</a>.
</p>
</section><section>
<h2>… For the disabled people</h2>
<p>
  Making sites accessible for those with accessibility issues is great UX and
  make our sites better for all. The argument, "we don't have blind users on our
  site", just does not wash. You have no idea what impairments your users have
  or how they're interacting with your site. Google Analytics can tell us many
  things about our users, but can't tell if they are using a screen reader,
  keyboard, mouse, braille keyboard to interact with our sites.
</p>
<p>There are many times when a11y helps normal users:</p>
<ul>
  <li>
    Due to my dyslexia I often get my computer to read long blog posts to me
  </li>
  <li>
    With old age comes:
    <ul>
      <li>Dexterity Issues</li>
      <li>Hearing Issues</li>
      <li>Visual Issues</li>
      <li>Cognitive Issues</li>
    </ul>
  </li>
  <li>
    When I have no headphones on public transport, captions help me watch videos
  </li>
  <li>Captions can also help with strong accents</li>
  <li>
    While drunk/intoxicated, an easy to read/simple site can aid
    understandability
  </li>
  <li>
    If a right-handed person breaks their arm and has it in a cast using a mouse
    or touch device becomes more difficult.
  </li>
</ul>
<p>
  The <a href="https://www.microsoft.com/en-us/design/inclusive" title="Microsoft Inclusive Design">Microsoft Inclusive Design site</a>, is a fantastic resource, especially their Inclusive Toolkit Manual, for understanding Permanent, Temporary and Situational disabilities. <a href="https://www.twitter.com/ninjanails">Seren Davies</a>, added a Cognitive section to their Inclusive Toolkit Manual.
</p>
<figure>
  <picture>
    <source srcset="/images/posts/cognitive-lg.png" media="(min-width: 1024px)" />
    <source srcset="/images/posts/cognitive-md.png" media="(min-width: 599px)" />
    <img src="/images/posts/cognitive-sm.png" srcset="/images/posts/cognitive-sm.png" alt="Cognitive Users" />
  </picture>
<figcaption>
  Seren Davies' addition to the Microsoft Inclusive Design Toolkit
</figcaption>
</figure>
</section><section>
<h2>Further Reading/Learning</h2>
<p>
  I can't recommend highly enough
  <a href="https://twitter.com/laurakalbag" title="Laura on Twitter"
    >Laura Kalbag's</a
  >
  <a
    href="https://abookapart.com/products/accessibility-for-everyone"
    title="Accessibility for Everyone - A book Apart"
    >Accessibility for Everyone</a
  >
  in my opinion this book is a game changer and anyone who works in the web
  industry should read this.
</p>
<p>
  <a href="https://twitter.com/ninjanails" title="Seren on Twitter"
    >Seren Davies'</a
  >
  talks on accessibility are fantastic:
</p>
<ul>
  <li>
    <a
      href="https://speakerdeck.com/ninjanails/death-to-icon-fonts"
      title="Death to Icon Fonts on Speakerdeck"
      >Death to Icon Fonts</a
    >
    - this talk made
    <a
      href="https://blog.github.com/2016-02-22-delivering-octicons-with-svg/"
      title="Github on removing Icon Fonts"
      >github change their site</a
    >
  </li>
  <li>
    <a
      href="https://speakerdeck.com/ninjanails/accessibility-is-more-than-just-supporting-screenreaders-2"
      title="A11y is more than just supporting screenreaders on Speakerdeck"
      >Accessibility is more than just supporting screenreaders</a
    >
  </li>
</ul>
</section><section>
<h2>People to follow</h2>
<p>
  Want to learn more about a11y, then I recommend you follow, as a start, these
  people on twitter:
</p>
<ul>
  <li>
    <a href="https://twitter.com/LeonieWatson" title="Léonie on Twitter"
      >Léonie Watson</a
    >
  </li>
  <li>
    <a href="https://twitter.com/stevefaulkner" title="Steve on Twitter"
      >Steve Faulkner</a
    >
  </li>
  <li>
    <a href="https://twitter.com/aardrian" title="Adrian on Twitter"
      >Adrian Roselli</a
    >
  </li>
  <li>
    <a href="https://twitter.com/ninjanails" title="Adrian on Twitter"
      >Seren Davies</a
    >
  </li>
  <li>
    <a href="https://twitter.com/laurakalbag" title="Laura on Twitter"
      >Laura Kalbag</a
    >
  </li>
</ul>
</section>
      ]]></content>
    </entry>
	
    
    <entry>
      <title>WWW - whoops, why, what?</title>
      <link href="https://code-red.uk/blog/www-whoops-why-what/"/>
      <updated>2021-02-18T00:00:00Z</updated>
      <id>https://code-red.uk/blog/www-whoops-why-what/</id>
      <content type="html"><![CDATA[
        <section><p>So the World Wide Web, often shortened to <abbr title="World Wide Web">www</abbr>, became a thing in 1989, and since then many people/companies/organisations have been prefixing their website <abbr title="Universal Resource Locator">URLs</abbr> with <abbr title="World Wide Web">www</abbr>. Even though nobody ever buys <samp>www.my-website-name.com</samp>, they would purchase <samp>my-website-name.com</samp>, and the <samp>www</samp> part is a subdomain of the domain.</p>
</section><section>
<h2>Whoops</h2>
<p>It is reported that <a href="https://en.wikipedia.org/wiki/World_Wide_Web#WWW_prefix" title="www prefix on Wikipedia">the www was a mistake</a>. It was originally meant to refer to the World Wide Web project page at CERN <span lang="fr">(Conseil européen pour la recherche nucléair)</span> and info.cern.ch was meant to be the home page for CERN, although the DNS records were never switched. Subsequently many organisations followed suit and www became the norm.</p>
<h3>Douglas Adams</h3>
<p>Douglas once quipped:</p>
<blockquote><p>The World Wide Web is the only thing I know of whose shortened form takes three times longer to say than what it’s short for</p><cite>Douglas Adams <a href="https://en.wikipedia.org/wiki/Pronunciation_of_%22www%22">www pronunciation</a></cite></blockquote>
<p>This is because World Wide Web has 3 syllables and double-u double-u double-u has 6.</p>
</section><section>
<h2>Why?</h2>
<p>So why do people/companies/organisations use www in the <abbr title="Universal Resource Locator">URL</abbr> of their site, well simply because that's how the first site did it.</p>
</section><section>
<h2>What, should you do?</h2>
<p>Well, technically, really it doesn't matter.</p>
<p>The way I think of it is what do you say out loud when you tell someone the URL of your site, I say - <em>code-red.uk</em> (that's <em>code dash red dot uk</em>). I, personally, would never say <em>double-u double-u double-u dot code dash red dot uk</em>.</p>
<h3>How to decide?</h3>
<p>Well if you're a company or organisation that has created loads of printed and digital materials, with either www or non-www then choose that way, the important thing to do is create the redirect on your web server.</p>
</section>
      ]]></content>
    </entry>
	
    
    <entry>
      <title>Animating a mobile menu</title>
      <link href="https://code-red.uk/blog/animating-a-mobile-menu/"/>
      <updated>2020-11-24T00:00:00Z</updated>
      <id>https://code-red.uk/blog/animating-a-mobile-menu/</id>
      <content type="html"><![CDATA[
        
<section>
<p>While designing my new site, I am first focussing on mobile first strategy, I want to learn and showcase ideas.</p>
<p>So I have decided that I want to animate the menu on mobile to make best use of the screen. Here is a small video of what I'm trying to achieve.</p>
<video controls="" width="722">
    <source src="/images/posts/mobile-menu-animation.mp4" type="video/mp4">
</video>
</section>
<section>
<h2>Logo starting point</h2>
<p><img src="/images/posts/logo-starting-point.png" alt="Logo position when the menu is closed" width="719" height="587" /></p>
<h3>HTML</h3>
<pre>&lt;header&gt;
    &lt;svg&gt;&hellip;&lt;/svg&gt;
  &lt;/header&gt; 
  </pre>
<h3>CSS</h3>
<pre>header {
    position: relative;
    top: 0px; left 0;
    height: 45px;
    width: 100%;
    background-color: #D0021B;
    padding: 5px;
    <strong>margin</strong>: 0 0 0 <strong>27px</strong>;
  }
  
  svg {
  &nbsp; position: absolute;
    top: 1px; <strong>left: -30px;</strong>
    <strong>z-index: 10;</strong>
  } 
   
  header svg {
    <strong>transform: rotate(90deg);</strong>
  }  </pre>
<h3>Explanation</h3>
<p>I want the header to start half way through the circle in the logo hence the margin-left of 27px. As the header has this margin then the svg needs a left position of -30px. I want the Logo to be on top of the header so gave it a z-index of 10. I have also set the svg in the header to rotate 90&ordm; clockwise.</p>
</section>
<section>
<h2>Logo ending point</h2>
<p><img src="/images/posts/logo-ending-point.png" alt="Logo position when the menu is open" width="720" height="111" /></p>
<h3>HTML</h3>
<pre>&lt;header <strong>class="open"</strong>&gt;
    &lt;svg&gt;&hellip;&lt;/svg&gt;
  &lt;/header&gt; 
  </pre>
<h3>CSS</h3>
<pre>header {
    position: relative;
    top: 0px; left 0;
    height: 45px;
    width: 100%;
    background-color: #D0021B;
    padding: 5px;
    margin: 0 0 0 27px;
  }
  
  svg {
  &nbsp; position: absolute;
    top: 1px; left: -30px;
    z-index: 10;
  } 
   
  header.open svg {
    <strong>transform-origin: 28px 28px;</strong>
    <strong>transform: rotate(0deg);</strong>
  } </pre>
<h3>Explanation</h3>
<p>When the menu is open, the header has a <code>class="open"</code> and the logo will be in a horizontal position. It needs to rotate 90&ordm; anit-clockwise hence <code>transform: rotate(0deg)</code> which is going from 90&ordm; to 0&ordm;. As I want the rotation to happen in the centre of the circle in the logo I need to move the place where it rotates around, aka the origin, <code>transform-origin: 28px 28px</code>. With out this the default is to rotate in the centre of the image/svg.</p>
</section>
<section>
<h2>Menu open state</h2>
<p><img src="/images/posts/menu-open.png" alt="Menu in the open state" width="714" height="668" /></p>
<h3>HTML</h3>
<pre>&lt;header&gt;
    &lt;button <strong>class="hidden"</strong> name="menu"&gt;Menu☰&lt;/button&gt;
    &lt;nav id="menu"&gt;
      &lt;ul&gt;
        &lt;li&gt;Ethos&lt;/li&gt;
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;li&gt;Services&lt;/li&gt;
        &lt;li&gt;Work&lt;/li&gt;
        &lt;li&gt;Case Studies&lt;/li&gt;
        &lt;li&gt;Blog&lt;/li&gt;
        &lt;li&gt;Contact&lt;/li&gt;
        &lt;li&gt;&lt;a href="#"&gt;Close X&lt;/a&gt;&lt;/li&gt;
      &lt;/ul&gt;
    &lt;/nav&gt;
  &lt;/header&gt; </pre>
<h3>CSS</h3>
<pre><strong>button.hidden</strong> {
    color: #D0021B;
  }
   
  nav {
    margin-top: -40px;
    margin-left: -32px;
  }
   
  nav ul {
    background-color: #D0021B;
    color: #FAF9F9;
    font-family: 'Courier New';
    Font-weight: 700;
    font-size: 2em;
    list-style: none;
    margin: 23px 0 0 -27px;
    padding: 35px 10px 10px 33px;
    border-radius: 0 0 23px 0;
  }
   
  nav ul a {
    color: #FAF9F9;
  }
   
  nav ul a:hover {
    background-color: #FAf9f9;
    color: #D0021B;
  }  </pre>
<h3>Explanation</h3>
<p>This is all pretty simple the margin top and left are to position the menu around the header. The button is hidden while the menu is open.</p>
</section>
<section>
<h2>Menu hidden state</h2>
<p><img src="/images/posts/menu-closed.png" alt="Menu in the closed state" width="718" height="110" /></p>
<h3>HTML</h3>
<pre>&lt;header&gt;
    &lt;button name="menu"&gt;Menu☰&lt;/button&gt;
    &lt;nav <strong>class="hidden"</strong> id="menu"&gt;
      &lt;ul&gt;
        &lt;li&gt;Ethos&lt;/li&gt;
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;li&gt;Services&lt;/li&gt;
        &lt;li&gt;Work&lt;/li&gt;
        &lt;li&gt;Case Studies&lt;/li&gt;
        &lt;li&gt;Blog&lt;/li&gt;
        &lt;li&gt;Contact&lt;/li&gt;
        &lt;li&gt;&lt;a href="#"&gt;Close X&lt;/a&gt;&lt;/li&gt;
      &lt;/ul&gt;
    &lt;/nav&gt;
  &lt;/header&gt; </pre><h3>CSS</h3><pre>button {
    background-color: #D0021B;
    color: #FAF9F9;
    font-family: 'Courier New';
    font-size: 2em;
    Font-weight: 700;
    text-decoration: underline;
    border: none;
    margin: 5px 0 0 30px;
    cursor: pointer;
  }
   
  nav.hidden {
    <strong>max-height: 0;</strong>
  } 
  </pre>
<h3>Explanation</h3>
<p>In this instance the button is displayed and the nav hidden, this is done by setting the <code>max-height: 0;</code>. I am displaying the word "Menu" as I don't think that the 3 horizontal lines (☰), aka hamburger menu, is good enough for accessibility purposes.</p>
</section>
<section>
<h2>Click/touch interaction and recognition</h2>
<h3>HTML</h3>
<pre>&lt;header&gt;
    &lt;button <strong>id="menuButton" onclick="menuToggle()"</strong> name="menu"&gt;Menu☰&lt;/button&gt;
    &lt;nav class="hidden" id="menu"&gt;
      &lt;ul&gt;
        &lt;li&gt;Ethos&lt;/li&gt;
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;li&gt;Services&lt;/li&gt;
        &lt;li&gt;Work&lt;/li&gt;
        &lt;li&gt;Case Studies&lt;/li&gt;
        &lt;li&gt;Blog&lt;/li&gt;
        &lt;li&gt;Contact&lt;/li&gt;
        &lt;li&gt;&lt;a href="#" <strong>onclick="menuToggle()"</strong>&gt;Close X&lt;/a&gt;&lt;/li&gt;
      &lt;/ul&gt;
    &lt;/nav&gt;
  &lt;/header&gt; </pre>
<h3>JavaScript</h3>
<pre>const menuButton = document.querySelector("#menuButton");
  const nav = document.querySelector("#menu");
  const header = document.querySelector("header");
   
  function menuToggle() {
    menuButton.classList.toggle("hidden");
    nav.classList.toggle("hidden");
    header.classList.toggle("open");
  }  </pre>
<h3>Explanation</h3>
<p>In the HTML I have added an <code>id="menuButton"</code> to make it easy to target incaase there are other buttons on the page, and an <code>onclick</code> event listener to the bnutton and close link.</p>
<p>In the JavaScript I am setting up 3 variables:</p>
<ul>
    <li>menuButton</li>
    <li>nav</li>
    <li>header</li>
</ul>
<p>I have then created a function thattargets the 3 varibales and toggles the classes on or off depending on their current state. For example if there is no <code>class="hidden"</code> then it adds it and if the is a <code>class="hidden"</code> then it removes it.</p>
</section>
<section>
<h2>Animate logo</h2>
<h3>CSS</h3>
<pre>header svg {
  &nbsp; transform-origin: 28px 28px;
    transform: rotate(0deg);
    <strong>transition: transform 2s ease;</strong>
  } </pre>
<h3>Explanation</h3>
<p>To the svg style I have added a <code>transition</code> property. This tells it that any transform should take <code>2s</code> (seconds) and <code>ease</code> (start slowly accelerate end slowly).</p>
</section>
<section>
<h2>Animate menu</h2>
<h3>CSS</h3>
<pre>nav {
    <strong>max-height: 500px;</strong>
    <strong>transition: max-height 2s ease;</strong>
    overflow: hidden;
    margin-top: -40px;
    margin-left: -32px;
  }
   
  nav.hidden {
    max-height: 0;
    <strong>transition: max-height 2s ease;</strong>
  }  </pre>
<h3>Explanation</h3>
<p>Here I have added a <code>max-height: 500px;</code> to the nav this is an arbitary value that is larger than the menu will be so that the is a value to transition upon. Then I have a transition: max-height 2s ease; which performs the transition on the <code>max-height</code> property for <code>2s</code> (seconds) and <code>ease</code>s.</p>
</section>
<section>
<h2>Add delays</h2>
<h3>CSS</h3>
<pre>header.open svg {
    transform-origin: 28px 28px;
    transform: rotate(-90deg);
    <strong>transition-delay: 0s;</strong>
  }
   
  header svg {
    transform-origin: 28px 28px;
    transform: rotate(0deg);
    transition: transform 2s ease;
    <strong>transition-delay: 2s;</strong>
  } 
  
  nav {
    max-height: 500px;
    transition: max-height 2s ease;
    <strong>transition-delay: 2s;</strong>
    overflow: hidden;
    margin-top: -40px;
    margin-left: -32px;
  }
   
  nav.hidden {
    max-height: 0;
    transition: max-height 2s ease;
    <strong>transition-delay: 0s;</strong>
  } </pre>
<h3>Explanation</h3>
<p>So here I want the following to happen:</p>
<ul>
    <li>On menu open:
        <ul>
            <li>Logo folds up</li>
            <li>Menu opens down</li>
        </ul>
    </li>
    <li>on menu close:
        <ul>
            <li>Menu closes up</li>
            <li>Logo folds down</li>
        </ul>
    </li>
</ul>
<p>The logo folding up should happen immediately, so no delay, <code>transition-delay: 0s;</code> when that has complete the menu opens down <code>transition-delay: 2s;</code> (this is 2 seconds as that is how long the first part takes).</p>
<p>The menu closing up should happen immediately, so no delay, <code>transition-delay: 0s;</code> when that has complete the logo folds down <code>transition-delay: 2s;</code>.</p>
</section>
<section>
<h2>Fallback for no JavaScript, prefers-reduced-motion or no transition support</h2>
<p>It is really important to deal with the following situations:</p>
<ul>
    <li>The user has set <code>perfers-reduced-motion</code>, there are a number of reasons this may be enabled, such as:
        <ul>
            <li>Users may suffer with a condition where too much motion can induce migraines</li>
            <li>User may have disabled animations due to performance</li>
        </ul>
    </li>
    <li>The browser they are using may not support animations</li>
    <li>The browser may have JavaScript disabled</li>
</ul>
<p>In these, and many other, situations we should provide a fallback</p>
<h3>HTML</h3>
<pre>&lt;html <strong>class="no-js"</strong>&gt;
    &lt;head&gt;
      &hellip;
      &lt;script&gt;
        document.documentElement.classList.remove("no-js");
      &lt;/script&gt;
    &lt;/head&gt;
    &lt;body&gt;&hellip;&lt;/body&gt;
  &lt;/html&gt;  </pre>
<h3>CSS</h3>
<pre><strong>@media (prefers-reduced-motion)</strong> {
    nav.hidden 
      max-height: 500px;
    }
    header svg {
      transform: rotate(-90deg);
    }
  }
   
  <strong>@supports not (transition)</strong> {
    nav.hidden {
      max-height: 500px;
    }
  }
   
  <strong>.no-js nav.hidden</strong> {
    max-height: 500px;
  }
   
  <strong>.no-js header svg</strong> {
    transform: rotate(-90deg);
  } </pre>
<h3>Explanation</h3>
<p>In the HTML there is a class="no-js" applied and removed automatically if JavaScript is enabled, if not I can target this class for <code>.no-js nav.hidden</code> &amp; <code>.no-js header svg</code>.</p>
<p>The media and supports queries can also be used to see if <code>prefers-reduced-motion</code> is enabled or is the browser does not support <code>transition</code>.</p>
</section>
<section>
<h2>Full working example</h2>
<p class="codepen" data-height="431" data-border-color="#D0021B" data-active-link-color="#FAF9F9" data-active-tab-color="#D0021B" data-tab-link-color="#D0021B" data-theme-id="dark" data-default-tab="html,result" data-user="code-red-uk" data-slug-hash="XWKvpVQ" style="height: 431px; box-sizing: border-box; display: flex; align-items: center; justify-content: center; border: 2px solid; margin: 1em 0; padding: 1em;" data-pen-title="Code Red Logo Rotate with fallback"><span>See the Pen <a href="https://codepen.io/code-red-uk/pen/XWKvpVQ">Code Red Logo Rotate with fallback</a> by Dave Letorey (<a href="https://codepen.io/code-red-uk">@code-red-uk</a>) on <a href="https://codepen.io">CodePen</a>.</span></p>
<script async src="https://static.codepen.io/assets/embed/ei.js"></script> 
</section>
      ]]></content>
    </entry>
	
    
    <entry>
      <title>SVG Favicons and Dark Mode</title>
      <link href="https://code-red.uk/blog/svg-favicons-and-dark-mode/"/>
      <updated>2020-11-19T00:00:00Z</updated>
      <id>https://code-red.uk/blog/svg-favicons-and-dark-mode/</id>
      <content type="html"><![CDATA[
        
<section>
<p>So I've now started building a new site for a company that I am setting up and I wanted to make sure that the favicon is an SVG.</p>
</section>
<section>
<h2>What is a favicon</h2>
<p>A favicon is a small image that sits in the tab of your browser, usually the company logo.</p>
<figure><img src="/images/posts/Example-of-favicons.jpg" alt="Example of favicons in pinned tabs of Firefox">
<figcaption> Example of favicons, this shows <a href="https://www.bbc.co.uk" title="BBC Home ">BBC</a>, <a href="https://www.gmail.com" title="Google Mail">gmail</a>, <a href="https://www.github.com" title="Github">Github</a> &amp; <a href="https://quit.letorey.co.uk/" title="My Quits Smoking tracker">Dave Quits</a> </figcaption></figure>
</section>
<section>
<h2>What is an SVG</h2>
<p>An SVG is a Scalable Vector Graphic, and more importantly is a text file that uses circles, rectangles, paths, text, etc. This means that the file can be:</p>
<ul>
    <li>much smaller that a bitmap type image</li>
    <li>Scalable, you can enlarge it without losing definition</li>
    <li>Crisp at any size</li>
    <li>Text inside can be read by screen readers and is selectable</li>
</ul>
<p>This is great for logos and simple images, although complex images can also be created with SVGs.</p>
</section>
<section>
<h2>What is Dark Mode</h2>
<p>Dark mode is a system setting that allows a user to choose whether to have dark text on light background (Light Mode) or light text on dark background (Dark Mode). This setting can be set at multiple levels:</p>
<ul>
    <li>Operating System 
        <ul>
            <li>MacOS</li>
            <li>Windows</li>
            <li>Android</li>
            <li>iOS</li>
        </ul>
    </li>
    <li>Application 
        <ul>
            <li>Twitter</li>
            <li>Instagram</li>
        </ul>
    </li>
    <li>Website 
        <ul>
            <li><a href="https://stuffandnonsense.co.uk/blog/redesigning-your-product-and-website-for-dark-mode" title="Andy Clarke's post on designing for Dark Mode">Stuff &amp; Nonsense</a></li>
            <li><a href="https://chrisburnell.com/article/the-flip-flop-technique/" title="Chris Burnell's post on creating Dark Mode for a site">Chris Burnell</a></li>
        </ul>
    </li>
</ul>
<h3>Enabling Dark Mode</h3>
<p>This is different for each Operating System:</p>
<ul>
    <li><a href="https://blogs.windows.com/windowsexperience/2016/08/08/windows-10-tip-personalize-your-pc-by-enabling-the-dark-theme/" title="Enable Dark Mode Windows 10">Windows 10+</a></li>
    <li><a href="https://support.google.com/accessibility/android/answer/6151800?hl=en-GB" title="Enable Dark Mode Android 11 and above">Android 11+</a></li>
    <li><a href="https://support.apple.com/en-gb/HT210332" title="Enable Dark Mode iOS 11 and above">iOS 11+</a></li>
    <li><a href="https://support.apple.com/en-gb/HT208976" title="Enable Dark Mode MacOS 10.14 and above">MacOS Mojave (10.14)</a></li>
</ul>
<figure><img src="/images/posts/Dark-mode-enablingMacOS.jpg" alt="Light/Dark Mode setting MacOS" width="372" height="90">
<figcaption> Light/Dark mode switcher MacOS System Preferences &gt; General </figcaption></figure>
<h3>Using Dark Mode on a website</h3>
<p>CSS has a media query that checks what color scheme a user prefers <code> @media (prefers-color-scheme: dark) </code> . This allows you to check what the users preference is and load different styles for light or dark.</p>
<pre>body {
&nbsp; background-color: white;
color: black; 
} 
@media (prefers-color-scheme: dark) {
body {
background-color: black;
color: white;
}
}</pre>
<p>This says make the background white and text color black, but if the user perfers a dark color scheme make the background black and the text color white.</p>
<p>This media query has <a href="https://caniuse.com/mdn-css_at-rules_media_prefers-color-scheme" title="Can I Use support for @media prefers-color-scheme">good support on all modern browsers</a> and for those that do not support it it will just use the default white background with black text.</p>
</section>
<section>
<h2>Using SVG as a favicon</h2>
<p>At the time of writing <a href="https://caniuse.com/link-icon-svg" title="Can I Use support info for SVG favicons">not all browsers support SVG favicons</a>, although this is still not a reason for not doing it. Again browsers are awesome with HTML and CSS, if it doesn't recognise it, it just moves on so we can add a fallback.</p>
<pre>&lt;link rel="icon" type="image/svg+xml" href="./images/favicon.svg"&gt;
&lt;link rel="<strong>alternate</strong> icon" href="./images/favicon.ico"&gt;
&lt;link rel="mask-icon" href="./images/favicon.svg"&gt;</pre>
<p>The first line sets the icon to an SVG.</p>
<p>The second line sets an alternate icon as a ICO for browsers that do not recognise SVGs for favicons.</p>
<p>The third line is for Safari on desktop and iOS as the support SVG favicons is limited to pinned tabs only.</p>
<blockquote>
    <p>Safari 9+ has support for "<a href="https://developer.apple.com/library/prerelease/content/releasenotes/General/WhatsNewInSafari/Articles/Safari_9_0.html#//apple_ref/doc/uid/TP40014305-CH9-SW20">pinned tab</a>" SVG icons, but this requires an unofficial <code>rel="mask-icon"</code> to be set and only works for all-black icons on Pinned Tabs. - <a href="https://caniuse.com/link-icon-svg">https://caniuse.com/link-icon-svg</a></p>
</blockquote>
</section>
<section>
<h2>Dark Mode in SVGs</h2>
<p>Since we can embed CSS inside <code>&lt;style&gt;&lt;/style&gt;</code> inside an SVG we can also check inside the SVG if the user <code> prefers-color-scheme: dark; </code> .</p>
<h3>Normal SVG</h3>
<p>Here we have a normal SVG with the fill set inline:</p>
<pre>&lt;svg width="866px" height="866px"&gt;
&nbsp; &lt;title&gt;Company Logo&lt;/title&gt;
&lt;desc&gt;Red Circle with forward slash surrounded by pointy brackets&lt;/desc&gt;
&lt;circle <strong>fill="#D0021B"</strong> cx="433" cy="433" r="433"&gt;&lt;/circle&gt;
&lt;text font-family="Courier New" font-size="200" font-weight="bold" letter-spacing="13.3333333" <strong>fill="#FAF9F9"</strong>&gt;
&amp;lt;/&amp;gt;
&lt;/text&gt;
&lt;/svg&gt;</pre>
<p>In here we are declaring the color of the circle and text inline with fill.</p>
<h3>SVG with a style tag</h3>
<p>Here we have an SVG with <code>&lt;style&gt;&lt;/style&gt;</code> tags to declare the fill color:</p>
<pre>&lt;svg width="866px" height="866px"&gt;
<strong>&lt;style&gt;
&nbsp;&nbsp;&nbsp;&nbsp;circle {fill: #D0021B;}
text {fill: #FAF9F9} 
&lt;/style&gt;</strong>
&nbsp; &lt;title&gt;Company Logo&lt;/title&gt;
&lt;desc&gt;Red Circle with forward slash surrounded by pointy brackets&lt;/desc&gt;
&lt;circle cx="433" cy="433" r="433"&gt;&lt;/circle&gt;
&lt;text font-family="Courier New" font-size="200" font-weight="bold" letter-spacing="13.3333333"&gt;
&amp;lt;/&amp;gt;
&lt;/text&gt;
&lt;/svg&gt;</pre>
<p>In here we are declaring the color of the circle and text in the <code>&lt;style&gt;&lt;/style&gt;</code> tags.</p>
<h3>SVG with a style tag and prefer-color-scheme media query</h3>
<p>Here we have a media query within the <code>&lt;style&gt;&lt;/style&gt;</code> tags of the&nbsp;SVG&nbsp;&nbsp;to declare the fill color for users who prefer dark color scheme:</p>
<pre>&lt;svg width="866px" height="866px"&gt;
&lt;style&gt;
&nbsp;&nbsp;&nbsp;&nbsp;circle {fill: #D0021B;}
text {fill: #FAF9F9} 
<strong>@media (prefers-color-scheme: dark) {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; circle {fill: #FAF9F9;}
text {fill: #D0021B;} 
}</strong>
&lt;/style&gt;
&nbsp; &lt;title&gt;Company Logo&lt;/title&gt;
&lt;desc&gt;Red Circle with forward slash surrounded by pointy brackets&lt;/desc&gt;
&lt;circle cx="433" cy="433" r="433"&gt;&lt;/circle&gt;
&lt;text font-family="Courier New" font-size="200" font-weight="bold" letter-spacing="13.3333333"&gt;
&amp;lt;/&amp;gt;
&lt;/text&gt;
&lt;/svg&gt;</pre>
<p>In here we are declaring the color for <code> prefers-color-scheme: dark </code> of the circle and text in the media query.</p>
<h3>Examples of SVG Favicons in Light and Dark mode</h3>
<h4>Light Mode</h4>
<figure><img src="/images/posts/Light-mode-letorey.jpg" alt="Letorey.co.uk Light Mode favicon in tab">
<figcaption> Light mode favicon for letorey.co.uk in a Chrome tab </figcaption></figure>
<figure><img src="/images/posts/Light-mode-code-red.jpg" alt="Code-Red.uk Light Mode favicon in tab">
<figcaption> Light mode favicon for code-red.uk in a Chrome tab </figcaption></figure>
<h4>Dark Mode</h4>
<figure><img src="/images/posts/Dark-mode-letorey.jpg" alt="Letorey.co.uk Dark Mode favicon in tab">
<figcaption> Dark mode favicon for letorey.co.uk in a Chrome tab </figcaption></figure>
<figure><img src="/images/posts/Dark-mode-code-red.jpg" alt="Code-Red.uk Dark Mode favicon in tab">
<figcaption> Dark mode favicon for code-red.uk in a Chrome tab</figcaption></figure>
</section>        
      ]]></content>
    </entry>
	
    
    <entry>
      <title>=, == or ===</title>
      <link href="https://code-red.uk/blog/js-equals/"/>
      <updated>2020-01-06T00:00:00Z</updated>
      <id>https://code-red.uk/blog/js-equals/</id>
      <content type="html"><![CDATA[
        
<section>
<p>So in JavaScript there a 3 types of equals <code>=</code> , <code>==</code> and <code>===</code> . So why so many and what are they for?</p>
</section>
<section>
<h2><code>=</code> single equals</h2>
<p>This 1 is easy to understand, it's used to set a variable. For example <code> var age = 50; </code> .</p>
<p>As we know there are 3 ways to declare a variable:</p>
<ul>
    <li><code>var</code></li>
    <li><code>let</code></li>
    <li><code>const</code></li>
</ul>
<p>The first 2, <code>var</code> &amp; <code>let</code> , can be reassigned (changed), where as <code>const</code> can not and if you try to you'll get an error:</p>
<pre>Uncaught TypeError: Assignment to constant variable.
</pre>
<p><code>var</code> is the old way of declaring variables, before the advent of <a href="https://en.wikipedia.org/wiki/ECMAScript#6th_Edition_-_ECMAScript_2015" title="ECMAScript 6">ES6</a>. Since then we have had 2 ways to declare variables <code>let</code> for variables that can change and <code>const</code> for variable that don't.</p>
</section>
<section>
<h2><code>==</code> double equals &amp; <code>===</code> triple equals</h2>
<p>Both of these are for checking if a value is equal to something. For example is age equal to 50:</p>
<ul>
    <li><code> age == 50; </code></li>
    <li><code> age === 50; </code></li>
</ul>
<p>So why the need for both?</p>
<p>While it would appear that these two versions are the same they technically are not <code>===</code> triple equals is much stricter, so I'll start with that.</p>
<h3><code>===</code> triple equals</h3>
<p>As this is the stricter of the two types of equals, it checks not only the value but also the type of variable:</p>
<h4>Variable as a number</h4>
<pre>&gt; let age = 50;
&gt; age === 50;
&lt; true
&gt; typeof age;
&lt; "number"&nbsp;</pre>
<h4>Variable as a string</h4>
<pre>&gt; let age = '50';
&gt; age === 50;
&lt; false
&gt; typeof age;
&lt; "string"&nbsp;</pre>
<h4>with <code>==</code> double equals</h4>
<pre>&gt; let age = '50';
&gt; age == 50;
&lt; true
&gt; typeof age;
&lt; "string"&nbsp;</pre>
<p>It is recommended that <code>===</code> triple equals is used in the vast majority of cases as you'd want to make sure that not only the value is the same but also the type of variable is the same.</p>
<h3><code>==</code> double equals</h3>
<p>There is a use for the less strictness of == double equals and this is when we want to check if a varible does not have a value, either null or undefined:</p>
<pre>&gt; let empty;
&gt; empty;
&lt; undefined;&nbsp;
&gt; empty == undefined;
&lt; true
&gt; empty == null;
&lt; true&nbsp;
</pre>
<p>This will return true for both <code>undefined</code> and <code>null</code> .</p>
<pre>&gt; let empty;
&gt; empty;
&lt; undefined;&nbsp;
&gt; empty === undefined;
&lt; true
&gt; empty === null;
&lt; false</pre>
<p>Where as <code>===</code> triple equals will return false for null.</p>
</section>
<section>
<h2>Conclusion</h2>
<ul>
    <li><code>=</code> single equals is used for setting the value of variables</li>
    <li><code>==</code> double equals &amp; <code>===</code> triple equals are used to check if a variable is set to something</li>
    <li><code>===</code> triple equals use this, almost, always to check if a value equals something</li>
    <li><code>==</code> double equals use this to check if a variable is either <code>undefined</code> OR <code>null</code></li>
</ul>
</section>
      ]]></content>
    </entry>
	
    
    <entry>
      <title>JavaScript Quotes</title>
      <link href="https://code-red.uk/blog/javascript-quotes/"/>
      <updated>2019-12-09T00:00:00Z</updated>
      <id>https://code-red.uk/blog/javascript-quotes/</id>
      <content type="html"><![CDATA[
        
<section>
<h2>Before I start</h2>
<p>So last month I decided that it was, after over 15 years of web development, about time that I learnt JavaScript properly.</p>
<p>To do this has decided to use 3 resources:</p>
<ul>
    <li><a href="https://www.codecademy.com/learn/introduction-to-javascript" title="Introduction to JavaScript on Codecademy">Codecademy - Introduction to Javascript</a></li>
    <li><a href="https://javascript.info/" title="JavaScript Info Website">JavaScript.info</a></li>
    <li><a href="https://beginnerjavascript.com/" title="Beginner JavaScript by Wes Bos">Wes Bos - Beginner JavaScript</a></li>
</ul>
<p>I choose these for a number of reasons, the first two are free to take online, although you can pay Codecademy for a Pro version that gives you access to more content. Beginner JavaScript is a paid for course by <a href="https://twitter.com/wesbos">Wes Bos</a>, Ive&nbsp;&nbsp;previously bought two of his other courses (<a href="https://es6.io/" title="ES6 for everyone course by Wes Bos">ES6 for Everyone</a> &amp; <a href="https://reactforbeginners.com/" title="React for Beginners by Wes Bos">React for Beginners</a>), I paid for this because I know that my learning style is best when someone is explaining it to me, and Wes does a great job of doing this, plus I can rewatch the videos over and over. Learning styles are important and you can find out <a href="https://www.how-to-study.com/learning-style-assessment/quiz-item.asp" title="How to Study - Learning Style Assessment">your learning style</a> by doing an online quiz.</p>
</section>
<section>
<h2>Quotes in JavaScript</h2>
<p>There are 3 different quotes that can be used in JavaScript to declare strings, settings, etc. They are:</p>
<ul>
    <li>Single quotes - <code>'</code></li>
    <li>Double quotes - <code>"</code></li>
    <li>Backticks - <code>`</code></li>
</ul>
<h3>Issues with quotes</h3>
<p>It's easy to declare a variable in JavaScript:</p>
<pre>const myVariable = "Whatever I set this to";</pre>
<p>This is all good until you want to set a string with double quotes within it:</p>
<pre>const myVariable = "Dave said: "Hello World"";</pre>
<p>What happens here is the second <code>"</code> , just before Hello closes this string and we will get an error <code> Uncaught SyntaxError: Unexpected identifier </code> .</p>
<p>This can easily be solved by using ' (single quotes) to declare the variable string with the double quotes within them:</p>
<pre>const myVariable = 'Dave said: "Hello World";'</pre>
<p>This is great and works until our string contains an apostrophe:</p>
<pre>const myVariable = 'Dave's friend said: "Hello World"';</pre>
<p>This time the apostrophe in Dave's stops the string and we again the same error <code> Uncaught SyntaxError: Unexpected identifier </code> .</p><p>Again there is a way to fix this by escaping the internal quotes, escaping is done by placing a backslash before the quote:</p>
<pre>const myVariable = 'Dave\'s friend said: "Hello World"';</pre>
<p>With the advent of ES6 in 2015 we can now also use <code>`</code> backticks. This means that there will be less need to escape as backticks are just much less used.</p>
<pre>const myVariable = `Dave's friend said: "Hello World"`;</pre>
<h3>Other advantages of <code>`</code> backticks</h3>
<h4>Multi-line strings</h4>
<p>While multi-line strings can be created without <code>`</code> backticks, by escaping the end of the line:</p>
<pre>const multiLineString = 'This is \
a multi-line \
string'; 
</pre>
<p>When the string is output on a single line:</p>
<pre>&gt;&nbsp; multiLineString
&lt;&nbsp;"This is a multi-line string"
</pre>
<p>Using ` backticks we can just write the multi-line string:</p>
<pre>const multiLineString = `This is 
a multi-line 
string`;
</pre>
<p>This might not seam like something that you'll want to do but sometimes we want a string that is a block of code:</p>
<pre>const myHTML = `
&lt;ul&gt;
&nbsp; &nbsp;&lt;li&gt;one&lt;/li&gt;
&nbsp; &nbsp;&lt;li&gt;two&lt;/li&gt;
&nbsp; &nbsp;&lt;li&gt;three&lt;/li&gt;&nbsp;
&nbsp; &lt;/ul&gt;
`;
</pre>
<p>This will return the multi-line string correctly:</p>
<pre>&gt; myHTML
&lt;&nbsp;"
&nbsp;&lt;ul&gt;
&nbsp; &nbsp;&lt;li&gt;one&lt;/li&gt;
&nbsp; &nbsp;&lt;li&gt;two&lt;/li&gt;
&nbsp; &nbsp;&lt;li&gt;three&lt;/li&gt;
&nbsp;&lt;/ul&gt;&nbsp;
"&nbsp;</pre>
<h4 id="interpolation">Interpolation</h4>
<p>/ɪntəːpəˈleɪʃ(ə)n/<br><em>noun</em></p>
<ol>
    <li>the insertion of something of a different nature into something else.</li>
    <li>a remark interjected in a conversation.</li>
</ol>
<p>What this means is that we can inject other variables into our strings using the syntax <code>${myVariable}</code> . For example:</p>
<pre>const myName = `Dave`;
const myAge = 50;
const myHobby = `Coding`;
const sayDetails =`My name is ${myName} I am ${myAge} years old and my hobby is ${myHobby}.`;
</pre>
<p>Previously this had to be done breaking the string and using <code>+</code> plus to add in the variables and restarting the string:</p>
<pre>const myName = `Dave`;
const myAge = 50;
const myHobby = `Coding`;
const sayDetails = "My name is " + myName + "I am " + myAge + " years old and my hobby is " + myHobby + ".";
</pre>
<p>Both of these examples will output:</p>
<pre>My name is Dave I am 50 years old and my hobby is Coding.</pre>
<p>When injecting variables into strings using interpolation you can also perform maths on them. For example:</p>
<pre>const myName = `Dave`;
const myAge = 50;
const sayDogYears = `My name is ${myName} I am ${myAge} years old, although in dog years I would be ${myAge * 7} years old.`</pre>
<p>The output of sayDogYears would be:</p>
<pre>"My name is Dave I am 50 years old, although in dog years I would be 350 years old."</pre>
</section>
<section>
<h2>ESLint</h2>
<p>I use <a href="https://eslint.org/" title="Fix JavaScript Code as you write">ESLint</a> with <a href="https://code.visualstudio.com/" title="Visual Studio Code">VS Code</a> to check my code is valid while I write it, as probably many other do too.</p>
<p>I have created a config that changes <code>'</code> (single quotes) and <code>"</code> (double quotes) to <code>`</code> backticks.</p>
<p>This is done by editing the <code>.eslintrc</code> file in VS Code, a configuration file for the setting of ESLint:</p>
<pre> "rules": {
"quotes": [
"error",
"backtick"
]
</pre>
<p>This adds a rule for quotes, which returns either an <strong>error</strong> or <strong>warning</strong> and then has a setting of what to make sure the quotes are set to in this case a <strong>backtick</strong>.</p>
<p>To disable ESLint in a file you can just add a comment at the top of the JavaScript file:</p>
<pre>// eslint disable</pre>
<h3 id="issue">Issue</h3>
<p>Although there is an issue that at present I can't fix, so any help would be awesome.</p>
<p>If I have single quotes, when I save they are converted to backticks correctly. When I have double quotes, when I save they are converted to single quotes. Which means that I have to save twice to change double quotes into backticks.</p>
      ]]></content>
    </entry>
	
</feed>
