Javascript News

Syndicate content
Pipes Output
Updated: 48 weeks 6 days ago

Essential Tools & Libraries for Modern JavaScript Developers

Mo, 2015-08-10 20:00

Learning JavaScript is a great journey, but knowing the language and its syntax is only the beginning. Once the novice becomes a journeyman, they are confronted with a seemingly endless number of tools and libraries which are used to create, manage and maintain modern JavaScript code. Invariably, confusion strikes! As in a real journey, you […]

Continue reading %Essential Tools & Libraries for Modern JavaScript Developers%

Monitoring Your Particle Devices With IFTTT

Mo, 2015-08-10 18:00

I build plenty of IoT demos here at SitePoint but there's one thing I'd never considered - keeping track of whether or not my devices are online! It's one of those downsides of the Internet of Things... without the Internet, they can become rather powerless things!

In this article, we'll explore how to quickly and easily set up monitoring for Particle devices like the Core and Photon using IFTTT, Slack and Google Spreadsheets. We'll get notifications on Slack about when our devices go online/offline and we'll record that in a Google Spreadsheet for our records.

If you're totally new to the Particle ecosystem, you can find out more on the Particle website. You may know them as "Spark Core", as that was their previous name before they rebranded themselves. I put together a demo with the Particle Core and NeoPixels a few weeks back too. They're basically cloud connected microcontrollers that are a lot of fun to work with!

What is IFTTT?

IFTTT is a wonderful online service that is short for "If This Then That". It allows you to set up rules for various services that either provide an action that can be triggered remotely or provide the trigger for our actions. For example, about two months ago I built a demo on Connecting LIFX Light Bulbs to the IoT Using IFTTT. In that demo, smart lightbulbs would change color or turn on and off depending on various rules I'd set. If I set my Jawbone UP to sleep mode, my lights would know to turn off. If my favorite sporting team were playing, my lights could change color to the team colors to get some team spirit happening!

Connecting Particle to IFTTT

This article will assume you've already got an account on IFTTT set up and ready to go. If not, sign up on the IFTTT website to get started. If you need more info, we covered it in more detail in the previous IFTTT article mentioned above.

To get started, head over to the Particle IFTTT Channel page (or search for it on the IFTTT "Channels" page) and click "Connect":

It will prompt you for your Particle username and password. Enter those in and click "Sign In":

Then click "Okay" to give IFTTT access to your Particle data:

If all goes well, you should have a "Channel Connected!" success message appear for a little bit and a Particle channel page that looks like so:

Connecting Slack to IFTTT

Slack is pretty similar to connecting up the Particle channel, however it asks a few more questions. Start at the Slack IFTTT Channel page and click "Connect":

It will ask you to sign into the Slack domain you'd like the messages to appear inside. I used a domain I've got for an upcoming website project, rather than driving people at the SitePoint channel insane with my Particle alerts!

Then click "Authorize" to allow Slack to post messages into that Slack domain.

Once your Slack domain and IFTTT are able to talk to each other, you should have a Slack Channel page that looks like so:

Creating Our Particle and Slack Recipes

Now we've got Particle and Slack connected up to IFTTT, lets create our recipes with them. Click on the dropdown with your name in the top right and choose "Create" to create a new IFTTT recipe:

Click "this" to get started choosing our trigger:

Type in Particle to find the Particle channel and select that as our trigger:

Continue reading %Monitoring Your Particle Devices With IFTTT%

Video: Database Access with PHP

Mo, 2015-08-10 17:30

In this screencast I explain how to connect and extract data from a database using PHP, touching on topics like, PHP Data Objects (PDO), preventing SQL injection, and finally extracting your data in variety of different formats (as arrays, classes, or objects).

Loading the player...

Continue reading %Video: Database Access with PHP%

Drupal 8 Theming Revamped – Updates and New Features

Mo, 2015-08-10 16:00

If you are a Drupal developer who has dabbled in theming older versions of Drupal (5, 6, 7) you understand why frustration is the trusty companion of any Drupal themer. Luckily, though, Drupal 8 promises so many improvements that even the Angry Themer is happy for a change. It is only natural we jump in […]

