home.js 12 KB

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