Repository navigation
Expand file tree
/
Copy pathapp.js
More file actions
105 lines (86 loc) · 2.65 KB
/
Copy pathapp.js
File metadata and controls
105 lines (86 loc) · 2.65 KB
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
$(function() {
if ($('#single-page').length) {
$('.header').addClass("header-fixed");
}
if (!$('#home-page').length) {
return false;
}
//adding header-fixed class to the header on scrolling
$(window).scroll(function() {
if ($(this).scrollTop() > 1){
$('.header').addClass("header-fixed");
}
else{
$('.header').removeClass("header-fixed");
}
});
//scrolling on clicking links on header
$('.header a:not(.navigation-logo a)').on("click", function(event) {
event.preventDefault();
// set scroll selector from data attribute
var $selector = '#' + $(this).data('scrollto');
// scrolling to the selected sectiondocument.title,
scrollTo($selector)
});
window.onload = function() {
// set section selector from location
var $selector = window.location.hash;
// scrolling to the selected sectiondocument.title,
scrollTo($selector);
//replacing hash from url
history.pushState("", document.title, window.location.pathname);
};
function scrollTo(selector){
selector = $(selector);
if (selector.length) {
var scrollTo = selector.offset().top - 130;
$("html, body").animate({
scrollTop: scrollTo
}, 500);
}
}
var $contactForm = $('#contact-form');
var contactValidationSettings = {
errorClass:'has-error',
validClass:'success',
errorElement:"span",
// add error class
highlight: function(element, errorClass, validClass) {
$(element).parents("div.form-group")
.addClass(errorClass)
.removeClass(validClass);
},
// add error class
unhighlight: function(element, errorClass, validClass) {
$(element).parents(".has-error")
.removeClass(errorClass)
.addClass(validClass);
},
rules: {
name: {
required: true,
},
email: {
required: true,
email: true
},
message: {
required: true,
}
},
messages: {
name: {
required: "Please enter your name!",
},
email: {
required: "Please enter your email!",
email: "Please enter correct email!"
},
message: {
required: 'Please enter your message!',
}
}
};
// validating contact form
$contactForm.validate(contactValidationSettings);
});