Continue reading %Drupal 8 Theming Revamped – Updates and New Features%

Rails Authentication with Authlogic

Mo, 2015-08-10 14:00

Today, I ill like introduce you to AuthLogic, a simple authentication solution for Ruby built by Ben Johnson

AuthLogic is unobtrusive and pretty low-level. It does not rely on generated code (like Devise, for example) - instead it provides only the tools that you can use to code your app the way you like. In a sense, AuthLogic is similar to Sorcery.

Let's build a Rails app to allow users to register, sign in,and out, as well as reset their password. While doing this, we will discuss AuthLogic's various features and settings. After reading this tutorial you will be ready to use AuthLogic in your real projects.

Source code can be found on GitHub.

Demo app is available at sitepoint-authlogic.herokuapp.com.

Getting Started

The demo app that I am going to show you is built with Rails 4.1, but AuthLogic supports Rails 3, and even Rails 2 (there is a separate branch for it).

Create a new "Logical" app without the default testing suite:

[bash]
$ rails new Logical -T
[/bash]

Drop in the following gems:

Gemfile

[ruby]
[...]
gem 'bootstrap-sass'
gem 'authlogic', '3.4.6'
[...]
[/ruby]

and run

[bash]
$ bundle install
[/bash]

Continue reading %Rails Authentication with Authlogic%

How to Use Slack for Business: 6 Use Cases

Fr, 2015-08-07 20:41

Airbnb. Vox Media. Spotify. Stripe. Eventbrite.  This could be a list of some of Silicon Valley’s darlings—but it’s not. It’s a very incomplete list of companies that use group chat platform Slack.  As of June, there were more than a million users logging in to Slack every day, making it by far the fastest-growing business app ever.  And of […]

Continue reading %How to Use Slack for Business: 6 Use Cases%

Rendering Data in Yii 2 with GridView and ListView

Fr, 2015-08-07 16:00

In my previous article about the Yii 2.0, I introduced the ActiveRecord implementation. Once you have some data in your database you’ll want to be able to show it. Yii uses DataProviders to interact with data sources and it provides some widgets to output the data. Of these, the ListView and GridView provide the most functionality.

The example

I’m going to work with the database example that I introduced in my previous article again. Not very original, but quite useful as an example; a blog like SitePoint.

A small wrap-up of this database design and its Yii models which I’ll be using in this example:

  • The Authors model has one relation method call getArticles() that provides an Articles[] attribute to the model.
  • The Articles model has one relation method call getAuthor() that provides the Author and a method getTags() that provides the Tags[].
  • The Tags model has one relation method call getArticles that provides Articles[]

I won’t be using the ArticlesTags table since it is just used for an N:M relation. Of course, there is a model available for it which is used in the relation definition of the other models.

DataProviders

There are three different types:

  • The ActiveDataProvider is fed through an ActiveQuery instance and usually holds an array of models. You’ll normally use it to hold and render data that can be built from normal ActiveRecord instances with their relations.
  • The ArrayDataProvider is built using an array of data. This is quite useful when building all sorts of reports based on multiple models and/or custom aggregations.
  • The SqlDataProvider is a very useful one for the SQL masters among us. It is an easy way to get the data of those complex queries.

They don’t have huge differences, except slightly in views. The data provider itself is a base component that holds data and handles pagination and sorting.

Continue reading %Rendering Data in Yii 2 with GridView and ListView%

Creating an Audio Calling App with Ionic and PhoneRTC

Fr, 2015-08-07 15:00

In this tutorial I’m going to create an audio calling app with Ionic. We will be implementing it using PhoneRTC, a Cordova plugin which allows you to use WebRTC on Android and iOS devices.

Continue reading %Creating an Audio Calling App with Ionic and PhoneRTC%

20+ Docs and Guides for Front-end Developers (No. 5)

Do, 2015-08-06 23:02

