Javascript News

Syndicate content
Pipes Output
Updated: 10 min 37 sec ago

Building an Internationalized Blog with FigDice

Sa, 2014-11-22 17:00

In part one of this two-part series I started looking at FigDice, a PHP templating system that takes a slightly different approach to most.

So far we’ve put together a very simple example website using Figdice. We’ve implemented a couple of pages, a Twitter feed and some template partials.

In this second and final part we’re going to add a simple blog to our example site, which allows us to look in more detail at Figdice’s concept of data feeds. We’ll also look at internationalization, translating some of the site’s content into a couple of additional languages.

The Code

I’ve created a separate repository for the code for this second part of the series, which you’ll find on Github. It expands upon the code we wrote in Part One.

There’s also an online demo.

Building a Simple Blog

Now let’s create a more complex example of a data feed, by implementing a simple blog.

First, create another feed class - this time for a blog.

Continue reading %Building an Internationalized Blog with FigDice%

Using the Shopify API with WordPress

Fr, 2014-11-21 21:00

WordPress is extremely popular with small businesses, but more and more product businesses are also opening up e-commerce stores using Shopify. It’s possible to keep an existing info site and use of the Shopify API with a custom page template to pull a feed of products from Shopify into a WordPress site. There is a […]

Continue reading %Using the Shopify API with WordPress%

Pagination and SEO: Red Flags and Best Practices

Fr, 2014-11-21 20:00

For any webmaster of a large site, content pagination is a topic of interest. When you have a vast amount of content it’s difficult to avoid pagination. In addition to your pagination concerns from a usability point of view, the SEO aspects are also worth considering. Pagination is not rocket science but as far as […]

Continue reading %Pagination and SEO: Red Flags and Best Practices%

Junior, a Front-end Framework for HTML 5 Mobile Apps

Fr, 2014-11-21 19:30

Junior is a front-end framework for creating HTML 5 mobile apps. Depending on external libraries like modernizer, zepto, zepto flickable, lodash and backbone, it creates mobile apps with a native look and feel by utilizing Ratchet CSS UI components.

What we’ll be creating

In this tutorial, we’ll create a simple ToDo list app from scratch using the Junior framework. We’ll have 2 screens, one to add the todo list items and the second to view all the added items.

The source code from this tutorial is available on GitHub.

Continue reading %Junior, a Front-end Framework for HTML 5 Mobile Apps%

Making a Case for Mobile First Designs

Fr, 2014-11-21 19:00

Did you know that mobile traffic (i.e. smartphones, etc.) accounts for about 30% of website page views today? That’s up 3x from a measly 10% just 2 years ago. In the same period, desktop access is now down to 60% (here’s how this data is measured).

Looking at the time spent instead of just the page views, this report by comScore shows that mobile platforms account for 60% of digital media time spent.

I could share more numbers to drive home the point, but those of you wh are data-inclined can look up more here and here. These numbers are just an indication of how rapidly web usage patterns are changing.

Luke Wroblewski talked about the need for Mobile First designs back in 2011 and shared some early data in 2012, much before we saw such a major shift in web usage patterns. Two years on, with smartphones and tablets replacing PCs dramatically, even at the workplace, it’s alarming to see most designers and developers still stuck designing the traditional way – for large screen desktops – and still talking about progressive enhancement versus graceful degradation.

Continue reading %Making a Case for Mobile First Designs%

On Our Radar This Week: Watch Apple, and Intuitive Animations

Fr, 2014-11-21 18:00

Welcome to On Our Radar, a weekly round-up of news, trends and other cool stuff from the world of web development. Watch your usability Apple have released development kit information for their new Apple Watch, with info on how the device will work (at least initially) and details about getting your iPhone app ready for […]

Continue reading %On Our Radar This Week: Watch Apple, and Intuitive Animations%

Building OctoberCMS Plugins: Google Analytics

Fr, 2014-11-21 17:00

OctoberCMS is one of the rising stars in content management systems, and as in every CMS we need plugins to extend the functionality. In this article, we’re going to go through the basics of creating a plugin for October CMS.

What we’re building

Almost all websites need Google Analytics. We’re going to make a plugin that inserts the Google Analytics tracking code into the page using a component tag.

After inserting your tracking id in the settings form, you’ll need to insert the component tag on the pages that you want to track, or inside a partial.

{% component 'gaCode' %}

You can see the final result on github and try it out.

Managing Plugins

October has a plugins folder inside the root directory, where you can find, install, remove and develop plugins.

