<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:media="http://search.yahoo.com/mrss/"><channel><title><![CDATA[simeydotme ≈ frontend & ux developer]]></title><description><![CDATA[simon goellner; trying to make nice things on the web.]]></description><link>http://simey.me/</link><generator>Ghost 0.7</generator><lastBuildDate>Fri, 30 Oct 2020 11:11:50 GMT</lastBuildDate><atom:link href="http://simey.me/rss/" rel="self" type="application/rss+xml"/><ttl>60</ttl><item><title><![CDATA[Svelte3, Rollup and Babel7]]></title><description><![CDATA[<p><a href="https://svelte.dev/">Svelte3</a> rocks. Please check it out if you haven't yet!</p>

<h3 id="transpiling">Transpiling</h3>

<p>After cloning the REPL and initialising your Svelte3 project; one thing that you don't seem to get is <strong>transpiling</strong>. </p>

<p>When using VueCLI, for example, transpiling comes as standard. </p>

<p>I am running an experiment to see how to convert a</p>]]></description><link>http://simey.me/svelte3-rollup-and-babel7/</link><guid isPermaLink="false">9c8ae013-f9f9-4bd5-91e5-85ca3b2b05db</guid><dc:creator><![CDATA[Simon Goellner]]></dc:creator><pubDate>Thu, 23 May 2019 05:15:03 GMT</pubDate><content:encoded><![CDATA[<p><a href="https://svelte.dev/">Svelte3</a> rocks. Please check it out if you haven't yet!</p>

<h3 id="transpiling">Transpiling</h3>

<p>After cloning the REPL and initialising your Svelte3 project; one thing that you don't seem to get is <strong>transpiling</strong>. </p>

<p>When using VueCLI, for example, transpiling comes as standard. </p>

<p>I am running an experiment to see how to convert a Vue2 project over to Svelte3 for learning purposes, but I found that I couldn't get transpiling with Babel working easily.</p>

<p><a href="http://simey.me/svelte3-rollup-and-babel7/#justcode">Jump directly to the code</a></p>

<h3 id="issues">Issues</h3>

<p>After following the tutorials/documentation for adding the <code>rollup-plugin-babel</code>, <code>@babel/core</code>, <code>@babel/preset-env</code> packages, and <a href="https://rollupjs.org/guide/en/#babel">setting up</a> <a href="https://github.com/rollup/rollup-plugin-babel">everything</a> <a href="https://babeljs.io/setup#installation">as described</a>; I simply found that it hadn't transpiled my <code>bundle.js</code> as I expected.</p>

<p>After some time messing around, and being new to <strong>svelte/rollup/babel</strong>, I figured out that it <strong><em>was</em></strong> in-fact transpiling <strong><em>some</em></strong> code, but not the svelte/imported module code.</p>

<h3 id="reason">Reason</h3>

<p>By what I can tell, the reason I was not getting the expected results is because the documentation or tutorials for these Svelte/Rollup/Babel are not sufficiently up-to-date in order to get it working correctly. All the tools have recently gone through major updates. The main issues were surrounding the <code>.babelrc</code> and the <code>rollup.config.js</code>.</p>

<h3 id="resolution">Resolution</h3>

<p>I discovered a couple of steps needed to get transpiling down to <code>ie9</code> working <em>(or you may use a <code>es2015</code>preset instead)</em>.</p>

<h4 id="1installthedependencies">1. Install the dependencies</h4>

<pre><code class="language-sh ">yarn add --dev @babel/core @babel/preset-env rollup-plugin-babel  
</code></pre>

<h4 id="2createababelconfigjsfileinroot">2. Create a <code>babel.config.js</code> file in root</h4>

<pre><code class="language-javascript">module.exports = function (api) {  
    api.cache(true);
    const presets = [[ "@babel/env", { "targets": "ie 9" } ]];
    return { presets }
}
</code></pre>

<p>This is <a href="https://babeljs.io/docs/en/configuration#babelconfigjs">based on the documentation</a> as it appears by using the default <code>.babelrc</code> file, each imported module (including Svelte3) will have it's own Babel config. This is what prevents transpiling the Svelte code.</p>

<h4 id="3addthebabelplugintorollupconfigjs">3. Add the Babel plugin to <code>rollup.config.js</code></h4>

<p>Firstly import babel;  </p>

<pre><code class="language-javascript">import babel from 'rollup-plugin-babel';  
</code></pre>

<p>then add the <code>babel()</code> plugin <strong>after</strong> the <code>svelte()</code> plugin;</p>

<pre><code class="language-javascript">babel({  
    extensions: [ ".js", ".mjs", ".html", ".svelte" ]
})
</code></pre>

<p>A key part of this config, is the <code>.mjs</code> and <code>.svelte</code> values in the <code>extensions</code> property.  Inside the Svelte3 package; a lot of the compiler is written in <code>.mjs</code>, and your project's Svelte code is likely written in <code>.svelte</code> components. Both of these are not handled by Babel by default.</p>

