home.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. "use strict";
  2. var projectCards;
  3. (function ($) {
  4. jQuery(document).ready(function () {
  5. var isMobile = false, isTablet = false, isLaptop = false;
  6. function detectDevice() {
  7. if (window.innerWidth <= 425) {
  8. isMobile = true;
  9. isTablet = false;
  10. isLaptop = false;
  11. } else if (window.innerWidth <= 768) {
  12. isMobile = false;
  13. isTablet = true;
  14. isLaptop = false;
  15. } else {
  16. isMobile = false;
  17. isTablet = false;
  18. isLaptop = true;
  19. }
  20. }
  21. detectDevice();
  22. // =========== Typing Carousel ================
  23. // get data from hidden ul and set as typing data
  24. if (document.getElementById('typing-carousel-data') != undefined) {
  25. var ul = document.getElementById('typing-carousel-data').children;
  26. if (ul.length != 0) {
  27. var data = [];
  28. Array.from(ul).forEach(el => {
  29. data.push(el.textContent);
  30. })
  31. ityped.init('#ityped', {
  32. strings: data,
  33. startDelay: 200,
  34. loop: true
  35. });
  36. }
  37. }
  38. // ================= Smooth Scroll ===================
  39. // Add smooth scrolling to all links
  40. $("a").on('click', function (event) {
  41. // Make sure this.hash has a value before overriding default behavior
  42. if (this.hash !== "") {
  43. // Prevent default anchor click behavior
  44. event.preventDefault();
  45. // Store hash
  46. var hash = this.hash;
  47. // Using jQuery's animate() method to add smooth page scroll
  48. // The optional number (800) specifies the number of milliseconds it takes to scroll to the specified area
  49. $('html, body').animate({
  50. scrollTop: $(hash).offset().top
  51. }, 800, function () {
  52. // Add hash (#) to URL when done scrolling (default click behavior)
  53. window.location.hash = hash;
  54. });
  55. } // End if
  56. });
  57. // ============== Fix Timelines Horizontal Lines =========
  58. var hLines = document.getElementsByClassName("horizontal-line");
  59. for (let i = 0; i < hLines.length; i++) {
  60. if (i % 2) {
  61. hLines[i].children[0].children[0].classList.add("bottom-right");
  62. hLines[i].children[2].children[0].classList.add("top-left");
  63. } else {
  64. hLines[i].children[0].children[0].classList.add("top-right");
  65. hLines[i].children[2].children[0].classList.add("bottom-left");
  66. }
  67. }
  68. // ============== Fix Timelines Vertical lines =========
  69. var vLines = document.getElementsByClassName("vertical-line");
  70. for (let i = 0; i < vLines.length; i++) {
  71. if (i % 2) {
  72. vLines[i].classList.add("vertical-line-left-adjustment");
  73. }
  74. }
  75. // ==================== Adjust height of the skills card =============
  76. function adjustSkillCardsHeight() {
  77. if (!isMobile) { // no need to adjust height for mobile devices
  78. // primary skills
  79. var skillCards = document.getElementById("primary-skills");
  80. if (skillCards != null) {
  81. var el = skillCards.children;
  82. var maxHeight = 0;
  83. for (let i = 0; i < el.length; i++) {
  84. if (el[i].children[0].clientHeight > maxHeight) {
  85. maxHeight = el[i].children[0].clientHeight;
  86. }
  87. }
  88. for (let i = 0; i < el.length; i++) {
  89. el[i].children[0].setAttribute("style", "min-height: " + maxHeight + "px;")
  90. }
  91. }
  92. }
  93. }
  94. adjustSkillCardsHeight();
  95. // ================== Project cards =====================
  96. // Add click action on project category selector buttons
  97. var btns = document.getElementById("project-filter-buttons").children;
  98. for (let i = 0; i < btns.length; i++) {
  99. btns[i].onclick = function () {
  100. showGithubStars(btns[i].id);
  101. }
  102. }
  103. if (document.getElementById("project-card-holder").children.length != 0) {
  104. projectCards = $(".filtr-projects").filterizr({ layout: 'sameWidth' });
  105. }
  106. function showGithubStars() {
  107. // fix the github button class
  108. // we had set it to github-button-inactive in projects holder cards so that respective javascript
  109. // don't render it and replace respective span with shadow root
  110. let githubButtons = document.getElementsByClassName("github-button-inactive");
  111. while (githubButtons.length > 0) {
  112. if (githubButtons[0].classList != undefined) {
  113. githubButtons[0].classList.replace("github-button-inactive", "github-button");
  114. }
  115. }
  116. // now render github button. it will call the github API and fill the respective fields
  117. renderGithubButton();
  118. }
  119. showGithubStars();
  120. // ==================== Adjust height of the recent-posts card =============
  121. function adjustRecentPostsHeight() {
  122. if (!isMobile) { // no need to adjust height for mobile devices
  123. let el = document.getElementById("recent-post-cards").children;
  124. let maxHeight = 0;
  125. for (let i = 0; i < el.length; i++) {
  126. if (el[i].children[1].clientHeight > maxHeight) {
  127. maxHeight = el[i].children[1].clientHeight;
  128. }
  129. }
  130. for (let i = 0; i < el.length; i++) {
  131. el[i].children[1].setAttribute("style", "min-height: " + maxHeight + "px;")
  132. }
  133. }
  134. }
  135. adjustRecentPostsHeight();
  136. // =============== Achievements ===========
  137. function fourColumRow(gallery, entries, i) {
  138. let entry1 = document.createElement("div");
  139. entry1.classList.add("col-lg-6", "m-0", "p-0");
  140. entry1.appendChild(entries[i].cloneNode(true));
  141. entry1.children[0].classList.add("img-type-1");
  142. gallery.appendChild(entry1);
  143. i++;
  144. let entry2 = document.createElement("div");
  145. entry2.classList.add("col-lg-3", "m-0", "p-0");
  146. entry2.appendChild(entries[i].cloneNode(true));
  147. entry2.children[0].classList.add("img-type-1");
  148. gallery.appendChild(entry2);
  149. i++;
  150. let entry3 = document.createElement("div");
  151. entry3.classList.add("col-lg-3", "m-0", "p-0");
  152. entry3.appendChild(entries[i].cloneNode(true));
  153. entry3.children[0].classList.add("img-type-2");
  154. i++;
  155. entry3.appendChild(entries[i].cloneNode(true));
  156. entry3.children[1].classList.add("img-type-2");
  157. gallery.appendChild(entry3);
  158. i++;
  159. }
  160. function fourColumnReversedRow(gallery, entries, i) {
  161. let entry1 = document.createElement("div");
  162. entry1.classList.add("col-lg-3", "m-0", "p-0");
  163. entry1.appendChild(entries[i].cloneNode(true));
  164. entry1.children[0].classList.add("img-type-2");
  165. i++;
  166. entry1.appendChild(entries[i].cloneNode(true));
  167. entry1.children[1].classList.add("img-type-2");
  168. gallery.appendChild(entry1);
  169. i++;
  170. let entry2 = document.createElement("div");
  171. entry2.classList.add("col-lg-3", "m-0", "p-0");
  172. entry2.appendChild(entries[i].cloneNode(true));
  173. entry2.children[0].classList.add("img-type-1");
  174. gallery.appendChild(entry2);
  175. i++;
  176. let entry3 = document.createElement("div");
  177. entry3.classList.add("col-lg-6", "m-0", "p-0");
  178. entry3.appendChild(entries[i].cloneNode(true));
  179. entry3.children[0].classList.add("img-type-1");
  180. gallery.appendChild(entry3);
  181. i++;
  182. }
  183. function threeColumnRow(gallery, entries, i) {
  184. console.log(i);
  185. let entry1 = document.createElement("div");
  186. entry1.classList.add("col-lg-6", "col-md-6", "m-0", "p-0");
  187. entry1.appendChild(entries[i].cloneNode(true));
  188. entry1.children[0].classList.add("img-type-1");
  189. gallery.appendChild(entry1);
  190. i++;
  191. let entry2 = document.createElement("div");
  192. entry2.classList.add("col-lg-3", "col-md-3", "m-0", "p-0");
  193. entry2.appendChild(entries[i].cloneNode(true));
  194. entry2.children[0].classList.add("img-type-1");
  195. gallery.appendChild(entry2);
  196. i++;
  197. let entry3 = document.createElement("div");
  198. entry3.classList.add("col-lg-3", "col-md-3", "m-0", "p-0");
  199. entry3.appendChild(entries[i].cloneNode(true));
  200. entry3.children[0].classList.add("img-type-1");
  201. gallery.appendChild(entry3);
  202. i++;
  203. }
  204. function threeColumnReversedRow(gallery, entries, i) {
  205. let entry1 = document.createElement("div");
  206. entry1.classList.add("col-lg-3", "col-md-3", "m-0", "p-0");
  207. entry1.appendChild(entries[i].cloneNode(true));
  208. entry1.children[0].classList.add("img-type-1");
  209. gallery.appendChild(entry1);
  210. i++;
  211. let entry2 = document.createElement("div");
  212. entry2.classList.add("col-lg-3", "col-md-3", "m-0", "p-0");
  213. entry2.appendChild(entries[i].cloneNode(true));
  214. entry2.children[0].classList.add("img-type-1");
  215. gallery.appendChild(entry2);
  216. i++;
  217. let entry3 = document.createElement("div");
  218. entry3.classList.add("col-lg-6", "col-md-3", "m-0", "p-0");
  219. entry3.appendChild(entries[i].cloneNode(true));
  220. entry3.children[0].classList.add("img-type-1");
  221. gallery.appendChild(entry3);
  222. i++;
  223. }
  224. function twoColumnRow(gallery, entries, i) {
  225. let entry1 = document.createElement("div");
  226. entry1.classList.add("col-lg-6", "col-md-6", "m-0", "p-0");
  227. entry1.appendChild(entries[i].cloneNode(true));
  228. entry1.children[0].classList.add("img-type-1");
  229. gallery.appendChild(entry1);
  230. i++;
  231. let entry2 = document.createElement("div");
  232. entry2.classList.add("col-lg-6", "col-md-6", "m-0", "p-0");
  233. entry2.appendChild(entries[i].cloneNode(true));
  234. entry2.children[0].classList.add("img-type-1");
  235. gallery.appendChild(entry2);
  236. i++;
  237. }
  238. function singleColumnRow(gallery, entries, i) {
  239. let entry1 = document.createElement("div");
  240. entry1.classList.add("col-lg-6", "col-md-6", "m-0", "p-0");
  241. entry1.appendChild(entries[i].cloneNode(true));
  242. entry1.children[0].classList.add("img-type-1");
  243. gallery.appendChild(entry1);
  244. i++;
  245. }
  246. function showAchievements() {
  247. // show achievements from achievements-holder div
  248. let gallery = document.getElementById("gallery");
  249. gallery.innerHTML = "";
  250. const entries = document.getElementById("achievements-holder").children;
  251. let len = entries.length;
  252. let i = 0;
  253. let rowNumber = 1;
  254. while (i < len) {
  255. if (isLaptop) {
  256. if (i + 4 <= len) {
  257. if (rowNumber % 2) {
  258. fourColumRow(gallery, entries, i);
  259. } else {
  260. fourColumnReversedRow(gallery, entries, i);
  261. }
  262. i += 4;
  263. } else if (i + 3 <= len) {
  264. if (rowNumber % 2) {
  265. threeColumnRow(gallery, entries, i);
  266. } else {
  267. threeColumnReversedRow(gallery, entries, i);
  268. }
  269. i += 3;
  270. } else if (i + 2 <= len) {
  271. twoColumnRow(gallery, entries, i);
  272. i += 2;
  273. } else {
  274. singleColumnRow(gallery, entries, i);
  275. i++;
  276. }
  277. } else if (isTablet) {
  278. if (i + 2 <= len) {
  279. twoColumnRow(gallery, entries, i);
  280. i += 2;
  281. } else {
  282. singleColumnRow(gallery, entries, i);
  283. i++;
  284. }
  285. } else {
  286. singleColumnRow(gallery, entries, i);
  287. i++;
  288. }
  289. rowNumber++;
  290. }
  291. // show full image on click
  292. let elements = document.getElementsByClassName("achievement-entry");
  293. len = elements.length;
  294. for (let i = 0; i < len; i++) {
  295. elements[i].onclick = function () {
  296. let achievements = document.getElementsByClassName("achievement-entry");
  297. let len2 = achievements.length;
  298. for (let j = 0; j < len2; j++) {
  299. achievements[j].classList.toggle("hidden");
  300. }
  301. this.classList.toggle("achievement-details");
  302. this.classList.toggle("hidden");
  303. this.parentElement.classList.toggle("col-lg-12");
  304. this.parentElement.classList.toggle("col-md-12");
  305. this.parentElement.classList.toggle("col-sm-12");
  306. if (this.children["caption"] != undefined) {
  307. this.children["caption"].classList.toggle("hidden");
  308. }
  309. if (this.children["enlarge-icon"] != undefined) {
  310. this.children["enlarge-icon"].classList.toggle("fa-search-plus");
  311. this.children["enlarge-icon"].classList.toggle("fa-times");
  312. }
  313. if (this.children["achievement-title"] != undefined) {
  314. this.children["achievement-title"].classList.toggle("hidden");
  315. }
  316. }
  317. }
  318. }
  319. showAchievements();
  320. // re-render custom functions on window resize
  321. window.onresize = function () {
  322. detectDevice();
  323. adjustSkillCardsHeight();
  324. adjustRecentPostsHeight();
  325. showAchievements();
  326. };
  327. });
  328. })(jQuery);