email_name_textfield 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +73 -0
- data/Rakefile +1 -0
- data/email_name_textfield.gemspec +25 -0
- data/lib/email_name_textfield/version.rb +5 -0
- data/lib/email_name_textfield.rb +8 -0
- data/vendor/assets/javascripts/email_input_area_view.coffee +156 -0
- data/vendor/assets/javascripts/email_name_textfield.js +2 -0
- data/vendor/assets/javascripts/setup.coffee +5 -0
- metadata +109 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Dana Greenberg
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
# EmailNameTextfield
|
2
|
+
|
3
|
+
Text area entry tool that allows you to paste e-mail names and addresses from common
|
4
|
+
mail clients such as Gmail, Yahoo! and Outlook. This tool will recognize the pasted
|
5
|
+
input and parse out the first and last name as well as validating the e-mail address.
|
6
|
+
|
7
|
+
## Requirements
|
8
|
+
|
9
|
+
* Rails
|
10
|
+
* CoffeeScript
|
11
|
+
* Backbone.js
|
12
|
+
* Underscore.js
|
13
|
+
|
14
|
+
## Installation
|
15
|
+
|
16
|
+
Add this line to your application's Gemfile:
|
17
|
+
|
18
|
+
gem 'email_name_textfield'
|
19
|
+
|
20
|
+
And then execute:
|
21
|
+
|
22
|
+
$ bundle
|
23
|
+
|
24
|
+
Add this line to your application.js file after the lines that require
|
25
|
+
Backbone.js and Underscore.js:
|
26
|
+
|
27
|
+
//= require email_name_textfield
|
28
|
+
|
29
|
+
## Usage
|
30
|
+
|
31
|
+
Reference this text area by creating a new object:
|
32
|
+
|
33
|
+
myemailnamefield = new EmailNameTextField.EmailInputAreaView(placeholder: "email@address.com")
|
34
|
+
|
35
|
+
The placeholder text is simply the text that will appear by default when no e-mail
|
36
|
+
addresses are shown.
|
37
|
+
|
38
|
+
Now, render this object to your view:
|
39
|
+
|
40
|
+
$("mydiv").html(myemailnamefield.render())
|
41
|
+
|
42
|
+
Emails will be immediately validated upon pasting or losing the focus on the text area.
|
43
|
+
|
44
|
+
To access the resulting list of emails and names call:
|
45
|
+
|
46
|
+
myemailnamefield.name_data()
|
47
|
+
|
48
|
+
Result will be an array of JSON objects in the format of:
|
49
|
+
|
50
|
+
{ firstName: "Mary", lastName: "Smith", email: "msmith@example.com" }
|
51
|
+
|
52
|
+
## Supported email formats
|
53
|
+
|
54
|
+
* Gmail - "Mary Smith" <msmith@example.com>
|
55
|
+
* Yahoo! - Mary Smith <msmith@example.com>
|
56
|
+
* Outlook - Smith, Mary <msmith@example.com>
|
57
|
+
* Hotmail - Mary Smith(msmith@example.com)
|
58
|
+
|
59
|
+
### Other formats
|
60
|
+
|
61
|
+
* msmith@example.com
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
## Contributing
|
68
|
+
|
69
|
+
1. Fork it
|
70
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
71
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
72
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
73
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'email_name_textfield/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "email_name_textfield"
|
8
|
+
spec.version = EmailNameTextfield::Rails::VERSION
|
9
|
+
spec.authors = ["Dana Greenberg"]
|
10
|
+
spec.email = ["dgreenbe@constantcontact.com"]
|
11
|
+
spec.description = "Text area for pasting in multiple emails and validating by name and e-mail address"
|
12
|
+
spec.summary = "Text area entry tool that allows you to paste e-mail names and addresses from common mail clients such as Gmail, Yahoo! and Outlook. This tool will recognize the pasted input and parse out the first and last name as well as validating the e-mail address."
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
|
24
|
+
spec.add_dependency "coffee-rails", "> 2.1.0"
|
25
|
+
end
|
@@ -0,0 +1,156 @@
|
|
1
|
+
class @EmailNameTextField.EmailInputAreaView extends Backbone.View
|
2
|
+
IP_LOOK_ALIKE: "[^@]+@(\\d+\\.)+\\d+$"
|
3
|
+
EMAIL_PATTERN: "[\\w!#$%&'*+/=?^`{|}~-]+(?:\\.[\\w!#$%&'*+/=?^`{|}~-]+)*@(?:[\\w](?:[\\w-]*[\\w])?\\.)+[\\w](?:[\\w-]*[\\w])"
|
4
|
+
NAME_PATTERN: "([\\w\\xC0-\\xFF'.-]+)(\\s*,)?([\\s,\\w\\xC0-\\xFF'.-]*)"
|
5
|
+
|
6
|
+
events: ->
|
7
|
+
'keydown #email_input' : 'keydown_input'
|
8
|
+
'paste #email_input' : 'validate_input'
|
9
|
+
'blur #email_input' : 'validate_input'
|
10
|
+
'click #input_wrapper' : 'click_wrapper'
|
11
|
+
|
12
|
+
render: =>
|
13
|
+
@$el.html @custom_html()
|
14
|
+
|
15
|
+
initialize: ->
|
16
|
+
@placeholder = @options.placeholder
|
17
|
+
|
18
|
+
custom_html: ->
|
19
|
+
"<div id='input_wrapper'>
|
20
|
+
<div class='example-text'>#{@placeholder}</div>
|
21
|
+
<ul>
|
22
|
+
<li class='input-target'>
|
23
|
+
<textarea id='email_input' name='email_input'>
|
24
|
+
</textarea>
|
25
|
+
</li>
|
26
|
+
</ul>
|
27
|
+
|
28
|
+
</div>"
|
29
|
+
|
30
|
+
reset: =>
|
31
|
+
$(".email-node").remove()
|
32
|
+
@reset_email_input()
|
33
|
+
|
34
|
+
reset_email_input: =>
|
35
|
+
$(".input-target").appendTo("#input_wrapper ul")
|
36
|
+
$("#email_input").val("").focus()
|
37
|
+
|
38
|
+
total_email_count: =>
|
39
|
+
@valid_email_count() + @.invalid_email_count()
|
40
|
+
|
41
|
+
valid_email_count: =>
|
42
|
+
$(".pill-email").length
|
43
|
+
|
44
|
+
invalid_email_count: =>
|
45
|
+
$(".pill-invalid").length
|
46
|
+
|
47
|
+
name_data: ->
|
48
|
+
addrs = _.map $(".pill-email .email-node"), (node) ->
|
49
|
+
[
|
50
|
+
$(node).data("firstName"),
|
51
|
+
$(node).data("lastName"),
|
52
|
+
$(node).data("email")
|
53
|
+
]
|
54
|
+
JSON.stringify(addrs)
|
55
|
+
|
56
|
+
toggle_sample_text: =>
|
57
|
+
if @total_email_count() == 0 then $(".example-text").show() else $(".example-text").hide()
|
58
|
+
|
59
|
+
keydown_input: (e) =>
|
60
|
+
@noblur = false
|
61
|
+
$email_input = $("#email_input")
|
62
|
+
if $email_input.val() != "" && e.which in ctct.keys 'enter tab'
|
63
|
+
e.preventDefault()
|
64
|
+
@check_email_input()
|
65
|
+
if $email_input.val() == "" && e.which in ctct.keys 'backspace delete'
|
66
|
+
$(e.currentTarget).parent().prev().remove()
|
67
|
+
@trigger 'data_changed'
|
68
|
+
|
69
|
+
click_wrapper: (e) =>
|
70
|
+
$(".example-text").hide()
|
71
|
+
$('#invalid_email').hide()
|
72
|
+
$("#email_input").focus()
|
73
|
+
|
74
|
+
validate_input: (e) =>
|
75
|
+
@toggle_sample_text() if e.type == "focusout"
|
76
|
+
return if @noblur and e.type == "focusout"
|
77
|
+
_.delay 0, => @check_email_input()
|
78
|
+
|
79
|
+
check_email_input: =>
|
80
|
+
email_input = $("#email_input").val()
|
81
|
+
email_input = email_input.replace(/\(/g, " (").replace(/,([^\s])/g, ", $1")
|
82
|
+
return unless email_input?
|
83
|
+
splitit = email_input.split(/[\n;]/)
|
84
|
+
for inputemail in splitit
|
85
|
+
while inputemail.length > 0
|
86
|
+
email_match = inputemail.match @email_with_name_pattern()
|
87
|
+
if email_match?
|
88
|
+
extra_chars = ""
|
89
|
+
[input, quote, first, comma, last, email] = email_match
|
90
|
+
if (idx = inputemail.indexOf(input)) > 0
|
91
|
+
extra_chars = inputemail.substr(0, idx)
|
92
|
+
if extra_chars.match(email)
|
93
|
+
input = extra_chars + input
|
94
|
+
extra_chars = ""
|
95
|
+
else
|
96
|
+
@create_element(extra_chars.replace(/[,;'"]/g,""), "pill-invalid")
|
97
|
+
ip_match = email.match @IP_LOOK_ALIKE
|
98
|
+
if ip_match #immediately reject IP emails
|
99
|
+
@create_element(input,"pill-invalid")
|
100
|
+
else if email.length > 80
|
101
|
+
@create_element(input,"pill-invalid")
|
102
|
+
else
|
103
|
+
@create_element(input,"pill-email")
|
104
|
+
@add_name_data(first, comma, last, email)
|
105
|
+
inputemail = inputemail.replace(extra_chars,"").replace(input,"")
|
106
|
+
else
|
107
|
+
@create_element(inputemail.replace(/[,;'"]/g,""), "pill-invalid")
|
108
|
+
inputemail = ""
|
109
|
+
@trigger 'data_changed'
|
110
|
+
@reset_email_input()
|
111
|
+
@noblur = true
|
112
|
+
|
113
|
+
create_element: (input, pillclass) =>
|
114
|
+
input = $.trim(input)
|
115
|
+
input = input.slice(0,-1) if input.match(/[,;]$/)
|
116
|
+
return unless input.length > 0
|
117
|
+
new_element = $("<li/>").addClass("pill")
|
118
|
+
@email_node = $("<span class='email-node'/>").text(input).click(@edit_element)
|
119
|
+
delete_anchor = $("<a href='#' class='close delete-email'>×</a>").click(@remove_element)
|
120
|
+
@email_node.appendTo new_element
|
121
|
+
delete_anchor.appendTo new_element
|
122
|
+
new_element.addClass pillclass
|
123
|
+
new_element.insertBefore $("#email_input").parent()
|
124
|
+
|
125
|
+
add_name_data: (first, comma, last, email) =>
|
126
|
+
last = $.trim(last)
|
127
|
+
[last, first] = [first, last] if comma?
|
128
|
+
first = "" if first == email
|
129
|
+
@email_node.data("first-name", first)
|
130
|
+
@email_node.data("last-name", last)
|
131
|
+
@email_node.data("email", email)
|
132
|
+
|
133
|
+
edit_element: (e) =>
|
134
|
+
@check_email_input()
|
135
|
+
$email_input = $("#email_input")
|
136
|
+
$email_element = $(e.target)
|
137
|
+
$email_input.parent().insertBefore($email_element.parent())
|
138
|
+
$email_input.val($email_element.text()).focus()
|
139
|
+
$email_element.parent().remove()
|
140
|
+
|
141
|
+
remove_element: (e) =>
|
142
|
+
e.preventDefault()
|
143
|
+
$(e.target).parent().remove()
|
144
|
+
@trigger 'data_changed'
|
145
|
+
@toggle_sample_text()
|
146
|
+
|
147
|
+
email_with_name_pattern: ->
|
148
|
+
///
|
149
|
+
(?:(["'])?
|
150
|
+
#{@NAME_PATTERN}
|
151
|
+
\1\s+)? #find name as First Last or Last, First
|
152
|
+
[<|(]? #start delimiter
|
153
|
+
(#{@EMAIL_PATTERN}) #match e-mail
|
154
|
+
[>|)]?,? #end delimiter
|
155
|
+
(?:\s|$)
|
156
|
+
///
|
metadata
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: email_name_textfield
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Dana Greenberg
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-05-10 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.3'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.3'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: coffee-rails
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>'
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 2.1.0
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>'
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.1.0
|
62
|
+
description: Text area for pasting in multiple emails and validating by name and e-mail
|
63
|
+
address
|
64
|
+
email:
|
65
|
+
- dgreenbe@constantcontact.com
|
66
|
+
executables: []
|
67
|
+
extensions: []
|
68
|
+
extra_rdoc_files: []
|
69
|
+
files:
|
70
|
+
- .gitignore
|
71
|
+
- Gemfile
|
72
|
+
- LICENSE.txt
|
73
|
+
- README.md
|
74
|
+
- Rakefile
|
75
|
+
- email_name_textfield.gemspec
|
76
|
+
- lib/email_name_textfield.rb
|
77
|
+
- lib/email_name_textfield/version.rb
|
78
|
+
- vendor/assets/javascripts/email_input_area_view.coffee
|
79
|
+
- vendor/assets/javascripts/email_name_textfield.js
|
80
|
+
- vendor/assets/javascripts/setup.coffee
|
81
|
+
homepage: ''
|
82
|
+
licenses:
|
83
|
+
- MIT
|
84
|
+
post_install_message:
|
85
|
+
rdoc_options: []
|
86
|
+
require_paths:
|
87
|
+
- lib
|
88
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
+
none: false
|
96
|
+
requirements:
|
97
|
+
- - ! '>='
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
requirements: []
|
101
|
+
rubyforge_project:
|
102
|
+
rubygems_version: 1.8.23
|
103
|
+
signing_key:
|
104
|
+
specification_version: 3
|
105
|
+
summary: Text area entry tool that allows you to paste e-mail names and addresses
|
106
|
+
from common mail clients such as Gmail, Yahoo! and Outlook. This tool will recognize
|
107
|
+
the pasted input and parse out the first and last name as well as validating the
|
108
|
+
e-mail address.
|
109
|
+
test_files: []
|