Add Google+ Comments To Your Site

On the 18th April 2013 Google announced that they have made a Google Plus commenting system which you can have on your website just like the Facebook comments. This allows people to come to your site and when they comment on an article this comment will be shared on Google plus.

Google+ Comments

The difference that Google plus comments has over Facebook comments is a massive benefit of including all comments from Google plus on your page. This means that if someone shares your article on Google plus it will appear in your commenting system, if this then leads to a conversation happening on Google Plus about your article this will also appear on your comment system. So all conversations that are happening about your page will come through and be displayed on your website. This allows you to keep in touch with every conversation that is happening on Google plus about your page.
Continue reading »

Display Disqus On Click Event

I have recently redesigned Paulund and it was design to concentrate on page loading speeds, I wanted to make Paulund load as fast as possible. There are lots of things you can do to improve the loading speeds of your website, you can compress images, improve your web hosts, make your website code more efficient. But one thing that I choose to do with this redesign was to reduce the amount of HTTP requests each page makes when it first loads.

When looking into the amount of HTTP requests each page was making I noticed a large amount of HTTP calls being made from Disqus. This is a commenting system that you can place on any website, it makes it really easy to add to any site as you just need to include a couple of lines of Javascript to your page. If your site is running WordPress it's even easier to include on your site as you just need to download the WordPress plugin.

Disqus
Continue reading »

Create An Interactive Metro Style Grid Dashboard

Since Windows 8 released it's first pictures of the new design, people have been going crazy over the metro style. People love it, it's modern, it's clean, it's simple and makes it really easy to use on mobile devices, especially on tablet devices.

windows8-metro

In 2013 it is going to be a trend that you will start seeing more websites applying this metro style to their designs. But for websites is this a good idea, does this styling work for different website designs.

In this tutorial we are going to create a metro style dashboard, to do this we are going to use a very useful jQuery plugin called gridster.

Gridster

Gridster will allow you to create a drag and drop multi-column grid. All the layout of the grid is taken care of by the plugin, all you have to do is define how many rows and columns each box will spread across. Then define the height and width of a single box and the plugin will work out how big each box has to be.

gridster.js
Continue reading »

Create Google Maps With gmaps.js

gmaps.js

How To Use GMaps.js

GMaps is a javascript plugin that makes it really easy to use Google Maps to display a map to your user. There are multiple options that make it easy to add pointers to the map, directions, information boxes and lots more.

This plugin is massive there is loads of options to go through, in this tutorial I'm not going to go through all of them. I'm just going to go through the options which will be the ones you are most likely going to use.

If you want to see all the options for this plugin you can view the documentation on the Github Repository.

Documentation

To start using GMap.js you need to download the latest version from Github.

Download GMap

Once you have the latest now include the Javascript file and jQuery on your page inside your head tag.

< !DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true"></script>
<script src="gmaps.js"></script>
</head>
<body>
</body>
</html>

Continue reading »

Create Your Own Share Buttons With Sharrre

People are now members of multiple social networks be it Facebook, Twitter, Google Plus, Linkedin etc.

All of these social networks have created their own button which makes it really easy for your visitors to share the current page with their friends and followers.

Facebook Like Button

Twitter Tweet Button

Google Plus +1 Button

Everyone knows what these buttons look like, this is good as people understand how to use them and what they will do. People see these all over the web and use them quickly and easily to share content online.

But with every website using the same buttons they aren't very original. If you have a very creative website, you should want to show that you can be original with all areas of your site.

Why not create your own Social sharing buttons?

The reason is because these social sharing buttons comes with a social proof feature, showing you exactly how many other people have shared this page. If your content is shared a lot on the social networks you want to show this off to your visitors, when people see other people have shared this...they want to share it.

Therefore if you want to make your own social sharing buttons you really need to include this feature of displaying how many shares your page has.

This is where a jQuery plugin called Sharrre can help, this plugin is designed to simulate all the major social networks share buttons but will separate up the button into different HTML elements to make it easier to style.
Continue reading »

Handle Keyboard Shortcuts With Mousetrap.js

Mousetrap

Mousetrap.js is a javascript plugin that makes it easy to setup keyboard shortcuts for your web applications.

