Javascript News

Syndicate content
Pipes Output
Updated: 1 Stunde 9 min ago

Pitching Your SaaS to the Media

2 hours 9 min ago

You might not know it, but when I’m not writing here at SitePoint, I regularly post app round-ups and reviews (both on my site and elsewhere). This means I get a lot of pitches from new SaaS owners wanting to see if I’d be interested in covering their app. Sadly, a lot of these are […]

Continue reading %Pitching Your SaaS to the Media%

Building an Ad Manager in Symfony 2

3 hours 9 min ago

Just this once won’t hurt - I am not going to write about Sass but Symfony. I had to do a little bit of backend at work and ended up with an interesting problem to solve, involving quite a lot of things so I thought it wouldn’t be such a bad idea to write an article about it.

But first, let me explain. The main idea was to build an ad manager. What the hell is an ad manager you say? Let’s say you have some places on your site/application to display ads. We do have things like this on our site, and one of our teams is (partially) dedicated to bringing those places to life with content.

Now for some boring reasons I won’t list here, we couldn’t use an existing tool, so we were doomed to build something from scratch. As usual, we wanted to do a lot without much coding, while keeping an overall simplicity for the end user (who is not a developer). I think we came up with a fairly decent solution for our little project.

Here are the features we set up:

  • YAML configuration + FTP access;
  • Either images, videos or HTML content;
  • Ability to customize cache duration;
  • Either sliders (yes, the pattern sucks) or random item in collection.

Continue reading %Building an Ad Manager in Symfony 2%

On Our Radar This Week: Scroll Magic and Lobotomized Owls

4 hours 9 min ago

Welcome to On Our Radar, our weekly round-up of news, trends and other cool stuff from the world of web development. Multiple goodness from Google With Halloween approaching, some people are focused on the end of the year instead. The James Dyson Foundation has been working on its own list, Dyson's 20 best inventions of the year. Meanwhile, Google have been working hard according to their product strategy, where the company just makes two of everything and tests which works better: A/B testing writ large. They even have a second email system now called Inbox. Google have also given us their Material Design icons. A cool colour scheme designer also appeared, where you can press the spacebar to go through different colour designs, and lock your favourite ones in place. On the other hand, Stylify Me helps you to explore the colours and themes that other web sites use. Lobotomized owls Getting deeper with CSS this week, we've been exploring axiomatic CSS and the Lobotomized Owl selector, * + *. Sass has also been covered, with scaling values across breakpoints using Sass, and the self-aware Sass mixin, and we now have a unit tester for Sass, which is going to get some heavy use. When you've finished working on your CSS you can also now get all of your post-processing done with Pleeease, and work it in to your build system too. Visualisations and web performance Mozilla have given us Nunjucks, a powerful templating engine with inheritance and asynchronous control, that they've used to replace their pre-existing Django-driven marketplace. If you want to improve your own sites, we have a nice article on optimizing the critical rendering path, and here's a curated list of web performance optimization options helping you to dive deeply in to the topic. Getting more graphical, here's a good tutorial on D3.js for creating data visualisations. We also explore seven JavaScript libraries for specific visualizations that make certain specific ideas easier to achieve. Google's Material Design for the Android has inspired an implementation of the ripple effect that you can use elsewhere now, and Scroll Magic is a nice plugin that alerts you use the scrollbar to trigger all sorts of interesting animations. Delving deeper in to Node and Unit testing Some more tips arrived recently. Firstly, how to work better with Arrays, how to use coupling for highly scalable and maintainable JavaScript. We also help you to prepare for ECMAScript 6 with details on the new number methods. Node.js has been getting some love this week too, with a complete Node.js rewrite for Android, a Linear regression library implemented in Node.js with gradient descent, a block-based web server in node.js that lets you aggregate content from multiple sources, and Synaptic is an architecture-free neural network library for Node.js and the browser. Some good unit testing articles include the series Unit Testing Succinctly, with info about why you should unit test, and how unit testing works. There are also guides to different unit testing tools and, more recently, guides to testing with NUnit and advanced unit testing details.

Continue reading %On Our Radar This Week: Scroll Magic and Lobotomized Owls%

More Common Trip-ups for New Rubyists

5 hours 9 min ago

