Created
November 5, 2013 02:43
-
-
Save patelprashant/7312998 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //////////HTML///////////////////////// | |
| <label for="email">Email</label> | |
| <input id="email" name="email" type="email" placeholder="[email protected]"> | |
| //////////CSS///////////////////////// | |
| @import url(http://fonts.googleapis.com/css?family=Source+Sans+Pro); | |
| body { | |
| font-family: 'Source Sans Pro', sans-serif; | |
| font-size: large; | |
| max-width: 500px; | |
| margin: 0 auto; | |
| } | |
| input[type=email] { | |
| font-size: large; | |
| width: 400px; | |
| } | |
| label { | |
| display: block; | |
| font-size: small; | |
| text-transform: uppercase; | |
| letter-spacing: 2px; | |
| color: #999; | |
| } | |
| //////////JS///////////////////////// | |
| var EmailDomainSuggester = { | |
| domains: ["yahoo.com", "gmail.com", "google.com", "hotmail.com", "me.com", "aol.com", "mac.com", "live.com", "comcast.com", "googlemail.com", "msn.com", "hotmail.co.uk", "yahoo.co.uk", "facebook.com", "verizon.net", "att.net", "gmz.com", "mail.com"], | |
| bindTo: $('#email'), | |
| init: function() { | |
| this.addElements(); | |
| this.bindEvents(); | |
| }, | |
| addElements: function() { | |
| // Create empty datalist | |
| this.datalist = $("<datalist />", { | |
| id: 'email-options' | |
| }).insertAfter(this.bindTo); | |
| // Corelate to input | |
| this.bindTo.attr("list", "email-options"); | |
| }, | |
| bindEvents: function() { | |
| this.bindTo.on("keyup", this.testValue); | |
| }, | |
| testValue: function(event) { | |
| var el = $(this), | |
| value = el.val(); | |
| // email has @ | |
| // remove != -1 to open earlier | |
| if (value.indexOf("@") != -1) { | |
| value = value.split("@")[0]; | |
| EmailDomainSuggester.addDatalist(value); | |
| } else { | |
| // empty list | |
| EmailDomainSuggester.datalist.empty(); | |
| } | |
| }, | |
| addDatalist: function(value) { | |
| var i, newOptionsString = ""; | |
| for (i = 0; i < this.domains.length; i++) { | |
| newOptionsString += | |
| "<option value='" + | |
| value + | |
| "@" + | |
| this.domains[i] + | |
| "'>"; | |
| } | |
| // add new ones | |
| this.datalist.html(newOptionsString); | |
| } | |
| } | |
| EmailDomainSuggester.init(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment