| 1 | #!/usr/bin/env perl |
| 2 | |
| 3 | use strict; |
| 4 | use warnings; |
| 5 | |
| 6 | # VERSION |
| 7 | |
| 8 | use lib qw{lib ../lib}; |
| 9 | use JavaScript::Minifier qw/minify/; |
| 10 | |
| 11 | my $JS = get_js(); |
| 12 | print minify(input => $JS) . "\n"; |
| 13 | |
| 14 | sub get_js { |
| 15 | return <<'END_JS'; |
| 16 | function setup_sample_form_data() { |
| 17 | var els, i, l; |
| 18 | els = $$('.sample_form_data'); |
| 19 | |
| 20 | for ( i = 0, l = els.length; i < l; i++ ) { |
| 21 | els[i].set( |
| 22 | 'data-sample-form-data', |
| 23 | els[i].get('data-sample-form-data').replace('\\n', "\n") |
| 24 | ); |
| 25 | |
| 26 | if ( els[i].get('value') == '' ) { |
| 27 | els[i].set('value', els[i].get('data-sample-form-data')); |
| 28 | } |
| 29 | else if ( els[i].get('value') != els[i].get('data-sample-form-data') ) { |
| 30 | els[i].removeClass('sample_form_data'); |
| 31 | } |
| 32 | |
| 33 | var funct_clear_sample_data = function() { |
| 34 | var i, l, els = this.getElements('.sample_form_data'); |
| 35 | for ( i = 0, l = els.length; i < l; i++ ) { |
| 36 | els[i].set('value', ''); |
| 37 | } |
| 38 | } |
| 39 | els[i].getParent('form').removeEvent('submit', funct_clear_sample_data ); |
| 40 | els[i].getParent('form').addEvent('submit', funct_clear_sample_data ); |
| 41 | |
| 42 | els[i].addEvent('focus', function() { |
| 43 | if ( this.get('value') == this.get('data-sample-form-data') ) { |
| 44 | this.set('value', ''); |
| 45 | this.removeClass('sample_form_data'); |
| 46 | } |
| 47 | }); |
| 48 | |
| 49 | els[i].addEvent('blur', function() { |
| 50 | if ( this.value == '' ) { |
| 51 | this.set('value', this.get('data-sample-form-data')); |
| 52 | this.addClass('sample_form_data'); |
| 53 | } |
| 54 | }); |
| 55 | } |
| 56 | } |
| 57 | END_JS |
| 58 | } |