<p>Another key part is removing the <code>exclude: 'node_modules/**'</code> configuration. This is because we need to transpile the code that comes from the Svelte3 compiler.</p>

<h3 id="success">Success</h3>

<p>After these steps, your <code>bundle.js</code> or whatever you've called it should be completely transpiled down to the environment you've specified in the <code>babel.config.js</code>.</p>

<h2 id="justcode">Just Code</h2>

<p>If you just came here for the code reference; here it is;</p>

<h4 id="packagejson">Package.json</h4>

<pre><code class="language-javascript">  "devDependencies": {
    "@babel/core": "^7.4.5",
    "@babel/preset-env": "^7.4.5",
    "npm-run-all": "^4.1.5",
    "rollup": "^1.10.1",
    "rollup-plugin-babel": "^4.3.2",
    "rollup-plugin-commonjs": "^9.3.4",
    "rollup-plugin-livereload": "^1.0.0",
    "rollup-plugin-node-resolve": "^5.0.0",
    "rollup-plugin-svelte": "^5.0.3",
    "rollup-plugin-terser": "^4.0.4",
    "sirv-cli": "^0.4.0",
    "svelte": "^3.0.0"
  }
</code></pre>

<h4 id="rollupconfigjs">rollup.config.js</h4>

<pre><code class="language-javascript">import svelte from 'rollup-plugin-svelte';  
import resolve from 'rollup-plugin-node-resolve';  
import commonjs from 'rollup-plugin-commonjs';  
import babel from 'rollup-plugin-babel';  
import livereload from 'rollup-plugin-livereload';  
import { terser } from 'rollup-plugin-terser';

const production = !process.env.ROLLUP_WATCH;

export default {  
    input: 'src/main.js',
    output: {
        sourcemap: true,
        format: 'iife',
        name: 'app',
        file: 'public/bundle.js'
    },
    plugins: [
        svelte({
            // enable run-time checks when not in production
            dev: !production,
            // we'll extract any component CSS out into
            // a separate file — better for performance
            css: css =&gt; {
                css.write('public/bundle.css');
            }
        }),

        babel({
            extensions: [ ".js", ".mjs", ".html", ".svelte" ]
        }),

        // If you have external dependencies installed from
        // npm, you'll most likely need these plugins. In
        // some cases you'll need additional configuration —
        // consult the documentation for details:
        // https://github.com/rollup/rollup-plugin-commonjs
        resolve(),
        commonjs(),

        // Watch the `public` directory and refresh the
        // browser on changes when not in production
        !production &amp;&amp; livereload('public'),

        // If we're building for production (npm run build
        // instead of npm run dev), minify
        production &amp;&amp; terser()

    ],
    watch: {
        clearScreen: false
    }
};
</code></pre>

<h4 id="babelconfigjs">babel.config.js</h4>

