Comparing version 0.1.8 to 0.1.9
# Changelog | ||
## 0.1.9 | ||
* change button position from absolute to fixed | ||
## 0.1.8 | ||
@@ -4,0 +8,0 @@ |
@@ -1,1 +0,1 @@ | ||
!function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).drkmdJs=t()}}((function(){return function t(e,o,n){function r(a,s){if(!o[a]){if(!e[a]){var c="function"==typeof require&&require;if(!s&&c)return c(a,!0);if(i)return i(a,!0);var d=new Error("Cannot find module '"+a+"'");throw d.code="MODULE_NOT_FOUND",d}var u=o[a]={exports:{}};e[a][0].call(u.exports,(function(t){return r(e[a][1][t]||t)}),u,u.exports,t,e,o,n)}return o[a].exports}for(var i="function"==typeof require&&require,a=0;a<n.length;a++)r(n[a]);return r}({1:[function(t,e,o){"use strict";function n(t,e){for(var o=0;o<e.length;o++){var n=e[o];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}Object.defineProperty(o,"__esModule",{value:!0}),o.default=o.IS_BROWSER=void 0;var r="undefined"!=typeof window;o.IS_BROWSER=r;var i=function(){function t(e){var o=this;if(function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),r){e=Object.assign({},{top:"unset",bottom:"20px",right:"20px",left:"unset",buttonLight:"#fff",buttonDark:"#000",events:!0,cookie:!1,localStorage:!0,label:"🌓",autoMatchOsTheme:!0},e),this.options=e,this.dark=!1,e.autoMatchOsTheme&&(window.matchMedia("(prefers-color-scheme: dark)").addListener((function(t){return t.matches&&o.switchThemePrefers()})),window.matchMedia("(prefers-color-scheme: light)").addListener((function(t){return t.matches&&o.switchThemePrefers()})));var n=e.localStorage?localStorage.getItem("darkmode"):e.cookie?this.getCookie():null;null!==n?"true"===n||!0===n?this.toDark():this.toLight():e.autoMatchOsTheme&&this.preferedTheme()?this.toDark():this.toLight()}else console.warn("Detected environment without a `window` object")}var e,o,i;return e=t,(o=[{key:"attach",value:function(){var t=this,e="\n .drkmd-toggle-button{\n position: absolute;\n z-index: 1000;\n left: ".concat(this.options.left,";\n right: ").concat(this.options.right,";\n bottom: ").concat(this.options.bottom,";\n top: ").concat(this.options.top,";\n height: 3rem;\n min-width: 3rem;\n border-radius: 3rem;\n display: flex;\n align-items: center;\n justify-content: center;\n background: ").concat(this.options.buttonDark,";\n color: ").concat(this.options.buttonLight,";\n cursor: pointer;\n }\n\n .drkmd-toggle-button span{\n margin: 0;\n padding: 0px 10px;\n }\n\n .theme-dark .drkmd-toggle-button{\n background: ").concat(this.options.buttonLight,";\n color: ").concat(this.options.buttonDark,"\n }\n "),o=document.createElement("div"),n=document.createElement("span");n.innerHTML=this.options.label,o.className="drkmd-toggle-button",o.setAttribute("title","Toggle dark mode"),o.setAttribute("aria-label","Toggle dark mode"),o.setAttribute("aria-checked","false"),o.setAttribute("role","checkbox"),o.appendChild(n),o.addEventListener("click",(function(){!0===t.dark?t.toLight():t.toDark()})),document.body.insertBefore(o,document.body.firstChild),this.addStyle(e)}},{key:"toLight",value:function(){this.options.events&&window.dispatchEvent(new CustomEvent("theme",{detail:{to:"light"}})),document.documentElement.setAttribute("data-theme","light"),this.options.localStorage?localStorage.setItem("darkmode",!1):this.options.cookie&&this.setCookie(!1),document.body.classList.remove("theme-dark"),document.body.classList.add("theme-light"),this.dark=!1}},{key:"toDark",value:function(){this.options.events&&window.dispatchEvent(new CustomEvent("theme",{detail:{to:"dark"}})),document.documentElement.setAttribute("data-theme","dark"),this.options.localStorage?localStorage.setItem("darkmode",!0):this.options.cookie&&this.setCookie(!0),document.body.classList.add("theme-dark"),document.body.classList.remove("theme-light"),this.dark=!0}},{key:"preferedTheme",value:function(){return window.matchMedia&&window.matchMedia("(prefers-color-scheme: dark)").matches}},{key:"switchThemePrefers",value:function(){!0===this.preferedTheme()?this.swichToDark():this.swichToLight()}},{key:"getCookie",value:function(){var t=document.cookie.match(RegExp("(?:^|;\\s*)darkmode=([^;]*)"));return t?t[1]:null}},{key:"setCookie",value:function(t){document.cookie="darkmode=".concat(t)}},{key:"toggle",value:function(){return this.dark?this.toLight():this.toDark(),this.dark}},{key:"isActivated",value:function(){return this.dark}},{key:"addStyle",value:function(t){var e=document.createElement("link");e.setAttribute("rel","stylesheet"),e.setAttribute("type","text/css"),e.setAttribute("href","data:text/css;charset=UTF-8,"+encodeURIComponent(t)),document.head.appendChild(e)}}])&&n(e.prototype,o),i&&n(e,i),t}();o.default=i},{}],2:[function(t,e,o){"use strict";function n(t){return(n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}Object.defineProperty(o,"__esModule",{value:!0}),o.default=void 0;var r=function(t){if(t&&t.__esModule)return t;if(null===t||"object"!==n(t)&&"function"!=typeof t)return{default:t};var e=i();if(e&&e.has(t))return e.get(t);var o={},r=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var a in t)if(Object.prototype.hasOwnProperty.call(t,a)){var s=r?Object.getOwnPropertyDescriptor(t,a):null;s&&(s.get||s.set)?Object.defineProperty(o,a,s):o[a]=t[a]}o.default=t,e&&e.set(t,o);return o}(t("./drkmd"));function i(){if("function"!=typeof WeakMap)return null;var t=new WeakMap;return i=function(){return t},t}var a=r.default;o.default=a,r.IS_BROWSER&&function(t){t.Darkmode=r.default}(window)},{"./drkmd":1}]},{},[2])(2)})); | ||
!function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).drkmdJs=t()}}((function(){return function t(e,o,n){function r(a,s){if(!o[a]){if(!e[a]){var c="function"==typeof require&&require;if(!s&&c)return c(a,!0);if(i)return i(a,!0);var d=new Error("Cannot find module '"+a+"'");throw d.code="MODULE_NOT_FOUND",d}var u=o[a]={exports:{}};e[a][0].call(u.exports,(function(t){return r(e[a][1][t]||t)}),u,u.exports,t,e,o,n)}return o[a].exports}for(var i="function"==typeof require&&require,a=0;a<n.length;a++)r(n[a]);return r}({1:[function(t,e,o){"use strict";function n(t,e){for(var o=0;o<e.length;o++){var n=e[o];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}Object.defineProperty(o,"__esModule",{value:!0}),o.default=o.IS_BROWSER=void 0;var r="undefined"!=typeof window;o.IS_BROWSER=r;var i=function(){function t(e){var o=this;if(function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),r){e=Object.assign({},{top:"unset",bottom:"20px",right:"20px",left:"unset",buttonLight:"#fff",buttonDark:"#000",events:!0,cookie:!1,localStorage:!0,label:"🌓",autoMatchOsTheme:!0},e),this.options=e,this.dark=!1,e.autoMatchOsTheme&&(window.matchMedia("(prefers-color-scheme: dark)").addListener((function(t){return t.matches&&o.switchThemePrefers()})),window.matchMedia("(prefers-color-scheme: light)").addListener((function(t){return t.matches&&o.switchThemePrefers()})));var n=e.localStorage?localStorage.getItem("darkmode"):e.cookie?this.getCookie():null;null!==n?"true"===n||!0===n?this.toDark():this.toLight():e.autoMatchOsTheme&&this.preferedTheme()?this.toDark():this.toLight()}else console.warn("Detected environment without a `window` object")}var e,o,i;return e=t,(o=[{key:"attach",value:function(){var t=this,e="\n .drkmd-toggle-button{\n position: fixed;\n z-index: 1000;\n left: ".concat(this.options.left,";\n right: ").concat(this.options.right,";\n bottom: ").concat(this.options.bottom,";\n top: ").concat(this.options.top,";\n height: 3rem;\n min-width: 3rem;\n border-radius: 3rem;\n display: flex;\n align-items: center;\n justify-content: center;\n background: ").concat(this.options.buttonDark,";\n color: ").concat(this.options.buttonLight,";\n cursor: pointer;\n }\n\n .drkmd-toggle-button span{\n margin: 0;\n padding: 0px 10px;\n }\n\n .theme-dark .drkmd-toggle-button{\n background: ").concat(this.options.buttonLight,";\n color: ").concat(this.options.buttonDark,"\n }\n "),o=document.createElement("div"),n=document.createElement("span");n.innerHTML=this.options.label,o.className="drkmd-toggle-button",o.setAttribute("title","Toggle dark mode"),o.setAttribute("aria-label","Toggle dark mode"),o.setAttribute("aria-checked","false"),o.setAttribute("role","checkbox"),o.appendChild(n),o.addEventListener("click",(function(){!0===t.dark?t.toLight():t.toDark()})),document.body.insertBefore(o,document.body.firstChild),this.addStyle(e)}},{key:"toLight",value:function(){this.options.events&&window.dispatchEvent(new CustomEvent("theme",{detail:{to:"light"}})),document.documentElement.setAttribute("data-theme","light"),this.options.localStorage?localStorage.setItem("darkmode",!1):this.options.cookie&&this.setCookie(!1),document.body.classList.remove("theme-dark"),document.body.classList.add("theme-light"),this.dark=!1}},{key:"toDark",value:function(){this.options.events&&window.dispatchEvent(new CustomEvent("theme",{detail:{to:"dark"}})),document.documentElement.setAttribute("data-theme","dark"),this.options.localStorage?localStorage.setItem("darkmode",!0):this.options.cookie&&this.setCookie(!0),document.body.classList.add("theme-dark"),document.body.classList.remove("theme-light"),this.dark=!0}},{key:"preferedTheme",value:function(){return window.matchMedia&&window.matchMedia("(prefers-color-scheme: dark)").matches}},{key:"switchThemePrefers",value:function(){!0===this.preferedTheme()?this.swichToDark():this.swichToLight()}},{key:"getCookie",value:function(){var t=document.cookie.match(RegExp("(?:^|;\\s*)darkmode=([^;]*)"));return t?t[1]:null}},{key:"setCookie",value:function(t){document.cookie="darkmode=".concat(t)}},{key:"toggle",value:function(){return this.dark?this.toLight():this.toDark(),this.dark}},{key:"isActivated",value:function(){return this.dark}},{key:"addStyle",value:function(t){var e=document.createElement("link");e.setAttribute("rel","stylesheet"),e.setAttribute("type","text/css"),e.setAttribute("href","data:text/css;charset=UTF-8,"+encodeURIComponent(t)),document.head.appendChild(e)}}])&&n(e.prototype,o),i&&n(e,i),t}();o.default=i},{}],2:[function(t,e,o){"use strict";function n(t){return(n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}Object.defineProperty(o,"__esModule",{value:!0}),o.default=void 0;var r=function(t){if(t&&t.__esModule)return t;if(null===t||"object"!==n(t)&&"function"!=typeof t)return{default:t};var e=i();if(e&&e.has(t))return e.get(t);var o={},r=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var a in t)if(Object.prototype.hasOwnProperty.call(t,a)){var s=r?Object.getOwnPropertyDescriptor(t,a):null;s&&(s.get||s.set)?Object.defineProperty(o,a,s):o[a]=t[a]}o.default=t,e&&e.set(t,o);return o}(t("./drkmd"));function i(){if("function"!=typeof WeakMap)return null;var t=new WeakMap;return i=function(){return t},t}var a=r.default;o.default=a,r.IS_BROWSER&&function(t){t.Darkmode=r.default}(window)},{"./drkmd":1}]},{},[2])(2)})); |
{ | ||
"name": "drkmd-js", | ||
"version": "0.1.8", | ||
"version": "0.1.9", | ||
"description": "Simple dark-mode/light-mode toggle for any website", | ||
@@ -5,0 +5,0 @@ "main": "dist/drkmd-js.min.js", |
@@ -45,3 +45,3 @@ export const IS_BROWSER = typeof window !== 'undefined'; | ||
.drkmd-toggle-button{ | ||
position: absolute; | ||
position: fixed; | ||
z-index: 1000; | ||
@@ -48,0 +48,0 @@ left: ${this.options.left}; |
18567