Javascript News

Syndicate content
Pipes Output
Updated: 9 min 41 sec ago

3 Risks When Growing Your Business

Mi, 2014-11-26 21:00

You’d be hard-pressed to find a manager/entrepreneur, who doesn’t dream of growing his or her business. While growing a business is usually good, unfortunately it’s more than common to see your successful small business go south when you try to grow. There are too many businesses that have shutdown because their managers/owners didn’t understand the […]

Continue reading %3 Risks When Growing Your Business%

Getting Started with React and JSX

Mi, 2014-11-26 20:00

React is an open source library for building user interfaces. It lets you create views easily while making sure your UI stays in sync with the underlying data model. This article, targeted towards beginners, covers the basics of React and JSX syntax.

Getting Started with React

To get started, head over to the official React official website and download the React starter kit. It contains all the files you need to get started.

Once you have download the .zip, extract it to a location on your machine. You will see a directory named React-<version>. On my machine the name of the directory is react-0.12.0. Open it and go to the build directory. We are going to need the following two files:

  1. JSXTransformer.js - Lets you create JavaScript objects through simple HTML.
  2. react.js - The core React library.

Let's create a file named index.html inside the directory react-<version> and add the following snippet:

[html] < !DOCTYPE html> [/html]

The above snippet prints Hello, Universe on the UI. You should note the following points:

  1. React follows component oriented development. The general idea is to break your whole UI into a set of components. In our case we have just one component named Greeting. In React, you create a component by calling React.createClass(). Every component has a render() method which returns markup to render. In the above snippet we simply returned <p>Hello, Universe</p>, which is then displayed in the view.
  2. A component doesn't do anything until it's rendered. To render a component you call React.render() with the component to render as the first argument. The second argument is the HTML element where you would like to render your component. In our case we render our Greeting component into div#greeting-div .
  3. You might be wondering what <Greeting/> really is? This syntax is known as JSX (JavaScript XML) which lets you build DOM nodes with HTML-like syntax. However, JSX is completely optional and you don't need it in order to use React. But it has a lot of nice features and there is no reason not to take advantage of it.
  4. Since the browser doesn't understand JSX natively, we need to transform it to JavaScript first. This is handled by including the following script:

Continue reading %Getting Started with React and JSX%

Write CSS3 without Worrying about Prefixes

Mi, 2014-11-26 19:00

Using CSS3 properties can give your websites a huge boost in appeal and interactivity. 3D transformations, keyframe animations, background gradients, and columns are great tools, but they require extra work on the developer’s part. Various browsers support them experimentally and require vendor-specific prefixes for these properties. Here’s an example of what I mean:

[code language="css"] .rotated-element { -webkit-transform: rotate(45deg); -ms-transform: rotate(45deg); transform: rotate(45deg); } [/code]

In order to use this transform property across modern browsers (that is, anything after IE8), two additional copies of the rule are needed: -webkit- (for Safari, Mobile Safari, and recent Chrome) and -ms- (for IE9). Firefox (16+) and Chrome (36+) read the unprefixed property correctly.

A site that uses lots of CSS3 properties therefore needs lots of prefixes. That raises two problems. First, how do you know which prefixes to use? Sometimes you’ll see a site that uses everything (-webkit-, -o-, -moz-, -ms-, and unprefixed). That’s just bloat. You could look up every property on Can I Use, but that’s time-consuming. The second problem is simply that nobody wants to write all those prefixes.

We need to automate this. Let’s look at some tools that help us automate vendor prefixes.

Continue reading %Write CSS3 without Worrying about Prefixes%

How to Add QR Codes to WordPress Posts

Mi, 2014-11-26 18:30

QR codes (or 'Quick Response codes') are one of the most popular types of barcodes in use today, with the ability to encode up to 4296 characters. The QR code has become incredibly popular due to their fast readability and greater storage capacity compared to other types of barcodes.

