home.js 12 KB

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