Summary

  • self is always the current object.
  • Rather than declaring instance variables in constructors as in static languages, it's sometimes better to take advantage of lazy initialization methods.
  • #instance_eval runs a block or string in the context of an instance, including instances of Class
  • Use #class_eval to define methods for all instances of a class.
  • There is no difference between compile-time and run-time code in Ruby.
  • In Ruby, a constant is any word that begins with a capital letter.
  • Constants are mostly used for class and module names, never as enums like in other languages.
  • The scope-resolution operator :: is used to specify constants
  • Put :: at the front of a constant to specify a root level constant.
  • Private methods are methods that cannot have an explicit receiver, including self.
  • Objects receive messages to call methods.
  • The . operator is shorthand for #send to send a message to an object
  • #method_missing can intervene when an object does not know how to respond to a message.
  • It's important to define #respond_to_missing when defining #method_missing.
  • An eigenclass or singleton class is a unique class an object is linked to.
  • The class < < syntax can be used to open an object's eigenclass, including a class object.
  • Class methods cannot be private, but eigenclass methods defined on classes can.
  • Methods like attr_accessor can be defined as class-level methods of classes or instance-level methods of Class.

Continue reading %More Common Trip-ups for New Rubyists%

4 Big Ideas from TechCrunch Disrupt Europe 2014

11 hours 39 min ago

Before spending 7 years in Melbourne and then moving to Germany I lived and grew up in London. I am one of Londons rarities, a real, born-and-bred, bona fide Londoner. In fact I am actually a Cockney and one of the last few.

I decided to leave London and the UK 8 years ago for several reasons, but one of the main ones was that it felt like a dying city. Nothing seemed to be changing, it seemed to be stuck in a rut and living in the past. Up until recently it hadn’t felt like this had changed in the UK, but in the past few years (I would say post 2012 Olympics) this has suddenly changed.

The UK and especially London is undergoing something of focused flurry of activity right now. London and its ‘Silicon Roundabout’ is in the top five global locations for startups and entrepreneurs and many are flocking to its concrete beaches to try their luck.

This was the second TechCrunch Disrupt in Europe (well, London) and the event aims to be a focus event of the best in entrepreneurship and disruptive technology. It wasn’t quite enough to convince me to move back to London but it was such a fantastic event that it nearly did, all this despite battling a horrible cold the entire conference.

What were the trends we noticed, who did we meet and what did we learn? Quite a lot! Join me whilst I disseminate it all into something cohesive and comprehendible.

Continue reading %4 Big Ideas from TechCrunch Disrupt Europe 2014%

How to Make Your Project Attractive to Investors

18 hours 9 min ago

In an era where almost anyone can build revolutionary projects with nothing but a computer and determination, everyone wants to create the next Facebook or Google. Unfortunately entrepreneurs are probably more likely to be struck by lightning than they are to secure a venture capital round. In general it’s possible to build out a decent […]

Continue reading %How to Make Your Project Attractive to Investors%

Designing Interfaces for Cross Device Use

Do, 2014-10-23 18:30

Digital mobility and connectivity is becoming increasingly important every day. Users have their mobile devices nearby, check notifications frequently, and in some occasions use multiple devices at once. They are not limited to use one screen at a time anymore. They do things with the device they believe is the best for a particular task or simply the one closest. Users connect to the Internet through multiple devices, starting an operation on their smartphone and completing it on their tablet or laptop. The continuous changing of devices has become common practice for a large number of people.

You can understand how crucial it is to start thinking about designing interfaces for cross-device usage. If you are curious to know more about this topic, this article is a great start.

Continue reading %Designing Interfaces for Cross Device Use%

Sass Grids: From Neat To Susy

Do, 2014-10-23 18:00

For the last several months, I've been using a Sass grid system called Neat. It's done almost everything I need and it's pretty easy to get started with. However, lately I've found myself writing extra styles to augment the Neat grid. Rather than extend it on my own, I decided to find a Sass grid system that was more powerful. That system is Susy.

A Grid Framework, Not a Grid System

Before we get into the how to use Susy, let's talk about the importance of using a Sass grid framework, not a grid system. As I've been using Sass grid frameworks for layout, I've found 3 main advantages.

First, I can give my markup whatever classes I like. It doesn't matter if you like BEM, SMACSS, OOCSS, or any other class naming structure: you can use a framework like Susy without changing your markup. On the other hand, grid systems (like Bootstrap, for example) require you to add their class names to your markup.

