home.js 12 KB

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