To manage your plugins, you can click the System > updates link. We have two different ways to manage our plugins.

Continue reading %Building OctoberCMS Plugins: Google Analytics%

The Basics of Node.js Streams

Do, 2014-11-20 20:00

Node.js is asynchronous and event driven in nature. As a result, it's very good at handling I/O bound tasks. If you are working on an app that performs I/O operations, you can take advantage of the streams available in Node.js. So, let's explore Streams in detail and understand how they can simplify I/O.

What are Streams

Streams are unix pipes that let you easily read data from a source and pipe it to a destination. Simply put, a stream is nothing but an EventEmitter and implements some specials methods. Depending on the methods implemented, a stream becomes Readable, Writable, or Duplex (both readable and writable). Readable streams let you read data from a source while writable streams let you write data to a destination.

If you have already worked with Node.js, you may have come across streams. For example, in a Node.js based HTTP server, request is a readable stream and response is a writable stream. You might have used fs module which lets you work with both readable and writable file streams.

Now that you know the basics, lets understand different type of streams. In this article, we will discuss readable and writable streams. Duplex streams are beyond the scope of this article.

Readable Stream

A readable stream lets you read data from a source. The source can be anything. It can be a simple file on your file system, a buffer in memory or even another stream. As streams are EventEmitters, they emit several events at various points. We will use these events to work with the streams.

Reading From Streams

The best way to read data from a stream is to listen to data event and attach a callback. When a chunk of data is available, the readable stream emits a data event and your callback executes. Take a look at the following snippet:

[js] var fs = require('fs'); var readableStream = fs.createReadStream('file.txt'); var data = ''; readableStream.on('data', function(chunk) { data+=chunk; }); readableStream.on('end', function() { console.log(data); }); [/js]

The function call fs.createReadStream() gives you a readable stream. Initially, the stream is in a static state. As soon as you listen to data event and attach a callback it starts flowing. After that, chunks of data are read and passed to your callback. The stream implementor decides how often data event is emitted. For example, an HTTP request may emit a data event once a few KB of data are read. When you are reading data from a file you may decide you emit data event once a line is read.

When there is no more data to read (end is reached), the stream emits an end event. In the above snippet, we listen to this event to get notified when the end is reached.

There is also another way to read from stream. You just need to call read() on the stream instance repeatedly until every chunk of data has been read.

[js] var fs = require('fs'); var readableStream = fs.createReadStream('file.txt'); var data = ''; var chunk; readableStream.on('readable', function() { while ((chunk=readableStream.read()) != null) { data += chunk; } }); readableStream.on('end', function() { console.log(data) }); [/js]

Continue reading %The Basics of Node.js Streams%

Sass Multiple Arguments, Lists or Arglist

Do, 2014-11-20 19:00

I do a lot of Sass code reviews. Along the same lines, I like to read frameworks' code. Needless to say, I have seen a lot of things, both good and bad, when it comes to Sass.

If there is something that always make me grind my teeth when I read other people's Sass, it's seeing mixins and functions using lists instead of variable arguments, or using lists instead of multiple named arguments.

In this article I'd like to take a look at this issue and, hopefully, show when to use what more clearly.

Terminology

Before going any further let's have a quick look at the terminology. Both functions and mixins are able to accept arguments, from 0 to infinity. That means you can make an argument-less function/mixin or one with a multitude of arguments. Now let's go deeper.

In Sass, a list is the equivalent to an array in other languages. A value that happens to have list as a type (checked with the type-of function) is a collection of several values that have a specific type (number, string, bool, color, list, map or null). For a deeper understanding of Sass lists, I suggest you read my article about this.