Typical QR code applications include product tracking, item identification, time tracking, document management, general marketing, URLs and much more. It's also used for the tracking of physical items, such as mail and packages. Barcodes are now commonly used for tickets which are scanned to allow to access to events.

QR codes are widely used on websites where they generally represent the URL of the website. When someone wants to read the content of your web page on their mobile phone, they can scan the QR code and which opens the URL in a browser instead of manually typing a long URL.

There are several types of QR codes, Model 1, Micro, IQR, SQRC and LogoQ. Model 1 is the most common type of QR code type and it's the one we'll be using in our example.

In this tutorial, I'll show you how to create a plugin that adds a QR code to the end of every WordPress post that represents the full URL.

Continue reading %How to Add QR Codes to WordPress Posts%

Easy Internet Explorer Testing with RemoteIE

Mi, 2014-11-26 18:00

Web developers have a duty to ensure their shiny new web site or application works on a variety of browsers. At the absolute minimum, that means Chrome/Opera, Firefox and Internet Explorer. Ideally, Safari and a few mobile iOS and Android browsers would complete the job. Testing is not easy. It's laborious and our efforts are thwarted by the availability of browsers on our OS of choice. Windows/Linux users cannot install Safari and Mac/Linux users cannot install Internet Explorer. Services such as BrowserStack can help but are only suitable for basic testing because it's difficult to use developer tools. The most viable option is to use another PC or install the OS/browser in a virtual machine environment such as VirtualBox, VMware or Hyper-V. To their credit, Microsoft provide a range of VM images at but the downloads can be several Gigabytes in size because they include the whole OS stack. They also expire after several months. It's not conducive to quick and dirty testing and, somewhat understandably, many developers don't bother. Fortunately, Microsoft has created a faster, slicker option. RemoteIE allows you run the latest version of Internet Explorer from the cloud on Windows, Mac, iOS or Android without having to install or manage a virtual machine. The free service is currently in beta but it works and is technically stunning!

Continue reading %Easy Internet Explorer Testing with RemoteIE%

PHP News You May Have Missed – October / November 2014

Mi, 2014-11-26 17:00

In an already all too familiar format, here’s more PHP news you may have missed over the past month or so. Some of these will be presented in more depth in future posts, but it’s just as important to have a heads up about them. HHVM HHVM is on fire lately – we have four […]

Continue reading %PHP News You May Have Missed – October / November 2014%

The 7 Best Search Engines for Finding Free Images

Mi, 2014-11-26 16:42

Since the birth of the digital camera, there has certainly never a shortage of imagery. In fact, Yahoo! estimates we'll take 880 billion digital photos in 2014. Our challenge has never been a lack of choice -- it's locating precisely the image we want in this vast ocean of imagery. As Coleridge wrote "Water, water, everywhere, Nor any drop to drink.”.

Of course, it can often depend on the kind of image you seek. If you're looking for commonly photographed objects such as computers, books, or flowers, you shouldn't have to search long to find dozens of good ones.

However, try searching for less common objects, or for abstract concepts -- perhaps a sunny day or a particular type of flower -- and it can get tougher. Part of the difficulty stem from the fact that even a perfect image, it may not be tagged in a way that allows you to find it.

In these cases you can waste a lot of time on various sites with free images and still leave empty-handed. Ouch. This explains why commercial stock agencies advertise on free image sites -- their search facilities is often worth the up-sell. In order to avoid this as much as possible, you might want to try a free image search engine. Free image search engines

The advantage of these search engines for free images is that they (in theory) search multiple sites with free images at once. However, in practice some of these search engines search just a bunch of sites, not dozens of them. Anyway, it's more than nothing but if you hope these image search engines are a blessing, you'd better get realistic.

It's hard to compare the quality of the 7 search engines included in the article. At first I wanted to run the same queries through all of them and compare the results.

