Monday, November 30, 2015

jQuery Interactive Image Plugin

A jQuery plugin to embed interactive images on your website.

Features:

  • Insert interactive texts and images over large pictures
  • Flexible configuration
  • Easily customizable with CSS
  • Fully tested with CasperJS
  • Installable via package managers

The post jQuery Interactive Image Plugin appeared first on jQuery Rain.


by Admin via jQuery Rain

#SocialMedia Tips: How To Become A Twitter Marketing Pro With $0 Budget - #infographic

How To Maximize Your Influence On Twitter - #infographic

Are you leveraging Twitter for business?

“Whether you are attempting to land a lucrative marketing job or have been tasked with handling your company’s social media accounts, becoming a Twitter expert is a great way to gain visibility and engagement for yourself and your organization. After all, having the know-how to use social media and manage real-time conversations has been named one of the top skills today’s candidates should have.

As Twitter and other social media platforms continue to become an integral part of the customer service and marketing process, knowing how to reach goals with little to no budget can make you an important part of any business.”

Here are some tips and tools, in an infographic from Salesforce, that anyone can use to become a Twitter marketing pro.

by Irfan Ahmad via Digital Information World

Introducing SitePoint Premium Collections (and Our Best Price Ever)

Huge discounts on SitePoint Premium

We've just launched something new, and we're celebrating with a huge discount on SitePoint Premium memberships.

Introducing Collections: we've made it even easier to watch playlists of screencasts on your favorite topics (and by your favorite teachers) in grouped bundles so you can learn more intuitively - the next instalment is right there in the relevant Collection, exactly where you need it. New videos are added daily.

Watch one lesson or binge away, the choice is yours, free for all SitePoint Premium Members.

To celebrate the launch, we're doing something we never, ever do and offering SitePoint Premium Membership at a massive discount for one week only:

Monthly - $7 (normally $15)
Annual - $48 (normally $108)

And, for the first time ever, you can now have a SitePoint Premium Lifetime Membership! A one time cost of $199 for ongoing access to the best resources to develop your skills - forever. That’s unlimited access to all SitePoint books, courses, collections and screencasts.

We're reverting to our usual pricing at the end of the week, so now's the time to join!

Join SitePoint Premium

Continue reading %Introducing SitePoint Premium Collections (and Our Best Price Ever)%


by SitePoint Offers via SitePoint

The Importance of Writing Code That Humans Can Read

Have you ever finished a project in a single run without ever needing to look at the code again? Neither have I. When working on an older project, you probably want to spend little to no time figuring out how code works. Readable code is imperative to keep a product maintainable and to keep yourself, and your colleagues or collaborators happy.

Exaggerated examples of unreadable code can be found on JS1k contests, where the goal is to write the best JavaScript applications with 1024 characters or less, and JSFuck, an esoteric programming style which uses only six different characters to write JavaScript code. Looking at code on either of these sites will make you wonder what is going on. Imagine writing such code and trying to fix a bug months later.

If you surf the internet regularly, or build interfaces, you may know that it’s easier to quit a large, bulky form than one that seems simple and small. The same can be said about code. When perceived as easier to read and to work on, one may enjoy working on it more. At least it will save you tossing out your computer in frustration.

In this article, I’m going to look at tips and tricks to make your code more readable, as well as pitfalls to avoid.

Code Splitting

[author_more]

Sticking with the form analogy, forms are sometimes split in parts, making them appear less of a hurdle. The same can be done with code. By splitting it up into parts, readers can skip to what is relevant for them instead of ploughing through a jungle.

Across Files

For years, we have been optimising things for the web. JavaScript files are no exception of that. Think of minification and pre-HTTP/2, we saved HTTP requests by combining scripts into a single one. Today, we can work as we want and have a task runner like Gulp or Grunt process our files. It’s safe to say we get to program the way we like, and leave optimization (such as concatenation) to tools.

// Load user data from API
var getUsersRequest = new XMLHttpRequest();
getUsersRequest.open('GET', '/api/users', true);
getUsersRequest.addEventListener('load', function() {
    // Do something with users
});