Last but not least, there is a variable argument. You may not have known that arglist is an actual Sass data type (it's mentioned nowhere in the docs). The thing is, you cannot easily create an arglist (deliberately) because it is usually an internal mecanism from Sass which happens when you use the variable argument notation within a mixin/function signature.

For instance:

Continue reading %Sass Multiple Arguments, Lists or Arglist%

Getting Started with Google Maps Recipes

Do, 2014-11-20 18:00

There are many ways to add a Google Map to a web page. Google offers a variety of map types whose use depends essentially on your needs.

Without taking into account some specific uses (APIs for Places or Earth for example) the types of maps most commonly used are:

  • Static Maps and Street View Images
  • Embedded Maps
  • JavaScript Maps

There are also many web services to improve your map as as well as specific APIs for mobile devices. In this article, we’ll cover only basic APIs for web pages. If you are interested in going deeper with Google Maps, take a look at the Google Maps API main page.

Getting an API key

As explained on the Google Maps Developer site:

All Maps API applications should load the Maps API using an API key. Using an API key enables you to monitor your application’s Maps API usage, and ensures that Google can contact you about your application if necessary. If your application’s Maps API usage exceeds the Usage Limits, you must load the Maps API using an API key in order to purchase additional quota”.

You have to request a free API Key (see Google Maps Tutorial: Obtaining an API Key). It allows you to load the map for a defined number of times per day (every API has its specific limit). If you need more traffic, you have to purchase an additional quota (see Google Maps Usage limits).

The API key need for maps is a bit of a confusing question. When Google published v3 APIs, a key wasn’t needed. Now, Google has changed its policy, but for backwards compatibility you can load APIs (not all anyway) without a key (see Google Maps API Faq).

To request an API key, first go to the Google Developer Console page (you must own a Google account), create a new project and activate the APIs you need (you’ll find that some APIs are already active):

Note that sometimes Google Maps documentation redirects you to the previous developer console: despite of the old Google interface. It is the same as the new one.

The recipes illustrated in this article will need the Maps Embed, Maps JavaScript, Static Maps, and Street View Image APIs.

We have now to generate a new public key and, if needed, constrain it to specific domains.

Click on Credential in the left menu, then choose Create new Key in the Public API access section. A dialog will appear where you can choose the Browser key option.

Now you can set one or more http referrers to enable the new key only for them, or (as in this case), simply click the Create button.

Continue reading %Getting Started with Google Maps Recipes%

A Box of Tricks for Building Responsive Email

Do, 2014-11-20 17:22

In my previous article on newsletter authoring we’ve seen how a handful of tricks can make a huge difference in how your email displays in different clients.

Moreover, we have to take account of mobile devices,whose use in email consumption continues to grow daily. This brings us to the question of building responsive layouts for email.

Since we know email templates are built with HTML tables, and have the inline CSS, our work is a bit more complicated than usual:

  • Inlined CSS rules have high specificity values (they always win an arm wrestle).
  • Tables are not designed for layout composition so we must take care to compose our emails keeping in mind the need that cells – which have a naturally horizontal positioning – should be arranged vertically in mobile devices.
  • Of course, we can’t use JavaScript.

Luckily, most mobile devices have a high compatibility with modern CSS rules, so we are able to tackle all these problems easily using media queries, making a large use of the !important declaration (to over-rule inline styles), and paying careful attention to the way your content is arranged.

A mobile first approach to this kind of projects is very important and allow to avoid layout that can’t be properly arranged in small devices.

Consider that even if, in this article, we will only address responsiveness issues, responsive mobile emails are not automatically good ones. Effective mobile email design involves many elements including font sizing, layout composition and so on: these are very important tasks and we’ll cover them in an another article.

Email layouts patterns

Regarding responsiveness, we can identify two types of email: single column and multicolumn ones.

Single column layout

Single column layouts (often with a single header image) don’t have particular needs. Since they don’t need to rearrange elements, we have only to take care that all widths degrades gracefully to match device sizes. Rather than Responsive design, this is a classic example of Scalable design (see Scalable, Fluid or Responsive: Understanding Mobile Email Approaches.

[caption id="attachment_95033" align="aligncenter" width="565"] A single column layout[/caption]

To ensure your email resizes correctly, you have only to adjust table width:

<table cellspacing="0" cellpadding="0" border="0" width="600"> <!-- email content --> </table> @media screen and (max-width:480px) { table { width: 100%!important; } }

You will need to resize images too (see the About images paragraph at the end of this article) and to adjust your font-size also, but there aren’t any other particular needs.

Continue reading %A Box of Tricks for Building Responsive Email%

Getting Started with FigDice

Do, 2014-11-20 16:00

Amongst the many templating systems out there, most work in pretty much the same way; variables are “injected” using some syntax or another, be it curly braces, percentage signs or whatever that library’s convention happens to be. They’ll usually have basic control structures, such as if...then and, of course, iteration.

FigDice, however, takes an altogether different approach. Inspired by PHPTAL - the subject of a future article - it gives the view layer the reponsibility of “pulling” in the data it requires, rather than relying on controllers to assemble and “push” it into the templates.

In this two-part series, I’m going to take a more detailed look at it, at how it works and how to use it.

Installation

You can get the code from the website, Github or, better still, Composer:

"figdice/figdice": "dev-master"

The library is also available as a .phar; you can download the latest version (direct link) or generate it yourself using figdice-make-phar.php, available in the Github repository.

Basic Usage

Let’s first look at FigDice at its most basic - creating and rendering a view.

To begin, create a new instance of the view:

$view = new \figdice\View();

Obviously, you’ll need to ensure the library is available - using Composer provides a suitable autoloader.

Next, you need to load in the appropriate template, relative to the current path:

$view->loadFile( '../templates/home.html' );

To render the template, call render():

$view->render(); // returns the HTML content

With that in mind, let’s start building some templates.

Continue reading %Getting Started with FigDice%

Mini-chat with Rails and Server-Sent Events

Do, 2014-11-20 15:00

Recently, I've penned a couple of articles on building a chat application with Rails (Mini-Chat with Rails and Realtime Mini-Chat with Rails and Faye - check out the working demo here). In those articles, I explained how to build a simple mini-chat application and make it truly asynchronous using two alternatives: AJAX polling (less preferred) and Web Sockets.

One of the readers noted in the comments that Web Sockets could be replaced with HTML5 Server-Sent Events, so I decided to research the topic. Thus, this article came to life :).

Continue reading %Mini-chat with Rails and Server-Sent Events%

KPIs for Freelancers

Mi, 2014-11-19 20:00

As the old management saying goes: “What gets measured, grows.” Tech startups (and startups in general) are typically fiends for metrics, measuring everything and tracking their growth. Freelancers, on the other hand, are notorious for being less-than-organized. There’s so much work that comes with running a business-of-one that it’s easy to let measurement slip through […]

Continue reading %KPIs for Freelancers%

Developing for the WordPress.org Plugin Directory

Mi, 2014-11-19 19:00

The official WordPress.org Plugin Directory is home to an amazing collection of useful plugins, it's usually the first place WordPress users look when seeking to extend the functionality of their sites. The Plugin Directory offers great opportunities for developers, however there are some guidelines you need to follow. A base plugin will help you to easily and quickly get started in the development process.

[caption id="attachment_94992" align="aligncenter" width="1024"] The Official WordPress.org Plugin Directory[/caption] Base Plugin Directories and Files

These are the necessary files and directories for every plugin that you want to publish to the WordPress plugin directory. These files and directories represent your base plugin. The current plugin version and all future releases will be packed into one single directory i.e. plugin-name.

Continue reading %Developing for the WordPress.org Plugin Directory%

Flask for the Masses

Mi, 2014-11-19 18:00

Flask is a microframework for Python based on Werkzeug, Jinja 2 and good intentions. - official flask documentation

To explain this quote a bit further, werkzeug is a python utility library and jinja 2 is a template engine for Python.

Why Flask?

About a year ago, I was looking into another programming language outside of PHP. I’d been an active PHP developer for 10 years, and, to be honest, doing apps only in PHP gets a bit boring. It not having any standardized libraries or frameworks didn’t help either. I found myself spending half of my time reinventing the wheel just for the sake of reinventing something. Thinking I know better than the other PHP developers often leads to spending too much time on the project. This is very common in the PHP world - almost every other developer is building his own framework, and this can lead to certain types of chaos, but let’s not go there now.

I was searching for something new, and at work we had just started to use Django for serious web development. Django, at that point, seemed like too big of a framework and I wanted something small that I could build upon. Then, I stumbled upon Flask, and I’ve been using it for most of my personal development projects since.

In this article, I will cover installing and configuring Flask and running a basic hello world example. Also, I will presume that you have a linux machine installed (or mac) or that you’re running some sort of decent virtual machine, such as Homestead Improved.

Continue reading %Flask for the Masses%

Yii 2.0 ActiveRecord Explained

Mi, 2014-11-19 17:00

The ActiveRecord class in Yii provides an object oriented interface (aka ORM) for accessing database stored data. Similar structures can be found in most modern frameworks like Laravel, CodeIgniter, Smyfony and Ruby. Today, we’ll go over the implementation in Yii 2.0 and I’ll show you some of the more advanced features of it.

Model class intro

The Yii ActiveRecord is an advanced version of the base yii\base\Modelwhich is the foundation of the Model-View-Controller architecture. I’ll quickly explain the most important functionality that ActiveRecord inherits from the Model class:

Attributes

The business data is held in attributes. These are publicly available properties of the model instance.
All the attributes can conveniently be assigned massively by assigning any array to the attributes property of a model. This works because the base Component class (the base of almost everything in Yii 2.0) implements the __set() method which in turn calls the setAttributes() method in the Model class. The same goes for retrieving; all attributes can be retrieved by getting the attributes property. Again, built upon the Component class which implements __get() which calls the getAttributes() in the Model class.
Models also supply attribute labels which are used for display purposes which makes using them in forms on pages easier.

Continue reading %Yii 2.0 ActiveRecord Explained%

Travelling by Typeface: San Francisco via San Serriffe

Mi, 2014-11-19 10:36

April 1977 must have been a confusing time for travel agents in London. Suddenly hundreds of people were trying to book trips to the beautiful islands of San Serriffe deep in the Indian Ocean. It turned out that the Guardian newspaper had just published a 7-page special report on San Serriffe. They noted the bustling docks at Port Clarendon, praised the golden beaches of Gill Sands and highlighted the important work taking place at the University of Perpetua. The problem was San Seriffe didn't exist. It was nothing more than a prank -- although arguably one of the most elaborate and successful April Fools' Day pranks ever. Conceived by Guardian Features Manager Philip Davies and Features Editor Stuart St Clair Legge, it paid homage to many type-inspired destinations including the capital Bodoni, the remote Thirty Point, and the lapping waves of Garamondo. Even advertisers including Kodak and Texaco gleefully joined in on the gag. In fact, what was to have been a single page had to be extended to accommodate advertiser demand. Unfortunately the task of convincing grumpy englishmen that there were no available flights to San Serriffe proved more difficult than travel agents might have hoped. Places & Faces Places have often provided inspiration to type designers. Microsoft has used Matthew Carter's Georgia prominently for many years. In the 1980's, all Macs shipped with Susan Kare's New York, Los Angeles, Venice, Monaco, Geneva, Toronto and Chicago. Chicago was much-loved, becoming the 'the OS face of Apple' for more than a decade from 1984. It even returned briefly in 2001 for the earliest iPod screens.

Continue reading %Travelling by Typeface: San Francisco via San Serriffe%

Video: How to Build a Freelance Business in 90 Days

Mi, 2014-11-19 02:00

Whether you’re stuck in a soul-sucking job and are planning on leaving, or you’ve found yourself needing to build up your freelance business much quicker than planned due to outside influences, sometimes, you just need more clients — and fast. In this Learnable screencast I will show you how to build up your freelance income […]

Continue reading %Video: How to Build a Freelance Business in 90 Days%

Experimenting with the Web Speech API

Di, 2014-11-18 20:00

A few days ago, I spoke at WebTech Conference 2014 giving a presentation titled Talking and listening to web pages where I discussed the Web Speech API and what a developer can do with it to improve the user experience. This talk was inspired by two articles I wrote for SitePoint titled Introducing the Web Speech API and Talking Web Pages and the Speech Synthesis API. In this tutorial we'll build upon the knowledge acquired and we'll develop a demo that use both the interfaces defined by this API. If you need an introduction of the Web Speech API I recommend to read the two previously mentioned articles because this one will assume you have a good knowledge of it. Have fun! Developing an Interactive Form The goal of this article is to build an interactive form that our users can fill with their voice. For the sake of this example we'll develop a registration form but you can apply the same concepts to any form you want. An important concept to keep in mind is that the use of the voice should never be the only source of input because no matter how accurate a speech recognizer is, it'll never be perfect. So, the user should always be able to modify any field to fix any error the recognizer has made. In this demo we'll provide a button that, once clicked, will start asking a question to the user and then the interaction continues with the user speaking the answer. The recognizer transforms the speech into text that is placed in the text field. Once the interaction is completed, which means all the fields of our form have been filled, our application will be polite and thank the user. As a final point remember that at the time of this writing the Web Speech API is very experimental and completely supported by Chrome only. Therefore our experiment will work in this browser only. Without further ado, let's start building the markup of the registration form. The HTML of the Registration Form To keep things as easy as possible, our form will contain only three fields, but you can add as many of them as you need. In particular we'll require our user to fill the name, surname, and nationality. If you have a basic knowledge of HTML, performing this task should be pretty easy. I suggest you to try to implement it before taking a look at the code below (my implementation): [html] Name: Surname: Nationality: [/html] The previous code shows nothing but a classic form that can be only filled with the use of a keyboard or similar input devices. So, we need to find a way to specify the question we want to ask for each of the fields defined in the form. A good and simple solution is to employ the data-* attribute of HTML5. In particular we'll specify a data-question attribute for every label-input pair. I've decided to set the attribute to the label associated to the input but you can easily change the demo to define the attribute on the input element.

Continue reading %Experimenting with the Web Speech API%