However, after I tried some very popular terms (computers in particular) and got thousands of results from some of the engines as well as no results for some not so popular terms (probably because I simply didn't use the right keywords), I decided that such a test would give misleading results.

What's more, these search engines index new images daily, so even if today there is not a single image for “sunny day”, for example, tomorrow dozens of such images might get added and my conclusions will be wrong. Therefore, I won't be comparing the quality of the search for these 7 engines – I will just list my impressions with them, as well as some facts, such as the number of photos they include in the search or the sites they search.

Before we go on with the search engines themselves, here is a word of advice. Even if in the search results you find images labeled as free for commercial use, always check the source site itself for the latest version of the license. It's not unheard of images that were licensed as free but later the author had second thoughts and modified the license. Because of this, always check the license before you use the image.

1. Google Images

For many of us, Google Images is the first (and frequently the only) choice to find free images that are allowed for commercial use as well. In order to take advantage of Google Images, after you type your keywords in the search box and hit Enter, click the Images tab (1).

Continue reading %The 7 Best Search Engines for Finding Free Images%’s Most Popular Plugins for 2014

Di, 2014-11-25 21:00

You might have noticed that lists the most popular plugins in the right sidebar in the plugins directory. As we're nearing the end of 2014, I thought it would be interesting to not only provide a quick explanation of each of these plugins, but to also explore some of the other popular alternatives. Just because a plugin is listed in the most popular list, doesn't always mean it's the best fit for your project. Last week we talked about selecting the best WordPress theme, many of the same rules apply when selecting a plugin. Be ruthless and only use quality plugins. I haven't included the star rating because all of them (apart from WordPress Importer) rate 4 stars or 5 stars. It's not a definitive list, only based on my experiences. Hopefully you'll come across a few new plugins that you might not yet have heard of! These numbers are taken from (, current as of the 26th November, 2014. As you will probably notice, the ranking isn't based on downloads alone. Automattic has their own criteria to determine this list based on other factors.

Continue reading’s Most Popular Plugins for 2014%

Why JavaScript and the Internet of Things?

Di, 2014-11-25 20:00

JavaScript has proven itself worthy on both the client and server side world of web applications, but why does it have potential in the ever expanding Internet of Things (IoT)?

Over the past two years, I've covered the growing amount of technology that JavaScript developers can get involved with in my JavaScript Beyond the Web and JavaScript Beyond the Web in 2014 articles here at SitePoint, as well as in various presentations at conferences and meetups. There is a huge level of enthusiasm for JavaScript and the IoT which is great (nice to know I'm not alone in this passion), but many developers ask one very reasonable question - why JavaScript? What are the advantages of using JavaScript with the Internet of Things? I decided it'd be useful to explore this topic in a bit more detail and put a lot of my thoughts down in writing.

Much of the Internet already speaks JavaScript

The whole idea of the Internet of Things is a simple one. We want to connect a range of new devices to the Internet so they can speak to servers and devices around the world. While the next big IoT device that changes the world is likely to be something we don't see coming (that's just the nature of technology right?), we know the technology pillars that it is likely to stand upon - connecting devices to web APIs in new and unexpected ways to (hopefully) benefit society. What language can our web pages and web apps speak right now? JavaScript. It makes sense to extend the same standard platform to the Internet of Things, communicating to a larger range of devices using that same language.

We can share functionality

JavaScript's ability to be everywhere is huge. When connecting up a network of devices to your server, having them all speak the same language makes life easier. If you've got a large number of different connected devices that all understand JavaScript and you've got a server running Node.js, you've reduced complexity and can share functions that do the similar functions across different devices. Say you have business logic in your app which you need to reuse for different devices and server responses. With JavaScript, you can reuse the same functions for calls to different devices with ease - build once and reuse.

Existing libraries, plugins, and APIs

JavaScript has a range of existing libraries, plugins, and APIs, many of which can be utilized in the Internet of Things. While the jQuery plugins of old aren't the most reusable for non-client side code, there is an evolving world of npm modules in JavaScript that are reusable for a multitude of solutions on the client, server, and beyond.