<pre><code class="language-javascript">module.exports = function (api) {

    api.cache(true);

    const presets = [
        [ "@babel/env", { "targets": "ie 9" } ]
    ];

    return {
        presets
    }

}
</code></pre>]]></content:encoded></item><item><title><![CDATA[Saving / Loading files with Javascript (from the browser)]]></title><description><![CDATA[<p>Something I was experimenting with on a project recently was <strong>saving and loading JSON strings to file</strong> from the browser. It's something that immediately seems obvious and simple, but <em>in all my years doing frontend web development</em> it's not something I've tried before.</p>

<p>I'll show how I achieved it in</p>]]></description><link>http://simey.me/saving-loading-files-with-javascript/</link><guid isPermaLink="false">108a04f3-13f3-4966-acb0-2b6caabfbe05</guid><dc:creator><![CDATA[Simon Goellner]]></dc:creator><pubDate>Sun, 15 Oct 2017 10:57:44 GMT</pubDate><content:encoded><![CDATA[<p>Something I was experimenting with on a project recently was <strong>saving and loading JSON strings to file</strong> from the browser. It's something that immediately seems obvious and simple, but <em>in all my years doing frontend web development</em> it's not something I've tried before.</p>

<p>I'll show how I achieved it in jQuery, you can migrate the idea over to vanillaJS if needed, but please bear in mind this <strong>will only work in IE10+</strong>.</p>

<h2 id="saving">Saving</h2>

<p>Let's start with saving a file. </p>

<p>Firstly we'll need a string of JSON to store. This is achieved simply by taking whatever text you have and parsing it as JSON which might be familiar to anyone who does AJAX transactions.</p>

<pre><code class="language-javascript">// object we want to save
var myObject = { name: "simon", surname: "goellner" };  
// convert to json string
var myJSON = JSON.stringify( myObject );  
</code></pre>

<p>So now we have our text to save, the idea is that we <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#attr-download">create a download link</a>, and then trigger a click on it to force the download process.</p>

<pre><code class="language-javascript">// create a link DOM fragment
var $link = $("&lt;a /&gt;");  
// encode any special characters in the JSON
var text = encodeURIComponent( myJSON );

// &lt;a download="filename.txt" href='data:application/octet-stream,...'&gt;&lt;/a&gt;
$link
  .attr( "download", "filename.txt" )
  .attr( "href", "data:application/octet-stream," + text )
  .appendTo( "body" )
  .get(0)
  .click()
</code></pre>

<p>That's it, super simple. How you generate the contents, and what they will be depends wholly on your project and content. The filename and extension are completely up to you and can/should be generated.</p>

<hr>

<h2 id="loading">Loading</h2>

<p>Loading is a little more complicated, but it's still a fairly simple endeavour.</p>

<p>The main idea is that we provide a <code>&lt;input /&gt;</code> field to load the file, use the <code>FileReader()</code> api to read the file contents and store it to a variable.</p>

<h4 id="html">html</h4>

<pre><code class="language-markup">&lt;!-- the html element we listen to --&gt;  
&lt;input id="fileField" type="file" /&gt;  
</code></pre>

<h4 id="javascript">javascript</h4>

<p>With the field created in HTML, we need only now to reference it and listen to a change event.</p>

<p>Firstly we set up references to the file <code>&lt;input /&gt;</code> field, and the <code>FileReader</code> API.  </p>

<pre><code class="language-javascript">// get the file field
var $field = $("#fileField");  
// create a new FileReader object
var reader = new FileReader();  
</code></pre>

<p>Now we create a <strong>load event listener</strong> to do our work. The file contents are eventually passed to this <code>onload</code> event; accessible through the <code>event.target.result</code> property.</p>

<pre><code class="language-javascript">// when the file has finished reading,
// store it's contents to a variable (async)
reader.onload = function( ev ) {

   var contents = JSON.parse( decodeURIComponent( ev.target.result ) );
   // execute follow-up work here...

};
</code></pre>

<p>Then we set up a <strong>change event listener</strong> on the file input. Once the field changes we read the contents of the file selected and store them to a variable called <code>contents</code>.</p>

<pre><code class="language-javascript">// when it changes (ie: user selects a file)
$field.on("change", function() {

    // get the file item from the input field
    var file = this.files[0];
    // read the file as text
    reader.readAsText( file );
    // and then then load event will trigger ...

});
</code></pre>

<p>I hope this is helpful, <a href="https://developer.mozilla.org/en-US/docs/Web/API/FileReader">please reference MDN for any advanced information</a>, the FileReader() API is super useful and powerful!</p>]]></content:encoded></item><item><title><![CDATA[Building a custom Lodash library with NPM]]></title><description><![CDATA[<div class="lg-txt+2 / sm-txt+1 / txt-c / mar-v4">

<p>Let's use the command line (and NPM scripts) to build lodash; but with only the methods needed by our application.</p>

</div>

<p>We're going to be using <code>lodash-cli</code> installed and accessed via <code>npm</code>. Using Lodash's <code>include=...</code> utility from <a href="https://lodash.com/custom-builds">the lodash custom builds page</a>, we will build the library with only the methods</p>]]></description><link>http://simey.me/custom-lodash-builder-with-npm/</link><guid isPermaLink="false">7ef36668-ee0c-44f6-b9b6-5ff96c23cc1a</guid><dc:creator><![CDATA[Simon Goellner]]></dc:creator><pubDate>Mon, 30 May 2016 19:12:50 GMT</pubDate><content:encoded><![CDATA[<div class="lg-txt+2 / sm-txt+1 / txt-c / mar-v4">

<p>Let's use the command line (and NPM scripts) to build lodash; but with only the methods needed by our application.</p>

</div>

<p>We're going to be using <code>lodash-cli</code> installed and accessed via <code>npm</code>. Using Lodash's <code>include=...</code> utility from <a href="https://lodash.com/custom-builds">the lodash custom builds page</a>, we will build the library with only the methods used in our source files by searching through our application for references to Lodash.</p>

<p>Firstly, we need to set up a <code>package.json</code> in our app. Once we've done this, we can install the <code>npm</code> modules we need:</p>

<pre><code class="language-bash">npm install lodash-cli --save-dev  
</code></pre>

<p>After lodash is installed, we can go ahead and start building our script. In the <code>scripts: {}</code> section of our <code>package.json</code> we need to define a new script -- let's call this <strong>"lojack"</strong>.</p>

<h3 id="packagejson">package.json</h3>

<p>If you only want the code, it's right here. Just swap out the folder paths accordingly.  </p>

<pre><code class="language-javascript">{
  "name": "myapp",
  // ...
  "scripts": {
    "lojack": "lodash -o ./dist/lodash.js include=$( grep -roh \"_\\.[[:alpha:]]*\" ./src/js --include=*.js | sort | uniq | cut -b 3- | tr \"\n\" \",\" )"
  }
  // ...
}
</code></pre>

<p>Our script can now be run from the command line, or during the build process with:</p>

<pre><code class="language-bash">npm run lojack  
</code></pre>

<hr>

<h3 id="letsbreakitdown">Let's break it down</h3>

<p>Now, that script might look like a mess if you're not Neo from The Matrix, or a seasoned command-line guru... so let's dissect it.</p>

