From 5d7554af89a0ccf7f92c24e1b04eff3fc77674df Mon Sep 17 00:00:00 2001 From: Vitaliy Filippov Date: Wed, 13 Mar 2013 20:51:24 +0000 Subject: [PATCH] Add minifier script for hinter.js, fix autocomplete=off, fix onChange showing --- hinter.js | 11 ++--------- mangle.pl | 31 +++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 9 deletions(-) create mode 100644 mangle.pl diff --git a/hinter.js b/hinter.js index 6574d30..a4411b9 100644 --- a/hinter.js +++ b/hinter.js @@ -92,7 +92,6 @@ var SimpleAutocomplete = function(input, dataLoader, params) this.delay = 300; // Variables - this.origAutocomplete = input.autocomplete; this.more = 0; this.timer = null; this.closure = []; @@ -111,6 +110,7 @@ var SimpleAutocomplete = function(input, dataLoader, params) SimpleAutocomplete.prototype.init = function() { var e = this.input; + e.autocomplete = 'off'; var l = SimpleAutocomplete.SimpleAutocompletes; this.id = this.input.id + l.length; l.push(this); @@ -348,10 +348,7 @@ SimpleAutocomplete.prototype.toggleValue = function(index) SimpleAutocomplete.prototype.hide = function() { if (!this.skipHideCounter) - { this.hintLayer.style.display = 'none'; - this.input.autocomplete = this.origAutocomplete; - } else this.skipHideCounter = 0; }; @@ -365,7 +362,6 @@ SimpleAutocomplete.prototype.show = function() this.hintLayer.style.top = (p.top+this.input.offsetHeight) + 'px'; this.hintLayer.style.left = p.left + 'px'; this.hintLayer.style.display = ''; - this.input.autocomplete = 'off'; } }; @@ -379,9 +375,8 @@ SimpleAutocomplete.prototype.disable = function() // Enable hinter SimpleAutocomplete.prototype.enable = function() { - var show = this.disabled; this.disabled = false; - if (show) + if (this.hasFocus) this.show(); } @@ -524,7 +519,6 @@ SimpleAutocomplete.prototype.onKeyPress = function(ev) SimpleAutocomplete.prototype.onInputFocus = function() { this.show(); - this.input.autocomplete = 'off'; this.hasFocus = true; return true; }; @@ -533,7 +527,6 @@ SimpleAutocomplete.prototype.onInputFocus = function() SimpleAutocomplete.prototype.onInputBlur = function() { this.hide(); - this.input.autocomplete = this.origAutocomplete; this.hasFocus = false; return true; }; diff --git a/mangle.pl b/mangle.pl new file mode 100644 index 0000000..f86fa97 --- /dev/null +++ b/mangle.pl @@ -0,0 +1,31 @@ +#!/usr/bin/perl +# Mangle names in SimpleAutocomplete code for better compression + +use strict; + +my $output = 'hinter.min.js'; +my %whitelist = map { $_ => 1 } qw(input remove replaceItems hide onChange); +my %var = (); +my @names = 'a'..'ba'; + +local $/ = undef; +open FD, "hinter.js"; +open OFD, "| yui-compressor --type js -o $output"; +while() +{ + s/(this|self|SimpleAutocomplete(?:\.prototype)?)\.([a-zA-Z0-9_]+)/$1 . '.' . ($whitelist{$2} ? $2 : ($var{$2} ||= shift @names))/egs; + print OFD $_; +} +close FD; +close OFD; + +open FD, "+<", $output; +$_ = ; +seek FD, 0, 0; +print FD "// (c) Vitaliy Filippov 2011-2013 +// \@license MPL 2.0 http://www.mozilla.org/MPL/2.0/ +// http://yourcmc.ru/wiki/SimpleAutocomplete +$_"; +close FD; + +print "Compressed SimpleAutocomplete written to $output\n";