/* * jQuery Email Autocomplete - v0.0.2 * A jQuery plugin that suggests and autocompletes the domain in email fields. * https://github.com/yzlow/email-autocomplete * * Made by Low Yong Zhen * Under MIT License < http://yzlow.mit-license.org> */ "use strict";!function(a,b,c,d){function e(b,c){this.$field=a(b),this.options=a.extend(!0,{},g,c),this._defaults=g,this._domains=this.options.domains,this.init()}var f="emailautocomplete",g={suggClass:"eac-sugg",domains:["yahoo.com","hotmail.com","gmail.com","me.com","aol.com","mac.com","live.com","comcast.net","googlemail.com","msn.com","hotmail.co.uk","yahoo.co.uk","facebook.com","verizon.net","sbcglobal.net","att.net","gmx.com","outlook.com","icloud.com"]};e.prototype={init:function(){Array.prototype.indexOf||this.doIndexOf(),this.fieldLeftOffset=(this.$field.outerWidth(!0)-this.$field.width())/2;var b=a("
").css({display:this.$field.css("display"),position:"relative",fontSize:this.$field.css("fontSize")});this.$field.wrap(b),this.$cval=a("").css({visibility:"hidden",position:"absolute",display:"inline-block",fontFamily:this.$field.css("fontFamily"),fontWeight:this.$field.css("fontWeight"),letterSpacing:this.$field.css("letterSpacing")}).insertAfter(this.$field);var c=(this.$field.outerHeight(!0)-this.$field.height())/2;this.$suggOverlay=a("").css({display:"block","box-sizing":"content-box",lineHeight:this.$field.css("lineHeight"),paddingTop:c+"px",paddingBottom:c+"px",fontFamily:this.$field.css("fontFamily"),fontWeight:this.$field.css("fontWeight"),letterSpacing:this.$field.css("letterSpacing"),position:"absolute",top:0,left:0}).insertAfter(this.$field),this.$field.on("keyup.eac",a.proxy(this.displaySuggestion,this)),this.$field.on("keydown.eac",a.proxy(function(a){(39===a.which||9===a.which)&&this.autocomplete()},this)),this.$suggOverlay.on("mousedown.eac touchstart.eac",a.proxy(this.autocomplete,this))},suggest:function(a){var b=a.split("@");if(!(b.length>1))return"";if(a=b.pop(),!a.length)return"";var c=this._domains.filter(function(b){return 0===b.indexOf(a)}).shift()||"";return c.replace(a,"")},autocomplete:function(){return"undefined"==typeof this.suggestion||this.suggestion.length<1?!1:(this.$field.val(this.val+this.suggestion),this.$suggOverlay.text(""),void this.$cval.text(""))},displaySuggestion:function(a){this.val=this.$field.val(),this.suggestion=this.suggest(this.val),this.suggestion.length?a.preventDefault():this.$suggOverlay.text(""),this.$suggOverlay.text(this.suggestion),this.$cval.text(this.val);var b=this.$cval.width();this.$field.outerWidth()>b&&this.$suggOverlay.css("left",this.fieldLeftOffset+b+"px")},doIndexOf:function(){Array.prototype.indexOf=function(a,b){if(this===d||null===this)throw new TypeError('"this" is null or not defined');var c=this.length>>>0;for(b=+b||0,1/0===Math.abs(b)&&(b=0),0>b&&(b+=c,0>b&&(b=0));c>b;b++)if(this[b]===a)return b;return-1}}},a.fn[f]=function(b){return this.each(function(){a.data(this,"yz_"+f)||a.data(this,"yz_"+f,new e(this,b))})}}(jQuery,window,document);