<p><img src="https://media.giphy.com/media/3oEduSgfF3EmcTrHUI/giphy.gif" alt="Neo owns the command line..."></p>

<h4 id="grep">grep</h4>

<p>Starting at the bottom, the most fundamental part of this script is <code>grep</code>, we will be using this to search through all the javascript files in the <code>/src/</code> folder and returning any <code>_.method</code> type methods;</p>

<pre><code class="language-bash">grep -roh "_\\.[[:alpha:]]*" ./src --include=*.js  
</code></pre>

<p>This will recursively (<code>-r</code>) search the <code>./src</code> folder for <code>.js</code> files (<code>--include=*.js</code>). Only returning the matched characters (<code>-o</code>) without the filename/line (<code>-h</code>).</p>

<pre><code class="language-bash"># we should then have a result like:
_.filter  
_.each  
_.filter  
_.map  
_.escape  
_.has  
_.has  
_.map  
</code></pre>

<p>This is great, but it's not usable yet.</p>

<h4 id="sort">sort</h4>

<p>We don't really need to sort the result, but I like to. This method pretty much speaks for itself. We just pipe the result of <code>grep</code> in to <code>sort</code>.</p>

<pre><code class="language-bash"># the result is now:
_.each  
_.escape  
_.filter  
_.filter  
_.has  
_.has  
_.map  
_.map  
</code></pre>

<h4 id="uniq">uniq</h4>

<p>Next we will remove all duplication of methods. <code>lodash-cli</code> could get confused if we supply it with multiple <code>filter</code>s and such. So we pipe the result of <code>sort</code> in to <code>uniq</code>.</p>

<pre><code class="language-bash"># result now looks like:
_.each  
_.escape  
_.filter  
_.has  
_.map  
</code></pre>

<h4 id="cut">cut</h4>

<p>The next step is to pipe the output from <code>uniq</code> in to <code>cut</code>, this will allow us to remove the <code>_.</code> prefix which is not needed. </p>

<pre><code class="language-bash">cut -b 3-  
</code></pre>

<p>The option <code>-b 3-</code> basically says: <em>"Take the third byte of each line until the end of that line"</em>.</p>

<pre><code class="language-bash"># which will give us:
each  
escape  
filter  
has  
map  
</code></pre>

<h4 id="tr">tr</h4>

<p>Finally, we need to change those <code>\n</code> (new lines) in to <code>,</code> (commas). We use <strong>translate</strong> utility to do this;</p>

<pre><code class="language-bash">tr "\n" ","  
</code></pre>

<p>Which just says: <em>"turn any new lines in to commas"</em>.</p>

<pre><code class="language-bash"># which will give us:
each,escape,filter,has,map  
</code></pre>

<hr>

<h3 id="finally">Finally!</h3>

<p>Now we have a result that is usable with the <code>include=</code> option, we just need to wrap it all up in a <code>$()</code> which will evaluate the commands to a string.</p>

<pre><code class="language-bash">$( grep -roh "_\\.[[:alpha:]]*" ./src/js --include=*.js | sort | uniq | cut -b 3- | tr "\n" "," )
</code></pre>

<p>And then pass it to the <code>lodash</code> builder.</p>

<pre><code class="language-bash">lodash -o ./dist/lodash.js include=$( grep -roh "_\\.[[:alpha:]]*" ./src/js --include=*.js | sort | uniq | cut -b 3- | tr "\n" "," )  
</code></pre>

<p>Now we should have two files in the <code>./dist/</code> folder which have the names: <code>lodash.js</code> and <code>lodash.min.js</code> which contain only the methods we need for our application!</p>

<p>Huzzah.</p>

<p>This command can now be run directly from the command line. All we do is tell <code>npm</code> to run it <a href="http://simey.me/custom-lodash-builder-with-npm/#packagejson">as shown at the top of this post</a>. We also need to escape quote marks for <code>.json</code> syntax.</p>

<p><small> <br>
<em>Note: this tutorial is based on unix systems, if you want to achieve it with windows, I suggest installing something like <strong>babun</strong> for a unix-like environment.</em></small></p>]]></content:encoded></item><item><title><![CDATA[jade & prismjs]]></title><description><![CDATA[How to use the jsTransformer for PrismJs in Jade templating language.]]></description><link>http://simey.me/jade-prismjs/</link><guid isPermaLink="false">b8ad4008-a6fa-4510-9490-923b98e5e414</guid><category><![CDATA[jade]]></category><category><![CDATA[prism]]></category><category><![CDATA[tips]]></category><dc:creator><![CDATA[Simon Goellner]]></dc:creator><pubDate>Sat, 02 Apr 2016 15:44:08 GMT</pubDate><content:encoded><![CDATA[<p>If you're using &ldquo;<strong>Jade</strong>&rdquo; language for your templates, you may want to consider using the <a href="https://github.com/jstransformers/jstransformer-prismjs"><code>:prismjs</code> filter from jstransformers</a> so that you can style your code snippets.</p>

<p>However, after installing it myself I had some trouble finding help on how to define the language, but eventually stumbled across it with a simple attribute:</p>