getUsersRequest.send();

//---------------------------------------------------
// Different functionality starts here. Perhaps
// this is an opportunity to split into files.
//---------------------------------------------------

// Load post data from API
var getPostsRequest = new XMLHttpRequest();
getPostsRequest.open('GET', '/api/posts', true);
getPostsRequest.addEventListener('load', function() {
    // Do something with posts
});

getPostsRequest.send();

Functions

Functions allow us to create blocks of code we can reuse. Normally, a function’s content is indented, making it easy to see where a function starts and ends. A good habit is to keep functions tiny—10 lines or less. When a function is named correctly, it’s also easy to understand what is happening when it’s being called. We’ll get to naming conventions later.

// Load user data from API
function getUsers(callback) {
    var getUsersRequest = new XMLHttpRequest();
    getUsersRequest.open('GET', '/api/users', true);
    getUsersRequest.addEventListener('load', function() {
        callback(JSON.parse(getUsersRequest.responseText));
    });

    getUsersRequest.send();
}

// Load post data from API
function getPosts(callback) {
    var getPostsRequest = new XMLHttpRequest();
    getPostsRequest.open('GET', '/api/posts', true);
    getPostsRequest.addEventListener('load', function() {
        callback(JSON.parse(getPostsRequest.responseText));
    });

    getPostsRequest.send();
}

// Because of proper naming, it’s easy to understand this code 
// without reading the actual functions
getUsers(function(users) {
    // Do something with users
});
getPosts(function(posts) {
    // Do something with posts
});

We can simplify the above code. Note how both functions are almost identical? We can apply the Don’t Repeat Yourself (DRY) principle. This prevents clutter.

function fetchJson(url, callback) {
    var request = new XMLHttpRequest();
    request.open('GET', url, true);
    request.addEventListener('load', function() {
        callback(JSON.parse(request.responseText));
    });

    request.send();
}

// The below code is still easy to understand 
// without reading the above function
fetchJson('/api/users', function(users) {
    // Do something with users
});
fetchJson('/api/posts', function(posts) {
    // Do something with posts
});

What if we want to create a new user through a POST request? At this point, one option is to add optional arguments to the function, introducing new logic to the function, making it too complex for one function. Another option is to create a new function specifically for POST requests, which would result in duplicate code.

We can get the best of both with object-oriented programming, allowing us to create a configurable single-use object, while keeping it maintainable.

Note: if you need a primer specifically on object-oriented JavaScript, I recommend this video: The Definitive Guide to Object-Oriented JavaScript

Object Oriented Programming

Consider objects, often called classes, a cluster of functions that are context-aware. An object fits beautifully in a dedicated file. In our case, we can build a basic wrapper for XMLHttpRequest.

HttpRequest.js

function HttpRequest(url) {
    this.request = new XMLHttpRequest();

    this.body = undefined;
    this.method = HttpRequest.METHOD_GET;
    this.url = url;

    this.responseParser = undefined;
}

HttpRequest.METHOD_GET = 'GET';
HttpRequest.METHOD_POST = 'POST';

HttpRequest.prototype.setMethod = function(method) {
    this.method = method;
    return this;
};

HttpRequest.prototype.setBody = function(body) {
    if (typeof body === 'object') {
        body = JSON.stringify(body);
    }

    this.body = body;
    return this;
};

HttpRequest.prototype.setResponseParser = function(responseConverter) {
    if (typeof responseParser !== 'function') return;

    this.responseParser = responseParser;
    return this;
};

HttpRequest.prototype.send = function(callback) {
    this.request.addEventListener('load', function() {
        if (this.responseParser) {
            callback(this.responseParser(this.request.responseText));
        } else {
            callback(this.request.responseText);
        }
    }, false);

    this.request.open(this.method, this.url, true);
    this.request.send(this.body);
    return this;
};

app.js

