stefanbc/Asgar

View on GitHub
assets/js/index.js

Summary

Maintainability
A
0 mins
Test Coverage
parcelRequire=function(e,r,t,n){var i,o="function"==typeof parcelRequire&&parcelRequire,u="function"==typeof require&&require;function f(t,n){if(!r[t]){if(!e[t]){var i="function"==typeof parcelRequire&&parcelRequire;if(!n&&i)return i(t,!0);if(o)return o(t,!0);if(u&&"string"==typeof t)return u(t);var c=new Error("Cannot find module '"+t+"'");throw c.code="MODULE_NOT_FOUND",c}p.resolve=function(r){return e[t][1][r]||r},p.cache={};var l=r[t]=new f.Module(t);e[t][0].call(l.exports,p,l,l.exports,this)}return r[t].exports;function p(e){return f(p.resolve(e))}}f.isParcelRequire=!0,f.Module=function(e){this.id=e,this.bundle=f,this.exports={}},f.modules=e,f.cache=r,f.parent=o,f.register=function(r,t){e[r]=[function(e,r){r.exports=t},{}]};for(var c=0;c<t.length;c++)try{f(t[c])}catch(e){i||(i=e)}if(t.length){var l=f(t[t.length-1]);"object"==typeof exports&&"undefined"!=typeof module?module.exports=l:"function"==typeof define&&define.amd?define(function(){return l}):n&&(this[n]=l)}if(parcelRequire=f,i)throw i;return f}({"RR7p":[function(require,module,exports) {
"use strict";function e(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function t(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function n(e,n,r){return n&&t(e.prototype,n),r&&t(e,r),e}Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;var r=function(){function t(){e(this,t)}return n(t,[{key:"get",value:function(e,t){return t?t.querySelector(e):document.querySelector(e)}},{key:"getAll",value:function(e){return document.querySelectorAll(e)}},{key:"make",value:function(e,t){return t?t.createElement(e):document.createElement(e)}},{key:"has",value:function(e,t){return e.classList.contains(t)}},{key:"toggle",value:function(e,t){e.classList.toggle(t)}}]),t}();exports.default=r;
},{}],"VrKV":[function(require,module,exports) {
"use strict";function e(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function t(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function n(e,n,r){return n&&t(e.prototype,n),r&&t(e,r),e}Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;var r=function(){function t(){e(this,t)}return n(t,[{key:"get",value:function(e){return new Promise(function(t,n){var r=new XMLHttpRequest;r.onload=function(){r.status>=200&&r.status<300?t(JSON.parse(r.response)):n(r.status)},r.open("GET",e),r.send()})}}]),t}();exports.default=r;
},{}],"yzDb":[function(require,module,exports) {
"use strict";function e(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function t(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function r(e,r,n){return r&&t(e.prototype,r),n&&t(e,n),e}Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;var n=function(){function t(){e(this,t),this.storage=window.localStorage}return r(t,[{key:"get",value:function(e){return JSON.parse(this.storage.getItem(e))}},{key:"set",value:function(e,t){this.storage.setItem(e,JSON.stringify(t))}},{key:"remove",value:function(e){this.storage.removeItem(e)}}]),t}();exports.default=n;
},{}],"QJbV":[function(require,module,exports) {
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.GLOBALS=void 0;var o={api:"".concat(window.location.origin,"/custom/api")};exports.GLOBALS=o;
},{}],"pP8l":[function(require,module,exports) {
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.PAGES=void 0;var e=[{name:"about",childType:"col",childTemplate:'<a href="${url}" title="${name}" target="_blank" rel="noopener"><i class="${icon === "envelope" ? "fas" : "fab"} fa-${icon}" aria-hidden="true"></i></a>'},{name:"projects",childType:"row",childTemplate:'<td>${name}</td><td>${description}</td><td class="text-center"><a href="${url}" title="Fork ${name}" target="_blank"><i class="fas fa-code-branch"></i></a></td>'},{name:"speaking",childType:"row",childTemplate:'<td>${name}</td><td>${year}</td><td class="text-center"><div class="row">${slides ? `<div class="one-half column"><a href="${slides}" title="Slides"><i class="fas fa-file-powerpoint"></i></a></div>` : ""}${video ? `<div class="one-half column"><a href="${video}" title="Video"><i class="fas fa-video"></i></a></div>` : ""}${url ? `<div class="one-half column"><a href="${url}" title="More"><i class="fas fa-link"></i></a></div>` : ""}</div></td>'}];exports.PAGES=e;
},{}],"by1F":[function(require,module,exports) {
"use strict";function e(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function t(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function n(e,n,r){return n&&t(e.prototype,n),r&&t(e,r),e}Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;var r=function(){function t(){e(this,t)}return n(t,[{key:"getCurrentPageName",value:function(){return location.pathname.replace(/\//gi,"")}},{key:"checkSystemDarkMode",value:function(){return window.matchMedia&&window.matchMedia("(prefers-color-scheme: dark)").matches}}]),t}();exports.default=r;
},{}],"PxvA":[function(require,module,exports) {
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;var t=o(require("./services/dom")),e=o(require("./services/http")),n=o(require("./services/storage")),a=require("./common/globals"),r=require("./common/pages"),i=o(require("./common/utils"));function o(t){return t&&t.__esModule?t:{default:t}}function s(t,e,n){return(s=u()?Reflect.construct:function(t,e,n){var a=[null];a.push.apply(a,e);var r=new(Function.bind.apply(t,a));return n&&c(r,n.prototype),r}).apply(null,arguments)}function u(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch(t){return!1}}function c(t,e){return(c=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function l(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function d(t,e){for(var n=0;n<e.length;n++){var a=e[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(t,a.key,a)}}function h(t,e,n){return e&&d(t.prototype,e),n&&d(t,n),t}var f=function(){function o(){l(this,o),this.http=new e.default,this.dom=new t.default,this.storage=new n.default,this.globals=a.GLOBALS,this.pages=r.PAGES,this.utils=new i.default,this.data=""}return h(o,[{key:"init",value:function(){var t=this;document.addEventListener("DOMContentLoaded",function(){t._loadData(),t._loadEvents()})}},{key:"_loadData",value:function(){var t=this;this.getCurrentPage()&&(this.data=JSON.parse(this.storage.get("asg_data")),this.currentPage=this.getCurrentPage(),this.toggleLoading(),this.data?this.addData(this.data):this.http.get(this.globals.api).then(function(e){t.data=e,t.storage.set("asg_data",JSON.stringify(e)),t.addData(e)},function(t){console.log(t)}))}},{key:"_loadEvents",value:function(){this.darkModeEvent()}},{key:"darkModeEvent",value:function(){var t=this,e=this.dom.get(".color-switcher"),n=this.dom.get("body"),a=function(a){t.dom.toggle(e,"fa-flip-horizontal"),t.dom.toggle(n,"dark-mode"),t.storage.set("asg_dm",a)};(this.utils.checkSystemDarkMode()&&null===this.storage.get("asg_dm")||this.storage.get("asg_dm"))&&a(!0),e.addEventListener("click",function(){a(!t.dom.has(n,"dark-mode"))})}},{key:"addData",value:function(t){var e=this,n=this.dom.get(".".concat(this.currentPage.name,"-list"));if(this.currentPage&&n){this.currentPage.pageElement=n,this.currentPage.data=t[this.currentPage.name];var a=this.parseTemplate(this.currentPage.childTemplate);this.currentPage.data.forEach(function(t){e.addChildElement(a(t),e.currentPage.pageElement,e.currentPage.childType)})}}},{key:"addChildElement",value:function(t,e){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"row",a=this.dom.make("row"===n?"tr":"span");a.innerHTML=t,"row"===n?this.dom.get("tbody",e).appendChild(a):"col"===n&&e.appendChild(a)}},{key:"getCurrentPage",value:function(){var t=this;return this.pages.find(function(e){return e.name===t.utils.getCurrentPageName()})}},{key:"toggleLoading",value:function(){var t=this.dom.get(".fa-sync");t&&(t.style.display="none")}},{key:"parseTemplate",value:function(t){return function(e){var n=[],a=[];if(e){for(var r in e)n.push(r),a.push(e[r]);return s(Function,n.concat(["return `"+t+"`;"])).apply(void 0,a)}}}}]),o}();exports.default=f;
},{"./services/dom":"RR7p","./services/http":"VrKV","./services/storage":"yzDb","./common/globals":"QJbV","./common/pages":"pP8l","./common/utils":"by1F"}],"Focm":[function(require,module,exports) {
"use strict";var e=r(require("./asgar"));function r(e){return e&&e.__esModule?e:{default:e}}var t=new e.default;t.init();
},{"./asgar":"PxvA"}]},{},["Focm"], null)