<pre><code class="language-css">:prismjs( language="css" ) 

    .my-class { color: red; }
</code></pre>

<p>It seems super simple, and it is... but it's really not documented anywhere, and caused me some headache.</p>]]></content:encoded></item><item><title><![CDATA[Nicer Anchors]]></title><description><![CDATA[Demonstrating how to create anchor links which don't sit flush against the top of the viewport using css.]]></description><link>http://simey.me/nicer-anchors/</link><guid isPermaLink="false">c16b3e4d-a5c6-46a0-b586-afd60b662b0e</guid><dc:creator><![CDATA[Simon Goellner]]></dc:creator><pubDate>Mon, 11 Jan 2016 17:41:21 GMT</pubDate><content:encoded><![CDATA[<div class="lg-txt+2 / sm-txt+1 / txt-c / mar-v4">

<p>If you've ever written an FAQ or long-body-format web page, you'll undoubtedly have used <strong>anchor tags</strong> for deep-linking.</p>

</div> 

<p>Generally we use <code>href="much-link.htm"</code> every day for hyperlinks to other pages, but we'll also link to headings or sections of our own body when it is called for; <code>href="#wow"</code>.</p>

<p>There's a small aesthetic issue when using <code>href="#so-anchor"</code> though, and that's to do with <strong>the way browsers handle it</strong>; they move the top of the element exactly to the top of the viewport &mdash; as demonstrated below. </p>

<div class="mar-v2">

<p data-height="220" data-theme-id="246" data-slug-hash="ff6f7d742bc101c15bb2a3529931f633" data-default-tab="result" data-user="simeydotme" class="codepen">See the Pen <a href="http://codepen.io/simeydotme/pen/ff6f7d742bc101c15bb2a3529931f633/">heading-anchor-bad</a> by Simon Goellner (<a href="http://codepen.io/simeydotme">@simeydotme</a>) on <a href="http://codepen.io">CodePen</a>.</p>  
<script async src="//assets.codepen.io/assets/embed/ei.js"></script>

</div>

<p class="txt+2 / txt-book / txt-c">You wouldn't put your header against the top of the page normally, so why do it when deep-linking?</p>

<p>It's also <strong>exacerbated or just unusable if we have any kind of fixed-header</strong>. So the general way people try to get around this aesthetic issue is by using <code>javascript</code> to smooth-scroll the element in to view and then scroll up a little bit more with a calculation.</p>

<p>I propose a method without any javascript, see below;</p>

<div class="mar-v2">

<p data-height="220" data-theme-id="246" data-slug-hash="ac315c9f9de845075f5bfcd1c8f8f895" data-default-tab="result" data-user="simeydotme" class="codepen">See the Pen <a href="http://codepen.io/simeydotme/pen/ac315c9f9de845075f5bfcd1c8f8f895/">heading-anchor-gooder</a> by Simon Goellner (<a href="http://codepen.io/simeydotme">@simeydotme</a>) on <a href="http://codepen.io">CodePen</a>.</p>  
<script async src="//assets.codepen.io/assets/embed/ei.js"></script>

</div>

<hr>

<h3 id="how">How?</h3>

<p>We'll use pseudo-elements and pseudo-classes to apply a <strong>"padding"</strong> above the currently targetted anchor.</p>

<p>Firstly let's make use of the <code>:target</code> pseudo-class which allows us to style any element which has the same <code>href="#"</code> as the hash in the url. It's <strong>available from IE9</strong> as <a href="http://caniuse.com/#feat=css-sel3">shown on caniuse</a> </p>

<pre><code class="language-css">.anchor:target {}
</code></pre>

<p>We then use this to append a pseudo-element to the anchor which will give us a set amount of space above the anchor:</p>

<pre><code class="language-css">.anchor:target:before {
    /* first we need to give it layout */
    content: "";
    display: block;

    /* then dimensions */
    height: 1em;
    margin-top: -1em;
    width: 0;
}
</code></pre>

<p>Now the <code>1em</code> value is up to you, I find it works nice as it's always proprtional to the heading size. We also use <code>width: 0;</code> so that the browser doesn't draw a nasty <code>outline</code> around the pseudo-element when we're focussed on it. Finally <code>margin-top: -1em;</code> is used to remove the extra whitespace created above the heading.</p>

<hr>

<h3 id="suchattract">such attract.</h3>

<p>Why not go one step further and inspect the code for this blog's headings &mdash; you'll see the <code>:target</code> being used to paint a fancy icon and change the colour of headings. <a href="http://simey.me/nicer-anchors/#how">Try it out by clicking here</a>.</p>]]></content:encoded></item><item><title><![CDATA[Gooey Editor Themes]]></title><description><![CDATA[Gooey, Pastel, Code editor themes for Sublime Text and Atom.]]></description><link>http://simey.me/editor-themes/</link><guid isPermaLink="false">414204ca-8244-48d5-b25e-8b8aa71d1e47</guid><category><![CDATA[Sublime]]></category><category><![CDATA[Theme]]></category><dc:creator><![CDATA[Simon Goellner]]></dc:creator><pubDate>Sun, 23 Aug 2015 07:27:00 GMT</pubDate><content:encoded><![CDATA[<div class="lg-txt+2 / sm-txt+1 / txt-c / mar-v4">

