diff options
author | Gustavo Sillero <gustavo@sille.ro> | 2015-02-25 22:59:41 -0300 |
---|---|---|
committer | Gustavo Sillero <gustavo@sille.ro> | 2015-02-25 22:59:41 -0300 |
commit | 8e8e32039b5a57205ebdd39ebc79666d47bf9e61 (patch) | |
tree | 4740bc35a7f59e99a39740496a42679b887d83ce /index.js | |
parent | 75834f2e6b9130a9bc1d1b732b71eafaca9ae72b (diff) | |
download | awesomplete-8e8e32039b5a57205ebdd39ebc79666d47bf9e61.zip awesomplete-8e8e32039b5a57205ebdd39ebc79666d47bf9e61.tar.gz awesomplete-8e8e32039b5a57205ebdd39ebc79666d47bf9e61.tar.bz2 |
advanced examples, email example
Diffstat (limited to 'index.js')
-rw-r--r-- | index.js | 22 |
1 files changed, 22 insertions, 0 deletions
@@ -11,3 +11,25 @@ $$("section > h1").forEach(function (h1) { }); } }); + +//email example +var emailInput = $("#emailInput"); +var emailAwesomplete = new Awesomplete(emailInput, { + list: ["@aol.com", "@att.net", "@comcast.net", "@facebook.com", "@gmail.com", "@gmx.com", "@googlemail.com", "@google.com", "@hotmail.com", "@hotmail.co.uk", "@mac.com", "@me.com", "@mail.com", "@msn.com", "@live.com", "@sbcglobal.net", "@verizon.net", "@yahoo.com", "@yahoo.co.uk"], + item: function(text, input){ + var newText = input.slice(0, input.indexOf("@")) + text; + + return Awesomplete.$.create("li", { + innerHTML: newText.replace(RegExp(input.trim(), "gi"), "<mark>$&</mark>"), + "aria-selected": "false" + }); + }, + filter: function(text, input){ + var atPosition = input.indexOf("@"); + var inputIsEmail = !!~atPosition && (input.length > atPosition + 1); + var emailPart = input.slice(input.indexOf("@")); + var textMatchWithInput = RegExp("^" + emailPart.trim(), "i").test(text); + + return (inputIsEmail && textMatchWithInput); + } +}); |