resume/src/Sikofitt/js/resume.js

66 lines
2.9 KiB
JavaScript

jq = jQuery.noConflict();
jq(document).ready(function (jq) {
jq('form#recaptcha').on('submit', function (event) {
event.stopImmediatePropagation();
event.stopPropagation();
jq.post(jq(this).attr('action'), jq(this).serialize(), function (response) {
data = JSON.parse(response);
if (false === data.valid) {
data.message.every(function (d) {
UIkit.notify('<i class="uk-icon-medium uk-icon-frown-o uk-icon-justify"></i> ' + d, {
pos: 'bottom-center',
status: 'danger'
});
});
} else if (true === data.valid) {
var divRoot = jq('<div />'),
h1 = jq('<h1 />'),
href = jq('<a />'),
phone = jq('.hidden-phone');
href
.attr('href', 'tel:' + data.message.phone)
.text(data.message.phone);
h1.append(href);
phone.attr('href', 'tel:' + data.message.phone);
phone.text(data.message.phone);
divRoot.append(h1);
jq('#recaptcha-wrapper').replaceWith(divRoot);
}
});
}); // Phone form
jq('form[name=contact]').on('submit', function(event) {
jq.post(jq(this).attr('action'), jq(this).serialize(), function(response) {
if(response.status !== 'success') {
jq('#' + response.id).addClass('uk-form-danger');
UIkit.notify('<i class="uk-icon uk-icon-frown-o uk-icon-justify uk-margin-right"></i>' + response.message + ' ('+response.code+')</div>', {
pos: 'top-center',
status: 'danger'
});
console.log(response);
} else {
console.log(response);
UIkit.notify('<i class="uk-icon uk-icon-check uk-icon-justify uk-margin-right"></i> ' + response.message, {
pos: 'top-center',
status: 'success'
});
var $wrapper = jq('#contact-form'),
$button = jq('<button class="uk-modal-close uk-button uk-button-massive uk-button-primary uk-align-center" type="button">Close</button>'),
$thankYouText = jq('<p class="uk-text-lead uk-text-center">Thank you for your message.</p><p class="uk-text-center">I will get back to you as soon as possible.</p>');
$wrapper.empty().append($thankYouText).append($button);
jq('a[href="#contact-form-wrapper"]').replaceWith('eric@ericwheeler.net');
}
});
});
jq('form[name=contact] input, form[name=contact] textarea').on('focus', function() {
if(jq(this).hasClass('uk-form-danger')) {
jq(this).removeClass('uk-form-danger');
}
});
});