<p>Writing beautiful code is easier when it looks damn sweet!</p>

</div>

<p>I was at a <a href="http://www.meetup.com/HarbourFrontHK/">local meetup/gathering</a> in Hong Kong where developers and designers give short, awesome talks; <a href="http://mrmrs.cc/">@mrmrs_</a> was showcasing some <a href="http://cssstats.com/">css statistics</a> and all through the talk I gazed at the pretty colours in his Terminal. I tried to recreate the style in for SumblimeText.</p>

<h3 id="gooey">Gooey</h3>

<p>Gooey has a lot of greens and blues, with purple accents.</p>

<p><img src="http://simey.me/content/images/2015/10/screenshot-151023--144845-.png" alt=""></p>

<h3 id="gooeypastel">Gooey Pastel</h3>

<p>Gooey Pastel is a more subdued version of Gooey, with magenta highlights.</p>

<p><img src="http://simey.me/content/images/2015/10/screenshot-151023--144557-.png" alt=""></p>

<h3 id="download">Download</h3>

<p>You can get both the <strong>Sublime Text themes</strong> from <a href="http://colorsublime.com/?q=gooey">ColorSublime</a>, and you can see the source code for both at <a href="https://github.com/Colorsublime/Colorsublime-Themes/search?l=xml&amp;q=Gooey&amp;utf8=%E2%9C%93">Github</a></p>

<p>For <strong>Atom</strong> you can get it from the <a href="https://atom.io/themes/atom-gooey-syntax">Atom package manager site</a>.</p>]]></content:encoded></item><item><title><![CDATA[SVG Loader Challenge]]></title><description><![CDATA[A nicer loading indicator using SVG and CSS.]]></description><link>http://simey.me/svg-loader-challenge/</link><guid isPermaLink="false">b7089eb8-968b-4c01-b0a5-a689ad295d32</guid><category><![CDATA[Code / Tutorials]]></category><category><![CDATA[CSS]]></category><category><![CDATA[logo]]></category><category><![CDATA[animation]]></category><category><![CDATA[SVG]]></category><category><![CDATA[loading]]></category><dc:creator><![CDATA[Simon Goellner]]></dc:creator><pubDate>Wed, 27 May 2015 08:14:00 GMT</pubDate><content:encoded><![CDATA[<div class="lg-txt+2 / sm-txt+1 / txt-c">

<p>Loading Spinners. We've all seen them; across the web and in our favourite apps. Popping up <em>just</em> as you were about to buy that thing that you like, or sign in to that app which you love.</p>

<p><span class="mark / txt-bold">Today I'm going to show you something a little&nbsp;different!</span></p>

</div>  

<figure class="txt-c / mar-v5 / no-shadow">  
<img src="http://simey.me/content/images/2015/10/spinner.gif" alt="">
<figcaption>A particularly energetic and annoying spinner</figcaption>  
</figure>

<p>Recently there was a detailed case-study on <a href="https://cssanimation.rocks/buffer/">cssanimation.rocks</a> about the loading animation from <a href="https://bufferapp.com/">bufferapp.com</a>. It's a great article and I highly recommend reading it!</p>

<p>The loader  is pure <strong>#awesome</strong> &mdash; not your usual spinning circle of doom &mdash; and it's done with <code>svg</code>!</p>

<hr>

<h2 id="ichallengeyou">I challenge you!</h2>

<p>After reading the article from cssanimation.rocks, my UX Designer colleage (<a href="https://twitter.com/fearghal_">@fearghal_</a>) challenged me to do the same for our company; <strong>Lane Crawford</strong>. </p>

<figure class="txt-c / mar-v4">  
<img src="http://simey.me/content/images/2015/10/screenshot-challenge.png" alt="I Challenge You">
<figcaption>See! Look! He really did! On Facebook and everything!</figcaption>  
</figure>

<p><strong>Lane Crawford</strong> is a luxury fashion retail brand; it's supposed to symbolise elegance and prestige. So I wanted to create something which was <em>refined, subtle</em> and <em>elegant</em>. It should be asking you eloquently:  </p>

<blockquote>
  <p>&ldquo;Please wait one moment...&rdquo;   </p>
</blockquote>

<p>instead of:  </p>

<blockquote>
  <p>&ldquo;oh crap, something&apos;s happening!!&rdquo;  </p>
</blockquote>

<hr>

<h3 id="theresult">the result</h3>

<p>I came up with this &ldquo;rolling breath&rdquo; animation; it incorporates the logo, and it doesn't scream at you. &mdash; I experimented with a couple of speeds and colours as you'll see below.</p>

