danog.github.io/js/contact_me.js

147 lines
6.8 KiB
JavaScript
Raw Normal View History

2015-08-27 23:06:33 +02:00
$(function() {
2016-04-10 14:33:37 +02:00
$('#ghapidata').html('<div id="loader"><img src="css/loader.gif" alt="loading..."></div>');
var username = "danog";
var requri = 'https://api.github.com/users/' + username;
var repouri = 'https://api.github.com/users/' + username + '/repos';
requestJSON(requri, function(json) {
if (json.message == "Not Found" || username == '') {
$('#ghapidata').html("<h2>No User Info Found</h2>");
} else {
// else we have a user and we display their info
var fullname = json.name;
var username = json.login;
var aviurl = json.avatar_url;
var profileurl = json.html_url;
var location = json.location;
var followersnum = json.followers;
var followingnum = json.following;
var reposnum = json.public_repos;
if (fullname == undefined) {
fullname = username;
}
var outhtml = '<h2>' + fullname + ' <span class="smallname">(@<a href="' + profileurl + '" target="_blank">' + username + '</a>)</span></h2>';
outhtml = outhtml + '<div class="ghcontent"><div class="avi"><a href="' + profileurl + '" target="_blank"><img src="' + aviurl + '" width="80" height="80" alt="' + username + '"></a></div>';
outhtml = outhtml + '<p>Followers: ' + followersnum + ' - Following: ' + followingnum + '<br>Repos: ' + reposnum + '</p></div>';
outhtml = outhtml + '<div class="repolist clearfix">';
var repositories;
$.getJSON(repouri, function(json) {
repositories = json;
outputPageContent();
});
function outputPageContent() {
if (repositories.length == 0) {
outhtml = outhtml + '<p>No repos!</p></div>';
} else {
outhtml = outhtml + '<p><strong>Repos List:</strong></p> <ul>';
$.each(repositories, function(index) {
2016-04-10 14:39:44 +02:00
if (repositories[index].fork === false && (repositories[index].name != "video-dl" && repositories[index].name != "gigaclone" && repositories[index].name != "php-login-freelancer" && repositories[index].name != "binwalker" &&repositories[index].name != "dl2cloud" && repositories[index].name != "learn-bash" && repositories[index].name != "aura-camera")) {
2016-04-10 14:33:37 +02:00
outhtml = outhtml + '<li><a href="https://daniil.it/' + repositories[index].name + '" target="_blank">' + repositories[index].name + ' - ' + repositories[index].description + '</a></li>';
}
});
outhtml = outhtml + '</ul></div>';
}
$('#ghapidata').html(outhtml);
} // end outputPageContent()
} // end else statement
}); // end requestJSON Ajax call
2016-02-17 14:05:07 +01:00
$("#contactForm input,#contactForm textarea").jqBootstrapValidation({
2015-08-27 23:06:33 +02:00
preventSubmit: true,
submitError: function($form, event, errors) {
// additional error messages or events
},
submitSuccess: function($form, event) {
// Prevent spam click and default submit behaviour
$("#btnSubmit").attr("disabled", true);
event.preventDefault();
2016-02-17 14:05:07 +01:00
2015-08-27 23:06:33 +02:00
// get values from FORM
var name = $("input#name").val();
var email = $("input#email").val();
var phone = $("input#phone").val();
var message = $("textarea#message").val();
2015-08-29 21:34:50 +02:00
var domain = "1";
2015-08-27 23:06:33 +02:00
var firstName = name; // For Success/Failure Message
// Check for white space in name for Success/Fail message
if (firstName.indexOf(' ') >= 0) {
firstName = name.split(' ').slice(0, -1).join(' ');
}
$.ajax({
2015-08-29 21:34:50 +02:00
url: "https://mail.daniil.it/",
2015-08-27 23:06:33 +02:00
type: "POST",
data: {
name: name,
phone: phone,
email: email,
2015-08-29 22:09:40 +02:00
message: message,
2015-08-29 21:34:50 +02:00
domain: domain
2015-08-27 23:06:33 +02:00
},
cache: false,
2016-02-17 14:05:07 +01:00
success: function(data) {
$("#btnSubmit").attr("disabled", false);
2016-04-10 14:33:37 +02:00
if (data == "ok") {
2016-02-17 12:45:54 +01:00
// Success message
$('#success').html("<div class='alert alert-success'>");
$('#success > .alert-success').html("<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;")
.append("</button>");
$('#success > .alert-success')
2016-02-17 14:10:38 +01:00
.append("<strong>The message has been sent. </strong>");
2016-02-17 12:45:54 +01:00
$('#success > .alert-success')
.append('</div>');
//clear all fields
$('#contactForm').trigger("reset");
} else {
// Fail message
$('#success').html("<div class='alert alert-danger'>");
$('#success > .alert-danger').html("<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;")
.append("</button>");
2016-02-17 14:10:38 +01:00
$('#success > .alert-danger').append("<strong>Sorry " + firstName + ", it looks like an error occurred. Please try again later!</strong>");
2016-02-17 12:45:54 +01:00
$('#success > .alert-danger').append('</div>');
//clear all fields
$('#contactForm').trigger("reset");
}
2015-08-27 23:06:33 +02:00
},
error: function() {
2016-02-17 14:05:07 +01:00
$("#btnSubmit").attr("disabled", false);
2015-08-27 23:06:33 +02:00
// Fail message
$('#success').html("<div class='alert alert-danger'>");
$('#success > .alert-danger').html("<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;")
.append("</button>");
2016-02-17 14:10:38 +01:00
$('#success > .alert-danger').append("<strong>Sorry " + firstName + ", it looks like an error occurred. Please try again later!</strong>");
2015-08-27 23:06:33 +02:00
$('#success > .alert-danger').append('</div>');
//clear all fields
$('#contactForm').trigger("reset");
},
})
},
filter: function() {
return $(this).is(":visible");
},
});
$("a[data-toggle=\"tab\"]").click(function(e) {
e.preventDefault();
$(this).tab("show");
});
});
// When clicking on Full hide fail/success boxes
$('#name').focus(function() {
$('#success').html('');
});
2016-04-10 14:33:37 +02:00
function requestJSON(url, callback) {
$.ajax({
url: url,
complete: function(xhr) {
callback.call(null, xhr.responseJSON);
}
});
}