It’s that time again to choose the tool or technology that we want to brush up on. If you feel like you’ve been working hard at building but maybe not learning as much as you’d like, I’ve got your back covered.

Please enjoy the fifth installment of our Docs and Guides series and don’t forget to let us know of any others that we haven’t yet included in this or a previous post.

1. SitePoint Sass Reference

SitePoint’s very own project, a reference site based on Sass built by our resident expert Hugo Giraudel and Stu Robson, SitePoint’s Sass editor.

2. SVG viewBox and preserveAspectRatio Interactive Demo

This is an interactive page to go along with a related article series by Sara Soueidan. This demo helps readers visualize some of the concepts associated with the viewBox and preserveAspectRatio attributes used on SVG elements. Noteworthy also is that the demo page has an associated cheat sheet.

3. CSS 2.1 Index List

This is a W3C document I came across recently. It’s a giant list of just about every CSS term, with links to each term or feature. In some cases the link is to a simple definition somewhere in the spec, in other cases it’s a link to that feature’s place in the spec.

4. Popular Coding Convention on Github

Choose from different languages including JavaScript, Ruby, and PHP then this page will show you chart-based data to indicate how prevalent certain coding patterns are on GitHub-hosted projects.

5. Dungeons and Developers

This is not an interactive game, but a RPG-like talent tree representation of web development skills, with links to various places to learn the different skills listed.

6. JSON API

“If you’ve ever argued with your team about the way your JSON responses should be formatted, JSON API is your anti-bikeshedding weapon. By following shared conventions, you can increase productivity, take advantage of generalized tooling, and focus on what matters: your application.”

7. jQuery UI Events Cheatsheet

A chart that specifies which jQuery events are applicable for desktop vs mobile and mouse vs keyboard.

8. Weightof.it

A quick reference app to view and compare JavaScript libraries by weight with an option to view the size Gzipped or not. The app also lets you add different libraries to a “stack” (like adding to a shopping cart) so you can view your total library weight.

9. JavaScript in one pic

This a very nicely done visualization of all of JavaScript’s native features. Not exactly the most practical way to learn the language, but from scanning this you might find something interesting to do further research on.

10. Understanding NPM

“Since its creation, the role of npm has expanded to fulfill the broader needs of the JavaScript and Node.js developer community to include management of front-end web applications, mobile applications and other JavaScript development tools and frameworks […] This visualization is intended to help you understand the role and scope of npm.”

Continue reading %20+ Docs and Guides for Front-end Developers (No. 5)%

Aesop Story Engine: Write Stories Instead of Code

Do, 2015-08-06 19:30

I’m the first to admit it. I’m definitely a copywriter, a storyteller, a content marketer at heart. It’s where my passion lies. I’ve come late to the world of WordPress, web development and HTML. I’m still much more comfortable in the world of pronouns and adjectives, than that of h1's and h2's. Perhaps that is why I love WordPress so much; it enables less than technical experts (like myself) to not only build, but to manage websites. It makes the web more accessible to everyone.

So, when I stumbled upon Aesop Story Engine, it’s fair to say my interest was piqued. It almost seemed as though Aesop Story Engine’s tagline was written just for me: Write Stories Instead of Code.

After all, at the very crux of it, I use WordPress to tell stories. And here was a plugin promising to turn me into a modern day fabulist, a plugin that would let me focus on writing prose, rather than HTML. Surely it was too good to be true.

What is Aesop Story Engine?

Aesop Story Engine is, when everything else is stripped away, a free WordPress plugin. It is comprised of thirteen different components and tools, all of which have been designed to give web developers (and writers) the ability to build WordPress themes specifically for long-form storytelling.

Continue reading %Aesop Story Engine: Write Stories Instead of Code%

Video: Classes in Swift

Do, 2015-08-06 17:30

In this video we'll look how classes and instances of classes are made in Swift.

Loading the player...

Continue reading %Video: Classes in Swift%

How to Get Good Clients by Utilizing Influencers

Do, 2015-08-06 16:00

