Category Archives: jQuery

MODx Evolution to Revolution Tag Converter

I’ve been doing a few MODx Evolution to Revolution conversions recently, and developed a simple jQuery script to handle converting the Evolution template tags to the new Revolution syntax. It’s pretty basic, but it does the job, so I thought I’d share with the community. Hopefully in the future there will be an easy way to upgrade, but in the meantime little tools like this should help a little :)  Check it out

MODx Evolution to Revolution Tag Converter
Read More

5 Comments

HTML5 & jQuery: localStorage forms

Working on a very cool new HTML5 application, I’ve had some useful experience with using localStorage. For those new to localStorage, it’s simply a way to store key and value pairs locally, meaning that like with cookies,  even after the user has left the page, data can be retrieved. It works differently from cookies in that the data is not stored on the server, rather its stored within the client web browser. It’s especially useful for forms and enhancing the user’s personal experience.

Modern browsers support it well (even IE from 8+). It’s very simple to implement with a little JavaScript. In this example I’ll show you how can store the user’s form data using some jQuery.

First we’ll create a simple form.

1
2
3
4
5
6
7
<form name="local_storage_form" method="post" action="">
 
<input type="text" name="your_name" id="your_name" value="" />
<input type="text" name="your_surname" id="your_surname" value="" />
 
<input type="submit" value="Submit" />
</form>
<form name="local_storage_form" method="post" action="">

<input type="text" name="your_name" id="your_name" value="" />
<input type="text" name="your_surname" id="your_surname" value="" />

<input type="submit" value="Submit" />
</form>

Notice I’ve given the input field the class “localStore”. You can apply this class to all of your fields. We’ll later use this to store the data.

Now the jQuery. We want to check a field as it is updated, and update the localStorage value on the fly. For this we’ll create the function:

1
2
3
$('.localStore').keyup(function () {
    localStorage[$(this).attr('id')] = $(this).val();
});
$('.localStore').keyup(function () {
    localStorage[$(this).attr('id')] = $(this).val();
});

This function will update localStorage, using your field ID, every time you press a key. You could choose to use change() or whatever suits your needs.

Now we will create an init() function to fill in the form automatically if there are values stored in the relevant keys.

1
2
3
4
5
6
7
8
function init() {
    if (localStorage["your_name"]) {
        $('#your_name').val(localStorage["your_name"]);
    }
    if (localStorage["your_surname"]) {
        $('#your_surname').val(localStorage["your_surname"]);
    }
}
function init() {
    if (localStorage["your_name"]) {
        $('#your_name').val(localStorage["your_name"]);
    }
    if (localStorage["your_surname"]) {
        $('#your_surname').val(localStorage["your_surname"]);
    }
}

In this example, we’re identifying each field manually. We check if the variable is set, and if so update our field. You could potentially loop through the keys as well.

So our full code is

1
2
3
4
5
6
7
8
9
10
11
12
13
14
$(document).ready(function () {
    function init() {
        if (localStorage["your_name"]) {
            $('#your_name').val(localStorage["your_name"]);
        }
        if (localStorage["your_surname"]) {
            $('#your_surname').val(localStorage["your_surname"]);
        }
    }
    $('.localStore').keyup(function () {
        localStorage[$(this).attr('id')] = $(this).val();
    });
    init();
});
$(document).ready(function () {
    function init() {
        if (localStorage["your_name"]) {
            $('#your_name').val(localStorage["your_name"]);
        }
        if (localStorage["your_surname"]) {
            $('#your_surname').val(localStorage["your_surname"]);
        }
    }
    $('.localStore').keyup(function () {
        localStorage[$(this).attr('id')] = $(this).val();
    });
    init();
});

Once your completed, go ahead and fill in the form, leave you browser and come back to see your data sat there waiting for you :)

This is a very basic example of what can be done with localStorage. The possibilities are really great and are already in use around the internet today; games, apps, user customisation. Support is good within modern browsers, but I would still see this as a bonus feature rather than something to be used as a fundemental of a site. Check out the w3 working draft on Web Storage here.

HTML5 & jQuery: localStorage forms
Read More

8 Comments

Crucial BMX Shop

After starting many moons ago, a site I’ve developed with Adi Gilbert and Richard Homer of 99Seconds has just gone live. Crucial BMX is the biggest BMX shop in the South West, and they needed a good online shop to sell their well-over-1000 different products. It’s clean and simple with awesome artwork by Adi, and has some personality packed in with javascript touches here and there.

Check it out! It’s powered by MODx Evolution and Foxycart and accepts major credit/debit cards securely.

www.crucialbmxshop.com

Crucial BMX Shop
Read More

Leave a comment

AM Vintage – E-commerce & Build

An e-commerce project I’ve been working on with andwhat has just gone live. AM vintage, an online vintage shopping experience offers a wide selection of affordable, good quality vintage clothing and accessories. Originally featured in the ASOS marketplace, they wanted their own home on the internet. The site was designed and branded by andwhat, and marketing is ongoing by them, while Toasted Digital handled the whole build, including the ever super slick FoxyCart part and a few cool jQuery features built in to show off the products.

Visit AM Vintage

AM Vintage – E-commerce & Build
Read More

1 Comment

jQuery – Browser Detection

Something I came across being very important when animating with jQuery was the way different browsers can handle the load. Internet explorer was substantially slower than the other rivals, with Chrome being fastest (although seemingly IE9 has caught up speed wise). This was especially apparant while using Cufon + animation, yeilding very jerky results while animating in IE8 and below. Another issue was IE8s lack of support for animating alpha. So what was needed was a way to handle slightly different animations depending on which Browser is being used to view the website.  jQuery.browser makes this very simple: with both conditional handlers for browser type and browser version.

So for example we want to have alternative content for Internet Explorer users, we can use:

if ( $.browser.msie ) {
$(‘.mydiv’).html(‘<p>Hi There, you’re using Internet Explorer</p>’);
}

And we can take this further by checking the version of the browser:

if ( $.browser.msie ) {
if ($.browser.version <= 6)
{
$(‘.mydiv’).html(‘<p>Hi There, you’re using Internet Explorer 6 =(</p>’);
}
}

Very simple stuff! It’s best practice to try and avoid browser specific code where possible, but in certain situations it can be an essential little piece of knowledge. For more info check out the jQuery documentation.

jQuery – Browser Detection
Read More

3 Comments

Animating divs using jquery

One of the big decisions I’ve had to make over the past few months with regards the new Toasted Digital website is Flash or no Flash. A large part of the work I do is Flash based, therefore it seems appropriate to display my portfolio in that format. However the internet is changing, and Flash while a big part of the work I do is generally not my favorite thing to use for full websites anyway. The downsides of its SEO capabilities and incompatibility with apple products can be frustrating. So I’ve decided to run a few experiments and tests using jquery to animate divs. I’ve seen a few examples around the net but can jquery alone give me the level of animation I need to make my website?  I’ve not yet seen an example of sophisticated animation using  jquery as an alternative to Flash, but the animation required for my website is simple and slick, therefore it may work.

Results

http://www.toasteddigital.com/ex/

Update – Check back soon for a more in depth tutorial. Follow TD on Twitter or Facebook for updates!

Animating divs using jquery
Read More

16 Comments