home.js 12 KB

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