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