[SPIP] +spip v3.0.17
[lhc/web/clavette_www.git] / www / prive / javascript / jquery.placeholder-label.js
1 /**
2 * Placeholder label
3 * https://github.com/AbleTech/jquery.placeholder-label
4 *
5 * Copyright (c) 2010 Able Technology Consulting Limited
6 * http://www.abletech.co.nz/
7 */
8 (function($) {
9 $.placeholderLabel = {
10 placeholder_class: null,
11 add_placeholder: function(){
12 if($(this).val() == $(this).attr('placeholder')){
13 $(this).val('').removeClass($.placeholderLabel.placeholder_class);
14 }
15 },
16 remove_placeholder: function(){
17 if($(this).val() == ''){
18 $(this).val($(this).attr('placeholder')).addClass($.placeholderLabel.placeholder_class);
19 }
20 },
21 disable_placeholder_fields: function(){
22 $(this).find("input[placeholder]").each(function(){
23 if($(this).val() == $(this).attr('placeholder')){
24 $(this).val('');
25 }
26 });
27
28 return true;
29 }
30 };
31
32 $.fn.placeholderLabel = function(options) {
33 // detect modern browsers
34 var dummy = document.createElement('input');
35 if(dummy.placeholder != undefined){
36 return this;
37 }
38
39 var config = {
40 placeholder_class : 'placeholder'
41 };
42
43 if(options) $.extend(config, options);
44
45 $.placeholderLabel.placeholder_class = config.placeholder_class;
46
47 this.each(function() {
48 var input = $(this);
49
50 input.focus($.placeholderLabel.add_placeholder);
51 input.blur($.placeholderLabel.remove_placeholder);
52
53 input.triggerHandler('focus');
54 input.triggerHandler('blur');
55
56 $(this.form).submit($.placeholderLabel.disable_placeholder_fields);
57 });
58
59 return this;
60 }
61 })(jQuery);