JavaScript utility libraries like Underscore.js, lodash, traverse and Async can be perfect to use in a range of common situations across different devices. There are some very powerful functions in the above modules that would be useful to IoT projects.

Another example of a great JavaScript module that is perfect for IoT is - a module providing real time event based communication across multiple devices.

Continue reading %Why JavaScript and the Internet of Things?%

Developing Cross Platform Applications with Qt

Di, 2014-11-25 19:30

Qt is a cross platform application development framework with a long history and now maintained by the Qt Project. It enables developers to create applications and UIs for desktop, embedded and mobile operating systems. It provides a GUI (Graphical User Interface) for ease of development and allows creation of hybrid applications. Applications can be developed using C++ or the QML language, a JavaScript like language.

In this tutorial, we’ll get started with Qt framework and create a beginner’s mobile/desktop application.

Continue reading %Developing Cross Platform Applications with Qt%

How to Use Susy With Bootstrap

Di, 2014-11-25 19:00

Susy is a grid layout engine that was built to help web developers create web layouts easily. It allows us to create custom grids and it does its job extremely well.

One of the common complaints about Susy is that it is too simple, it's only the grid layout engine. There are no UI kits that come with it, and that slows down developers who want to prototype quickly.

The good news is Susy can be integrated into almost any framework or UI kit, including the major ones, like Bootstrap and Foundation.

This is precisely what this tutorial is all about – integrating Susy with another framework, Bootstrap, to be specific. Even if you are not a fan of Bootstrap, you can still glean insights on how to integrate Susy with your UI kit of choice through this tutorial.

Assumptions and Results of This Tutorial

This tutorial assumes that you have some familiarity with Susy and Bootstrap.

If you are completely new to Bootstrap, I suggest you check out this tutorial by Fazle before continuing.

If you are completely new to Susy, I suggest that you check out my introductory tutorial on Susy first.

We are using Bower to install Bootstrap's Sass package into the project because that would allow us to customise which files to include. You should also have Bower installed on your system before moving on.

For this tutorial, we are going to create part of Bootstrap's homepage using Susy. We will also learn how to

  • Use buttons, forms, and other Bootstrap UI Elements
  • Customize Bootstrap variables for your project
  • Include only the necessary Bootstrap components to reduce the CSS and JS footprint.

Continue reading %How to Use Susy With Bootstrap%

Implementing TitleCapitalization in StackEdit

Di, 2014-11-25 18:00

While working on posts for the PHP Channel here at SitePoint, I often forget how to properly capitalize titles. I usually end up going to TitleCapitalization for the quick fix, but I often fantasize about having a button next to StackEdit’s title field for a quick auto-apply. Well, we’ve already covered getting a local instance (or several) of StackEdit up and running. Why not build the button, too?

Getting Ready

To prepare for the upgrade, we need to check out a local copy of StackEdit. I will, of course, be using my trusty old Homestead Improved box, just like here. You can use your own Linux OS, it’s up to you, but this is definitely simplest.

[code] git clone hi_stackedit cd hi_stackedit vagrant up vagrant ssh [/code]

Once inside the VM, we clone StackEdit.

[code] cd ~/Code git clone cd stackedit npm install --no-bin-link [/code]

Continue reading %Implementing TitleCapitalization in StackEdit%

Breaking Bad Habits: Ineffective UX Patterns

Di, 2014-11-25 17:23

It isn't always true that what becomes a hot trend is good for UX. Just because everyone is implementing a particular icon, navigation menu or pattern, it doesn't mean that people will understand it, and that it will be a good solution for their personal project. Often the wide adoption of a given convention is driven by a chain of copy and paste, rather than well-considered reason. In this screencast, Annarita will focus on some ineffective UX patterns to wary of when building websites. All are still prevalent across the web but, however she will look into some considerations you may need to make when considering including these patterns into your next web project. We'll be looking at: 1. The Hamburger Icon - a three-bar icon used to indicate a menu 2. Image Carousels 3. Infinite Pagination