new HttpRequest('/users')
    .setResponseParser(JSON.parse)
    .send(function(users) {
        // Do something with users
    });

new HttpRequest('/posts')
    .setResponseParser(JSON.parse)
    .send(function(posts) {
        // Do something with posts
    });

// Create a new user
new HttpRequest('/user')
    .setMethod(HttpRequest.METHOD_POST)
    .setBody({
        name: 'Tim',
        email: 'info@example.com'
    })
    .setResponseParser(JSON.parse)
    .send(function(user) {
        // Do something with new user
    });

Continue reading %The Importance of Writing Code That Humans Can Read%


by Tim Severien via SitePoint

Web Design Weekly #214

Headlines

Seriously, Don’t Use Icon Fonts

Make time for this one. A very entertaining post by Tyler Sticka that gives us lots of great reasons to stop using icon fonts and get on the SVG train. (cloudfour.com)

Dance to Calypso

Matt Mullenweg writes about WordPress’s new publishing and site management experience which has had a lot of hype this week. (ma.tt)

Articles

Frameworks

An excerpt from Ethan Marcotte’s new book, Responsive Design: Patterns & Principles. If you haven’t ordered the book already, I’m sure you won’t hesitate after reading this. As always, wise words by Mr RWD. (alistapart.com)

Simplicity Wins over Abundance of Choice

A good reminder that keeping the number of options within an interface allows people to make decisions easier and complete tasks faster. (nngroup.com)

Finding the Right Color Palettes for Data Visualizations

While good color palettes are easy to come by these days, finding the right color palette for data visualizations is still quite challenging. Thankfully Samantha Zhang shares some trade secrets to potentially make our job easier. (medium.com)

Code Review Done Right

Next time you need to do a code review, taking 5 minutes to read this great article by Jezen Thomas could go a long way. (jezenthomas.com)

Designing with constraint: Twitter’s approach to email (blog.twitter.com)

Tools / Resources

Building a UI style guide with AngularJS directives

The team at Sauce have taken the time to build a live style guide so developers, designers and product managers can be consistent across all products. It’s built with AngularJS as Kuba SiemiÄ…tkowski explains. (saucelabs.com)

How to animate “box-shadow” with silky smooth performance

If performance is your thing, both this article by Tobias Ahlin and Harry Robert’s quick screencast about speeding up Tobias’s site are full of handy tips. (tobiasahlin.com)

ally.js

A small JavaScript library to help web applications with accessibility. (allyjs.io)

Sketch Keyboard Shortcuts and Tricks (designcode.io)

How do Promises Work? (robotlolita.me)

Inspiration

The Keys to Scaling Yourself as a Technology Leader (firstround.com)

The Start of a Great Hiring Experience (uie.com)

Jobs

Web Developer at Hello

As a developer, you will build complex web sites and applications and must be able to collaborate with multi-disciplinary teams consisting of strategists, designers and programmers. (hellodesign.com)

UX Designer at Booking.com

As a member of our Front End team you’ll be given the freedom to make meaningful and measurable improvements impacting millions of people. You’ll join us at our beautiful Amsterdam HQ and work with some of our industry’s smartest people. (booking.com)

Need to find passionate developers? Why not advertise in the next newsletter

Last but not least…

Agility Follows an S-Curve

This article Ben Sandofsky is focused more towards shipping iOS apps but has some really interesting thoughts around hitting deadlines. (sandofsky.com)

The post Web Design Weekly #214 appeared first on Web Design Weekly.


by Jake Bresnehan via Web Design Weekly

JavaScript Beyond the Web in 2015

2015 has been a big year for the Internet of Things. We have seen huge advancements in the size and capability of devices, big players like Microsoft and Samsung are really moving into the space and the IoT community overall is starting to grow ever larger! Over the past two years here at SitePoint, it has become a bit of a tradition for me to look at the year that was for the Internet of Things and JavaScript (see JavaScript Beyond the Web and JavaScript Beyond the Web in 2014). Whilst the initial hype and excitement of having JavaScript as a language of the Internet of Things (IoT) seemed to calm down a bit over 2015, JavaScript still continues to pop up as a rather strong option for enabling magic within more IoT platforms than people realise.