Trying to land freelance clients can be difficult. Confusing, even. Where do you find them? And once you find them, how do you compete with all the other freelancers out there? Finding clients can also be time consuming. You could easily spend hours responding to bids, cold calling or emailing, and scrabbling for scraps. At […]

Continue reading %How to Get Good Clients by Utilizing Influencers%

Phoenix for Railsies

Do, 2015-08-06 14:00

So, what is Phoenix? It's a Rails-like framework built for Elixir. You might ask: what on Earth is the point of learning yet another framework for yet another language that nobody really seems to be using (yet)? There are a couple of reasons. First of all, the Erlang VM is pretty darn fast and Elixir inherits this speed. There are benchmarks that show this. But of course, we can sit around all day and poke holes in those so you'll just have to build something with both technologies to believe it.

Secondly, Elixir is an interesting language because it manages to combine functional programming, OOP, and a Lisp-like conception of metaprogramming (Elixir's macros are pretty insanely powerful). Finally, Rails definitely feels a bit behind-the-curve when it comes to things like WebSockets. Phoenix comes with these right of the box. Best of all, you get most of these benefits without having to leave the niceties of Rails behind. Granted, there aren't as many packages for Phoenix as there are for Rails but the framework itself is fairly feature-complete. Let's take a look at the basics of Phoenix.

Continue reading %Phoenix for Railsies%

Is There a Perfect Paragraph Length for the Web?

Do, 2015-08-06 01:33

[caption id="attachment_112063" align="alignright" width="400"] The original Magna Carta document[/caption]

This is the original Magna Carta written in 1215. Parchment was very expensive in the 11th century, so thrifty scribes wrote in tiny, densely packed latin.

While it's quite beautiful, the absence of paragraphs gives it a rather impenetrable look – even allowing for the latin. It's hard for our modern eyes to traverse that sheer wall of text.

Why do we even need paragraphs?

Paragraphs serve three useful purposes in writing. Firstly they help the writer to order and organise their thoughts. Secondly, they give the reader 'rest points' as they work through the text.

And finally, paragraphs give us entry and exit points into documents – shortcuts for navigating around text. This is particularly useful on the web, where we know that readers browse, scan and snack on text much more than they do on printed texts.

What is the ideal paragraph length?

[caption id="attachment_112062" align="alignright" width="318"] Sentence Lengths in SOTU over time - Source: Language Log[/caption]

Predictably, there are lots of answers for this question, but the general consensus has been getting shorter for 200 years. Mark Liberman from Language Log wrote a script that analyzed the structure of every US presidential 'Inaugural Address' and 'State of the Union' address since the late 1700's. Of course, sentence length and paragraph length are different, but there's certainly a relationship.

As Mark's chart shows, average sentence length has gone from over 40 words per sentence, to less than 20 words in 2011. I don't have a problem with this trend, but some do.

Whatever the driving forces, we've been continually selecting for shorter sentences and paragraphs for a long time.

Elsewhere Bob Brooke's Writers' Corner advises that you 'Try to limit your paragraph to five lines – not sentences. If it's too long, break it down into a series of paragraphs on subtopics'. Of course, on the web 'five lines' changes from device to device.

The Yahoo! Style Guide says “Keep paragraphs short. Two to three sentences is often enough.”

Which brings us to an interesting question.

As FEDs/designers/UX people, we take responsibility for setting type sizing, line-heights, kerning, contrast, and all other typographic choices to create the best possible user experience.

1) Is it also our job to try to design the ideal paragraph lengths for our layouts? (most would say no).

2) The 'ideal' paragraph length surely must differ for different screen sizes? What is most comfortable to read on a Kindle or desktop surely isn't the same as what works best on an iPhone.

Take this example of the same text on two devices:

On the phone above, a lot of the usefulness of paragraphs starts to disappear when you can only see one or at best two paragraphs at a time. We get a more 'magna carta-esque' wall of text.

Continue reading %Is There a Perfect Paragraph Length for the Web?%

5 Important Considerations for an SEO-Friendly Site Redesign

Mi, 2015-08-05 22:10

