fullmooncss
Version:
Front-end framework with a built-in dark mode and full customizability using CSS variables; great for building dashboards and tools
3 lines (2 loc) • 10.4 kB
JavaScript
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e||self).fullmooncss=t()}(this,function(){Element.prototype.matches||(Element.prototype.matches=Element.prototype.msMatchesSelector||Element.prototype.webkitMatchesSelector),Element.prototype.closest||(Element.prototype.closest=function(e){var t=this;do{if(t.matches(e))return t;t=t.parentElement||t.parentNode}while(null!==t&&1===t.nodeType);return null}),"document"in self&&("classList"in document.createElement("_")&&(!document.createElementNS||"classList"in document.createElementNS("http://www.w3.org/2000/svg","g"))||function(e){if("Element"in e){var t="classList",a="prototype",o=e.Element[a],s=Object,i=String[a].trim||function(){return this.replace(/^\s+|\s+$/g,"")},n=Array[a].indexOf||function(e){for(var t=0,a=this.length;a>t;t++)if(t in this&&this[t]===e)return t;return-1},r=function(e,t){this.name=e,this.code=DOMException[e],this.message=t},d=function(e,t){if(""===t)throw new r("SYNTAX_ERR","The token must not be empty.");if(/\s/.test(t))throw new r("INVALID_CHARACTER_ERR","The token must not contain space characters.");return n.call(e,t)},l=function(e){for(var t=i.call(e.getAttribute("class")||""),a=t?t.split(/\s+/):[],o=0,s=a.length;s>o;o++)this.push(a[o]);this._updateClassName=function(){e.setAttribute("class",this.toString())}},c=l[a]=[],m=function(){return new l(this)};if(r[a]=Error[a],c.item=function(e){return this[e]||null},c.contains=function(e){return~d(this,e+"")},c.add=function(){var e,t=arguments,a=0,o=t.length,s=!1;do{~d(this,e=t[a]+"")||(this.push(e),s=!0)}while(++a<o);s&&this._updateClassName()},c.remove=function(){var e,t,a=arguments,o=0,s=a.length,i=!1;do{for(t=d(this,e=a[o]+"");~t;)this.splice(t,1),i=!0,t=d(this,e)}while(++o<s);i&&this._updateClassName()},c.toggle=function(e,t){var a=this.contains(e),o=a?!0!==t&&"remove":!1!==t&&"add";return o&&this[o](e),!0===t||!1===t?t:!a},c.replace=function(e,t){var a=d(e+"");~a&&(this.splice(a,1,t),this._updateClassName())},c.toString=function(){return this.join(" ")},s.defineProperty){var u={get:m,enumerable:!0,configurable:!0};try{s.defineProperty(o,t,u)}catch(e){void 0!==e.number&&-2146823252!==e.number||(u.enumerable=!1,s.defineProperty(o,t,u))}}else s[a].__defineGetter__&&o.__defineGetter__(t,m)}}(self),function(){var e=document.createElement("_");if(e.classList.add("c1","c2"),!e.classList.contains("c2")){var t=function(e){var t=DOMTokenList.prototype[e];DOMTokenList.prototype[e]=function(e){var a,o=arguments.length;for(a=0;o>a;a++)t.call(this,e=arguments[a])}};t("add"),t("remove")}if(e.classList.toggle("c3",!1),e.classList.contains("c3")){var a=DOMTokenList.prototype.toggle;DOMTokenList.prototype.toggle=function(e,t){return 1 in arguments&&!this.contains(e)==!t?t:a.call(this,e)}}"replace"in document.createElement("_").classList||(DOMTokenList.prototype.replace=function(e,t){var a=this.toString().split(" "),o=a.indexOf(e+"");~o&&(a=a.slice(o),this.remove.apply(this,a),this.add(t),this.add.apply(this,a.slice(1)))}),e=null}());var e={pageWrapper:document.getElementsByClassName("page-wrapper")[0],stickyAlerts:document.getElementsByClassName("sticky-alerts")[0],darkModeOn:!1,createCookie:function(e,t,a){var o;if(a){var s=new Date;s.setTime(s.getTime()+24*a*60*60*1e3),o="; expires="+s.toGMTString()}else o="";document.cookie=e+"="+t+o+"; path=/"},readCookie:function(e){for(var t=e+"=",a=document.cookie.split(";"),o=0;o<a.length;o++){for(var s=a[o];" "===s.charAt(0);)s=s.substring(1,s.length);if(0===s.indexOf(t))return s.substring(t.length,s.length)}return null},eraseCookie:function(e){this.createCookie(e,"",-1)},toggleDarkMode:function(){document.body.classList.contains("dark-mode")?(document.body.classList.remove("dark-mode"),this.darkModeOn=!1,this.createCookie("halfmoon_preferredMode","light-mode",365)):(document.body.classList.add("dark-mode"),this.darkModeOn=!0,this.createCookie("halfmoon_preferredMode","dark-mode",365))},getPreferredMode:function(){return this.readCookie("halfmoon_preferredMode")?this.readCookie("halfmoon_preferredMode"):"not-set"},toggleSidebar:function(){this.pageWrapper&&(this.pageWrapper.getAttribute("data-sidebar-hidden")?this.pageWrapper.removeAttribute("data-sidebar-hidden"):this.pageWrapper.setAttribute("data-sidebar-hidden","hidden"))},deactivateAllDropdownToggles:function(){for(var e=document.querySelectorAll("[data-toggle='dropdown'].active"),t=0;t<e.length;t++)e[t].classList.remove("active"),e[t].closest(".dropdown").classList.remove("show")},toggleModal:function(e){var t=document.getElementById(e);t&&t.classList.toggle("show")},makeId:function(e){for(var t="",a="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",o=a.length,s=0;s<e;s++)t+=a.charAt(Math.floor(Math.random()*o));return t},toastAlert:function(e,t){var a=document.getElementById(e);if(void 0===t&&(t=5e3),!a.classList.contains("show")){a.classList.contains("alert-block")||a.classList.add("alert-block"),setTimeout(function(){a.classList.add("show")},250);var o=t+250;setTimeout(function(){a.classList.add("fade")},o),setTimeout(function(){a.classList.remove("alert-block"),a.classList.remove("show"),a.classList.remove("fade")},o+500)}},initStickyAlert:function(e){var t="content"in e?e.content:"",a="title"in e?e.title:"",o="alertType"in e?e.alertType:"",s="fillType"in e?e.fillType:"",i=!("hasDismissButton"in e)||e.hasDismissButton,n="timeShown"in e?e.timeShown:5e3,r=document.createElement("div");r.setAttribute("id",this.makeId(6)),a&&(t="<h4 class='alert-heading'>"+a+"</h4>"+t),r.classList.add("alert"),o&&r.classList.add(o),s&&r.classList.add(s),i&&(t="<button class='close' data-dismiss='alert' type='button' aria-label='Close'><span aria-hidden='true'>×</span></button>"+t),r.innerHTML=t,this.stickyAlerts.insertBefore(r,this.stickyAlerts.childNodes[0]),this.toastAlert(r.getAttribute("id"),n)},clickHandler:function(e){},keydownHandler:function(e){},onDOMContentLoaded:function(){e.pageWrapper||(e.pageWrapper=document.getElementsByClassName("page-wrapper")[0]),e.stickyAlerts||(e.stickyAlerts=document.getElementsByClassName("sticky-alerts")[0]),e.darkModeOn=e.readCookie("halfmoon_preferredMode")?"dark-mode"==e.readCookie("halfmoon_preferredMode"):!(!window.matchMedia||!window.matchMedia("(prefers-color-scheme: dark)").matches)||!!document.body.classList.contains("dark-mode"),(document.body.getAttribute("data-set-preferred-mode-onload")||document.body.getAttribute("data-set-preferred-theme-onload"))&&(e.darkModeOn?document.body.classList.contains("dark-mode")||document.body.classList.add("dark-mode"):document.body.classList.contains("dark-mode")&&document.body.classList.remove("dark-mode")),document.documentElement.clientWidth<=768?e.pageWrapper&&(e.pageWrapper.getAttribute("data-show-sidebar-onload-sm-and-down")||e.pageWrapper.setAttribute("data-sidebar-hidden","hidden")):e.pageWrapper&&"overlayed-all"===e.pageWrapper.getAttribute("data-sidebar-type")&&e.pageWrapper.setAttribute("data-sidebar-hidden","hidden"),document.addEventListener("click",function(t){var a=t,o=t.target;if(o.matches("[data-toggle='dropdown']")||o.matches("[data-toggle='dropdown'] *")?(o.matches("[data-toggle='dropdown'] *")&&(o=o.closest("[data-toggle='dropdown']")),o.classList.contains("active")?(o.classList.remove("active"),o.closest(".dropdown").classList.remove("show")):(e.deactivateAllDropdownToggles(),o.classList.add("active"),o.closest(".dropdown").classList.add("show"))):o.matches(".dropdown-menu *")||e.deactivateAllDropdownToggles(),(o.matches(".alert [data-dismiss='alert']")||o.matches(".alert [data-dismiss='alert'] *"))&&(o.matches(".alert [data-dismiss='alert'] *")&&(o=o.closest(".alert [data-dismiss='alert']")),o.parentNode.classList.add("dispose")),o.matches("[data-toggle='modal']")||o.matches("[data-toggle='modal'] *")){o.matches("[data-toggle='modal'] *")&&(o=o.closest("[data-toggle='modal']"));var s=document.getElementById(o.getAttribute("data-target"));s&&s.classList.contains("modal")&&e.toggleModal(o.getAttribute("data-target"))}if((o.matches(".modal [data-dismiss='modal']")||o.matches(".modal [data-dismiss='modal'] *"))&&(o.matches(".modal [data-dismiss='modal'] *")&&(o=o.closest(".modal [data-dismiss='modal']")),o.closest(".modal").classList.remove("show")),o.matches(".modal-dialog")){var i=o.closest(".modal");i.getAttribute("data-overlay-dismissal-disabled")||(i.classList.contains("show")?i.classList.remove("show"):window.location.hash="#")}e.clickHandler(a)},!1),document.addEventListener("keydown",function(t){var a=t;if(!(document.querySelector("input:focus")||document.querySelector("textarea:focus")||document.querySelector("select:focus")||(t=t||window.event).ctrlKey||t.metaKey)){if(document.body.getAttribute("data-sidebar-shortcut-enabled")&&t.shiftKey&&83==t.which){var o=!1;if(window.location.hash){var s=window.location.hash.substring(1);(i=document.getElementById(s))&&i.classList.contains("modal")&&(o=!0)}document.querySelector(".modal.show")&&(o=!0),o||(e.toggleSidebar(),t.preventDefault())}document.body.getAttribute("data-dm-shortcut-enabled")&&t.shiftKey&&68==t.which&&(e.toggleDarkMode(),t.preventDefault())}if(27===t.which)if(document.querySelector("[data-toggle='dropdown'].active"))(i=document.querySelector("[data-toggle='dropdown'].active")).classList.remove("active"),i.closest(".dropdown").classList.remove("show"),t.preventDefault();else{var i;window.location.hash&&(s=window.location.hash.substring(1),(i=document.getElementById(s))&&i.classList.contains("modal")&&(i.getAttribute("data-esc-dismissal-disabled")||(window.location.hash="#",t.preventDefault()))),document.querySelector(".modal.show")&&((i=document.querySelector(".modal.show")).getAttribute("data-esc-dismissal-disabled")||(i.classList.remove("show"),t.preventDefault()))}e.keydownHandler(a)});for(var t=document.querySelectorAll(".custom-file input"),a=0;a<t.length;a++){var o=t[a],s=document.createElement("div");s.classList.add("file-names");var i=o.getAttribute("data-default-value");s.innerHTML=i||"No file chosen",o.parentNode.appendChild(s),o.addEventListener("change",function(e){(s=e.target.parentNode.querySelector(".file-names")).innerHTML=1===e.target.files.length?e.target.files[0].name:e.target.files.length>1?e.target.files.length+" files":"No file chosen"})}e.pageWrapper&&e.pageWrapper.classList.add("with-transitions")}};return e});
//# sourceMappingURL=fullmoon.umd.js.map