<iframe height="360" scrolling="no" class="mar-t3" src="//codepen.io/simeydotme/embed/waoYrb/?height=360&theme-id=246&default-tab=result" frameborder="no" allowtransparency="true" allowfullscreen="true" style="width: 100%;">See the Pen <a href="http://codepen.io/simeydotme/pen/waoYrb/">Logo Loading Animation</a> by Simon Goellner (<a href="http://codepen.io/simeydotme">@simeydotme</a>) on <a href="http://codepen.io">CodePen</a>.  
</iframe>

<div class="txt / txt-c">You can inspect the codepen to see how it was done, or carry on reading for an explanation.</div>

<hr>

<h2 id="technicals">technicals</h2>

<p>I am not familiar with <code>svg</code> at all; I have never used it except for exporting from Illustrator. It looks <strong>very powerful</strong> and there's some amazing <a href="http://codepen.io/tag/svg%20animation/">examples</a> on <a href="http://codepen.io/collection/AxKdex/">Codepen</a>. </p>

<p>What I gather through my time reading articles is that <code>svg</code> appears to be well supported from IE10+, but it seems to have quite a few browser-quirks and difficulties associated with it when used as an image. However the power and flexibility of <code>svg</code>, especially in-line cannot be denied! &mdash; <strong>I had a lot of learning to do!</strong></p>

<h3 id="how">how</h3>

<p>So the requirements and general premise are as follows:  </p>

<ul>
<li>Have an <code>svg</code> logo</li>
<li>Make sure the existing <code>svg</code> code is suitable/compatible</li>
<li>Separate each character as a path</li>
<li>Apply a <code>css</code> animation to each character</li>
<li>Control animation with a wrapper class   </li>
</ul>

<h3 id="logo">logo</h3>

<p>Luckily <strong>Lane Crawford</strong> already had an <code>svg</code> version of their logo; which is used in the header of the site. Unfortunately, though, it was exported from software and <em>the code was messy</em>. So it needed some care before I could use it.</p>

<figure class="mar-v4">  
<img src="http://simey.me/content/images/2015/10/lane-crawford-header-1.png" alt="">
<figcaption>Lane Crawford's logo in the header of the site.</figcaption>  
</figure>

<h3 id="housekeeping">house-keeping</h3>

