Changeset 38912 for documented-examples
- Timestamp:
- 2024-04-09T12:56:44+12:00 (3 weeks ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
documented-examples/trunk/style-e/script/custom-script.js
r36371 r38912 1 1 function replaceStyle(stylesheet) { 2 //alert("In custom-sript.js::ReplaceStyle()"); 3 var body = document.getElementsByTagName('body')[0]; 4 var linkEl = document.getElementById("custom-style"); 5 var href = linkEl.getAttribute("href"); 6 var lastSlashIndex = href.lastIndexOf("/"); 7 var hrefPrefix = href.substring(0, lastSlashIndex); 2 // alert("In custom-sript.js::ReplaceStyle()"); 3 var body = document.getElementsByTagName('body')[0]; 4 var linkEl = document.getElementById("custom-style"); 5 if (linkEl === null) { 6 // we had previously clicked null, which means all stylesheet links are removed 7 // so we can't update a link. Lets just reload the page. It won't then use the selected stylesheet, but never mind. 8 location.reload(); 9 return; 8 10 9 href = hrefPrefix + "/" + stylesheet + ".css"; 10 linkEl.setAttribute("href", href); 11 11 } 12 var href = linkEl.getAttribute("href"); 13 var lastSlashIndex = href.lastIndexOf("/"); 14 var hrefPrefix = href.substring(0, lastSlashIndex); 15 16 href = hrefPrefix + "/" + stylesheet + ".css"; 17 linkEl.setAttribute("href", href); 18 19 20 // https://techstacker.com/how-to-remove-all-css-from-site-with-javascript/ 21 if(stylesheet == "") { /* gs3-style-red */ 22 document 23 .querySelectorAll('style,link[rel="stylesheet"]') 24 .forEach(item => item.remove()) 12 25 13 // https://techstacker.com/how-to-remove-all-css-from-site-with-javascript/ 14 if(stylesheet == "") { /* gs3-style-red */ 15 document 16 .querySelectorAll('style,link[rel="stylesheet"]') 17 .forEach(item => item.remove()) 18 19 // https://code-boxx.com/dynamically-load-replace-css/ 20 //document.head.appendChild(linkEl); 21 } 22 23 //reloadCss(); // https://stackoverflow.com/questions/2024486/is-there-an-easy-way-to-reload-css-without-reloading-the-page 26 // https://code-boxx.com/dynamically-load-replace-css/ 27 //document.head.appendChild(linkEl); 28 } 29 30 //reloadCss(); // https://stackoverflow.com/questions/2024486/is-there-an-easy-way-to-reload-css-without-reloading-the-page 24 31 } 25 32 … … 28 35 // It changes the current stylesheet to the named one of parameter 29 36 function SetStyle(stylename) { 30 31 var body = document.getElementsByTagName('body')[0];32 body.style.backgroundImage = "";33 34 styles = document.styleSheets;35 var i;36 for (i=0;i<styles.length;i++) {37 38 39 40 41 42 }37 //alert("In custom-sript.js::SetStyle()"); 38 var body = document.getElementsByTagName('body')[0]; 39 body.style.backgroundImage = ""; 40 41 styles = document.styleSheets; 42 var i; 43 for (i=0;i<styles.length;i++) { 44 style = styles[i]; 45 if (style.title == stylename) 46 style.disabled = false; 47 else 48 style.disabled = true; 49 } 43 50 } 44 51
Note:
See TracChangeset
for help on using the changeset viewer.