In this overview, we'll look at some of the big movements in the Internet of Things that will enable new possibilities for JavaScript developers and further JavaScript's potential beyond the web.

Tessel 2

[caption id="attachment_120043" align="aligncenter" width="1024"]The Tessel 2 (Photo credit: Tessel) The Tessel 2 (Photo credit: Tessel)[/caption]

The Tessel is a microcontroller (similar to an Arduino) that ran on JavaScript rather than the typical languages such as C. It was the perfect device to help JavaScript lovers leap into the Internet of Things. Last year it shipped to the world and people made some pretty neat things with it. The Tessel 2 released pre-orders this year and has some very exciting upgrades from the first generation Tessel.

The Tessel was able to run various npm packages, but wasn't able to run Node.js itself, so Tessel often had to build in compatibility specifically for commonly used packages. The Tessel 2 greatly improves on this by running the real Node.js out of the box. This fact alone made me pre-order it instantly. Access to npm modules brings a lot of potential to this microcontroller.

It also has two USB ports, providing access to USB devices (e.g. webcams) as well as ready made Tessel modules and the GPIO port (to directly connect all sorts of electronics via jumper wires to pins).

Getting Involved Via JavaScript

  • Pre-order Tessel 2 - Pre-order the Tessel 2 from their website and start planning your creations! The Tessel 2 should arrive in January 2016.
  • Official Tessel Documentation - You can start reading up on Tessel development already (Tessel 1 development should be very similar to Tessel 2).

Open Hybrid

[caption id="attachment_120075" align="aligncenter" width="974"]OpenHybrid in action (Photo credit: OpenHybrid) OpenHybrid in action (Photo credit: OpenHybrid)[/caption]

Augmented reality is a fascinating alternative method of controlling the Internet of Things around us. Rather than putting physical controls on objects, you can view them through an augmented reality interface like a smartphone app and control them in intuitive and limitless ways! Various companies are looking into ways of implementing this but in 2015, MIT Media Labs revealed (and open-sourced) a pretty impressive method called Open Hybrid. JavaScript IoT developers in particular might be very interested by this solution as it allows for application development via web technologies including HTML and JavaScript. Whilst it is still early days for augmented reality, now is the time to start tinkering with its potential alongside the IoT!

Getting Involved Via JavaScript

Samsung's IoT.js and JerryScript

[caption id="attachment_120046" align="aligncenter" width="1000"]The Samsung IoT.js and JerryScript pages The Samsung IoT.js and JerryScript pages[/caption]

Samsung has put plenty of resources towards enabling JavaScript to be the language for the Internet of Things. In 2015, they open sourced JerryScript, a JavaScript engine for the Internet of Things. It allows JavaScript to run on small, resource constrained devices like the microcontrollers commonly used in the IoT. To me, it sounds similar to what Tessel were attempting to put together in the first iteration of the Tessel but on a grander scale which is open to many more small IoT devices.

IoT.js is another endeavour of Samsung to enable JavaScript within the Internet of Things ecosystem. It was open sourced around the same time as JerryScript. IoT.js is a framework for creating an inter-operable platform for devices using JavaScript. It has been described as a lightweight version of Node.js, however I've yet to play around with it myself to get a true feel for how accurate that description is.

Both JerryScript and IoT.js are still in their early stages, so it will be exciting to see how they progress throughout 2016. I'm eagerly hoping for integration with the Samsung SmartThings platform at some point but I haven't heard of any mention of this yet!

Getting Involved Via JavaScript

  • Official JerryScript Page - The official page for JerryScript contains links to downloading the engine and guides on getting started.
  • Official IoT.js Page - The official page for IoT.js also has a download link and guides for getting started.

Continue reading %JavaScript Beyond the Web in 2015%


by Patrick Catanzariti via SitePoint

Building a Shopping List Application With CloudKit: Adding Relationships