Continue reading %Breaking Bad Habits: Ineffective UX Patterns%

10 Typical HTML Interview Exercises

Di, 2014-11-25 17:00

A few weeks ago SitePoint published two of my articles discussing some commonly asked JavaScript job interview questions (in case you missed them, the articles are 5 Typical JavaScript Interview Exercises and 5 More JavaScript Interview Exercises).

Both these articles have been a huge success in terms of page views and shares, which was quite unexpected. So, I thought it was time to write a similar article based on job interview questions on HTML and this is the result of my effort. Have fun!

1. Markup validation

Consider the following markup:

[code language="html"] A landscape of London by night [/code]

Is it valid? If not, can you explain why?


The markup uses the picture element, which is a pretty new addition to the specification. The code is all valid apart from the last image specified in the srcset attribute; 320y isn’t a valid value. If the y is replaced with a w, it becomes valid though.

2. The main element

Can you explain the definition of the main element? What is its goal? Are the two specifications (WHATWG and W3C) in agreement on its definition?


The main element has two different definitions depending on the specification used.

The W3C specification describes it as the main content of the page, that is, the content that describes the main topic of a page or is the central functionality of an application. The specification also states that a document must not include more than one main element.

The WHATWG specification doesn’t assign any semantic value to the main element and describes it as a container for the dominant contents of another element. Also, according to WHATWG, you don’t have a limit in the number of times you can use the main element in a single document. If you have multiple article elements on a page, you may want to markup the main content of each article with a separate main element.

Continue reading %10 Typical HTML Interview Exercises%

Revealing Elements with scrollReveal.js

Mo, 2014-11-24 20:00

CSS is the language we all use on the web to style websites since its creation in 1996. Today we're able to create awesome effects using CSS and it's becoming more powerful everyday thanks to the introduction of shapes, flex-box, and animations. This is of course true apart from the well-known joke that we can create animations but until few years ago we could not easily vertically center elements (and this is still true in some versions of Internet Explorer). Despite CSS being the language to accomplish certain tasks, from a long time now, JavaScript has been used to create nice animations. There are even entire JavaScript libraries dedicated to creating animations. In this article I'll cover one of these libraries named scrollReveal.js. What's scrollReveal.js? scrollReveal.js is a library to easily reveal elements as they enter the viewport. It's very small in size, as its weight is roughly 3Kb if minified and gzipped. It has no dependencies, so you don't need to add other libraries to use it like jQuery. In addition to the nice effects it supports, what I really like about this library is that you can use natural language to define the animation you want to run. We'll come back to this feature in a few moment, but first I want to show you a simple example of what this library can do for you: Nice, isn't it? And this demo is created with very few lines of code. The code for this demo is available as a JSFiddle. Now that I've hopefully interested you, let's proceed in an orderly fashion. Getting Started with scrollReveal.js In order to use scrollReveal.js in our web pages, we have to obtain a copy of the library. As usual this can be done either by downloading it from its GitHub repository, or through Bower using the following command: bower install scrollReveal.js Once downloaded, you have to include the library in your page by adding a script element as shown in the following code: [html] [/html]

Continue reading %Revealing Elements with scrollReveal.js%

Resources for JavaScript and DOM Compatibility Tables

Mo, 2014-11-24 19:30

One of the best info-apps to come about in recent years is the well-known and super-practical Can I Use by Alexis Deveria.

Although Can I Use is great for many cutting-edge features, there’s still a lot of JavaScript and DOM stuff that’s not included in there. So what other options are there for looking up browser support for many different JavaScript and DOM features?

I’m always doing research on various front-end technologies, but the one thing I’ve yet to find is a really good one-stop resource that lists browser support for all aspects of JavaScript and the DOM, including the various HTML5 APIs.

Although a single resource doesn’t really exist (at least none that I know of), there are a few resources I’ve come across that, together, form a pretty good overview of which features are supported in which browsers, and in particular any older versions of IE that you might still have to support.