Your website is often the face of your company, and there are oh so many reasons to give your website a facelift. Maybe it’s time to ramp up the functionality and enhance usability. Maybe the purpose of your site has changed, or its social media integration isn’t up to snuff. Maybe it still looks like this.

Whatever the reason, retaining - and even improving - your site’s SEO should be high up on your checklist.

Otherwise, your site will face heavy traffic loss, and all that work will be for naught. Sure, you may have poured significant time and money into your site’s overhaul, but if users can’t find the site, you’ve just remodeled a house with no address, on an island, an invisible island, in outer space.

To avoid traffic loss and conquer the search engines, here are five important considerations for an SEO-friendly redesign.

1. Ensure All Content Is Indexable

In order for a web page to be ranked in a search engine, it must be indexed by web crawlers. Think of these crawlers as an army of Pac-Men who scour webpages for little yellow dots of data. The crawlers then deliver that data to the search engine servers, where it’s catalogued and stored, much like a library.

But crawlers are picky eaters, and can only index certain types of data. In order for your content to be indexable, it must be formatted in a way that’s compatible with the crawlers’ particular dietary needs. Here are some guidelines:

  • Any content you want indexed should be written in HTML.

  • Any images you want indexed should contain alt tags.

  • If your website has video or audio content, and you’d like that content to be indexed, include a written transcript on the website.
  • Restricted pages, such as pages only accessible via a form or password, are not indexable, so avoid them when possible.
  • Unless you’re dealing with sensitive information, avoid any instances of robots.txt. A robots.txt tells crawlers _not _to scan or process certain areas of a website.

If you’re having trouble deciding on what is and what is not indexable, or you want to verify your site’s indexability after redesign, use the following tools:

  • Run Link Assistant’s Website Auditor to check for indexing and crawlability errors.
  • Use Cached View to see a visual representation of a webpage’s indexable content.
  • Take a mental break and play Pac-Man.

Continue reading %5 Important Considerations for an SEO-Friendly Site Redesign%

Browser Trends August 2015: Chrome Exceeds 50%

Mi, 2015-08-05 22:00

In last month's browser chart, Chrome had been struggling to jump above 50% usage. The browser fares better in July's StatCounter statistics

Worldwide Desktop & Tablet Browser Statistics, June to July 2015

The following table shows browser usage movements during the past month.

Continue reading %Browser Trends August 2015: Chrome Exceeds 50%%

Creating Isomorphic Apps with Node.js, React, and Express

Mi, 2015-08-05 20:00

Over the past few years, the Web community has been abuzz with “isomorphic apps”. They are apps where the markup is rendered on the server and fed to the browser as complete HTML, and the successive user interactions are handled by client side rendering. This is useful as it lead to outcomes like faster page loading, better search engine indexing, and better user experience. In this tutorial, we’ll crate a simple isomorphic app that uses Node, React, and Express to understand the underlying process behind it.

The Tech Stack

In this article, we’re going to use following software:

  • React: the UI framework that can rendered on both server and client.
  • webpack: a module bundler to be used for bundling JavaScript.
  • Express: the application server framework for Node.js.
  • react-router: the routing solution specially developed for React.js.
  • Babel: the JavaScript compiler with built-in support for ES2015 syntax and JSX.
  • Jade: a JavaScript powered templating engine that works on both server and client side.
Project Setup

Let's start the project by upgrading to Node v.0.12.6 and creating an empty directory that will act as our project folder. Once done, run the npm init command in the newly created directory and fill up the presented questions. The next thing we need to do is to install all the required packages. Execute the following command to achieve this task:

$ npm install --save-dev babel babel-loader express jade react react-hot-loader react-router webpack webpack-dev-sever nodemon

When the installation process is completed, we have to create a src folder inside our project folder. Then, we have to create the following directories inside src:

  • server: where the backend Node.js server and webpack dev server will reside.
  • client: this will be the entry point to handle React bundle.
  • shared: this folder will hold app's components, flux, routes, etc.

