-
Notifications
You must be signed in to change notification settings - Fork 2
/
sig.js
165 lines (149 loc) · 5.25 KB
/
sig.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
$.fn.clearValidation = function(){var v = $(this).validate();$('[name]',this).each(function(){v.successList.push(this);v.showErrors();});v.resetForm();v.reset();};
function copyText(element) {
var text = document.getElementById(element);
var selection = window.getSelection();
var range = document.createRange();
range.selectNodeContents(text);
selection.removeAllRanges();
selection.addRange(range);
document.execCommand('copy');
$("#success-alert").fadeIn(500, function(){
$("#success-alert").delay(5000).fadeOut(500);
});
}
function insertInOrder(list, toInsert){
var elementIndex = $(toInsert).data('index');
var length = $(list).children().length;
if(length == 0){
$(list).append(toInsert);
return;
}
var children = $(list).children();
for(var i=0;i<length;i++){
if($(children[i]).data('index') > elementIndex){
$(children[i]).before(toInsert);
return;
}
}
$(list).append(toInsert);
return;
}
$(function(){
//wipe the form on refresh
document.forms['siginfo'].reset();
var form = $('form');
$(document).ready(function(){
$('.social-media input[type=checkbox]').on('click', function(){
$currentField = $(this).parents('.input-group').find('input[type=text]');
if($currentField.is(":visible")){
$currentField.hide();
$('#signature td.' + $currentField.attr('id')).remove();
}
else {
$currentField.show();
insertInOrder($('.social tr'), $('.hidden .' + $currentField.attr('id')).clone());
}
});
$('.additions-group input[type=checkbox]').on('click', function(){
$currentField = $(this).parents('.form-group').find('label');
field = $currentField.attr('for');
if($('.additions .' + field).length){
$('.additions .' + field).remove();
}
else{
insertInOrder($('.additions'), $('.hidden .' + field).clone());
}
});
$('input[type=text]').on('keyup paste blur', function(){
if($(this).valid() || $(this).val() == ""){
// handle the social media urls first
if($(this).parents('.social-media').length){
$('td.' + $(this).attr('id') + ' a').attr('href', $(this).val());
return;
}
var target = "." + this.id + ".field";
if($(this).val() == "" && !$(this).hasClass('notshown'))
$(target).parents('span').hide();
else
$(target).parents('span').show();
//if we're adding text that wasn't previously there, or our new value is empty
//TODO if we're working with a hidden field, this logic doesn't work.
var resize = false;
if($(this).val() != $(target).text() && !$(this).hasClass('notshown') && ($(target).text() == "" || $(this).val() == "")){
resize = true;
}
if(this.id == 'name'){
$(target).html($(this).val().replace(/(,.*)/g, '<span style="font-weight:normal;font-size:0.9em;">$1</span>'))
}
else{
$(target).html($(this).val());
}
if(this.id == "url" || this.id == "department"){
if($('#url').val() && $('.field.department a').length)
$('.field.department a').attr('href', $('#url').val());
else if ($('#url').val())
$('.field.department').wrapInner("<a href='" + $('#url').val() + "' style='color: #337ab7; text-decoration: none; display: inline;'></a>");
else
$('.field.department > a').contents().unwrap();
}
if($(this).parents('.social-media').length){
$('#signature .' + $(this).attr('id')).attr('href', $(this).val());
$('.hidden .' + $(this).attr('id')).attr('href', $(this).val());
}
//Set up the pipe between phone numbers
if($('.field.phone').text() && $('.field.mobile').text() && $('.field.fax').text()){
$('.mid, .mid2, .icon').show();
}
else if($('.field.phone').text() && $('.field.mobile').text()){
$('.icon.fax, .mid2').hide();
$('.icon.phone, .icon.mobile, .mid').show();
}
else if($('.field.phone').text() && $('.field.fax').text()){
$('.icon.mobile, .mid2').hide();
$('.icon.phone, .icon.fax, .mid').show();
}
else if($('.field.mobile').text() && $('.field.fax').text()){
$('.icon.phone, .mid').hide();
$('.icon.mobile, .icon.fax, .mid2').show();
}
else{
$('.mid, .mid2, .icon').hide();
}
if($(this).val() == ""){
$(this).clearValidation();
}
}
});
});
$.validator.addMethod("emailRegex", function(value, element, regexpr) {
if(value.length > 0)
return regexpr.test(value);
return true;
}, "Be sure to use your Lane email address");
$("form").validate({
rules: {
name: "required",
email: {
email: true,
emailRegex: /[a-zA-Z]+@lanecc.edu/,
required: false
},
phone: {
phoneUS: true
},
mobile: {
phoneUS: true
},
fax: {
phoneUS: true
},
url: {
url: true
}
},
messages: {
url: "Please enter a valid URL, starting with http://",
phone: "Please specify a valid Phone Number, starting with the area code"
}
});
});