Introduce Your Plugin With WordPress Pointers

Updated: in Wordpress

In version 3.3 WordPress released a new feature called pointers. These are little pop-up notification boxes which you can use to point to new information on your WordPress admin area.

Pointer

This is a great idea if you are a plugin or theme developer, you can make it so that when a user installs your new plugin you can use the pointers to show exactly how they are suppose to use it.

For example if the plugin adds a new menu item to the WordPress admin area, you can use pointers to show the user that there is a new menu item and what it allows you to do with your wordpress site.

You can assign a pointer to be displayed on any HTML ID or class, it is just a jQuery widget which has a title bar, text area and close button.
Continue reading »

Javascript Full Screen API

Updated: in jQuery

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 »

Working With Cookies In Javascript

Updated: in jQuery

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

Detect IPhone, IPad or IPod User With Javascript

Updated: in Javascript

With mobile devices becoming more and more popular there will be times when you need to do something different for users coming to your site from one of these mobile devices.

If you want to change the design depending on the mobile device you will use media queries. But if you want to change functionality such as Javascript then you can use the below snippet to do something different for mobile devices.
Continue reading »

Create A Real E-Book With Turn.js

Updated: in jQuery

In today's tutorial we are going to see how we can create a "real" ebook by using the jQuery plugin turn.js. Using this jQuery plugin you can create a real looking turn of pages to create a magazine looking web page.

View the demo to see what you can create with Turn.js.

Demo

What Is Turn.js

Turn.js is a plugin for jQuery that adds a beautiful transition similar to real pages in a book or magazine. It works in all modern browsers including touch devices.
Continue reading »

How To Create An Exchange Rate Money Converter With Money.js

Updated: in jQuery

Update: 19/10/2012 You now have pay for the open exchange rates API. If you want to use this code on any future projects you will need to signup for an API key https://openexchangerates.org/signup. For this reason the demo on this pay will no longer work. The code is still valid but you will need to buy an API key.

In today's tutorial we are going to work with a Javascript library which allows you to easily deal with money in any web application.

Money JS

This JavaScript file will allow you to create an online application to easily convert from one currency to another using only one function.

Continue reading »

How To Use HTML5 GeoLocation API With Google Maps

Updated: in HTML5

In this tutorial we are going to learn how to use the Geolocation API to get your current latitude and longitude, from these results we can then connect to the Google Maps API to display your location in the browser.

Google Map

Demo

The Geolocation API

The Geolocation API defines an interface used to get location information of the visitor, from this interface you can return the latitude and longitude of the current visitor. Common sources of the location are GPS or IP Address.
Continue reading »