home.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  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 recentPostCards = document.getElementById("recent-post-cards")
  128. if (recentPostCards != null) {
  129. let el = recentPostCards.children;
  130. let maxHeight = 0;
  131. for (let i = 0; i < el.length; i++) {
  132. if (el[i].children[1].clientHeight > maxHeight) {
  133. maxHeight = el[i].children[1].clientHeight;
  134. }
  135. }
  136. for (let i = 0; i < el.length; i++) {
  137. el[i].children[1].setAttribute("style", "min-height: " + maxHeight + "px;")
  138. }
  139. }
  140. }
  141. }
  142. adjustRecentPostsHeight();
  143. // =============== Achievements ===========
  144. function fourColumRow(gallery, entries, i) {
  145. let entry1 = document.createElement("div");
  146. entry1.classList.add("col-lg-6", "m-0", "p-0");
  147. entry1.appendChild(entries[i].cloneNode(true));
  148. entry1.children[0].classList.add("img-type-1");
  149. gallery.appendChild(entry1);
  150. i++;
  151. let entry2 = document.createElement("div");
  152. entry2.classList.add("col-lg-3", "m-0", "p-0");
  153. entry2.appendChild(entries[i].cloneNode(true));
  154. entry2.children[0].classList.add("img-type-1");
  155. gallery.appendChild(entry2);
  156. i++;
  157. let entry3 = document.createElement("div");
  158. entry3.classList.add("col-lg-3", "m-0", "p-0");
  159. entry3.appendChild(entries[i].cloneNode(true));
  160. entry3.children[0].classList.add("img-type-2");
  161. i++;
  162. entry3.appendChild(entries[i].cloneNode(true));
  163. entry3.children[1].classList.add("img-type-2");
  164. gallery.appendChild(entry3);
  165. i++;
  166. }
  167. function fourColumnReversedRow(gallery, entries, i) {
  168. let entry1 = document.createElement("div");
  169. entry1.classList.add("col-lg-3", "m-0", "p-0");
  170. entry1.appendChild(entries[i].cloneNode(true));
  171. entry1.children[0].classList.add("img-type-2");
  172. i++;
  173. entry1.appendChild(entries[i].cloneNode(true));
  174. entry1.children[1].classList.add("img-type-2");
  175. gallery.appendChild(entry1);
  176. i++;
  177. let entry2 = document.createElement("div");
  178. entry2.classList.add("col-lg-3", "m-0", "p-0");
  179. entry2.appendChild(entries[i].cloneNode(true));
  180. entry2.children[0].classList.add("img-type-1");
  181. gallery.appendChild(entry2);
  182. i++;
  183. let entry3 = document.createElement("div");
  184. entry3.classList.add("col-lg-6", "m-0", "p-0");
  185. entry3.appendChild(entries[i].cloneNode(true));
  186. entry3.children[0].classList.add("img-type-1");
  187. gallery.appendChild(entry3);
  188. i++;
  189. }
  190. function threeColumnRow(gallery, entries, i) {
  191. console.log(i);
  192. let entry1 = document.createElement("div");
  193. entry1.classList.add("col-lg-6", "col-md-6", "m-0", "p-0");
  194. entry1.appendChild(entries[i].cloneNode(true));
  195. entry1.children[0].classList.add("img-type-1");
  196. gallery.appendChild(entry1);
  197. i++;
  198. let entry2 = document.createElement("div");
  199. entry2.classList.add("col-lg-3", "col-md-3", "m-0", "p-0");
  200. entry2.appendChild(entries[i].cloneNode(true));
  201. entry2.children[0].classList.add("img-type-1");
  202. gallery.appendChild(entry2);
  203. i++;
  204. let entry3 = document.createElement("div");
  205. entry3.classList.add("col-lg-3", "col-md-3", "m-0", "p-0");
  206. entry3.appendChild(entries[i].cloneNode(true));
  207. entry3.children[0].classList.add("img-type-1");
  208. gallery.appendChild(entry3);
  209. i++;
  210. }
  211. function threeColumnReversedRow(gallery, entries, i) {
  212. let entry1 = document.createElement("div");
  213. entry1.classList.add("col-lg-3", "col-md-3", "m-0", "p-0");
  214. entry1.appendChild(entries[i].cloneNode(true));
  215. entry1.children[0].classList.add("img-type-1");
  216. gallery.appendChild(entry1);
  217. i++;
  218. let entry2 = document.createElement("div");
  219. entry2.classList.add("col-lg-3", "col-md-3", "m-0", "p-0");
  220. entry2.appendChild(entries[i].cloneNode(true));
  221. entry2.children[0].classList.add("img-type-1");
  222. gallery.appendChild(entry2);
  223. i++;
  224. let entry3 = document.createElement("div");
  225. entry3.classList.add("col-lg-6", "col-md-3", "m-0", "p-0");
  226. entry3.appendChild(entries[i].cloneNode(true));
  227. entry3.children[0].classList.add("img-type-1");
  228. gallery.appendChild(entry3);
  229. i++;
  230. }
  231. function twoColumnRow(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. let entry2 = document.createElement("div");
  239. entry2.classList.add("col-lg-6", "col-md-6", "m-0", "p-0");
  240. entry2.appendChild(entries[i].cloneNode(true));
  241. entry2.children[0].classList.add("img-type-1");
  242. gallery.appendChild(entry2);
  243. i++;
  244. }
  245. function singleColumnRow(gallery, entries, i) {
  246. let entry1 = document.createElement("div");
  247. entry1.classList.add("col-lg-6", "col-md-6", "m-0", "p-0");
  248. entry1.appendChild(entries[i].cloneNode(true));
  249. entry1.children[0].classList.add("img-type-1");
  250. gallery.appendChild(entry1);
  251. i++;
  252. }
  253. function showAchievements() {
  254. // show achievements from achievements-holder div
  255. let gallery = document.getElementById("gallery");
  256. if (gallery == null) {
  257. return
  258. }
  259. gallery.innerHTML = "";
  260. const entries = document.getElementById("achievements-holder").children;
  261. let len = entries.length;
  262. let i = 0;
  263. let rowNumber = 1;
  264. while (i < len) {
  265. if (isLaptop) {
  266. if (i + 4 <= len) {
  267. if (rowNumber % 2) {
  268. fourColumRow(gallery, entries, i);
  269. } else {
  270. fourColumnReversedRow(gallery, entries, i);
  271. }
  272. i += 4;
  273. } else if (i + 3 <= len) {
  274. if (rowNumber % 2) {
  275. threeColumnRow(gallery, entries, i);
  276. } else {
  277. threeColumnReversedRow(gallery, entries, i);
  278. }
  279. i += 3;
  280. } else if (i + 2 <= len) {
  281. twoColumnRow(gallery, entries, i);
  282. i += 2;
  283. } else {
  284. singleColumnRow(gallery, entries, i);
  285. i++;
  286. }
  287. } else if (isTablet) {
  288. if (i + 2 <= len) {
  289. twoColumnRow(gallery, entries, i);
  290. i += 2;
  291. } else {
  292. singleColumnRow(gallery, entries, i);
  293. i++;
  294. }
  295. } else {
  296. singleColumnRow(gallery, entries, i);
  297. i++;
  298. }
  299. rowNumber++;
  300. }
  301. // show full image on click
  302. let elements = document.getElementsByClassName("achievement-entry");
  303. len = elements.length;
  304. for (let i = 0; i < len; i++) {
  305. elements[i].onclick = function () {
  306. let achievements = document.getElementsByClassName("achievement-entry");
  307. let len2 = achievements.length;
  308. for (let j = 0; j < len2; j++) {
  309. achievements[j].classList.toggle("hidden");
  310. }
  311. this.classList.toggle("achievement-details");
  312. this.classList.toggle("hidden");
  313. this.parentElement.classList.toggle("col-lg-12");
  314. this.parentElement.classList.toggle("col-md-12");
  315. this.parentElement.classList.toggle("col-sm-12");
  316. if (this.children["caption"] != undefined) {
  317. this.children["caption"].classList.toggle("hidden");
  318. }
  319. if (this.children["enlarge-icon"] != undefined) {
  320. this.children["enlarge-icon"].classList.toggle("fa-search-plus");
  321. this.children["enlarge-icon"].classList.toggle("fa-times");
  322. }
  323. if (this.children["achievement-title"] != undefined) {
  324. this.children["achievement-title"].classList.toggle("hidden");
  325. }
  326. }
  327. }
  328. }
  329. showAchievements();
  330. // re-render custom functions on window resize
  331. window.onresize = function () {
  332. detectDevice();
  333. adjustSkillCardsHeight();
  334. adjustRecentPostsHeight();
  335. showAchievements();
  336. };
  337. });
  338. })(jQuery);