Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Optional style sheet switcher using JavaScript
- Loading branch information
Showing
9 changed files
with
49 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
function LXSH_GetStyles() { | ||
var elements = document.getElementsByTagName('link'); | ||
var selected = new Array(); | ||
for (var i = elements.length - 1; i >= 0; i--) | ||
if (elements[i].getAttribute('rel').indexOf('stylesheet') >= 0) { | ||
var href = elements[i].getAttribute('href'); | ||
if (href && href.indexOf('http://peterodding.com/code/lua/lxsh/styles/') == 0) | ||
selected.push(elements[i]); | ||
} | ||
return selected; | ||
} | ||
|
||
function LXSH_ChangeStyle(newstyle) { | ||
var head = document.getElementsByTagName('head')[0]; | ||
var elements = LXSH_GetStyles(); | ||
for (var i = elements.length - 1; i >= 0; i--) | ||
elements[i].disabled = (elements[i].getAttribute('title') != newstyle); | ||
} | ||
|
||
window.onload = function() { | ||
var styles = LXSH_GetStyles(); | ||
var elements = document.getElementsByTagName('pre'); | ||
for (var i = elements.length - 1; i >= 0; i--) | ||
if (elements[i].getAttribute('class').indexOf('sourcecode') >= 0) | ||
for (var j = styles.length - 1; j >= 0; j--) { | ||
var name = styles[j].getAttribute('title'); | ||
var link = document.createElement('a'); | ||
link.style.padding = '3px'; | ||
link.style.cssFloat = 'right'; | ||
link.innerHTML = name; | ||
link.title = 'Switch to the ' + name + ' color scheme'; | ||
link.href = 'javascript:LXSH_ChangeStyle("' + name + '");'; | ||
elements[i].insertBefore(link, elements[i].firstChild); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters