MCPcopy Create free account
hub / github.com/frank-lam/fullstack-tutorial / handleSwitch

Function handleSwitch

notes/docsify/js/main.js:84–103  ·  view source on GitHub ↗
(activeHref, activeTitle)

Source from the content-addressed store, hash-verified

82 var sessionStorageKey = 'activeStylesheetHref';
83
84 function handleSwitch(activeHref, activeTitle) {
85 var activeElm = document.querySelector('link[href*="' + activeHref + '"],link[title="' + activeTitle + '"]');
86
87 if (!activeElm && activeHref) {
88 activeElm = document.createElement('link');
89 activeElm.setAttribute('href', activeHref);
90 activeElm.setAttribute('rel', 'stylesheet');
91 activeElm.setAttribute('title', activeTitle);
92
93 document.head.appendChild(activeElm);
94
95 activeElm.addEventListener('load', function linkOnLoad() {
96 activeElm.removeEventListener('load', linkOnLoad);
97 setActiveLink(activeElm);
98 });
99 }
100 else if (activeElm) {
101 setActiveLink(activeElm);
102 }
103 }
104
105 function setActiveLink(activeElm) {
106 var activeHref = activeElm.getAttribute('href');

Callers 1

initStyleSwitcherFunction · 0.85

Calls 1

setActiveLinkFunction · 0.85

Tested by

no test coverage detected