Continue reading %Creating Isomorphic Apps with Node.js, React, and Express%

Responsive Solutions for Feature Comparison Tables

Mi, 2015-08-05 18:00

Responsive Web Design and tables are not necessarily the best of friends. Many people have researched the situation and a lot of approaches have been devised (some of them were even rounded up in a recent article here on SitePoint). However we are still far away from the perfect solution and the search continues.

While things are still complicated in the generic case, certain specific cases can be treated with a lot more attention. I am talking here about the feature comparison table. We encounter it in many places – when choosing a car and trying to decide what extra options to choose; on web hosting websites when comparing plans and features; on any membership-based portal that lets you decide what features you need to receive in exchange for your money.

Because this kind of table has a relatively stable and consistent structure, it is possible to coax a better behavior when displayed on small screens.

Anatomy of a Feature Comparison Table

The classic comparison table brings together at least three products (displayed in columns) while the features are displayed on rows below. In the traditional structure, the first cell of each row has the name of the feature, while the cells under each product have a checkmark or some other symbol, showing whether that feature belongs to the product or not. We can find great examples of this classic structure: here, here, and here

Based on these examples, we can summarize the structure of a comparison table with the following code:

[code language="html"]

  Product 1 Product 2 Product 3 Feature 1 ✔ ✔ ✔ Feature 2 — ✔ ✔ Feature 3 — — ✔ Feature 4 — — ✔

[/code]

It is easy to identify the elements mentioned earlier: the product names, the feature names, and the marks that show whether the feature is present or not. Note that the ✔ code represents a checkmark (✔) character.

We now arrive at the root of the problem. In order for the table to maintain optimum effectiveness at low screen widths, a few conditions must be fulfilled:

  • The user must be able to easily differentiate the products;
  • The features must be easily identifiable; and
  • It must be clear if a feature for a product is present or not.

The best way to achieve this result is to shift the cell containing the feature name on top of the other three cells that mark the presence or absence of the feature.

First Solution: Flexbox

How can we get this to happen? One answer is flexbox. If you don’t know what flexbox is or if you need a refresher, you can check out Nick Salloum’s recent article on the topic. The rest of us can dive into the solution.

First we need to make sure our changes happen only on small screens. For this to happen, we target our code using a media query, using the classic width of 768px as a breakpoint:

Continue reading %Responsive Solutions for Feature Comparison Tables%

Video: Controlled vs Uncontrolled Components in React

Mi, 2015-08-05 17:30

In this video we look at controlled inputs in React. This is unique concept to React that can be tricky to understand at first.

We'll be polishing the demo we started in the last lesson "Introduction to One-Way Data Flow."

Loading the player...

Continue reading %Video: Controlled vs Uncontrolled Components in React%

Mastering Image Optimization in WordPress

Mi, 2015-08-05 17:00

When building and maintaining WordPress websites, it’s important to find ways to improve site performance and decrease page load times. This helps reduce bounce rates and increase rankings on search engines.

There are several ways of achieving performance through a WordPress site’s theme and plugin code – for example, minifying JavaScript, CSS and images. There’s also server based configuration options – for example, enabling caching, or using a WordPress Plugin to help cache static content.

However, we can’t control the content – specifically images – that clients will add to their WordPress web site. Images may be uploaded in their original form, leading to site performance issues and increasing page load times.

In this article we will explore different ways of optimizing JPEG and PNG images, which are uploaded by clients and site owners into WordPress.

Theme Image Sizes

When a WordPress user uploads an image, WordPress provides two functions which we can use to create copies of the original image, at specific dimensions. This is useful where we want to output an image at a specific size within our theme.

Thumbnail, Medium and Large Sizes

Within the WordPress Administration, under Settings > Media, there are three predefined image sizes: thumbnail, medium and large. Each can have their own dimensions set.

Because WordPress will always resize images to these sizes (resulting in 4 images being stored - the original, thumbnail, medium and large sizes), it’s worth setting these first and using them within your WordPress Theme where possible.

Continue reading %Mastering Image Optimization in WordPress%