jamescarr / javascript-testdrive-example

A collection of examples using various different frameworks to test drive javascript

This URL has Read+Write access

javascript-testdrive-example / jsunit-berlios / Html5Placeholder.js
100644 17 lines (16 sloc) 0.452 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
function Html5Emulator(dom){
  this.dom = dom;
}
Html5Emulator.prototype.emulatePlaceholders = function(){
    $('input', this.dom).each(function(){
      var placeholder = $(this).attr('placeholder');
      $(this).val(placeholder);
      $(this).focus(function(){
        if(placeholder == $(this).val())
          $(this).val('');
      }).blur(function(){
        if($(this).val() == '')
          $(this).val(placeholder);
      });
    });
}