It allows you to define functions to run on certain key pushes, you can set it on a single key or a combination of keys together or a sequence of keys.

Mousetrap.js is available on github and you can download it here.

Download Mousetrap.js

Browser Support

Mousetrap.js can be used in any browser, it has support built in to be used on:

  • Internet Explorer 6+
  • Chrome
  • Safari
  • Firefox
  • Opera

How To Use

Just like any other Javascript file all you have to do is include it on the page and a new mousetrap object will be created for you.

<script src="./js/mousetrap.js"></script>

Continue reading »

Javascript Full Screen API

The full screen API is an easy way to get the full web content to be displayed on the page. It's very similar to pressing F11 on your keyboard but this can be done at the developers choice. This is a great feature to use for things on slideshows, you can make the browser go into full screen on a click of an image.

The best thing about this feature is that it doesn't have to be the entire page, you can make any HTML element go full screen. This mean instead of always making the entire page go full screen, just assign the full screen API to an image and on the click of the image you can just focus on the image in full screen.

Full Screen API Support

Unfortunately not all browsers support this feature so you need to make sure that your visitors browser supports this feature before you try to use it.

If the browser they are using supports this then you can use it, if the browser doesn't support this feature then you can make sure you do something else instead of using full screen.

According to the website Can I Use the full screen API is currently supported on Firefox, Chrome/Safari and Opera.

Can I Use Full Screen

  • Chrome 15+
  • Firefox 10+
  • Safari 5.1+
  • Opera 12.50+

Continue reading »

Get Ready To Load Different Versions Of jQuery

If you have done any sort of front-web development the you will understand the benefits that jQuery can bring you when developing your websites. One of the best benefits of jQuery is that it performs the same on all browsers, so anything you do in the latest version of chrome will act the same in IE.

This is a massive benefit when working with jQuery animation, as you know whatever you do with jQuery will work on the other browsers. Even working with JSON or XML jQuery makes it very easy to work in the different browsers.

Recently on the jQuery blog they announced that from version 2 of jQuery they will not be support IE8 or lower.

jQuery 2.0 (early 2013, not long after 1.9): This version will support the same APIs as jQuery 1.9 does, but removes support for IE 6/7/8 oddities such as borked event model, IE7 “attroperties”, HTML5 shims, etc.

Continue reading »

Manipulate The Favicon With Tinycon

When you get alerts and notifications from Facebook, twitter or your email client depending on the browser you will be alerted of new activity. An example of this is if I leave my gmail open on another tag Chrome will highlight when I have a new email coming through by highlighting the gmail tab.

But if the tab is pinned I can only see that I have an unread email I can't see how many emails I have. It would be really useful if gmail can bring up a little alert on the browser tab with the amount of unread emails I currently have. Same with Facebook if I have some unseen notifications it would be good to show how many there are on the browser tab of the favicon.

I found this plugin that allows you to do exactly that, using this plugin you can generate an alert box on the favicon to notify your users of new activity.

Tinycon Plugin

Tinycon is a plugin that allows you to manipulate the website favicon by allowing you to add an alert box or change the image on the browser tab.

For browsers that don't support this Tinycon will also fallback to adding different numbers to the end of the title bar.

Download Tinycon

Tinycon is currently supported on browsers

  • Chrome 15+
  • Firefox 9+
  • Opera 11+

How To Use Tinycon Plugin

To use Tinycon it's very simple all you have to do is download the plugin from the github project, and add it to the page.

<script src="tinycon.js"></script>

Now there is a Javascript object added to the page called Tinycon, with this object you use two methods to define the alert box.

First you set the bubble properties by using the method setOptions(), with the following properties.

  • Width - The width of the alert box
  • Height - The height of the alert box
  • Font - Font used in the alert box
  • Colour - Font colour inside the alert box
  • Background - Background colour of the alert box
  • Fallback - Fallback to number in brackets on the title bar for browsers that don't support changing the favicon.
Tinycon.setOptions({
    width: 7,
    height: 9,
    font: '10px arial',
    colour: '#ffffff',
    background: '#FF0000',
    fallback: true
});

