-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
147 lines (146 loc) · 4.83 KB
/
main.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
//model
const model = {
isMobileNavOpen: false,
isDropdownOpen: false,
checkMobileNav: function() {
if (this.isMobileNavOpen === false) {
view.addMobileNav();
this.isMobileNavOpen = true;
} else {
view.removeMobileNav();
this.isMobileNavOpen = false;
}
},
checkDropdown: function() {
if (this.isDropdownOpen == false) {
view.addDropdown();
this.isDropdownOpen = true;
} else {
view.removeDropdown();
this.isDropdownOpen = false;
}
},
checkBodyClick: function(e) {
if (e.target.id != "openMobileNav") {
if (this.isMobileNavOpen === true) {
if (!e.target.closest(".mobile-navigation")) {
view.removeMobileNav();
this.isMobileNavOpen = false;
}
}
}
},
createProjectElement: function(element) {
const project = document.createElement("div");
project.classList.add("project");
const logoContainer = document.createElement("div");
logoContainer.classList.add("project-logo-container");
const icon = document.createElement("div");
icon.classList.add("icon");
icon.classList.add(`${element.iconClass}`);
logoContainer.appendChild(icon);
const projectTitle = document.createElement("div");
projectTitle.classList.add("project-title");
projectTitle.innerHTML = `${element.projectTitle}`;
const projectDescription = document.createElement("p");
projectDescription.classList.add("project-description");
projectDescription.innerHTML = `${element.projectDescription}`;
project.appendChild(logoContainer);
project.appendChild(projectTitle);
project.appendChild(projectDescription);
view.addProject(project);
}
};
//view
const view = {
addMobileNav: function() {
mobileNav.style.display = "flex";
document.getElementsByTagName("html")[0].style.overflow = "hidden";
},
removeMobileNav: function() {
mobileNav.style.display = "none";
document.getElementsByTagName("html")[0].style.overflow = "";
},
addDropdown: function() {
dropdown.style.display = "flex";
inputOpenBut.style.display = "none";
inputCloseBut.style.display = "inline";
inputCloseBut.classList.add("active");
},
removeDropdown: function() {
dropdown.style.display = "none";
inputOpenBut.style.display = "";
inputCloseBut.style.display = "none";
inputCloseBut.classList.remove("active");
},
addProject: function(project) {
const container = document.getElementById("projects");
container.appendChild(project);
}
};
//controller
const controller = {
openMobileNav: function() {
model.checkMobileNav();
},
openSearchDropdown: function() {
model.checkDropdown();
},
bodyClick: function(e) {
model.checkBodyClick(e);
},
initProjects: function() {
projectsArray.forEach(function callback(element) {
model.createProjectElement(element);
});
}
};
const mobileNavBut = document.getElementById("openMobileNav");
const mobileNav = document.getElementById("mobile-navigation");
mobileNavBut.addEventListener("click", controller.openMobileNav);
const inputOpenBut = document.getElementById("search-input-open");
const inputCloseBut = document.getElementById("search-input-close");
const dropdown = document.getElementById("search-dropdown");
inputOpenBut.addEventListener("click", controller.openSearchDropdown);
inputCloseBut.addEventListener("click", controller.openSearchDropdown);
document.body.addEventListener("click", controller.bodyClick);
const projectsArray = [
{
iconClass: "logo-spring-boot",
projectTitle: "Spring Boot",
projectDescription: `Takes an opinionated view of building Spring applications and gets
you up and running as quickly as possible.`
},
{
iconClass: "logo-spring-framework",
projectTitle: "Spring Framework",
projectDescription: `Provides core support for dependency injection, transaction
management, web apps, data access, messaging and more.`
},
{
iconClass: "logo-spring-cloud-dataflow",
projectTitle: "Spring Cloud Data Flow",
projectDescription: `An orchestration service for composable data microservice
applications on modern runtimes.`
},
{
iconClass: "logo-spring-cloud",
projectTitle: "Spring Cloud",
projectDescription: `Provides a set of tools for common patterns in distributed
systems. Useful for building and deploying microservices.`
},
{
iconClass: "logo-spring-data",
projectTitle: "Spring Data",
projectDescription: `Provides a consistent approach to data access – relational,
non-relational, map-reduce, and beyond.`
},
{
iconClass: "logo-spring-integration",
projectTitle: "Spring Integration",
projectDescription: `Supports the well-known
<em>Enterprise Integration Patterns</em> via lightweight messaging
and declarative adapters.`
}
];
window.addEventListener("load", controller.initProjects());