<p>Firstly I opened up the <code>.svg</code> file which was originally being included as a <code>background-image</code> (read the <a href="https://css-tricks.com/using-svg/">css tricks article</a> on why this is no good &mdash; it's to do with styling). </p>

<p>After taking a quick look, the file seemed a little strange (<em>thanks, Adobe Illustrator</em>) with the <code>w</code> character being the first path (?), and the <code>&lt;svg ...&gt;</code> tag being a mess.</p>

<figure class="mar-v4">  
<img src="http://simey.me/content/images/2015/10/svg-code-1.png" alt="">
<figcaption>Here's what we're dealing with...</figcaption>  
</figure>

<p>I begin by cleaning up the <code>&lt;svg ... &gt;</code> tag so it's usable, this means adding a proper <code>id</code> and giving it a usable <code>class</code> attribute, as well as sorting out the <code>viewbox</code> and <code>background</code>.</p>

<h5 id="before">before</h5>

<pre><code class="language-markup">&lt;svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"  
     width="270px" height="65px" viewBox="460.275 388.445 270 65" enable-background="new 460.275 388.445 270 65"
     xml:space="preserve"&gt;
</code></pre>

<h5 id="after">after</h5>

<pre><code class="language-markup">&lt;svg  
    version="1.1" 
    id="lanecrawford-logo" 
    class="logo lane-crawford-logo__svg"  
    viewBox="0 -4 236 64"
    xml:space="preserve"
    xmlns="http://www.w3.org/2000/svg" 
    xmlns:xlink="http://www.w3.org/1999/xlink" &gt;
</code></pre>

<p>
In all honesty, as I mentioned before, <span class="mark / txt-semi">I am a complete noob at svg</span>, so I cannot tell you what all those attributes mean. I do know, however, (after reading the <a href="https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute">mozdev svg attribute reference</a>) that certain things were unecessary (<code>x="0px"</code>, <code>y="0px"</code>). I also played around with the viewbox values after reading <a href="http://vanseodesign.com/web-design/svg-viewport/">this article from vanseo design</a>. </p>

<p><strong>#icanteven</strong> handle the values of <code>460.275 388.445</code> &mdash; they make no sense &mdash; they were refactored to be integers which maintain the aspect-ratio of the logo; <code>0 0 236 64</code>.</p>

<h3 id="characterseparation">character separation</h3>

<p>Technically the characters were already separated, however I wanted them to be in the correct order (for sanity, code navigation, <a href="https://twitter.com/hashtag/reasons">#reasons</a>), and each character required a <code>css</code> class so I could target it for animation.</p>

<pre><code class="language-markup">&lt;path class="l"  d="M20.188..." /&gt;  
&lt;path class="a"  d="M36.573..." /&gt;  
&lt;path class="n"  d="M56.617..." /&gt;  
&lt;path class="e"  d="M77.443..." /&gt;  
&lt;path class="c"  d="M114.986..." /&gt;  
&lt;path class="r"  d="M126.600..." /&gt;  
&lt;path class="a2" d="M136.202..." /&gt;  
&lt;path class="w"  d="M161.558..." /&gt;  
&lt;path class="f"  d="M190.896..." /&gt;  
&lt;path class="o"  d="M193.951..." /&gt;  
&lt;path class="r2" d="M215.781..." /&gt;  
&lt;path class="d"  d="M225.384..." /&gt;  
</code></pre>

<p>The letters <code>a</code> and <code>r</code> occur twice, so they get a <code>2</code> suffix. I used <code>class</code> instead of <code>id</code> as this means I can have multiple copies of this logo on the page if needed.</p>

<h3 id="stylingampanimation">styling &amp; animation</h3>

<p>firstly, since we are animating the paths up, we need the parent svg to allow the paths to overflow. And since we removed the <code>fill="#2b2b2b"</code> attribute from each <code>&lt;path&gt;</code> tag earlier, we must apply a fill to the paths &mdash; we will also animate the fill later.</p>

<pre><code class="language-scss">.logo {
    overflow: visible;

    .path {
        fill: #2b2b2b;
    }
}
</code></pre>

<p>Then we must set up our animation:  </p>

<pre><code class="language-scss">@-webkit-keyframes breathe {
    15% { fill: #d0b17b; }
    21% { transform: translateY(-3px); }
}
</code></pre>

<p>I knew that I wanted a golden-sheen to go from left-to-right across the logo, I also wanted the letters to jump up fast, and then slowly fall back down, like a <em>"sigh"</em> or a <em>"breath"</em>. So I have the golden colour appear at <code>15%</code>, and due to the defaults at <code>0%</code> and <code>100%</code> being our <code>#2b2b2b</code> from earlier, it will appear fast and fade out slowly. The same goes for the translation at <code>21%</code>.</p>

<p>The value of <code>-3px</code> is interesting, though; I played with a <code>%</code> value, but it was moving each letter a different distance according to its width. However, because <code>svg</code> scales; the <code>-3px</code> actually changes depending on the size of the <code>svg</code> image. It <em>&ldquo;feels&rdquo;</em> right.</p>

<p>Now to applying the animation with <code>scss</code>:  </p>

<pre><code class="language-scss">$lanecrawford: "l","a","n","e","c","r","a2","w","f","o","r2","d";
</code></pre>

<p>Using the power of <code>scss</code> I created a list containing all the class-names of the <code>&lt;path&gt;</code>s in the <code>svg</code>. This meant that I could run an <code>@each</code> loop on the letters and calculate the <code>animation-delay</code>s with math!</p>

<p>I apply the <code>breathe</code> animation to the <code>.logo</code> whenever it has the class <code>.loading</code>:  </p>

<pre><code class="language-scss">.logo.loading path {
    animation: breathe 2.6s ease infinite;
}
</code></pre>

<p>I now use the <code>@each</code> loop to give each letter an <code>animation-delay</code> so it plays on each time slightly later than the previous; making it appear to move from left-to-right:</p>

<pre><code class="language-scss">@each $letter in $lanecrawford {
    $i: index($lanecrawford, $letter);
    $t: 0.03s * $i;

    &amp;.loading path.#{$letter} {
        animation-delay: $t;
    }
}
</code></pre>

<p>If the <code>@each</code> loop syntax seems confusing, then I highly suggest reading <a href="http://thesassway.com/intermediate/if-for-each-while#each">the sass way's explanation</a> on the subject.</p>

<h3 id="controlling">controlling</h3>

<p>In the <a href="http://codepen.io/simeydotme/pen/waoYrb">codepen demo</a> I simply use some <code>jQuery</code> to apply the animation with a checkbox-toggle. However in the real world you'd apply it during ajax calls and page-transitions. -- <code>jQuery</code> cannot apply <code>css</code> classes to <code>svg</code>, so it's applied with the native <code>.classList.add()</code> method.</p>

<pre><code class="language-javascript  ">$( document )
    .ajaxStart(function() {
        $(".logo")[0].classList.add("loading");
    })
    .ajaxStop(function() {
        $(".logo")[0].classList.remove("loading");
    });
</code></pre>

<p>No matter when/why you apply the animation, it is triggered simply by applying the class of <code>.loading</code> to the <code>svg</code> element. #simples.</p>

<hr>

<h2 id="toconclude">to conclude</h2>

<ol>
<li><p>This is a super-neat way of indicating to the user that something is happening, keeping things on brand, and <em>not</em> looking like a half-broken <code>jQuery</code> plugin is &lsquo;acting up&rsquo;.</p></li>
<li><p>I'm not sure we will ever use this at <strong>Lane Crawford</strong>, but it was a nice experiment, and I am going to push for it.</p></li>
<li><p>In modern browsers it performs a lot better than an animated <code>.gif</code>.</p></li>
<li><p>With a little javascript effort it's fairly easy to substitute it for an animated <code>.gif</code> in IE8 or lower.</p></li>
</ol>]]></content:encoded></item></channel></rss>