To set the alert box to be displayed we then use the method setBubble( int ).

Tinycon.setBubble(15);

View the demo to see it in action.

Demo

Working With Cookies In Javascript

Cookies are variables of temporary data which is stored on the visitors computers. They are normally used for things like remember my username on a login form. This can be a useful way to store information about your returned visitors without them having to log in to store information on a database.

It's worth noting that cookies should not be used to store secure information as they are just files stored on your visitors computer.

You can set a cookie on both the server side and the client side in this article we are going to look at the process you would set-up a cookie on the client side using Javascript.

Raw Javascript

Working with cookies in Javascript is not the best feature of Javascript, there is no easy way of dealing with setting and getting cookies.

All Values

To get all the cookies which are set for the current document you need to use the following.

var allCookies = document.cookie;

Setting Values In Javascript

To set a cookie you need to use the Javascript variable document.cookie, to add values to this you need to setup the data as a query string and add onto the end of the document.cookie.

document.cookie = "website=paulund";
// cookie is website=paulund

If you want to add extra data to the cookie then you just need to repeat the above step.

document.cookie = "secondwebsite=paulund-demo";
// cookie is website=paulund;secondwebsite=paulund-demo;

Now this seems easy to set data but this will not deal with expiring the cookie or domain for the cookie.

To set the expiry of the cookie you need to add the expiry on the end of the document.cookie.

document.cookie += "; expires="+date.toGMTString();

To set the domain path of the cookie you then need to set the path on the end of the document.cookie.

document.cookie += "; path=/";

With these factors you can add to just setting data on the cookie it can be difficult to handle you need to write a function to handle the setting of the cookie.

function setCookie(name,value,days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime()+(days*24*60*60*1000));
        var expires = "; expires="+date.toGMTString();
    }
    else var expires = "";
    document.cookie = name+"="+value+expires+"; path=/";
}

Getting Values

As you can see there is a lot you need to do to set the values on the document.cookie but you will need to do even more to get values out of the document.cookie.

If you want to get a certain value you have set you can't just call the key of the data to get the value you have to use a function which will do a reg ex search to get the value of a key.

function getCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
}

Easier Way Of Working With Cookies In Javascript

There must be an easier way of handling the cookie data then having to create you own functions to deal with the different scenarios of setting, getting, all cookies, remove cookies, empty all cookies, testing if cookies are enabled.

There is an easier way of working with cookies there is a Github project called cookie.js, this is a simple javascript file which when included on your web page you can easily handle the cookie data.

Cookie.js

To use cookie.js all you have to do is download it from Github and include it on your page, download it from here.

Cookie.js

Then you can include it on the page by doing using the following code.

<script src="cookie.min.js"></script>

When this file is included there will be a new cookie object to use to set and get the data.

Setting Cookie

To set a cookie with cookie.js all you have to do is use the method set().

cookie.set( 'key', 'value' );

If you want to add extra parameters to the cookie you can set these up as the third argument on the method.

cookie.set( 'key' , 'value', {
   expires: 7,
   domain: "paulund.co.uk",
   path: "/",
   secure: false
});

Getting Cookie

To get the values from the cookie it is as easy as using the get() method, this will return string of the value of the key.

cookie.get( 'key1' );

Or you can even use a shorthand version of this by just doing.

cookie( 'key1' );

Get All Cookies

To get all the cookies available it is very simple by using the all() method.

var allCookies = cookie.all();

Removing Cookies

It is also easy to remove the cookies by referring to the key you have setup on the cookie, by using the remove() method.

cookie.remove( 'key1' );

You can even remove all cookies available on the domain by using the empty method.

cookie.empty();

Cookies Enabled

Visitors can turn cookies off on the browser so you will not be able to store data on the visitors computer, for this reason you will need to check if cookies are enabled before you try setting up new cookies.

With cookie.js you can do this easily by using the enabled() method.

if (cookie.enabled()) {
   // Cookies are on you can setup cookies
} else {
   // Cookies are turned off you can not use cookies
}

Cookie.js

As you can see using cookie.js is a much easier way to handle cookie data than using raw Javascript.

Download it from Github and use it on your next project.

Download Cookie.js