First blog redesign in 8 years, sort of

If you a reading this on purplesquirrels.com.au then you might not see any difference. If you are on benfoster.com.au then you will be seeing the new site.

It’s hard to believe that the last redesign of my blog was all the way back in 2014. I made a few tweaks back in 2019, but for the most part it has remained the same for 8 years! I felt it was well overdue for an update and took it as an opportunity to explore some newer technologies and techniques.

I started with the intention of deploying to purplesquirrels.com.au, then at some point along the way I decided I’d combine all my sites at benfoster.com.au. As I write this, the blog is still accessible at either URL, but the Purple Squirrels site is still using the old WordPress PHP theme.

READ MORE

Saving a Canvas element as an image

Here’s a little tip to allow your users download the contents of a canvas element as an image, without the need for a server. We can do this by using an Anchor tag with a download attribute.

Start with creating <canvas> and <a> tags:

<canvas id="mycanvas"></canvas>
<a href="#" download="MyImage.png" id="downloadlink">Save canvas</a>

The <a> tag’s download attribute can be set to a file name that will be used when saving the file. If no value is specified, it will just be called Download.png.

READ MORE

Automatic typography substitution

After reading the series of Death to Typewriters articles on Meduim, I decided to have a go at implementing their automatic character substition rules in JavaScript. Following the guide provided at Death to Typewriters: Automatic replacement and clean-up, I created a simple function that can be called as you type, or when text is pasted, into a text area. Certain character combinations and locations are looked for and replaced with other characters such as correct quotes, arrows and ellipsis. I have put the code up on GitHub with a little bit of documentation.

READ MORE

New website for Nemen Visual

I have just launched a new website for Nemen Visual. The new site is a big departure from the old site which I created over 3 years ago. I took the redesign as an opportunity to explore some new techniques and modernise it a bit.
READ MORE

CSS Diamond grid

Following on from the last post I decided to play a bit more with the hexagonal grid and created a diamond grid. It works similar to the last grid except it uses squares rotated 45 degrees, so it is basically a regular grid tipped on its side with even-odd number alternating rows.

Here is a live demo of the grid:

READ MORE

CSS Hexagonal packed grid

Most grids are square packed – that is each cell is stacked like a block which is great, but if you are after something slightly different maybe you should try a hexagonally packed grid. I will show you how to create a hexagonally packed grid using only CSS. But first, here is the difference between a square and a hexagonal packed grid:

packing

View demo

READ MORE

A LESS mixin for a transition with a prefixed transition-property

The most common mixin you will find in LESS for CSS3 transitions is something like the following:

.transition (@prop, @time, @ease) {
-webkit-transition: @prop @time @ease;
-moz-transition: @prop @time @ease;
-ms-transition: @prop @time @ease;
-o-transition: @prop @time @ease;
transition: @prop @time @ease;
}

The proplem with this is that if you want to transition a property that requires a prefix such as transform:

.transition(transform, 0.5s, ease-out)

You will end up with:

-webkit-transition: transform 0.5s ease-out;
-moz-transition: transform 0.5s ease-out;
-ms-transition: transform 0.5s ease-out;
-o-transition: transform 0.5s ease-out;
transition: transform 0.5s ease-out;

This is not what you want, you need to have the transition-property prefixed as well as the transition. Below is a mixin that I came up with that will solve this problem:

.transitionPrefixProp (@prop, @time, @ease) {
-webkit-transition: e("-webkit-@{prop}") @time @ease;
-moz-transition: e("-moz-@{prop}") @time @ease;
-ms-transition: e("-ms-@{prop}") @time @ease;
-o-transition: e("-o-@{prop}") @time @ease;
transition: @prop @time @ease;
}

Which will output:

-webkit-transition: -webkit-transform 0.5s ease-out;
-moz-transition: -moz-transform 0.5s ease-out;
-ms-transition: -ms-transform 0.5s ease-out;
-o-transition: -o-transform 0.5s ease-out;
transition: transform 0.5s ease-out;

This is kind of a brute force approach by adding all prefixes regardless of whether they are required, but it does work well.

Accessing command line arguments with Grunt

I needed to be able to set up a watch task with Grunt to only watch a specific client sub directory. This directory would change depending on the client I was working on and new clients were constantly added so I need a way to watch the specific client that I was working on only, without hard coding all the clients into separate tasks. The only thing I could think of doing this was to pass some sort of parameters when starting the watch task.

This is how I set it up. It might not be the best method but it works for me.

First I had to set a value in the grunt configuration, which would be taken from the command line args. With Grunt you can get them them using:

grunt.option('someCommandLineArg');

You can also set a configuration value using:

grunt.config.set('myValue', 'someValue');

So combining those two methods, the following will get a command line arg called “watchDir” (and assign a default value of src if it was not specified) and set it in the grunt config. I added this line after initConfig in my Gruntfile:

grunt.config.set('watchDir', grunt.option('watchDir') || 'src');

You can then access this property using a template string in your task:

watch: {
  less: {
   files: ['clients/&lt;%= watchDir %&gt;/**/*.less'],
   tasks: ['less']
  }
}

When running the Grunt task, we can specify the option “watchDir” by adding two dashes in front and setting it equal to the desired value:

grunt watch --watchDir="clientX"

The watch task above would in this case watch the following directory:

'clients/clientX/**/*.less'

This allows you to set up a generic task that can be pointed to different directories when it is started.

Inspiring Inspiration #12

A collection of cool video, motion graphics and interface design, mostly if not all from Vimeo…

READ MORE

Webcam to canvas or data URI with HTML5 and Javascript

This post has been sitting around unfinished since April so I thought I should finish it and get it out there.

In this post I am going to show how you can capture an image from a webcam via JavaScript and convert it to a Data URI which can then be saved in a database or displayed in an IMG tag.

Note: This is more of a proof of concept rather than a best practices example so the code is a bit messy and hacked together from various sources.

I have only tested this on Safari for iOS 6 and latest Chrome with a webcam. It may or may no work in other browsers.

View demo

All explanations for the the code and markup are in the code comments, so please read them for more detail.

READ MORE