Second, grid frameworks are more maintainable. You can change column widths and other visual layout styles by changing only some lines of Sass: your settings or a few mixins. But if you try changing your layout with a class-based grid system, you would have to rewrite your markup.

Third, preprocessor grid frameworks are lighter and faster for your users. Used properly, a framework will output only the styles you need for your specific layout choices. A grid system, on the other hand, will include all of the styles for all of the grids at all of the widths, requiring you to do a good bit of pruning if you want to keep your sites nice and lean.

Basic Syntax

Let's begin by going over the bare minimum you need to know to build a simple Susy based layout. Along the way, I'll be comparing it to Neat's syntax for the same output: if you're also switching from Neat to Susy, this will help you translate the basic concepts over.

Susy Config: $susy Map

All your global settings for Susy are stored in a map called $susy. This makes it easy to keep your config data in one place. If you were going to generate a 12-column grid at 960px with 20px of gutter between each column, you'd use the following map:

Continue reading %Sass Grids: From Neat To Susy%

Keep Your Sales Funnel From Leaking, Even on the Move

Do, 2014-10-23 17:00

This article was sponsored by Insightly. Thank you for supporting the sponsors that make SitePoint possible.

Customer Relationshop Management (CRM) is essential when running a business. With a large number of customers, you need to be able to properly track communications for sales quotes, projects and so on.

When you’re involved in sale, you’re probably going to be on the move when a prospective client reaches out to you. When working with potential customer you want to keep them as “warm” as possible; you don’t want to waste any time in getting back to your office first to browse though your conversation history or quotes. Say hello to mobile CRM. When using a proper tool for managing your contacts you can do it all from your phone or tablet.

In this article I’ll take a look at how a mobile CRM can benefit your business, looking specifically at Insightly’s tools. They offer both a free plan and a 14-day free trial so you can try it out yourself right away.

Why would you need a mobile CRM?

Imagine this: You’re out on the road, and a prospect you’ve been negotiating with for months calls. They want to close the deal on your product, but they want a quick rundown on the various options you offered them, just to be sure.

You know you agreed a certain discount with them, but you’ve forgotten the specific amount. You also pitched them a cross-sell to your product, but you’re not sure which one. What you do know is that you have it all stored in the prospect’s file. But your office is miles away, and the client wants to close right now. You suddenly remember you recently installed a CRM app on your phone.

You tell the prospect you’ll call him back in five minutes, and open the app. You check the prospect’s file, check for discount and cross-sell details and call them back. You put your client on the phone’s speaker, and quickly and calmly walk him through all the details.

The client is impressed with your professionalism and happily agrees to buy both your initial product as well as the cross-sell offer. You thank your client for doing business with you, move their state from “open” to “won” in the CRM app, and drive home satisfied. Because you don’t need to waste any time at the office, you can relax and take your spouse for dinner to celebrate.

It’s pretty clear how a mobile CRM can benefit you and your business. Let’s see how it works.

How to set up mobile CRM

Setting up a mobile CRM for your company is easy when you start using Insightly. As mentioned above, they offer both a free plan and a free trial for their paid plan. The free plan is limited to three users and 2500 records, without custom branding, Google Calendar and Contact sync or MailChimp integration.

If you’re already using Google Apps I’d advise you to consider the paid plan, since the integration options are quite useful.

All plans offer features like Contact, Project, Lead and Task management, all covered with automatic backups, better than decent encryption and unlimited support.

And there’s of course mobile access with an app for both iOs and Android. For this article I am using the Android app, on a Galaxy Note 3.

Continue reading %Keep Your Sales Funnel From Leaking, Even on the Move%

Content Research: Click Tracking, Heatmaps, and Recordings

Do, 2014-10-23 16:30

Last time, we talked about the idea of researching how your users use your content. And we created a rough research plan with a few questions that we wanted to answer. I mentioned that we decided click tracking would be a good way to find the answers to our questions. So let's look at this research method as it applies to content research. First up, the basics. What is click tracking? What does it give you? Click tracking software records the movements and clicks of users' mice (or fingers) as they navigate through your site. Depending on the click tracking software you choose, you might get a range of reports:

  • aggregate reports of clicks overlaid onto individual pages of your site
  • the same for mouse hovers
  • the same for scrolling patterns
  • anonymous recordings of individual sessions users have made on your site
