summaryrefslogtreecommitdiffstats
path: root/index.js
diff options
context:
space:
mode:
authorGustavo Sillero <gustavo@sille.ro>2015-02-25 22:59:41 -0300
committerGustavo Sillero <gustavo@sille.ro>2015-02-25 22:59:41 -0300
commit8e8e32039b5a57205ebdd39ebc79666d47bf9e61 (patch)
tree4740bc35a7f59e99a39740496a42679b887d83ce /index.js
parent75834f2e6b9130a9bc1d1b732b71eafaca9ae72b (diff)
downloadawesomplete-8e8e32039b5a57205ebdd39ebc79666d47bf9e61.zip
awesomplete-8e8e32039b5a57205ebdd39ebc79666d47bf9e61.tar.gz
awesomplete-8e8e32039b5a57205ebdd39ebc79666d47bf9e61.tar.bz2
advanced examples, email example
Diffstat (limited to 'index.js')
-rw-r--r--index.js22
1 files changed, 22 insertions, 0 deletions
diff --git a/index.js b/index.js
index ff15e83..8f51abd 100644
--- a/index.js
+++ b/index.js
@@ -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);
+ }
+});