-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscript.js
245 lines (203 loc) · 5.55 KB
/
script.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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
(function($, sr) {
// debouncing function from John Hann
// http://unscriptable.com/index.php/2009/03/20/debouncing-javascript-methods/
var debounce = function(func, threshold, execAsap) {
var timeout;
return function debounced() {
var obj = this,
args = arguments;
function delayed() {
if (!execAsap)
func.apply(obj, args);
timeout = null;
}
if (timeout)
clearTimeout(timeout);
else if (execAsap)
func.apply(obj, args);
timeout = setTimeout(delayed, threshold || 100);
};
};
// smartresize
jQuery.fn[sr] = function(fn) {
return fn ? this.bind('resize', debounce(fn)) : this.trigger(sr);
};
})(jQuery, 'smartresize');
var $ = jQuery;
(function() {
///////////////////////////////
// Set Home Slideshow Height
///////////////////////////////
function setHomeBannerHeight() {
var windowHeight = jQuery(window).height();
jQuery('#header').height(windowHeight);
}
///////////////////////////////
// Center Home Slideshow Text
///////////////////////////////
function centerHomeBannerText() {
var bannerText = jQuery('#header > .center');
var bannerTextTop = (jQuery('#header').actual('height') / 2) - (jQuery('#header > .center').actual('height') / 2) - 40;
bannerText.css('padding-top', bannerTextTop + 'px');
bannerText.show();
}
function setHeaderBackground() {
var scrollTop = jQuery(window).scrollTop(); // our current vertical position from the top
if (scrollTop > 300 || jQuery(window).width() < 700) {
jQuery('#header .top').addClass('solid');
} else {
jQuery('#header .top').removeClass('solid');
}
}
///////////////////////////////
// Initialize
///////////////////////////////
jQuery.noConflict();
setHomeBannerHeight();
centerHomeBannerText();
//Resize events
jQuery(window).smartresize(function() {
setHomeBannerHeight();
centerHomeBannerText();
});
})();
///////////////////////////////
// Smooth Scroll
///////////////////////////////
smoothScroll.init();
///////////////////////////////
// Animate Css
///////////////////////////////
var $ = jQuery;
function animationHover(element, animation) {
element = $(element);
element.hover(
function() {
element.addClass('animated ' + animation);
},
function() {
//wait for animation to finish before removing classes
window.setTimeout(function() {
element.removeClass('animated ' + animation);
}, 2000);
});
}
$(document).ready(function() {
$('#scrollToContent').each(function() {
animationHover(this, 'pulse');
});
});
///////////////////////////////
// Header Fixed
///////////////////////////////
var menu = $('#navigation');
var origOffsetY = menu.offset().top;
function scroll() {
if ($(window).scrollTop() >= origOffsetY) {
$('#navigation').addClass('nav-wrap');
$('#services').addClass('exp');
//$('.content').addClass('menu-padding');
} else {
$('#navigation').removeClass('nav-wrap');
$('#services').removeClass('exp');
//$('.content').removeClass('menu-padding');
}
}
document.onscroll = scroll;
///////////////////////////////
// Testimonial Slide
///////////////////////////////
$(document).ready(function() {
$("#testimonial-container").owlCarousel({
navigation: false, // Show next and prev buttons
slideSpeed: 700,
paginationSpeed: 400,
singleItem: true,
});
});
$(document).ready(function() {
$("#skype").click(function(e) {
e.preventDefault();
window.open('skype:richymel', '_blank');
return false;
});
// Subscribe was pressed
$("#subscribe").click(function(e) {
e.preventDefault();
if (validation()) {
subscribeUser(e);
}
});
});
function subscribeUser(e) {
console.log("Subscribe pressed");
var requestData = {
"email_address": $('#user_email').val(),
"status": "subscribed",
"merge_fields": {
"FNAME": $('#user_name').val()
}
};
console.log(requestData);
//prepare the POST request
requestData = JSON.stringify(requestData);
console.log("stringified:");
console.log(requestData);
var options = {
method: "post",
contentType: "application/json",
payload: requestData
};
//Execute the API call
console.log("calling MailChimp");
var subscribeOK = true; //simiulate ok
if (subscribeOK) {
$('#subscribe').hide();
//Input protect
$('#user_name').keypress(function(e) {
e.preventDefault();
});
$('#user_email').keypress(function(e) {
e.preventDefault();
});
$('#subscriberTag').text('Preferred Customer:');
$("#subscribedOK").show();
}
}
function validation() {
var user_email = $('#user_email').val();
var user_name = $('#user_name').val();
var errors = false;
$('#error1').hide();
$('#error2').hide();
if (!checkValidName(user_name)) {
console.log('name is invalid!');
$('#error1').show();
errors = true;
$('#user_name').focus();
} else {
//Capitalixe user name
user_name = user_name.toLowerCase().replace(/\b[a-z]/g, function(letter) {
return letter.toUpperCase();
});
$('#user_name').val(user_name);
}
if (!checkValidEmail(user_email)) {
console.log('email is invalid!');
$('#error2').show();
if (!errors) {
$('#user_email').focus();
}
errors = true;
}
return !(errors); /* false if errors */
}
function checkValidName(str) {
return !(!str || str.trim().length < 2);
}
function checkValidEmail(str) {
if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(str)) {
return true;
}
return false;
}