Some services offer click counts as well as hotspot image maps. Others offer extra features like user surveys and polls. We found the click tracking reports invaluable in uncovering usage trends for important pages of our site. But I also love watching the recordings. These give you a true sense of how individuals consume content. How does it work? A lot like Google Analytics: you put some code on each page of your site, and the analytics service starts collecting the data. Click tracking wins One of the questions we were trying to answer with our research was whether users even saw the tag cloud on the right-hand side of our site's pages. Another was about whether they used our lists of FAQs, which were presented as a feature area on landing pages. Click tracking swiftly revealed that yes, users used both these tools -- the click reports told us that in an instant. Accordingly, we shelved our plans for removing the FAQ area and instead revisited each page where FAQs were present to make sure the right ones were displaying in the right places. But that wasn't all. The screen recordings showed that not only were users clicking on tag clouds, they were using them to get ideas for search topics and refinements. They were, effectively, learning from the tags associated with the content. The click tracking also revealed a lot about how text and images work independently and together on our articles and landing pages. We're now designing for these usage trends. It's also informed us about the way users perceive screenshots of a flat-design app within support pages that also take a flat design style (spoiler: not well). For us, the click tracking service just keeps delivering. Click tracking limitations As you can see, it's pretty easy for click tracking to go to your head. But there are a few limitations with click tracking too. Firstly, heatmap analysis alone only tells you so much. If your click tracking tool doesn't come with recordings (Google Analytics, I'm looking at you) you're missing out on some great information that will help you make more sense of the heatmaps themselves. Secondly, you can only watch so many recordings. Don't go for a clicktracking package that gives you a gazillion recordings, because there's no way you'll be able to watch even a fraction of them. Click tracking tips and tricks Here are a few things we learned the hard way that might help you use click tracking effectively to better understand your content straight out of the gate.

Continue reading %Content Research: Click Tracking, Heatmaps, and Recordings%

The Best Mobile Development Reference Devices

Mi, 2014-10-22 18:30

We all know that at some point in an app development process we should start testing on real hardware. An emulator gives a good indication of how an app will look and feel, but nothing beats the real thing. Acquiring handsets to test with can be a costly business for small developers. Each operating system has a standard or ‘reference’ device that your app should work on at least. What are these devices? Below we present the devices and useful hardware specs for iOS, Android, Windows Phone and Firefox OS so you know how to get started.

Continue reading %The Best Mobile Development Reference Devices%

Saving Bandwidth on Slow Connections with Saveba.js

Mi, 2014-10-22 18:00

Performance, accessibility, and security are the most discussed topics of the last months, at least in my opinion. I'm very interested in them and I try to get my head around each subject by reading the new techniques and best practices unveiled by gurus of these fields. If you're a front-end developer you should too, because these are the hottest subjects right now. In this article I'll focus on performance by discussing a JavaScript library I've developed, called Saveba.js. It tries to improve the performance of a website, and thus the experience of users, by avoiding the download of some resources based on the user's connection. I'll also explain why I developed it, detailing what the problems with the current approaches used by developers. The Problem When people talk about performance, the discussion always ends up including mobile. It's certainly true that a website should be optimized for any device and connection, but often home and office connections are faster than mobile ones. Some of the most common techniques to optimize a website today are combining and minifying CSS and JavaScript files, loading JavaScript files asynchronously, providing modern font formats (WOFF and WOFF2), optimizing for the critical rendering path, etc. Another important concept to take into account is the optimization of images. Based on the last report of HTTPArchive, images represent more than the 60% of a page's total weight on average. To address this issue, many developers use tools like Grunt or Gulp, or services like TinyPNG or JPEGMini, to reduce their weight. Another practice is to employ the new srcset attribute and the new picture element to provide versions of the images optimized for the size of the viewport. But this is not enough. Back in August, I wrote an article about the Network Information API, where I expressed my concern about the limitations of this approach. In particular I wrote: While this approach works well for serving up images of the right size and resolution, it isn't ideal in all situations, video content being one example. What we really need in these cases is more information about the device's network connection. What I wanted to express is that if a user is on a really, really slow connection he/she may not care about some embellishment images or resources in general and want to focus on what really matters. Consider the following images that represents the current version of my website as seen on a Samsung Galaxy S3:

Continue reading %Saving Bandwidth on Slow Connections with Saveba.js%

CSS Post-Processing With Pleeease

Mi, 2014-10-22 17:30

Pre-processors such as Sass, Less, and Stylus have revolutionized CSS development. If you're a pre-processor skeptic like I was, try using Sass for a project or two: you won't ever return to raw CSS again. Despite this attention, developers rarely consider post-processors. Pleeease could change that perception… What's a CSS Post-Processor? A post-processor applies changes to a CSS file after it's been hand-coded or generated by a pre-processor. A basic example is minification: your CSS file is parsed to remove white space, comments, and unnecessary dimensions, e.g. margin: 0px 0px 0px 0px; becomes margin:0;. The result is saved to a new, smaller file, e.g. styles.min.css. Pleeease is a Node.js application that combines a selection of great post-processors into one handy command-line tool that works on any platform. Command-line? No Thanks! Don't be afraid; Pleeease is not complicated to install or run. That said, if you cannot bear the thought of typing a few commands, try the Pleeease online playground; you won't get all the benefits but you can test the system using cut-and-paste. Installing Pleeease First, install Node.js from nodejs.org. You can download installers for Windows, Mac OS, and Linux or use a package manager. Next, open a command-line/terminal window and enter the following command on Windows: [code language="bash"] npm install -g pleeease [/code] or, on Mac/Linux: [code language="bash"] sudo npm install -g pleeease [/code] Note the unique spelling of "pleeease", which has four e's with three in the middle. Using Pleeease From the command line you now need to navigate using the cd command to a web project folder where your CSS files reside. Assuming you have a folder named 'myproject\styles' in the Windows C: drive, you'd enter: [code language="bash"] c: cd \myproject\styles [/code] or, on Mac/Linux, if you have a 'myproject/styles' folder in your home folder, you'd enter: [code language="bash"] cd ~/myproject/styles [/code] Normally the prompt will change to show which folder you're in. To run Pleeease, now enter: [code language="bash"] pleeease compile [/code] By default, Pleeease will join all the CSS files into one and create a new app.min.css file in the same folder. Open that file in an editor to see what has been done.

Continue reading %CSS Post-Processing With Pleeease%

Parallels Plesk 12: Harden Up and Supercharge Your WordPress Site

Mi, 2014-10-22 17:00

This article was sponsored by Parallels. Thank you for supporting the sponsors who make SitePoint possible!

Web management tools aren't new, they've been around for many years and they all support one-click installs for common web applications. However, for the most part all this does is install the application and then you're on your own. You don't have visibility to manage these applications once they've been installed.

If you then throw in the fact that users love to install themes and plugins, the management becomes even more fun. The solution to this usually involves third-party services to centrally manage our WordPress sites. Wouldn't it be nice if these management features were built into our hosting control panel? Well, with the latest version of Plesk, this is now possible.

Parallels Plesk is one of the leading hosting control panel and automation platforms on the market. If you've used a few hosting providers, chances are you've used Plesk.

In this article I'll walk you through how to use Plesk 12 with a focus on the features that are most relevant to WordPress professionals, mainly the WordPress Toolkit. I will also touch on some of the other areas that those who manage multiple WordPress sites will be interested in.

First Impressions of the WordPress Toolkit in Plesk 12

When I first logged in, it was immediately obvious that the latest version of Plesk is seriously catering to WordPress developers and administrators.

While other web applications are supported, the WordPress-specific features are impressive. Plesk 12 has introduced what they call the 'WordPress Toolkit' and it brings professional WordPress management features to a mainstream web hosting control panel. This includes the ability to detect manual installations, create new installations (with control over various configuration options), perform bulk updates, and manage plugins/themes.

In addition to the WordPress management features, if you want to jump into a specific WordPress dashboard, there's usually a direct link available in most places within in the Plesk interface. That said, you can easily perform routine tasks without leaving Plesk.

Overview of features:

  • Security
  • Update Management
  • Plugin Management
  • Theme Management
  • ServerShield by CloudFlare
  • ModSecurity
  • Fail2ban
  • Outbound Antispam
  • Range of Editions
Installing WordPress Using the WordPress Toolkit Installing WordPress is easy and using the WordPress Toolkit is even easier. To install WordPress, log into Plesk and go to the 'Applications' page. On this page you have two options for installing WordPress via the drop-down box in the top right. The first option is 'Install' and that will run a default WordPress install. The second option is 'Install (Custom)'. This option will provide you with more control over the common configuration options. With this option you will be able to select the installation path, update settings and admin access. Further down the screen, you'll find your standard WordPress configuration options such as your site name, administrator email address, language, and database details. When your installation is complete, you'll see the message shown below: Security Plesk 12 also includes best-of-breed security controls, with both WordPress-focused options and traditional web security tools. Check Security This feature will allow you to perform a security check to make sure WordPress has been configured correctly and general security measures are in place. Users would usually install plugins to achieve the same results, but now this is available natively within Plesk.

Continue reading %Parallels Plesk 12: Harden Up and Supercharge Your WordPress Site%

Where are you? Implementing geolocation with Geocoder PHP

Mi, 2014-10-22 16:00

GeoCoder PHP

The beauty of SitePoint, to me, is that you can get inspired to try something or be told about some cool project out there. The internet is simply too big for one person to scout out on their own. GeoCoder was one of those for me. I had never heard about it and came across it on the authors Trello board.

I love working with maps and geographic information and I use (reverse) geocoding heavily for a project I did for a client; CableTracks. We actually use a paid service for this although not for everything. The paid results hold much more information than you get from free services. I found out that GeoCoder PHP actually is what I was missing for the integration of various services that we use.

GeoCoder PHP provides: “an abstraction layer for geocoding manipulations”. The library is split into three parts: an HttpAdapter for doing requests, several geocoding Providers and various Formatter/Dumpers to do output formatting.

Installation

Installation of GeoCoder is most easily done using composer. Add the following to your composer.json:

{ "require": { "willdurand/geocoder": "@stable" } }

Or get one of the archives from the GeoCoder PHP website.

Continue reading %Where are you? Implementing geolocation with Geocoder PHP%

LevelDB in Ruby

Mi, 2014-10-22 14:00

Typically when you set out with a Rails application, your data lives inside a MySQL (or PostgreSQL, or SQLite, or Oracle) database. But, it turns out that the traditional relational database is not a great fit for all types of data. For example, if you want very fast access to data that isn't flushed to disk all that often, you could hold that information in RAM. In this case, you might want Redis or Memcached. If your data can be represented as a graph, you'll want to check out Neo4j or OrientDB. But sometimes, you don't want or need a full-blown database server; instead, you can make do with a simple library that can be packaged along with your app. This is where LevelDB fits in: it is a key-value storage library that's meant to be fast.

In this article, we'll cover how to use LevelDB with a Ruby wrapper and also discuss where you should and shouldn't use LevelDB by presenting common usecases.

Continue reading %LevelDB in Ruby%

Debugging Sass Maps

Di, 2014-10-21 18:30

Maps are great, but maps are not that easy to debug. When you have simple maps, it's usually quite easy to understand what's going on, but when you work with huge and/or nested, possibly dynamically updated maps, it can get difficult to keep track of what happens.

...and then, all of a sudden, a bug appears somewhere in your code. Breaking the site you're developing somehow.

However, fear not my friends, I have a possible solution.

What about inspect() or @debug?

The other day, web developer Stuart Trann asked how we could debug a map to see what it looks like.

The first thing that came to my mind was the inspect() function. This function was added at pretty much the same time when maps came out, in order to inspect the content of a map.

You may have noticed that if you try to display a map as a CSS value, you get this message:

(sass: map) isn't a valid CSS value.

Dang. So that's why the inspect() function has been implemented to Sass core. So you can see something like:

[code language="sass"] test { inspect: (sass: map); } [/code]

A problem with inspect() is that it displays the map as a single line, which is far from convenient, especially when you have loads of keys in there. One could think of @debug, which intends to print some content in the console but that really doesn't help much since it also keeps it to one line.

Time to build something that helps us folks.

Continue reading %Debugging Sass Maps%

Building a Pull-Quote Custom Element with Polymer

Di, 2014-10-21 18:00

Custom elements allow developers to define their own HTML elements with custom tag names that closely resemble their design components. The W3C defines custom elements as the specification that:

Enables authors to define and use new types of DOM elements in a document.

The definition looks quite simple in theory, but in practice the process of creating and using a custom element involves:

  1. A decent amount of JavaScript
  2. Knowledge of the JavaScript API(s) to create the custom element
  3. Handling cross-browser inconsistencies.

If you manage to survive through these challenges, then you still have to worry about those browsers that do not support custom elements. Thankfully, Polymer saves the day by providing an easy-to-use framework to create and use custom elements.

If you need a quick refresher on Polymer and Web components then I would strongly recommend reading my previous article on Sitepoint that introduces these concepts in depth.

In this article, we will take a very basic example of creating a custom element with Polymer to render pull quotes. The idea originated from this article by Louis Lazaris where he sparked a debate on the semantic value of using blockquote vs aside to create pull quotes in your markup.

It’s fairly common to see blockquote, aside, or even a plain div element being used to mark up pull quotes. It’s time we put an end to this conundrum by creating a new custom element called <pull-quote> that can accurately represent our content. By the end of this article you will be able to create something like this:

Setting Up the Custom Element

Before we begin with our custom element, we will quickly set up the project folder by installing Polymer and all the dependencies via Bower.

[code language="bash"] $ bower install --save Polymer/polymer [/code]

Typically, creating a new custom element involves the following steps:

  1. Create an HTML file with the name of the custom element.
  2. Import the polymer.html file from the bower_components folder using <link>.
  3. Declare your custom element using <polymer-element>.
  4. Add the styles and the markup needed to define your custom element using the <template> tag.
  5. If your custom element involves JavaScript, call the Polymer() constructor to register the element in the DOM.

The basic approach is to first decide how you are going to use the custom element in your markup and then work your way backwards to create the template for the custom element. In this case, we plan to use the following markup every time we intend to use pull quotes in our document:

[code language="html"] Sample text and can even contain other HTML tags. [/code]

We’ll start by creating a file called pull-quote.html in the root directory. Edit the file and import the polymer.html file that can be found in the bower_components folder:

Continue reading %Building a Pull-Quote Custom Element with Polymer%

Creating a Note Taking App with React and Flux

Di, 2014-10-21 18:00

React, by Facebook, is a very nice library for creating user interfaces. The only problem is that React doesn't care how your application handles the data. Most people use React as the V in MV*. So, Facebook introduced a pattern called Flux which brings a functional approach to data handling inside an app. This tutorial gives a brief introduction on the Flux pattern and shows how to create a note taking app using React and Flux architecture.

A Primer on Flux

Flux relies on unidirectional data flow. We have two key components in the Flux pattern:

  1. Stores : A store component, as the name suggests, stores the application data.
  2. Actions : New data flows into the stores through actions. Stores listen to actions and do some tasks (e.g. modify data) when actions are invoked. This keeps the data flow unidirectional.

To reinforce the concept let's take a real world example. For example, in a note making app you can have the following arrangement:

  1. A store called NoteStore which stores a list of notes.
  2. You can have an action called createNote. The store NoteStore listens to the action createNote and updates its list with a new note whenever the action is invoked. Data flows into the store only through actions.
  3. The NoteStore triggers an event whenever its data changes. Your React component, say NoteListComponent, listens to this event and updates the list of notes presented on the view. This is how the data flows out of the store.

So, the data flow can be visualised as following :

The biggest advantage of the Flux pattern is that it keeps your application data flat. As mutation can be done only through actions, it's easier to understand how the data change affects the whole application.

Note:

If you have gone through Facebook's guide to Flux, you might have noticed the concept of a Dispatcher. A Dispatcher is a registry of callbacks into the stores. When an action is invoked, the Dispatcher responds to it and sends the associated data to all the registered stores. Stores then check the action type and perform tasks accordingly.

The above process has been greatly simplified by a library called Reflux . It removes the concept of Dispatchers by making the actions listenable. So, in Reflux stores can directly listen to actions and respond to their invocation.

To understand the Flux pattern fully let's build a simple note taking app with Reflux, React, and Node.js.

Continue reading %Creating a Note Taking App with React and Flux%

Continuous Delivery: The Right Way to Deploy Your Software

Di, 2014-10-21 17:00

How do you deploy your web site or application to your live server? Does this describe your process?…

  1. get a copy of the latest codebase
  2. add, edit and remove code as necessary
  3. test the update
  4. copy all/changed files to the server using FTP
  5. rinse and repeat
It's a simple work-flow used by many developers. A proportion of those will also manage updates without source control such as Git or SVN. The process may be adequate for small projects with infrequent updates. Unfortunately, it breaks down the moment your site or application reaches any level of complexity.

Continue reading %Continuous Delivery: The Right Way to Deploy Your Software%