|
| 1 | +const colorSchemes = [ |
| 2 | + { label: "Light", value: "light", style: 'background-color: #fff' }, |
| 3 | + { label: "Gray", value: "gray", style: 'background-color: #d8e2ef' }, |
| 4 | + { label: "Dark Gray", value: "dark-gray", style: 'background-color: #5e6e82' }, |
| 5 | + { label: "Dark", value: "dark", style: 'background-color: #000' }, |
| 6 | +]; |
| 7 | + |
| 8 | +const primaryColorSchemes = [ |
| 9 | + { label: "Primary", value: "primary", style: 'background-color: rgb(0, 122, 255);' }, |
| 10 | + { label: "Orange", value: "orange", style: 'background-color: rgb(245, 158, 11);' }, |
| 11 | + { label: "Red", value: "red", style: 'background-color: rgb(178, 39, 39);' }, |
| 12 | +]; |
| 13 | + |
| 14 | +const bootstrapHeadInfo = [ |
| 15 | + // { url: "../../assets/packages/bootstrap/bootstrap.min.css", type: "style" }, |
| 16 | + { url: "https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css", type: "style" }, |
| 17 | + // { url: "../../assets/packages/bootstrap/bootstrap.bundle.min.js", type: "script" }, |
| 18 | + { url: "https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js", type: "script" }, |
| 19 | +]; |
| 20 | +const tailwindHeadInfo = [ |
| 21 | + { url: "../../assets/packages/tailwind/tailwind.css", type: 'style' }, |
| 22 | +]; |
| 23 | +const headInfo = [ |
| 24 | + // demo color scheme (REQUIRED) |
| 25 | + { url: "https://fonts.googleapis.com/css2?family=DM+Serif+Display&display=swap", type: "style" }, |
| 26 | + { url: "https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap", type: "style" }, |
| 27 | + { url: "../../assets/demo/style.css", type: "style" }, |
| 28 | + |
| 29 | + { url: "../../assets/packages/jquery-3.6.0.min.js", type: "script" }, |
| 30 | + { url: "https://fonts.googleapis.com/css2?family=Roboto&display=swap", type: "style" }, |
| 31 | + { url: "../../assets/packages/fontawesome/all.min.css", type: "style" }, |
| 32 | + // {url: '../../assets/packages/owl-carousel/owl.carousel.min.js', type: 'script'}, |
| 33 | +]; |
| 34 | + |
| 35 | +document.addEventListener("DOMContentLoaded", function () { |
| 36 | + var body = document.getElementsByTagName("body")[0]; |
| 37 | + var topNavbar = document.createElement("div"); |
| 38 | + var topNavbarLeft = document.createElement("div"); |
| 39 | + var topNavbarRight = document.createElement("div"); |
| 40 | + topNavbar.classList = "demo-top-navbar"; |
| 41 | + |
| 42 | + |
| 43 | + var colorSchemeContent = document.createElement("div"); |
| 44 | + colorSchemeContent.classList = "ezy-color-scheme-group"; |
| 45 | + colorSchemes.forEach(function (item) { |
| 46 | + var button = document.createElement("button"); |
| 47 | + button.title = item.label; |
| 48 | + button.style = item.style; |
| 49 | + button.onclick = function () { |
| 50 | + changeColorScheme(item.value); |
| 51 | + }; |
| 52 | + colorSchemeContent.append(button); |
| 53 | + }); |
| 54 | + topNavbarLeft.append(colorSchemeContent); |
| 55 | + |
| 56 | + var primaryColorSchemeContent = document.createElement("div"); |
| 57 | + primaryColorSchemeContent.classList = "ezy-primary-color-scheme-group"; |
| 58 | + primaryColorSchemes.forEach(function (item) { |
| 59 | + var button = document.createElement("button"); |
| 60 | + button.title = item.label; |
| 61 | + button.style = item.style; |
| 62 | + button.onclick = function () { |
| 63 | + changePrimaryColorScheme(item.value); |
| 64 | + }; |
| 65 | + primaryColorSchemeContent.append(button); |
| 66 | + }); |
| 67 | + topNavbarLeft.append(primaryColorSchemeContent); |
| 68 | + |
| 69 | + // var backButton = document.createElement("a"); |
| 70 | + // backButton.innerHTML = "Back"; |
| 71 | + // backButton.href = "../../"; |
| 72 | + // backButton.classList = "back-button"; |
| 73 | + |
| 74 | + var typeChangeButton = document.createElement("button"); |
| 75 | + typeChangeButton.title = "Check Typo"; |
| 76 | + typeChangeButton.innerHTML = "Aa"; |
| 77 | + typeChangeButton.onclick = function () { |
| 78 | + if (document.body.classList.contains("ezy-checktypo")) { |
| 79 | + document.body.classList.remove("ezy-checktypo"); |
| 80 | + } else { |
| 81 | + document.body.classList.add("ezy-checktypo"); |
| 82 | + } |
| 83 | + }; |
| 84 | + |
| 85 | + topNavbarRight.append(typeChangeButton); |
| 86 | + // topNavbarRight.append(backButton); |
| 87 | + |
| 88 | + topNavbar.append(topNavbarLeft); |
| 89 | + topNavbar.append(topNavbarRight); |
| 90 | + body.append(topNavbar); |
| 91 | + |
| 92 | + changeColorScheme(window.localStorage.getItem("colorScheme") || "light"); |
| 93 | + changePrimaryColorScheme(window.localStorage.getItem("primaryColorScheme") || "primary"); |
| 94 | + |
| 95 | + // $elements = document.querySelectorAll('/(ezy__[a-z]*[0-9]*)([\s\"])/'); |
| 96 | + var elements = document.querySelectorAll('[class^="ezy"]'); |
| 97 | + var existingElements = []; |
| 98 | + |
| 99 | + elements.forEach(function (e) { |
| 100 | + if (typeof e.className === "string") { |
| 101 | + var matchClasses = e.className.match(/(ezy__[a-z]*[0-9]*)(\s|\"|$)/i); |
| 102 | + |
| 103 | + if (matchClasses && matchClasses[0] && !existingElements.includes(matchClasses[0])) { |
| 104 | + var optionCardId = matchClasses[0]; |
| 105 | + var componentName = optionCardId.replace("ezy__", ``); |
| 106 | + var componentName = componentName.charAt(0).toUpperCase() + componentName.slice(1); |
| 107 | + existingElements.push(optionCardId); |
| 108 | + |
| 109 | + var optionCard = document.createElement("div"); |
| 110 | + optionCard.classList = "ezy-option-card"; |
| 111 | + optionCard.innerHTML = `<span>ID: <b>${optionCardId}</b></span><span>Component Name: <b>${componentName}</b></span>`; |
| 112 | + |
| 113 | + e.parentNode.insertBefore(optionCard, e); |
| 114 | + } |
| 115 | + } |
| 116 | + }); |
| 117 | +}); |
| 118 | + |
| 119 | +function appendHeadInfo(frame) { |
| 120 | + if (frame === "bootstrap") { |
| 121 | + bootstrapHeadInfo.forEach(function (item) { |
| 122 | + _addHeadInfo(item); |
| 123 | + }); |
| 124 | + } else if (frame === "tailwind") { |
| 125 | + tailwindHeadInfo.forEach(function (item) { |
| 126 | + _addHeadInfo(item); |
| 127 | + }); |
| 128 | + } |
| 129 | + |
| 130 | + headInfo.forEach(function (item) { |
| 131 | + _addHeadInfo(item); |
| 132 | + }); |
| 133 | +} |
| 134 | + |
| 135 | +function _addHeadInfo(item) { |
| 136 | + var head = document.getElementsByTagName("head")[0]; |
| 137 | + |
| 138 | + var element; |
| 139 | + if (item.type === "script") { |
| 140 | + element = document.createElement("script"); |
| 141 | + element.src = item.url; |
| 142 | + } else if (item.type === "style") { |
| 143 | + element = document.createElement("link"); |
| 144 | + element.href = item.url; |
| 145 | + element.rel = "stylesheet"; |
| 146 | + } |
| 147 | + |
| 148 | + element && head.append(element); |
| 149 | +} |
| 150 | + |
| 151 | +function changeColorScheme(color) { |
| 152 | + document.body.classList.remove("light", "gray", "dark", "dark-gray"); |
| 153 | + |
| 154 | + switch (color) { |
| 155 | + case "light": |
| 156 | + document.body.classList.add("light"); |
| 157 | + window.localStorage.setItem("colorScheme", "light"); |
| 158 | + break; |
| 159 | + case "gray": |
| 160 | + document.body.classList.add("gray"); |
| 161 | + window.localStorage.setItem("colorScheme", "gray"); |
| 162 | + break; |
| 163 | + case "dark": |
| 164 | + document.body.classList.add("dark"); |
| 165 | + window.localStorage.setItem("colorScheme", "dark"); |
| 166 | + break; |
| 167 | + case "dark-gray": |
| 168 | + document.body.classList.add("dark-gray"); |
| 169 | + window.localStorage.setItem("colorScheme", "dark-gray"); |
| 170 | + break; |
| 171 | + default: |
| 172 | + break; |
| 173 | + } |
| 174 | +} |
| 175 | + |
| 176 | +function changePrimaryColorScheme(color) { |
| 177 | + document.body.classList.remove("ezy-primary", "ezy-orange", "ezy-red"); |
| 178 | + |
| 179 | + switch (color) { |
| 180 | + case "primary": |
| 181 | + document.body.classList.add("ezy-primary"); |
| 182 | + window.localStorage.setItem("primaryColorScheme", "primary"); |
| 183 | + break; |
| 184 | + case "orange": |
| 185 | + document.body.classList.add("ezy-orange"); |
| 186 | + window.localStorage.setItem("primaryColorScheme", "orange"); |
| 187 | + break; |
| 188 | + case "red": |
| 189 | + document.body.classList.add("ezy-red"); |
| 190 | + window.localStorage.setItem("primaryColorScheme", "red"); |
| 191 | + break; |
| 192 | + default: |
| 193 | + break; |
| 194 | + } |
| 195 | +} |
| 196 | + |
| 197 | +var checkReady = function (callback) { |
| 198 | + if (window.jQuery) { |
| 199 | + callback(jQuery); |
| 200 | + } else { |
| 201 | + window.setTimeout(function () { |
| 202 | + checkReady(callback); |
| 203 | + }, 1000); |
| 204 | + } |
| 205 | +}; |
0 commit comments