Of Course, Actual Testing Trumps All

Before getting into the resources, I think it goes without saying that doing actual testing on the different devices and browsers that you have to support should always be the primary method for determining support.

It’s nice to be able to get a second-hand overview of support. But “support” tables don’t always include any relevant bugs that might make the feature in question unusable. And that’s besides the fact that some resources can be just plain wrong.

So make sure to do testing and use the references described in this article as guides, not as the final word on whether something works in a particular browser on a particular platform on a particular device.

MDN’s reference

If you can’t find something on Can I Use, the first place you should look is Mozilla’s Developer Network. And I’m sure most of you do just that. In most cases, that’s all you’ll need to get a good preliminary overview of support for a particular JavaScript feature that you can’t find on Can I Use

For example, let’s say you want to look up addEventListener() and removeEventListener. You won’t find those on Can I Use. But you can find both, with browser info, on MDN.

As you can see in the screen grab above, in addition to the details showing which browsers have “Basic support”, there’s often additional info in that chart on features that might have been added in later versions of ECMAScript.

Remember also that MDN’s reference is editable by anyone, so if you discover that something is incorrect, feel free to update it.

Continue reading %Resources for JavaScript and DOM Compatibility Tables%

Boost Your Brand by Turning Your WordPress Blogs into eBooks

Mo, 2014-11-24 19:00

If you have a WordPress blog, chances are you've written or will write enough content to fill a book. Even if you don't have enough material for 200-300 pages, remember, today many eBooks are only 10-100 pages depending on the purpose and target audience. If you want to build up readership one of the best ways to increase your audience is through repurposing your content. By taking your best blog posts and combining them into a mini-booklet, you can then use it as a giveaway to improve your email marketing strategy, even sell the guides for a profit, or just use the materials as a way to boost your credibility.

Although packaging your blog posts into eBooks can sound like a daunting task, WordPress' versatility makes it possible for you to convert your content with ease by using off-the-shelf plugins.

Continue reading %Boost Your Brand by Turning Your WordPress Blogs into eBooks%

Geospatial Search with SOLR and Solarium

Mo, 2014-11-24 17:00

In a recent series of articles I looked in detail at Apache’s SOLR and Solarium.

To recap; SOLR is a search service with a raft of features - such as faceted search and result highlighting - which runs as a web service. Solarium is a PHP library which allows you to integrate with SOLR - whether local or remote - interacting with it as if it were a native component of your application. If you’re unfamiliar with either, then my series is over here, and I’d urge you to take a look.

In this article, I’m going to look at another part of SOLR which warrants its own discussion; Geospatial search.

An Example

I’ve put together a simple example application to accompany this article. You can get it from Github, or see it in action here.

Before we delve into that, let’s look at some of the background.

What is Geospatial Search?

Sometimes, the things you want to search for have geographical locations. Often, that provides vital context. It’s all very well me being able to search for “Italian restaurants”, but I’m hungry - a restaurant on another continent, as good as it might be, is of no help. Rather, it would be far more useful to be able to run a search which asks “show me Italian restaurants, but within 5 miles”. Or alternatively, “show me the ten closest Italian restaurants”. That’s where Geospatial search comes in.

Continue reading %Geospatial Search with SOLR and Solarium%

Unraveling String Key Performance in Ruby 2.2

Mo, 2014-11-24 15:00

Everyone wants their programs to be faster and to take up less memory. However, it's not often that this is achieved without having to modify source code. This post will introduce optimizations added in Ruby 2.2.0 when working with a Hash and string keys. To understand the optimization, you need to know current behavior.

In Ruby 2.1 and prior, if you write something like this:

[ruby] hash["access_string"] [/ruby]

Ruby will allocate the string "access_string" in order to look for an entry with a key by that name. Similarly, Ruby has to allocate a string every time you create a hash literal:

[ruby] hash = { "foo" => @variable } [/ruby]

Continue reading %Unraveling String Key Performance in Ruby 2.2%

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%