home.js 12 KB

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