Mule Design Studio's Blog: Ads are Content

Please read this piece about ads on your page, it makes a good point that the ads are part of your brand. And that you should pick them with care, not accept anything a banner farm throws at your site.

Mule Design Studio's Blog: Ads are Content: "The ads you allow on your site are part of your brand."

In my opinion this also is true about the speed you want to give your visitors. Still too many banner farms ( I won't name and shame, but you know how you are. ) and ad agencys don't do anything about speed. Using for instance extremely slow javascript solutions to serve the banners. At one of my clients I tried to convince them to just give us some xml or json and let us place the banners from the link provided by them, but they didn't wanted to do that. Hiding behind tracking the visitor 'cause it was important to them, the continued to worsen the experience we could provide for our visitors.

In fact it was so bad the the load time was multiplied by 5 with banners. FIVE times as long, all because they wanted to track users to better their experience...

Redesign in progress

As I have just upgraded my blog from wordpress to habari, I am now faced with a really nice gray skin called 'charcoal'. If you know me, you must know that this out of the box style is not my thing. So I am going for a redesign and will build a new theme as I am at it. The redesign will NOT be visible on this page, but you can follow it on habari.wnas.nl.

This is a clone of this site, as it uses the same database and stuff. In doing this I can work with real data, no lorum ipsum for me please and I won't bother you, the reader, with unnecessary breakage and stuff.

Be warned that I will not try to make the site look the same in every browser, in the end a user with ie6 or below should be able to read everything. But the really nice things will be done with css3 selectors and so on.

I short I will be pulling an andy on you. I will not be slowed down by the lowest common denominator. So for now peek behind the vail and please comment if you see anything you like...

jQuery UI slider

The past few weeks I had a lot of fun playing with jQuery UI for a client. They wanted to replace some elements in an application, sliders and such, with a more accessible solution. For that I turned to jQuery UI, as I had previously introduced jQuery as the standard javascript library for them.

As I started to play with the code I couldn't helped but be impressed by the great work that has been done by the UI team on this project. But as I looked at it more closely I found some things that could be improved.

So here are some of my grieves with it and a possible way to solve them. I am going to concentrate on the slider ( docs / demo ), as it was with that widget that I started to notice some things missing.

The way you use it is in a true jquery fashion nice and unobtrusive, once you have included the correct javascript files (for that see the documentation), you just do:

$("#slider").slider();

And shazaam, #slider has turned into a slider, nice... But, what happens to the input that people provide...

This solution is nothing without javascript, so in my book it is a nono. I can not imagine that I could use this widget on my sony erikkson k800 phone. So accessible it is not, at least not in the way the demo shows us. And as most people will just copy and paste from demo's, most sliders will not be accessible.

So what you say, a slider can never be accessible, rubbish I say. Stick with me and I will show you a very simple way to make this accessible. And in a few day I will put up some example sliders to accompany the code as suggested by Danny Lagrouw.

Improvement

First we will look at what a slider does, it provides a user the possibility to enter data. Whoa, a whole new concept... eh no.

Lets start with an simple < input type="text" /> that gives people a good opportunity to enter a value, no? But what about stepping you say, that we can solve with a few < input type="radio" />. All we have to do is write javascript that sends the value of the slider to the input and when the form is submitted, the server can sort it out.

If a user has no javascript a viable alternative is provided. So not only advantages on the user level, but did you notice that we just solved the data to server problem, in a way that requires us to write zero I admit it is boring but if you want your fancy interface to do something, it has to interface with the back-end as well.

So we start with the html, as that is the base for accessible solutions, we set up a free form slider. As we do this, we make sure that we create a fully functional option for everybody. That is, the purpose of the slider is to set a value.

<div class="slider free" id="slider">
<label for="text">
label
</label>
<input type="text" id="text" />
</div>

As you see a nice and clean solution where data can be entered and processed. What we miss is the fancy slider, which we will create with javascript like this:

// add a slider container div
// add a slider handle to slider container
// place a span to recieve the value
// and add a class to the container
// find and set the input to readonly
jQuery('.slider')
.append('<div class="slideContainer"> // br
<div class="ui-slider-handle""> // br
</div> // br
</div> // br
<span class="value"></span>') //br
.addClass('sliding') // br
.find('input').attr("readonly","readonly");
// linebreaks (br) added for readability

There you have it, an accessible solution for a slider, simple as that.

But wait, what if I have 5 steps that I want people to choose from. That I cannot do, so your solution sucks and I still am stuck with a pure javascript solution says the sceptic (I know who you are...). Oke, the second one is a slider with steps for you.

First let us see what that is, it is simply a option you choose from a limited number of options isn't it. The html solution for this is really easy, radio buttons. So of we go with html

<div class="slider steps" id="slider2">
<fieldset class="radios">
<legend>legend</legend>
<input type="radio" name="radio" value="0" id="v0" />
<label for="v0">zero</label>
<input type="radio" name="radio" value="1" id="v1" />
<label for="v1">one</label>
<input type="radio" name="radio" value="2" id="v2" />
<label for="v2">two</label>
<input type="radio" name="radio" value="3" id="v3" />
<label for="v3">three</label>
<input type="radio" name="radio" value="4" id="v4" />
<label for="v4">four</label>
</fieldset>
</div>

Just like that we have a viable and accessible solution in plain old semantic html, now for the javascript.

var sliderSteps = {
radiobuttons : ((jQuery(this) //br
.find('input[type="radio"]') //br
.length)-1) //br
.toFixed(0),
init : function(targ){
sliderSteps.createSlider(targ);
sliderSteps.set(targ)
},
set : function(targ){
var w = (100/((sliderSteps.radiobuttons*1)+1));
jQuery(targ) //br
.find('label, .ui-slider-handle') //br
.width(w+'%');
},
createSlider : function(targ){
jQuery(targ).slider({
// zoveel stappen als er radio button zijn...
steps : sliderSteps.radiobuttons,
change:function(e,ui){
var x = jQuery(this).slider('value');
var a = (x/100*((jQuery(this). //br
find('input[type="radio"]').//br
length)-1)).toFixed(0);
// set the value somewhere...
jQuery(this).find('.value').text(a);
// check the radiobutton.
var t = jQuery(this). //br
find('input[@type="radio"]')[a];
jQuery(t).attr('checked','true');
}}
);
}
}
sliderSteps.init('#slider2.steps');
// linebreaks (br) added for readability

So there you have it, a nice clean and accessible slider solution for the folks at jquery ui to include in their demos. And for everybody else to look at and maybe even use. So have fun with it and let me know if you like it.

If you see any faults in the code please let me know, but as I am on holiday now, don't except me to rush...

Here is all the demo code zip file wn.slider.zip for you to play with.

Technorati Tags:, , ,

jQuery plugin - autotab

Autotab

I recently came across a itch in jquery plugins. They are too well written, with tons of attributes and files to edit in order to configure them.
I don't want that, so I wrote a simple plug in just for auto tab.

HTML

The itch was caused by a project where the client wanted three fields for the date and wanted autotab from day to month to year. After that the user should tab himself further... I searched for a plugin as I am a lazy bastard, but the plugins available where too much for me. Some even had me giving id's to the input fields, something that I could not do as they are placed by jsf that generates id's for you. So I wanted a simple solution based on my situation, which is not an uncommon one I think.

I have three input fields on the page, with maxlength attributes so that the user could not enter wrong dates.

<input type="text" maxlength="2 />
<input type="text" maxlength="2" />
<input type="text" maxlength="4" />

As a user would want to have autotab on the page they would have to change the html to have a class of autotab on the input's that he wanted to have autotab, like this:

<input type="text" maxlength="2" class="autotab" />
<input type="text" maxlength="2" class="autotab" />
<input type="text" maxlength="4" />

Note that we need the maxlength attribute to make this work. I will explain later why...

All a user has to do to use the plugin is, include jquery on your page and the plugin, than write in you own code in the document ready function:

jQuery(document).ready(function() {
jQuery('input.autotab').autotab();
});
Presto you are done, let the script take over and relax.

the plugin

The plugin works like this, first we define that it is a plug in, something that I picked up reading this article.

jQuery.fn.autotab = function (){

Then we set it up to trigger on key up, as we need to measure the amount of code entered after his input.

 jQuery(this).keyup(function(e){

We then set up a couple of keys to be ignored as they only get in the way. For instance, if you let the tab key trigger the function it will not let you enter the field using shift tab. So no undo for you buddy...

switch(e.keyCode){
// ignore the following keys
case 9: // tab
return false;
case 16: // shift
return false;
case 20: // capslock
return false;

Once we have that sorted, we can decide it is time for action, so we will begin

default: // any other keyup actions will trigger 

First off we read out the maxlength of the targeted element and put it into a variable

var maxlength = jQuery(this).attr('maxlength');
// get maxlength value

Once we have the maximum of characters, we seek the current amount entered. (here is why we do keyup instead of keydown.)

var inputlength = jQuery(this).val().length;
// get the length of the text

If the amount of characters is equal or more than the max length

if ( inputlength >= maxlength ){
// if the text is equal or more
// than the max length

Set the focus on the next field

jQuery(this).next('input[type="text"]').focus();
// set focus to the next text field

Enjoy

Go and get the code with comments here or minified, let me know what you think of it...

And thanks for reading this far... :)

Technorati Tags:, ,

css naked day

What happened to the design?

To know more about why styles are disabled on this website visit theAnnual CSS Naked Day website for more information.