home.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  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 filterButtons = document.getElementById("project-filter-buttons");
  98. if (filterButtons != null) {
  99. var btns = filterButtons.children;
  100. for (let i = 0; i < btns.length; i++) {
  101. btns[i].onclick = function () {
  102. showGithubStars(btns[i].id);
  103. }
  104. }
  105. }
  106. var projectCardHolder = document.getElementById("project-card-holder");
  107. if (projectCardHolder != null && projectCardHolder.children.length != 0) {
  108. projectCards = $(".filtr-projects").filterizr({ layout: 'sameWidth' });
  109. }
  110. function showGithubStars() {
  111. // fix the github button class
  112. // we had set it to github-button-inactive in projects holder cards so that respective javascript
  113. // don't render it and replace respective span with shadow root
  114. let githubButtons = document.getElementsByClassName("github-button-inactive");
  115. while (githubButtons.length > 0) {
  116. if (githubButtons[0].classList != undefined) {
  117. githubButtons[0].classList.replace("github-button-inactive", "github-button");
  118. }
  119. }
  120. // now render github button. it will call the github API and fill the respective fields
  121. renderGithubButton();
  122. }
  123. showGithubStars();
  124. // ==================== Adjust height of the recent-posts card =============
  125. function adjustRecentPostsHeight() {
  126. if (!isMobile) { // no need to adjust height for mobile devices
  127. let el = document.getElementById("recent-post-cards").children;
  128. let maxHeight = 0;
  129. for (let i = 0; i < el.length; i++) {
  130. if (el[i].children[1].clientHeight > maxHeight) {
  131. maxHeight = el[i].children[1].clientHeight;
  132. }
  133. }
  134. for (let i = 0; i < el.length; i++) {
  135. el[i].children[1].setAttribute("style", "min-height: " + maxHeight + "px;")
  136. }
  137. }
  138. }
  139. adjustRecentPostsHeight();
  140. // =============== Achievements ===========
  141. function fourColumRow(gallery, entries, i) {
  142. let entry1 = document.createElement("div");
  143. entry1.classList.add("col-lg-6", "m-0", "p-0");
  144. entry1.appendChild(entries[i].cloneNode(true));
  145. entry1.children[0].classList.add("img-type-1");
  146. gallery.appendChild(entry1);
  147. i++;
  148. let entry2 = document.createElement("div");
  149. entry2.classList.add("col-lg-3", "m-0", "p-0");
  150. entry2.appendChild(entries[i].cloneNode(true));
  151. entry2.children[0].classList.add("img-type-1");
  152. gallery.appendChild(entry2);
  153. i++;
  154. let entry3 = document.createElement("div");
  155. entry3.classList.add("col-lg-3", "m-0", "p-0");
  156. entry3.appendChild(entries[i].cloneNode(true));
  157. entry3.children[0].classList.add("img-type-2");
  158. i++;
  159. entry3.appendChild(entries[i].cloneNode(true));
  160. entry3.children[1].classList.add("img-type-2");
  161. gallery.appendChild(entry3);
  162. i++;
  163. }
  164. function fourColumnReversedRow(gallery, entries, i) {
  165. let entry1 = document.createElement("div");
  166. entry1.classList.add("col-lg-3", "m-0", "p-0");
  167. entry1.appendChild(entries[i].cloneNode(true));
  168. entry1.children[0].classList.add("img-type-2");
  169. i++;
  170. entry1.appendChild(entries[i].cloneNode(true));
  171. entry1.children[1].classList.add("img-type-2");
  172. gallery.appendChild(entry1);
  173. i++;
  174. let entry2 = document.createElement("div");
  175. entry2.classList.add("col-lg-3", "m-0", "p-0");
  176. entry2.appendChild(entries[i].cloneNode(true));
  177. entry2.children[0].classList.add("img-type-1");
  178. gallery.appendChild(entry2);
  179. i++;
  180. let entry3 = document.createElement("div");
  181. entry3.classList.add("col-lg-6", "m-0", "p-0");
  182. entry3.appendChild(entries[i].cloneNode(true));
  183. entry3.children[0].classList.add("img-type-1");
  184. gallery.appendChild(entry3);
  185. i++;
  186. }
  187. function threeColumnRow(gallery, entries, i) {
  188. console.log(i);
  189. let entry1 = document.createElement("div");
  190. entry1.classList.add("col-lg-6", "col-md-6", "m-0", "p-0");
  191. entry1.appendChild(entries[i].cloneNode(true));
  192. entry1.children[0].classList.add("img-type-1");
  193. gallery.appendChild(entry1);
  194. i++;
  195. let entry2 = document.createElement("div");
  196. entry2.classList.add("col-lg-3", "col-md-3", "m-0", "p-0");
  197. entry2.appendChild(entries[i].cloneNode(true));
  198. entry2.children[0].classList.add("img-type-1");
  199. gallery.appendChild(entry2);
  200. i++;
  201. let entry3 = document.createElement("div");
  202. entry3.classList.add("col-lg-3", "col-md-3", "m-0", "p-0");
  203. entry3.appendChild(entries[i].cloneNode(true));
  204. entry3.children[0].classList.add("img-type-1");
  205. gallery.appendChild(entry3);
  206. i++;
  207. }
  208. function threeColumnReversedRow(gallery, entries, i) {
  209. let entry1 = document.createElement("div");
  210. entry1.classList.add("col-lg-3", "col-md-3", "m-0", "p-0");
  211. entry1.appendChild(entries[i].cloneNode(true));
  212. entry1.children[0].classList.add("img-type-1");
  213. gallery.appendChild(entry1);
  214. i++;
  215. let entry2 = document.createElement("div");
  216. entry2.classList.add("col-lg-3", "col-md-3", "m-0", "p-0");
  217. entry2.appendChild(entries[i].cloneNode(true));
  218. entry2.children[0].classList.add("img-type-1");
  219. gallery.appendChild(entry2);
  220. i++;
  221. let entry3 = document.createElement("div");
  222. entry3.classList.add("col-lg-6", "col-md-3", "m-0", "p-0");
  223. entry3.appendChild(entries[i].cloneNode(true));
  224. entry3.children[0].classList.add("img-type-1");
  225. gallery.appendChild(entry3);
  226. i++;
  227. }
  228. function twoColumnRow(gallery, entries, i) {
  229. let entry1 = document.createElement("div");
  230. entry1.classList.add("col-lg-6", "col-md-6", "m-0", "p-0");
  231. entry1.appendChild(entries[i].cloneNode(true));
  232. entry1.children[0].classList.add("img-type-1");
  233. gallery.appendChild(entry1);
  234. i++;
  235. let entry2 = document.createElement("div");
  236. entry2.classList.add("col-lg-6", "col-md-6", "m-0", "p-0");
  237. entry2.appendChild(entries[i].cloneNode(true));
  238. entry2.children[0].classList.add("img-type-1");
  239. gallery.appendChild(entry2);
  240. i++;
  241. }
  242. function singleColumnRow(gallery, entries, i) {
  243. let entry1 = document.createElement("div");
  244. entry1.classList.add("col-lg-6", "col-md-6", "m-0", "p-0");
  245. entry1.appendChild(entries[i].cloneNode(true));
  246. entry1.children[0].classList.add("img-type-1");
  247. gallery.appendChild(entry1);
  248. i++;
  249. }
  250. function showAchievements() {
  251. // show achievements from achievements-holder div
  252. let gallery = document.getElementById("gallery");
  253. if (gallery == null) {
  254. return
  255. }
  256. gallery.innerHTML = "";
  257. const entries = document.getElementById("achievements-holder").children;
  258. let len = entries.length;
  259. let i = 0;
  260. let rowNumber = 1;
  261. while (i < len) {
  262. if (isLaptop) {
  263. if (i + 4 <= len) {
  264. if (rowNumber % 2) {
  265. fourColumRow(gallery, entries, i);
  266. } else {
  267. fourColumnReversedRow(gallery, entries, i);
  268. }
  269. i += 4;
  270. } else if (i + 3 <= len) {
  271. if (rowNumber % 2) {
  272. threeColumnRow(gallery, entries, i);
  273. } else {
  274. threeColumnReversedRow(gallery, entries, i);
  275. }
  276. i += 3;
  277. } else if (i + 2 <= len) {
  278. twoColumnRow(gallery, entries, i);
  279. i += 2;
  280. } else {
  281. singleColumnRow(gallery, entries, i);
  282. i++;
  283. }
  284. } else if (isTablet) {
  285. if (i + 2 <= len) {
  286. twoColumnRow(gallery, entries, i);
  287. i += 2;
  288. } else {
  289. singleColumnRow(gallery, entries, i);
  290. i++;
  291. }
  292. } else {
  293. singleColumnRow(gallery, entries, i);
  294. i++;
  295. }
  296. rowNumber++;
  297. }
  298. // show full image on click
  299. let elements = document.getElementsByClassName("achievement-entry");
  300. len = elements.length;
  301. for (let i = 0; i < len; i++) {
  302. elements[i].onclick = function () {
  303. let achievements = document.getElementsByClassName("achievement-entry");
  304. let len2 = achievements.length;
  305. for (let j = 0; j < len2; j++) {
  306. achievements[j].classList.toggle("hidden");
  307. }
  308. this.classList.toggle("achievement-details");
  309. this.classList.toggle("hidden");
  310. this.parentElement.classList.toggle("col-lg-12");
  311. this.parentElement.classList.toggle("col-md-12");
  312. this.parentElement.classList.toggle("col-sm-12");
  313. if (this.children["caption"] != undefined) {
  314. this.children["caption"].classList.toggle("hidden");
  315. }
  316. if (this.children["enlarge-icon"] != undefined) {
  317. this.children["enlarge-icon"].classList.toggle("fa-search-plus");
  318. this.children["enlarge-icon"].classList.toggle("fa-times");
  319. }
  320. if (this.children["achievement-title"] != undefined) {
  321. this.children["achievement-title"].classList.toggle("hidden");
  322. }
  323. }
  324. }
  325. }
  326. showAchievements();
  327. // re-render custom functions on window resize
  328. window.onresize = function () {
  329. detectDevice();
  330. adjustSkillCardsHeight();
  331. adjustRecentPostsHeight();
  332. showAchievements();
  333. };
  334. });
  335. })(jQuery);