home.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  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 cardElems = skillCards.getElementsByClassName("card");
  63. var maxHeight = 0;
  64. for (let i = 0; i < cardElems.length; i++) {
  65. if (cardElems.item(i).clientHeight > maxHeight) {
  66. maxHeight = cardElems.item(i).clientHeight;
  67. }
  68. }
  69. for (let i = 0; i < cardElems.length; i++) {
  70. cardElems.item(i).setAttribute("style", "min-height: " + maxHeight + "px;");
  71. }
  72. }
  73. }
  74. }
  75. $(window).on("load", function () {
  76. adjustSkillCardsHeight();
  77. });
  78. // ================== Project cards =====================
  79. // Add click action on project category selector buttons
  80. var filterButtons = document.getElementById("project-filter-buttons");
  81. if (filterButtons != null) {
  82. var btns = filterButtons.children;
  83. for (let i = 0; i < btns.length; i++) {
  84. btns[i].onclick = function () {
  85. showGithubStars(btns[i].id);
  86. }
  87. }
  88. }
  89. var projectCardHolder = document.getElementById("project-card-holder");
  90. if (projectCardHolder != null && projectCardHolder.children.length != 0) {
  91. projectCards = $(".filtr-projects").filterizr({ layout: 'sameWidth' });
  92. }
  93. function showGithubStars() {
  94. // fix the github button class
  95. // we had set it to github-button-inactive in projects holder cards so that respective javascript
  96. // don't render it and replace respective span with shadow root
  97. let githubButtons = document.getElementsByClassName("github-button-inactive");
  98. while (githubButtons.length > 0) {
  99. if (githubButtons[0].classList != undefined) {
  100. githubButtons[0].classList.replace("github-button-inactive", "github-button");
  101. }
  102. }
  103. // now render github button. it will call the github API and fill the respective fields
  104. renderGithubButton();
  105. }
  106. showGithubStars();
  107. // ==================== Adjust height of the recent-posts card =============
  108. function adjustRecentPostsHeight() {
  109. if (!isMobile) { // no need to adjust height for mobile devices
  110. let recentPostCards = document.getElementById("recent-post-cards")
  111. if (recentPostCards != null) {
  112. let el = recentPostCards.children;
  113. let maxHeight = 0;
  114. for (let i = 0; i < el.length; i++) {
  115. if (el[i].children[1].clientHeight > maxHeight) {
  116. maxHeight = el[i].children[1].clientHeight;
  117. }
  118. }
  119. for (let i = 0; i < el.length; i++) {
  120. el[i].children[1].setAttribute("style", "min-height: " + maxHeight + "px;")
  121. }
  122. }
  123. }
  124. }
  125. adjustRecentPostsHeight();
  126. // =============== Achievements ===========
  127. function fourColumRow(gallery, entries, i) {
  128. let entry1 = document.createElement("div");
  129. entry1.classList.add("col-lg-6", "m-0", "p-0");
  130. entry1.appendChild(entries[i].cloneNode(true));
  131. entry1.children[0].classList.add("img-type-1");
  132. gallery.appendChild(entry1);
  133. i++;
  134. let entry2 = document.createElement("div");
  135. entry2.classList.add("col-lg-3", "m-0", "p-0");
  136. entry2.appendChild(entries[i].cloneNode(true));
  137. entry2.children[0].classList.add("img-type-1");
  138. gallery.appendChild(entry2);
  139. i++;
  140. let entry3 = document.createElement("div");
  141. entry3.classList.add("col-lg-3", "m-0", "p-0");
  142. entry3.appendChild(entries[i].cloneNode(true));
  143. entry3.children[0].classList.add("img-type-2");
  144. i++;
  145. entry3.appendChild(entries[i].cloneNode(true));
  146. entry3.children[1].classList.add("img-type-2");
  147. gallery.appendChild(entry3);
  148. i++;
  149. }
  150. function fourColumnReversedRow(gallery, entries, i) {
  151. let entry1 = document.createElement("div");
  152. entry1.classList.add("col-lg-3", "m-0", "p-0");
  153. entry1.appendChild(entries[i].cloneNode(true));
  154. entry1.children[0].classList.add("img-type-2");
  155. i++;
  156. entry1.appendChild(entries[i].cloneNode(true));
  157. entry1.children[1].classList.add("img-type-2");
  158. gallery.appendChild(entry1);
  159. i++;
  160. let entry2 = document.createElement("div");
  161. entry2.classList.add("col-lg-3", "m-0", "p-0");
  162. entry2.appendChild(entries[i].cloneNode(true));
  163. entry2.children[0].classList.add("img-type-1");
  164. gallery.appendChild(entry2);
  165. i++;
  166. let entry3 = document.createElement("div");
  167. entry3.classList.add("col-lg-6", "m-0", "p-0");
  168. entry3.appendChild(entries[i].cloneNode(true));
  169. entry3.children[0].classList.add("img-type-1");
  170. gallery.appendChild(entry3);
  171. i++;
  172. }
  173. function threeColumnRow(gallery, entries, i) {
  174. console.log(i);
  175. let entry1 = document.createElement("div");
  176. entry1.classList.add("col-lg-6", "col-md-6", "m-0", "p-0");
  177. entry1.appendChild(entries[i].cloneNode(true));
  178. entry1.children[0].classList.add("img-type-1");
  179. gallery.appendChild(entry1);
  180. i++;
  181. let entry2 = document.createElement("div");
  182. entry2.classList.add("col-lg-3", "col-md-3", "m-0", "p-0");
  183. entry2.appendChild(entries[i].cloneNode(true));
  184. entry2.children[0].classList.add("img-type-1");
  185. gallery.appendChild(entry2);
  186. i++;
  187. let entry3 = document.createElement("div");
  188. entry3.classList.add("col-lg-3", "col-md-3", "m-0", "p-0");
  189. entry3.appendChild(entries[i].cloneNode(true));
  190. entry3.children[0].classList.add("img-type-1");
  191. gallery.appendChild(entry3);
  192. i++;
  193. }
  194. function threeColumnReversedRow(gallery, entries, i) {
  195. let entry1 = document.createElement("div");
  196. entry1.classList.add("col-lg-3", "col-md-3", "m-0", "p-0");
  197. entry1.appendChild(entries[i].cloneNode(true));
  198. entry1.children[0].classList.add("img-type-1");
  199. gallery.appendChild(entry1);
  200. i++;
  201. let entry2 = document.createElement("div");
  202. entry2.classList.add("col-lg-3", "col-md-3", "m-0", "p-0");
  203. entry2.appendChild(entries[i].cloneNode(true));
  204. entry2.children[0].classList.add("img-type-1");
  205. gallery.appendChild(entry2);
  206. i++;
  207. let entry3 = document.createElement("div");
  208. entry3.classList.add("col-lg-6", "col-md-3", "m-0", "p-0");
  209. entry3.appendChild(entries[i].cloneNode(true));
  210. entry3.children[0].classList.add("img-type-1");
  211. gallery.appendChild(entry3);
  212. i++;
  213. }
  214. function twoColumnRow(gallery, entries, i) {
  215. let entry1 = document.createElement("div");
  216. entry1.classList.add("col-6", "m-0", "p-0");
  217. entry1.appendChild(entries[i].cloneNode(true));
  218. entry1.children[0].classList.add("img-type-1");
  219. gallery.appendChild(entry1);
  220. i++;
  221. let entry2 = document.createElement("div");
  222. entry2.classList.add("col-6", "m-0", "p-0");
  223. entry2.appendChild(entries[i].cloneNode(true));
  224. entry2.children[0].classList.add("img-type-1");
  225. gallery.appendChild(entry2);
  226. i++;
  227. }
  228. function singleColumnRow(gallery, entries, i) {
  229. let entry1 = document.createElement("div");
  230. entry1.classList.add("col-12", "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. }
  236. function showAchievements() {
  237. // show achievements from achievements-holder div
  238. let gallery = document.getElementById("gallery");
  239. if (gallery == null) {
  240. return
  241. }
  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["SmallImage"].hasAttribute("active")) {
  300. let mainLogo = this.children["LargeImage"].getAttribute("Style");
  301. this.children["LargeImage"].setAttribute("active",true);
  302. this.children["SmallImage"].removeAttribute("active");
  303. this.setAttribute("Style", mainLogo);
  304. } else {
  305. let mainLogo = this.children["SmallImage"].getAttribute("Style");
  306. this.children["SmallImage"].setAttribute("active",true);
  307. this.children["LargeImage"].removeAttribute("active");
  308. this.setAttribute("Style", mainLogo);
  309. }
  310. if (this.children["caption"] != undefined) {
  311. this.children["caption"].classList.toggle("hidden");
  312. }
  313. if (this.children["enlarge-icon"] != undefined) {
  314. this.children["enlarge-icon"].classList.toggle("fa-search-plus");
  315. this.children["enlarge-icon"].classList.toggle("fa-times");
  316. }
  317. if (this.children["achievement-title"] != undefined) {
  318. this.children["achievement-title"].classList.toggle("hidden");
  319. }
  320. }
  321. }
  322. }
  323. showAchievements();
  324. // re-render custom functions on window resize
  325. window.onresize = function () {
  326. detectDevice();
  327. adjustSkillCardsHeight();
  328. adjustRecentPostsHeight();
  329. showAchievements();
  330. };
  331. });
  332. })(jQuery);