|
| 1 | +const IndigoFooter = () => { |
| 2 | + const intl = useIntl(); |
| 3 | + const config = getConfig(); |
| 4 | + |
| 5 | + const indigoFooterNavLinks = config.INDIGO_FOOTER_NAV_LINKS || []; |
| 6 | + |
| 7 | + const messages = { |
| 8 | + "footer.poweredby.text": { |
| 9 | + id: "footer.poweredby.text", |
| 10 | + defaultMessage: "Powered by", |
| 11 | + description: "text for the footer", |
| 12 | + }, |
| 13 | + "footer.tutorlogo.altText": { |
| 14 | + id: "footer.tutorlogo.altText", |
| 15 | + defaultMessage: "Runs on Tutor", |
| 16 | + description: "alt text for the footer tutor logo", |
| 17 | + }, |
| 18 | + "footer.logo.altText": { |
| 19 | + id: "footer.logo.altText", |
| 20 | + defaultMessage: "Powered by Open edX", |
| 21 | + description: "alt text for the footer logo.", |
| 22 | + }, |
| 23 | + "footer.copyright.text": { |
| 24 | + id: "footer.copyright.text", |
| 25 | + defaultMessage: `Copyrights ©${new Date().getFullYear()}. All Rights Reserved.`, |
| 26 | + description: "copyright text for the footer", |
| 27 | + }, |
| 28 | + }; |
| 29 | + |
| 30 | + return ( |
| 31 | + <div className="wrapper wrapper-footer"> |
| 32 | + <footer id="footer" className="tutor-container"> |
| 33 | + <div className="footer-top"> |
| 34 | + <div className="powered-area"> |
| 35 | + <ul className="logo-list"> |
| 36 | + <li>{intl.formatMessage(messages["footer.poweredby.text"])}</li> |
| 37 | + <li> |
| 38 | + <a |
| 39 | + href="https://edly.io/tutor/" |
| 40 | + rel="noreferrer" |
| 41 | + target="_blank" |
| 42 | + > |
| 43 | + <img |
| 44 | + src={`${config.LMS_BASE_URL}/theming/asset/images/tutor-logo.png`} |
| 45 | + alt={intl.formatMessage( |
| 46 | + messages["footer.tutorlogo.altText"] |
| 47 | + )} |
| 48 | + width="57" |
| 49 | + /> |
| 50 | + </a> |
| 51 | + </li> |
| 52 | + <li> |
| 53 | + <a href="https://open.edx.org" rel="noreferrer" target="_blank"> |
| 54 | + <img |
| 55 | + src={`${config.LMS_BASE_URL}/theming/asset/images/openedx-logo.png`} |
| 56 | + alt={intl.formatMessage(messages["footer.logo.altText"])} |
| 57 | + width="79" |
| 58 | + /> |
| 59 | + </a> |
| 60 | + </li> |
| 61 | + </ul> |
| 62 | + </div> |
| 63 | + <nav className="nav-colophon"> |
| 64 | + <ol> |
| 65 | + {indigoFooterNavLinks.map((link) => ( |
| 66 | + <li key={link.url}> |
| 67 | + <a href={`${config.LMS_BASE_URL}${link.url}`}>{link.title}</a> |
| 68 | + </li> |
| 69 | + ))} |
| 70 | + </ol> |
| 71 | + </nav> |
| 72 | + </div> |
| 73 | + <span className="copyright-site"> |
| 74 | + {intl.formatMessage(messages["footer.copyright.text"])} |
| 75 | + </span> |
| 76 | + </footer> |
| 77 | + </div> |
| 78 | + ); |
| 79 | +}; |
| 80 | + |
| 81 | +const ToggleThemeButton = () => { |
| 82 | + const intl = useIntl(); |
| 83 | + const [isDarkThemeEnabled, setIsDarkThemeEnabled] = useState(false); |
| 84 | + |
| 85 | + const themeCookie = "indigo-toggle-dark"; |
| 86 | + const themeCookieExpiry = 90; // days |
| 87 | + const isThemeToggleEnabled = getConfig().INDIGO_ENABLE_DARK_TOGGLE; |
| 88 | + |
| 89 | + const getCookie = (name) => { |
| 90 | + return document.cookie |
| 91 | + .split("; ") |
| 92 | + .find((row) => row.startsWith(name + "=")) |
| 93 | + ?.split("=")[1]; |
| 94 | + }; |
| 95 | + |
| 96 | + const setCookie = (name, value, { domain, path, expires }) => { |
| 97 | + document.cookie = `${name}=${value}; domain=${domain}; path=${path}; expires=${expires.toUTCString()}; SameSite=Lax`; |
| 98 | + }; |
| 99 | + |
| 100 | + const getCookieExpiry = () => { |
| 101 | + const today = new Date(); |
| 102 | + return new Date( |
| 103 | + today.getFullYear(), |
| 104 | + today.getMonth(), |
| 105 | + today.getDate() + themeCookieExpiry |
| 106 | + ); |
| 107 | + }; |
| 108 | + |
| 109 | + const getCookieOptions = (serverURL) => ({ |
| 110 | + domain: serverURL.hostname, |
| 111 | + path: "/", |
| 112 | + expires: getCookieExpiry(), |
| 113 | + }); |
| 114 | + |
| 115 | + const addDarkThemeToIframes = () => { |
| 116 | + const iframes = document.getElementsByTagName("iframe"); |
| 117 | + const iframesLength = iframes.length; |
| 118 | + if (iframesLength > 0) { |
| 119 | + Array.from({ length: iframesLength }).forEach((_, ind) => { |
| 120 | + const style = document.createElement("style"); |
| 121 | + style.textContent = ` |
| 122 | + body{ |
| 123 | + background-color: #0D0D0E; |
| 124 | + color: #ccc; |
| 125 | + } |
| 126 | + a {color: #ccc;} |
| 127 | + a:hover{color: #d3d3d3;} |
| 128 | + `; |
| 129 | + if (iframes[ind].contentDocument) { |
| 130 | + iframes[ind].contentDocument.head.appendChild(style); |
| 131 | + } |
| 132 | + }); |
| 133 | + } |
| 134 | + }; |
| 135 | + |
| 136 | + const removeDarkThemeFromiframes = () => { |
| 137 | + const iframes = document.getElementsByTagName("iframe"); |
| 138 | + const iframesLength = iframes.length; |
| 139 | + |
| 140 | + Array.from({ length: iframesLength }).forEach((_, ind) => { |
| 141 | + if (iframes[ind].contentDocument) { |
| 142 | + const iframeHead = iframes[ind].contentDocument.head; |
| 143 | + const styleTag = Array.from(iframeHead.querySelectorAll("style")).find( |
| 144 | + (style) => |
| 145 | + style.textContent.includes("background-color: #0D0D0E;") && |
| 146 | + style.textContent.includes("color: #ccc;") |
| 147 | + ); |
| 148 | + if (styleTag) { |
| 149 | + styleTag.remove(); |
| 150 | + } |
| 151 | + } |
| 152 | + }); |
| 153 | + }; |
| 154 | + |
| 155 | + const onToggleTheme = () => { |
| 156 | + const serverURL = new URL(getConfig().LMS_BASE_URL); |
| 157 | + let theme = ""; |
| 158 | + |
| 159 | + if (getCookie(themeCookie) === "dark") { |
| 160 | + document.body.classList.remove("indigo-dark-theme"); |
| 161 | + removeDarkThemeFromiframes(); |
| 162 | + setIsDarkThemeEnabled(false); |
| 163 | + theme = "light"; |
| 164 | + } else { |
| 165 | + document.body.classList.add("indigo-dark-theme"); |
| 166 | + addDarkThemeToIframes(); |
| 167 | + setIsDarkThemeEnabled(true); |
| 168 | + theme = "dark"; |
| 169 | + } |
| 170 | + setCookie(themeCookie, theme, getCookieOptions(serverURL)); |
| 171 | + |
| 172 | + const learningMFEUnitIframe = document.getElementById("unit-iframe"); |
| 173 | + if (learningMFEUnitIframe) { |
| 174 | + learningMFEUnitIframe.contentWindow.postMessage( |
| 175 | + { "indigo-toggle-dark": theme }, |
| 176 | + serverURL.origin |
| 177 | + ); |
| 178 | + } |
| 179 | + }; |
| 180 | + |
| 181 | + const hanldeKeyUp = (event) => { |
| 182 | + if (event.key === "Enter") { |
| 183 | + onToggleTheme(); |
| 184 | + } |
| 185 | + }; |
| 186 | + |
| 187 | + if (!isThemeToggleEnabled) { |
| 188 | + return <div />; |
| 189 | + } |
| 190 | + |
| 191 | + const messages = { |
| 192 | + "header.user.theme": { |
| 193 | + id: "header.user.theme", |
| 194 | + defaultMessage: "Toggle Theme", |
| 195 | + description: "Toggle between light and dark theme", |
| 196 | + }, |
| 197 | + }; |
| 198 | + |
| 199 | + return ( |
| 200 | + <div className="theme-toggle-button mr-3"> |
| 201 | + <div className="light-theme-icon"> |
| 202 | + <Icon src={WbSunny} /> |
| 203 | + </div> |
| 204 | + <div className="toggle-switch"> |
| 205 | + <label htmlFor="theme-toggle-checkbox" className="switch"> |
| 206 | + <input |
| 207 | + id="theme-toggle-checkbox" |
| 208 | + defaultChecked={getCookie(themeCookie) === "dark"} |
| 209 | + onChange={onToggleTheme} |
| 210 | + onKeyUp={hanldeKeyUp} |
| 211 | + type="checkbox" |
| 212 | + title={intl.formatMessage(messages["header.user.theme"])} |
| 213 | + /> |
| 214 | + <span className="slider round" /> |
| 215 | + <span id="theme-label" className="sr-only">{`Switch to ${ |
| 216 | + isDarkThemeEnabled ? "Light" : "Dark" |
| 217 | + } Mode`}</span> |
| 218 | + </label> |
| 219 | + </div> |
| 220 | + <div className="dark-theme-icon"> |
| 221 | + <Icon src={Nightlight} /> |
| 222 | + </div> |
| 223 | + </div> |
| 224 | + ); |
| 225 | +}; |
| 226 | + |
| 227 | +const MobileViewHeader = () => { |
| 228 | + const config = getConfig(); |
| 229 | + const intl = useIntl(); |
| 230 | + const messages = { |
| 231 | + "mobile.view.header.logo.altText": { |
| 232 | + id: "mobile.view.header.logo.altText", |
| 233 | + defaultMessage: "My Open edX", |
| 234 | + description: "Mobile view header logo altText", |
| 235 | + }, |
| 236 | + }; |
| 237 | + return ( |
| 238 | + <div className="container-xl py-2 d-flex align-items-center justify-content-between"> |
| 239 | + <a |
| 240 | + className="logo" |
| 241 | + href={`${config.LMS_BASE_URL}/dashboard`} |
| 242 | + style={Object.assign({}, { display: "flex", alignItems: "center" })} |
| 243 | + > |
| 244 | + <img |
| 245 | + className="d-block" |
| 246 | + src={`${config.LMS_BASE_URL}/theming/asset/images/logo.png`} |
| 247 | + alt={intl.formatMessage(messages["mobile.view.header.logo.altText"])} |
| 248 | + height={21} |
| 249 | + /> |
| 250 | + </a> |
| 251 | + <ToggleThemeButton /> |
| 252 | + </div> |
| 253 | + ); |
| 254 | +}; |
0 commit comments