Add minifier script for hinter.js, fix autocomplete=off, fix onChange showing

master
Vitaliy Filippov 2013-03-13 20:51:24 +00:00
parent c44c49cb39
commit 5d7554af89
2 changed files with 33 additions and 9 deletions

View File

@ -92,7 +92,6 @@ var SimpleAutocomplete = function(input, dataLoader, params)
this.delay = 300; this.delay = 300;
// Variables // Variables
this.origAutocomplete = input.autocomplete;
this.more = 0; this.more = 0;
this.timer = null; this.timer = null;
this.closure = []; this.closure = [];
@ -111,6 +110,7 @@ var SimpleAutocomplete = function(input, dataLoader, params)
SimpleAutocomplete.prototype.init = function() SimpleAutocomplete.prototype.init = function()
{ {
var e = this.input; var e = this.input;
e.autocomplete = 'off';
var l = SimpleAutocomplete.SimpleAutocompletes; var l = SimpleAutocomplete.SimpleAutocompletes;
this.id = this.input.id + l.length; this.id = this.input.id + l.length;
l.push(this); l.push(this);
@ -348,10 +348,7 @@ SimpleAutocomplete.prototype.toggleValue = function(index)
SimpleAutocomplete.prototype.hide = function() SimpleAutocomplete.prototype.hide = function()
{ {
if (!this.skipHideCounter) if (!this.skipHideCounter)
{
this.hintLayer.style.display = 'none'; this.hintLayer.style.display = 'none';
this.input.autocomplete = this.origAutocomplete;
}
else else
this.skipHideCounter = 0; this.skipHideCounter = 0;
}; };
@ -365,7 +362,6 @@ SimpleAutocomplete.prototype.show = function()
this.hintLayer.style.top = (p.top+this.input.offsetHeight) + 'px'; this.hintLayer.style.top = (p.top+this.input.offsetHeight) + 'px';
this.hintLayer.style.left = p.left + 'px'; this.hintLayer.style.left = p.left + 'px';
this.hintLayer.style.display = ''; this.hintLayer.style.display = '';
this.input.autocomplete = 'off';
} }
}; };
@ -379,9 +375,8 @@ SimpleAutocomplete.prototype.disable = function()
// Enable hinter // Enable hinter
SimpleAutocomplete.prototype.enable = function() SimpleAutocomplete.prototype.enable = function()
{ {
var show = this.disabled;
this.disabled = false; this.disabled = false;
if (show) if (this.hasFocus)
this.show(); this.show();
} }
@ -524,7 +519,6 @@ SimpleAutocomplete.prototype.onKeyPress = function(ev)
SimpleAutocomplete.prototype.onInputFocus = function() SimpleAutocomplete.prototype.onInputFocus = function()
{ {
this.show(); this.show();
this.input.autocomplete = 'off';
this.hasFocus = true; this.hasFocus = true;
return true; return true;
}; };
@ -533,7 +527,6 @@ SimpleAutocomplete.prototype.onInputFocus = function()
SimpleAutocomplete.prototype.onInputBlur = function() SimpleAutocomplete.prototype.onInputBlur = function()
{ {
this.hide(); this.hide();
this.input.autocomplete = this.origAutocomplete;
this.hasFocus = false; this.hasFocus = false;
return true; return true;
}; };

31
mangle.pl Normal file
View File

@ -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(<FD>)
{
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;
$_ = <FD>;
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";