I have two things that relate to adding a character to the output view.
- Pronouns – Right now, it is hidden until someone types in their preferred pronoun. It’ll output her/she if that’s what they put, but I would like to do ‘(‘ + “her/she” + ‘)’;
2.The output is hidden until someone types a number. I would like to have it as display M: 739.383.3893.
I can get the outputs to display the input text but never the with the character. How do I go about adding characters into the output based on the input the user puts in?
Extreme beginner here, I’m sorry 🙁
JavaScript
x
257
257
1
(function() {
2
3
/*
4
* Input stuff
5
*/
6
var doc = document;
7
var form = doc.getElementById('form');
8
var copyButton = doc.getElementById('copy');
9
var resetButton = doc.getElementById('reset');
10
var inputPhone = doc.getElementById('phone');
11
var inputOffice = doc.getElementById('office');
12
var instructions = doc.getElementById('instructions');
13
var inputFullName = doc.getElementById('fullName');
14
var inputPronouns = doc.getElementById('pronouns');
15
var inputJobTitle = doc.getElementById('jobTitle');
16
var copyButtonOriginalHTML = '<i class="fas fa-copy"></i> Copy Signature';
17
var copyButtonDisabledHTML = '<i class="fas fa-exclamation-circle"></i> Enter your info first!';
18
var peopleTemplate = {
19
empty: {
20
fullName: "",
21
pronouns: "",
22
jobTitle: "",
23
phone: "",
24
office: ""
25
},
26
dummy: {
27
fullName: "Your Name",
28
jobTitle: "Your title",
29
pronouns: "Your pronouns",
30
office: "7890",
31
phone: "123-456-7890"
32
}
33
};
34
35
36
37
/*
38
* Output stuff
39
*/
40
var sig = doc.getElementById('sig');
41
var sigPhone = doc.querySelector('.sig__phone');
42
var sigFullName = doc.querySelector('.sig__fullName');
43
var sigJobTitle = doc.querySelector('.sig__jobTitle');
44
var sigPronouns = doc.querySelector('.sig__pronouns');
45
var sigOffice = doc.querySelector('.sig__office');
46
47
48
/*
49
* Instructions HTML
50
*/
51
var pasteInstructions = "<h3>Yay! Your signature was copied and is ready to paste.</h3>"
52
+ "<p>To create a new signature in Outlook, follow these directions:</p>"
53
+ "<ol><li>Update Outlook to the latest version.</li>"
54
+ "<li>Open Outlook.</li>"
55
+ "<li>Under <b>Outlook</b> in the main menu, select <b>Preferences</b>.</li>"
56
+ "<li>Under the <b>Email</b> section, click <b>Signatures</b>.</li>"
57
+ "<li>In the <b>Edit Signatures</b> section, click the <b>+</b> (plus) icon in the bottom left corner.</li>"
58
+ "<li>Select whatever is there already and paste your new signature into the box.</li>"
59
+ "</ol>";
60
61
/*
62
* Clear form inputs
63
*/
64
var resetForm = function () {
65
inputFullName.value = '';
66
inputJobTitle.value = '';
67
inputPhone.value = '';
68
inputPronouns.value = '';
69
inputOffice.value = '';
70
updateSignature();
71
instructions.innerHTML = '';
72
};
73
74
/*
75
* Fill signature with dummy info
76
*/
77
var fillDummySignature = function () {
78
sigFullName.textContent = "Your Name";
79
sigPronouns.textContent = ""
80
sigJobTitle.textContent = "Your title";
81
sigPhone.textContent = "";
82
sigOffice.textContent = "1234";
83
};
84
85
/*
86
* Check if nothing is entered
87
*/
88
var inputsAreEmpty = function () {
89
return inputFullName.value === ''
90
&& inputPronouns.value === ''
91
&& inputJobTitle.value === ''
92
&& inputPhone.value === ''
93
&& inputOffice.value === '';
94
};
95
96
var userName = document.querySelector('#phone');
97
98
userName.addEventListener('input', restrictNumber);
99
function restrictNumber (e) {
100
var newValue = this.value.replace(new RegExp(/[^d]/,'ig'), "");
101
this.value = newValue;
102
}
103
104
105
/*
106
* Reformat phone number syntax
107
*/
108
var formatPhone = function (n) {
109
110
// var pattern = /[^0-9.]+/g;
111
// if (n.search(pattern) !== -1) {
112
// console.log("not a number");
113
// // n.replace(pattern, '');
114
// return n;
115
// }
116
117
var o = n;
118
var l = n.length;
119
120
var noDash = function (value, index) {
121
return value.charAt(index) !== '.';
122
};
123
124
var insertDash = function (value, index) {
125
return value.slice(0, index) + '.' + value.slice(index, value.length + 1);
126
};
127
128
var no3 = noDash(o, 3);
129
var no7 = noDash(o, 7);
130
131
if (l > 3 && l <= 7) {
132
if (no3) {
133
o = insertDash(n, 3);
134
}
135
} else if (l > 7 && l <= 11) {
136
if (no3) {
137
o = insertDash(n, 3);
138
if (no7) {
139
o = insertDash(o, 7); // insert on the value we just updated
140
}
141
} else if (no7) {
142
o = insertDash(n, 7);
143
}
144
} else if (l > 12) {
145
o = n.slice(0, 12);
146
}
147
return o;
148
};
149
150
/*
151
* Add the input values into the actual signature
152
*/
153
var updateSignature = function (event) {
154
if (inputsAreEmpty()) {
155
fillDummySignature();
156
157
// Button states
158
copyButton.disabled = true;
159
copyButton.innerHTML = copyButtonDisabledHTML;
160
resetButton.style.display = 'none';
161
} else {
162
163
// Button states
164
copyButton.disabled = false;
165
copyButton.innerHTML = copyButtonOriginalHTML;
166
resetButton.style.display = 'inline-block';
167
168
// Populate signature fields
169
if (event && event.target.tagName === 'INPUT') {
170
var id = event.target.id;
171
var input = doc.getElementById(id);
172
var sigClassName = '.sig__' + id;
173
var inputIdName = '#' + id;
174
var sigTarget = doc.querySelector(sigClassName);
175
var inputTarget = doc.querySelector(inputIdName);
176
177
if (id === 'fullName') {
178
sigTarget.textContent = input.value;
179
} else if (id === 'phone') {
180
sigTarget.textContent = formatPhone(input.value);
181
inputTarget.value = formatPhone(input.value);
182
} else {
183
sigTarget.textContent = input.value;
184
}
185
} else {
186
sigFullName.textContent = inputFullName.value;
187
sigJobTitle.textContent = inputJobTitle.value;
188
sigPhone.textContent = inputPhone.value;
189
}
190
}
191
}
192
193
/*
194
* Insert a person's info when option is selected
195
*/
196
var insertPersonInfo = function (event) {
197
resetForm();
198
if (event.target.value !== 'custom') {
199
var person = people[this.selectedIndex - 1];
200
inputFullName.value = person.fullName;
201
inputPronouns.value = person.pronouns;
202
inputJobTitle.value = person.jobTitle;
203
inputPhone.value = person.phone;
204
updateSignature(event);
205
}
206
};
207
208
/*
209
* Populate the people info in the select menu on load
210
*/
211
document.addEventListener("DOMContentLoaded", function (event) {
212
updateSignature(event);
213
fillDummySignature();
214
});
215
216
/*
217
* Copy raw HTML output
218
*/
219
copyButton.addEventListener('click', function(event) {
220
// Have to remove any existing ranges :: Chrome bug
221
window.getSelection().removeAllRanges();
222
223
// Create range and add it to selection
224
var r = document.createRange();
225
r.selectNode(sig);
226
window.getSelection().addRange(r);
227
228
// Error catching
229
try {
230
var successful = document.execCommand('copy');
231
var msg = successful ? 'successful' : 'unsuccessful';
232
console.log('Copy command was ' + msg);
233
} catch(err) {
234
console.log('Oops, unable to copy');
235
}
236
237
// Remove range from selection again
238
window.getSelection().removeAllRanges();
239
240
if (successful) {
241
instructions.innerHTML = pasteInstructions;
242
// this.parentNode.removeChild(this);
243
}
244
});
245
246
/*
247
* Listeners
248
*/
249
form.addEventListener('input', updateSignature);
250
resetButton.addEventListener('click', resetForm);
251
inputPhone.addEventListener('paste', function(event) {
252
// formatPhone();
253
});
254
255
}());
256
257
JavaScript
1
145
145
1
.form__input, .button, .button--copy, .button--reset {
2
font-size: 14px;
3
margin: 0;
4
padding: 6px 9px;
5
border: 1px solid #e7e7e7;
6
border-radius: 2px;
7
line-height: 1;
8
}
9
* {
10
box-sizing: border-box;
11
}
12
.sig-gen {
13
font-family: 'Work Sans', 'Helvetica Neue', Arial, sans-serif;
14
font-size: 16px;
15
margin: 2em auto 4em;
16
width: 100%;
17
max-width: 800px;
18
}
19
.sig-gen__section {
20
margin-bottom: 2em;
21
}
22
.sig-gen__section--email {
23
margin-bottom: 3em;
24
}
25
26
.sig__field, .set-inform, .links-text {
27
font-family: 'Work Sans', 'Helvetica Neue', Arial, sans-serif;
28
}
29
.form {
30
display: flex;
31
justify-content: space-between;
32
flex-direction: column;
33
}
34
35
.set-inform {
36
display: inline-block;
37
}
38
39
@media screen and (min-width: 600px) {
40
.form {
41
/* flex-direction: row; */
42
}
43
}
44
.form__group {
45
margin-bottom: 12px;
46
}
47
.form__group:last-of-type {
48
margin-bottom: 0;
49
}
50
@media screen and (min-width: 600px) {
51
.form__group {
52
margin-bottom: 10px;
53
}
54
}
55
.form label {
56
display: block;
57
margin-bottom: 6px;
58
}
59
.form__input {
60
background: white;
61
width: 100%;
62
}
63
.form__input:focus, .form__input:active {
64
outline: 0;
65
border-color: #bebebe;
66
}
67
.email_generator {
68
position: relative;
69
border: 1px solid #e7e7e7;
70
border-top: none;
71
border-bottom: none;
72
border-bottom-left-radius: 6px;
73
border-bottom-right-radius: 6px;
74
box-shadow: 0 6px 0 #ccc;
75
}
76
.email_generator:before {
77
content: "";
78
position: absolute;
79
top: 0;
80
left: -1px;
81
width: calc(100% + 2 * 1px);
82
height: 28%;
83
background: linear-gradient(white, rgba(255, 255, 255, 0));
84
}
85
.email__container {
86
padding: 28px;
87
}
88
.email__sig {
89
margin-top: 51px;
90
}
91
.email__line {
92
height: 12px;
93
margin-bottom: 12px;
94
background: #e7e7e7;
95
border-radius: 1px;
96
}
97
.email__line:last-child {
98
width: 66%;
99
margin-bottom: 28px;
100
}
101
.email__signoff .email__line {
102
width: 17%;
103
}
104
.sig__field {
105
font-size: 14px;
106
}
107
.sig__fullName {
108
font-size: 18px;
109
}
110
.button, .button--copy, .button--reset {
111
padding: 9px 12px;
112
color: white;
113
cursor: pointer;
114
background: #8c4049;
115
border-color: #823b44;
116
}
117
.button:hover, .button--copy:hover, .button--reset:hover {
118
background: #97454e;
119
border-color: #8c4049;
120
}
121
.button:focus, .button--copy:focus, .button--reset:focus, .button:active, .button--copy:active, .button--reset:active {
122
outline: 0;
123
background: #77363e;
124
border-color: #622d33;
125
}
126
.button:disabled, .button--copy:disabled, .button--reset:disabled {
127
background: #656669;
128
border-color: #5d5e61;
129
cursor: not-allowed;
130
color: white;
131
}
132
.button--reset {
133
background: #e2e3e4;
134
border-color: #dadbdd;
135
color: #656669;
136
}
137
.button--reset:hover {
138
background: #eaebeb;
139
border-color: #e2e3e4;
140
}
141
.button--reset:focus, .button--reset:active {
142
outline: 0;
143
background: #d2d4d5;
144
border-color: #c2c4c6;
145
}
JavaScript
1
79
79
1
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
2
<div id="app" class="sig-gen">
3
<section class="sig-gen__section">
4
<h2>Email Signature Generator</h2>
5
</section>
6
<section class="sig-gen__section">
7
<form id="form" class="form">
8
<div class="form__group">
9
<label for="fullName">Full Name:</label>
10
<input type="text" id="fullName" class="form__input" placeholder="Your name" value="">
11
</div>
12
<div class="form__group">
13
<label for="pronouns">Pronouns:</label>
14
<input type="text" id="pronouns" class="form__input" placeholder="optional (they/them)" value="">
15
</div>
16
<div class="form__group">
17
<label for="jobTitle">Job Title:</label>
18
<input type="text" id="jobTitle" class="form__input" placeholder="Your title" value="">
19
</div>
20
<div class="form__group">
21
<label for="office">Office Extension:</label>
22
<input type="text" id="office" class="form__input" pattern="[0-9]" maxlength="4" placeholder="1234" value="">
23
</div>
24
<div class="form__group">
25
<label for="phone">Mobile:</label>
26
<input type="text" id="phone" class="form__input" pattern="[0-9]" maxlength="12" placeholder="optional" value="">
27
</div>
28
</form>
29
</section>
30
<section class="sig-gen__section sig-gen__section--email">
31
<div class="email_generator">
32
<div class="email__container">
33
<div id="sig" class="email__sig">
34
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse:collapse;mso-table-lspace:0pt;mso-table-rspace:0pt;-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%;font-family:Helvetica,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:normal;color:#313030;line-height:1.5;">
35
<tbody border="0" cellpadding="0" cellspacing="0">
36
<tr border="0" cellpadding="0" cellspacing="0">
37
<td align="left" height="28" style="mso-table-lspace:0pt;mso-table-rspace:0pt;-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%;font-family:Arial,sans-serif;font-size:16px;font-weight:normal;color:#313030;line-height:1.5;" valign="top">
38
<div>
39
<strong class="sig__field sig__fullName set-inform" style="font-size: 16px; color:#002857;"></strong><div class="sig__field sig__pronouns set-inform" style="font-size: 13px; color: #002857; font-style: italic;"></div>
40
</div>
41
<div class="sig__field sig__jobTitle" style="font-size: 15px; color: #7f7f7f"></div>
42
<div class="links-text" style="font-size: 15px; color: #7f7f7f">3847 New York, New York</div>
43
<div class="set-inform" style="font-size: 15px; color: #7f7f7f">O: 383.384.4838 ext.</div><div class="sig__field sig__office set-inform" style="font-size: 15px; color: #7f7f7f"></div><span> </span><div class="sig__phone set-inform" style="font-size: 15px; color: #7f7f7f"></div>
44
<div class="links-text" style="font-size: 15px;"><a style="color: #7f7f7f;" href="#">FB</a> | <a style="color: #7f7f7f;" href="#">Twitter</a> | <a style="color: #7f7f7f;" href="#">Instagram</a> | <a style="color: #7f7f7f;" href="#">LinkedIn</a></div>
45
</td>
46
</tr>
47
<tr border="0" cellpadding="0" cellspacing="0">
48
<td align="center" style="mso-table-lspace:0pt;mso-table-rspace:0pt;-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%;font-family:Arial,sans-serif;font-size:16px;font-weight:normal;color:#313030;line-height:1.5;margin:0;padding:0;" valign="top">
49
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse:collapse;mso-table-lspace:0pt;mso-table-rspace:0pt;-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%;font-family:Helvetica,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:normal;color:#313030;line-height:1.5;">
50
<tbody border="0" cellpadding="0" cellspacing="0">
51
52
<tr border="0" cellpadding="0" cellspacing="0">
53
<td align="left" style="mso-table-lspace:0pt;mso-table-rspace:0pt;-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%;line-height:1.4;" valign="top">
54
<a href="https://www.desales.edu" style="text-decoration: none;font-family:'DM Serif Text', serif;font-size:24px;font-weight:bold;color:#002857;" class="sig__logo" title="DeSales University - Home">New York University</a><span style="margin-left:10px;margin-right: 10px;border-left: solid; border-color: #002857;border-width: 2px;"></span><span style="font-weight: bold;color: #C20F2F;font-size:18px;letter-spacing: 1px;"> NYU</span>
55
</td>
56
</tr>
57
<tr border="0" cellpadding="0" cellspacing="0">
58
<td align="left" height="16" style="mso-table-lspace:0pt;mso-table-rspace:0pt;-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%;" valign="top">
59
</td>
60
</tr>
61
62
</tbody>
63
</table>
64
</td>
65
</tr>
66
</tbody>
67
</table>
68
</div>
69
</div>
70
</div>
71
</section>
72
<section class="sig-gen__section">
73
<button id="copy" class="button--copy"></button>
74
<button id="reset" class="button--reset"><i class="fas fa-sync"></i> Reset Form</button>
75
</section>
76
<section class="sig-gen__section">
77
<div id="instructions"></div>
78
</section>
79
</div>
Advertisement
Answer
[x] displaying of (pronoun)
is done,
[x] prepending M.
to the displayed mobile number is done,
JavaScript
1
259
259
1
(function() {
2
3
/*
4
* Input stuff
5
*/
6
var doc = document;
7
var form = doc.getElementById('form');
8
var copyButton = doc.getElementById('copy');
9
var resetButton = doc.getElementById('reset');
10
var inputPhone = doc.getElementById('phone');
11
var inputOffice = doc.getElementById('office');
12
var instructions = doc.getElementById('instructions');
13
var inputFullName = doc.getElementById('fullName');
14
var inputPronouns = doc.getElementById('pronouns');
15
var inputJobTitle = doc.getElementById('jobTitle');
16
var copyButtonOriginalHTML = '<i class="fas fa-copy"></i> Copy Signature';
17
var copyButtonDisabledHTML = '<i class="fas fa-exclamation-circle"></i> Enter your info first!';
18
var peopleTemplate = {
19
empty: {
20
fullName: "",
21
pronouns: "",
22
jobTitle: "",
23
phone: "",
24
office: ""
25
},
26
dummy: {
27
fullName: "Your Name",
28
jobTitle: "Your title",
29
pronouns: "Your pronouns",
30
office: "7890",
31
phone: "123-456-7890"
32
}
33
};
34
35
36
37
/*
38
* Output stuff
39
*/
40
var sig = doc.getElementById('sig');
41
var sigPhone = doc.querySelector('.sig__phone');
42
var sigFullName = doc.querySelector('.sig__fullName');
43
var sigJobTitle = doc.querySelector('.sig__jobTitle');
44
var sigPronouns = doc.querySelector('.sig__pronouns');
45
var sigOffice = doc.querySelector('.sig__office');
46
47
48
/*
49
* Instructions HTML
50
*/
51
var pasteInstructions = "<h3>Yay! Your signature was copied and is ready to paste.</h3>" +
52
"<p>To create a new signature in Outlook, follow these directions:</p>" +
53
"<ol><li>Update Outlook to the latest version.</li>" +
54
"<li>Open Outlook.</li>" +
55
"<li>Under <b>Outlook</b> in the main menu, select <b>Preferences</b>.</li>" +
56
"<li>Under the <b>Email</b> section, click <b>Signatures</b>.</li>" +
57
"<li>In the <b>Edit Signatures</b> section, click the <b>+</b> (plus) icon in the bottom left corner.</li>" +
58
"<li>Select whatever is there already and paste your new signature into the box.</li>" +
59
"</ol>";
60
61
/*
62
* Clear form inputs
63
*/
64
var resetForm = function() {
65
inputFullName.value = '';
66
inputJobTitle.value = '';
67
inputPhone.value = '';
68
inputPronouns.value = '';
69
inputOffice.value = '';
70
updateSignature();
71
instructions.innerHTML = '';
72
};
73
74
/*
75
* Fill signature with dummy info
76
*/
77
var fillDummySignature = function() {
78
sigFullName.textContent = "Your Name";
79
sigPronouns.textContent = ""
80
sigJobTitle.textContent = "Your title";
81
sigPhone.textContent = "";
82
sigOffice.textContent = "1234";
83
};
84
85
/*
86
* Check if nothing is entered
87
*/
88
var inputsAreEmpty = function() {
89
return [inputFullName, inputPronouns, inputJobTitle, inputPhone, inputOffice].every(({
90
value
91
}) => value === '')
92
};
93
94
var userName = document.querySelector('#phone');
95
96
userName.addEventListener('input', restrictNumber);
97
98
function restrictNumber(e) {
99
var newValue = this.value.replace(new RegExp(/[^d]/, 'ig'), "");
100
this.value = newValue;
101
}
102
103
104
/*
105
* Reformat phone number syntax
106
*/
107
var formatPhone = function(n) {
108
109
// var pattern = /[^0-9.]+/g;
110
// if (n.search(pattern) !== -1) {
111
// console.log("not a number");
112
// // n.replace(pattern, '');
113
// return n;
114
// }
115
116
var o = n;
117
var l = n.length;
118
119
var noDash = function(value, index) {
120
return value.charAt(index) !== '.';
121
};
122
123
var insertDash = function(value, index) {
124
return value.slice(0, index) + '.' + value.slice(index, value.length + 1);
125
};
126
127
var no3 = noDash(o, 3);
128
var no7 = noDash(o, 7);
129
130
if (l > 3 && l <= 7) {
131
if (no3) {
132
o = insertDash(n, 3);
133
}
134
} else if (l > 7 && l <= 11) {
135
if (no3) {
136
o = insertDash(n, 3);
137
if (no7) {
138
o = insertDash(o, 7); // insert on the value we just updated
139
}
140
} else if (no7) {
141
o = insertDash(n, 7);
142
}
143
} else if (l > 12) {
144
o = n.slice(0, 12);
145
}
146
return o;
147
};
148
149
/*
150
* Add the input values into the actual signature
151
*/
152
var updateSignature = function(event) {
153
if (inputsAreEmpty()) {
154
fillDummySignature();
155
156
// Button states
157
copyButton.disabled = true;
158
copyButton.innerHTML = copyButtonDisabledHTML;
159
resetButton.style.display = 'none';
160
} else {
161
162
// Button states
163
copyButton.disabled = false;
164
copyButton.innerHTML = copyButtonOriginalHTML;
165
resetButton.style.display = 'inline-block';
166
167
// Populate signature fields
168
if (event && event.target.tagName === 'INPUT') {
169
var id = event.target.id;
170
var input = doc.getElementById(id);
171
var sigClassName = '.sig__' + id;
172
var inputIdName = '#' + id;
173
var sigTarget = doc.querySelector(sigClassName);
174
var inputTarget = doc.querySelector(inputIdName);
175
176
if (id === 'fullName') {
177
sigTarget.textContent = input.value;
178
} else if (id === 'phone') {
179
// just save the value in a variable, and use that
180
const formattedPhone = formatPhone(input.value);
181
sigTarget.textContent = `M. ${formattedPhone}`;
182
inputTarget.value = formattedPhone
183
} else if (id === 'pronouns') {
184
// this case needed to be treated separately
185
sigTarget.textContent = `(${input.value})`
186
} else {
187
sigTarget.textContent = input.value;
188
}
189
} else {
190
sigFullName.textContent = inputFullName.value;
191
sigJobTitle.textContent = inputJobTitle.value;
192
sigPhone.textContent = inputPhone.value;
193
}
194
}
195
}
196
197
/*
198
* Insert a person's info when option is selected
199
*/
200
var insertPersonInfo = function(event) {
201
resetForm();
202
if (event.target.value !== 'custom') {
203
var person = people[this.selectedIndex - 1];
204
inputFullName.value = person.fullName;
205
inputPronouns.value = person.pronouns;
206
inputJobTitle.value = person.jobTitle;
207
inputPhone.value = person.phone;
208
updateSignature(event);
209
}
210
};
211
212
/*
213
* Populate the people info in the select menu on load
214
*/
215
document.addEventListener("DOMContentLoaded", function(event) {
216
updateSignature(event);
217
fillDummySignature();
218
});
219
220
/*
221
* Copy raw HTML output
222
*/
223
copyButton.addEventListener('click', function(event) {
224
// Have to remove any existing ranges :: Chrome bug
225
window.getSelection().removeAllRanges();
226
227
// Create range and add it to selection
228
var r = document.createRange();
229
r.selectNode(sig);
230
window.getSelection().addRange(r);
231
232
// Error catching
233
try {
234
var successful = document.execCommand('copy');
235
var msg = successful ? 'successful' : 'unsuccessful';
236
console.log('Copy command was ' + msg);
237
} catch (err) {
238
console.log('Oops, unable to copy');
239
}
240
241
// Remove range from selection again
242
window.getSelection().removeAllRanges();
243
244
if (successful) {
245
instructions.innerHTML = pasteInstructions;
246
// this.parentNode.removeChild(this);
247
}
248
});
249
250
/*
251
* Listeners
252
*/
253
form.addEventListener('input', updateSignature);
254
resetButton.addEventListener('click', resetForm);
255
inputPhone.addEventListener('paste', function(event) {
256
// formatPhone();
257
});
258
259
}());
JavaScript
1
190
190
1
.form__input,
2
.button,
3
.button--copy,
4
.button--reset {
5
font-size: 14px;
6
margin: 0;
7
padding: 6px 9px;
8
border: 1px solid #e7e7e7;
9
border-radius: 2px;
10
line-height: 1;
11
}
12
13
* {
14
box-sizing: border-box;
15
}
16
17
.sig-gen {
18
font-family: 'Work Sans', 'Helvetica Neue', Arial, sans-serif;
19
font-size: 16px;
20
margin: 2em auto 4em;
21
width: 100%;
22
max-width: 800px;
23
}
24
25
.sig-gen__section {
26
margin-bottom: 2em;
27
}
28
29
.sig-gen__section--email {
30
margin-bottom: 3em;
31
}
32
33
.sig__field,
34
.set-inform,
35
.links-text {
36
font-family: 'Work Sans', 'Helvetica Neue', Arial, sans-serif;
37
}
38
39
.form {
40
display: flex;
41
justify-content: space-between;
42
flex-direction: column;
43
}
44
45
.set-inform {
46
display: inline-block;
47
}
48
49
@media screen and (min-width: 600px) {
50
.form {
51
/* flex-direction: row; */
52
}
53
}
54
55
.form__group {
56
margin-bottom: 12px;
57
}
58
59
.form__group:last-of-type {
60
margin-bottom: 0;
61
}
62
63
@media screen and (min-width: 600px) {
64
.form__group {
65
margin-bottom: 10px;
66
}
67
}
68
69
.form label {
70
display: block;
71
margin-bottom: 6px;
72
}
73
74
.form__input {
75
background: white;
76
width: 100%;
77
}
78
79
.form__input:focus,
80
.form__input:active {
81
outline: 0;
82
border-color: #bebebe;
83
}
84
85
.email_generator {
86
position: relative;
87
border: 1px solid #e7e7e7;
88
border-top: none;
89
border-bottom: none;
90
border-bottom-left-radius: 6px;
91
border-bottom-right-radius: 6px;
92
box-shadow: 0 6px 0 #ccc;
93
}
94
95
.email_generator:before {
96
content: "";
97
position: absolute;
98
top: 0;
99
left: -1px;
100
width: calc(100% + 2 * 1px);
101
height: 28%;
102
background: linear-gradient(white, rgba(255, 255, 255, 0));
103
}
104
105
.email__container {
106
padding: 28px;
107
}
108
109
.email__sig {
110
margin-top: 51px;
111
}
112
113
.email__line {
114
height: 12px;
115
margin-bottom: 12px;
116
background: #e7e7e7;
117
border-radius: 1px;
118
}
119
120
.email__line:last-child {
121
width: 66%;
122
margin-bottom: 28px;
123
}
124
125
.email__signoff .email__line {
126
width: 17%;
127
}
128
129
.sig__field {
130
font-size: 14px;
131
}
132
133
.sig__fullName {
134
font-size: 18px;
135
}
136
137
.button,
138
.button--copy,
139
.button--reset {
140
padding: 9px 12px;
141
color: white;
142
cursor: pointer;
143
background: #8c4049;
144
border-color: #823b44;
145
}
146
147
.button:hover,
148
.button--copy:hover,
149
.button--reset:hover {
150
background: #97454e;
151
border-color: #8c4049;
152
}
153
154
.button:focus,
155
.button--copy:focus,
156
.button--reset:focus,
157
.button:active,
158
.button--copy:active,
159
.button--reset:active {
160
outline: 0;
161
background: #77363e;
162
border-color: #622d33;
163
}
164
165
.button:disabled,
166
.button--copy:disabled,
167
.button--reset:disabled {
168
background: #656669;
169
border-color: #5d5e61;
170
cursor: not-allowed;
171
color: white;
172
}
173
174
.button--reset {
175
background: #e2e3e4;
176
border-color: #dadbdd;
177
color: #656669;
178
}
179
180
.button--reset:hover {
181
background: #eaebeb;
182
border-color: #e2e3e4;
183
}
184
185
.button--reset:focus,
186
.button--reset:active {
187
outline: 0;
188
background: #d2d4d5;
189
border-color: #c2c4c6;
190
}
JavaScript
1
83
83
1
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
2
<div id="app" class="sig-gen">
3
<section class="sig-gen__section">
4
<h2>Email Signature Generator</h2>
5
</section>
6
<section class="sig-gen__section">
7
<form id="form" class="form">
8
<div class="form__group">
9
<label for="fullName">Full Name:</label>
10
<input type="text" id="fullName" class="form__input" placeholder="Your name" value="">
11
</div>
12
<div class="form__group">
13
<label for="pronouns">Pronouns:</label>
14
<input type="text" id="pronouns" class="form__input" placeholder="optional (they/them)" value="">
15
</div>
16
<div class="form__group">
17
<label for="jobTitle">Job Title:</label>
18
<input type="text" id="jobTitle" class="form__input" placeholder="Your title" value="">
19
</div>
20
<div class="form__group">
21
<label for="office">Office Extension:</label>
22
<input type="text" id="office" class="form__input" pattern="[0-9]" maxlength="4" placeholder="1234" value="">
23
</div>
24
<div class="form__group">
25
<label for="phone">Mobile:</label>
26
<input type="text" id="phone" class="form__input" pattern="[0-9]" maxlength="12" placeholder="optional" value="">
27
</div>
28
</form>
29
</section>
30
<section class="sig-gen__section sig-gen__section--email">
31
<div class="email_generator">
32
<div class="email__container">
33
<div id="sig" class="email__sig">
34
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse:collapse;mso-table-lspace:0pt;mso-table-rspace:0pt;-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%;font-family:Helvetica,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:normal;color:#313030;line-height:1.5;">
35
<tbody border="0" cellpadding="0" cellspacing="0">
36
<tr border="0" cellpadding="0" cellspacing="0">
37
<td align="left" height="28" style="mso-table-lspace:0pt;mso-table-rspace:0pt;-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%;font-family:Arial,sans-serif;font-size:16px;font-weight:normal;color:#313030;line-height:1.5;" valign="top">
38
<div>
39
<strong class="sig__field sig__fullName set-inform" style="font-size: 16px; color:#002857;"></strong>
40
<div class="sig__field sig__pronouns set-inform" style="font-size: 13px; color: #002857; font-style: italic;"></div>
41
</div>
42
<div class="sig__field sig__jobTitle" style="font-size: 15px; color: #7f7f7f"></div>
43
<div class="links-text" style="font-size: 15px; color: #7f7f7f">3847 New York, New York</div>
44
<div class="set-inform" style="font-size: 15px; color: #7f7f7f">O: 383.384.4838 ext.</div>
45
<div class="sig__field sig__office set-inform" style="font-size: 15px; color: #7f7f7f"></div><span> </span>
46
<div class="sig__phone set-inform" style="font-size: 15px; color: #7f7f7f"></div>
47
<div class="links-text" style="font-size: 15px;"><a style="color: #7f7f7f;" href="#">FB</a> | <a style="color: #7f7f7f;" href="#">Twitter</a> | <a style="color: #7f7f7f;" href="#">Instagram</a> | <a style="color: #7f7f7f;" href="#">LinkedIn</a></div>
48
</td>
49
</tr>
50
<tr border="0" cellpadding="0" cellspacing="0">
51
<td align="center" style="mso-table-lspace:0pt;mso-table-rspace:0pt;-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%;font-family:Arial,sans-serif;font-size:16px;font-weight:normal;color:#313030;line-height:1.5;margin:0;padding:0;" valign="top">
52
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse:collapse;mso-table-lspace:0pt;mso-table-rspace:0pt;-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%;font-family:Helvetica,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:normal;color:#313030;line-height:1.5;">
53
<tbody border="0" cellpadding="0" cellspacing="0">
54
55
<tr border="0" cellpadding="0" cellspacing="0">
56
<td align="left" style="mso-table-lspace:0pt;mso-table-rspace:0pt;-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%;line-height:1.4;" valign="top">
57
<a href="https://www.desales.edu" style="text-decoration: none;font-family:'DM Serif Text', serif;font-size:24px;font-weight:bold;color:#002857;" class="sig__logo" title="DeSales University - Home">New York University</a>
58
<span style="margin-left:10px;margin-right: 10px;border-left: solid; border-color: #002857;border-width: 2px;"></span><span style="font-weight: bold;color: #C20F2F;font-size:18px;letter-spacing: 1px;"> NYU</span>
59
</td>
60
</tr>
61
<tr border="0" cellpadding="0" cellspacing="0">
62
<td align="left" height="16" style="mso-table-lspace:0pt;mso-table-rspace:0pt;-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%;" valign="top">
63
</td>
64
</tr>
65
66
</tbody>
67
</table>
68
</td>
69
</tr>
70
</tbody>
71
</table>
72
</div>
73
</div>
74
</div>
75
</section>
76
<section class="sig-gen__section">
77
<button id="copy" class="button--copy"></button>
78
<button id="reset" class="button--reset"><i class="fas fa-sync"></i> Reset Form</button>
79
</section>
80
<section class="sig-gen__section">
81
<div id="instructions"></div>
82
</section>
83
</div>