Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proof of concept with HTML5 Custom Elements #104

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions hp/hp.css
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pre {
pre { font-size: 23px; }
}

pre span {
pre * {
opacity: 0.5;
}

Expand All @@ -59,33 +59,33 @@ a:hover {
background-color: #333;
}

.text {
r-text {
color: #bbb;
opacity: 1;
}

.text:first-child {
r-text:first-child {
color: #fff;
text-decoration: underline;
}

.wall { color: #666; }
.corridor { color: #ccc; }
.staircase { color: #aaa; }
.door { color: #a60; }
.trap { color: #f0f; }
.scroll { color: #fff; }
.water { color: #33f; }
.potion { color: #3ff; }
r-wall { color: #666; }
r-corridor { color: #ccc; }
r-staircase { color: #aaa; }
r-door { color: #a60; }
r-trap { color: #f0f; }
r-scroll { color: #fff; }
r-water { color: #33f; }
r-potion { color: #3ff; }

.money, .money a {
r-money, r-money a {
color: #fe0;
opacity: 1;
}

.player { color:#f00; }
.kobold { color:#3f3; }
.orc { color:#3f3; }
.goblin { color:#00f; }
.ogre { color:#3a3; }
.dragon { color:#f33; }
r-player { color:#f00; }
r-kobold { color:#3f3; }
r-orc { color:#3f3; }
r-goblin { color:#00f; }
r-ogre { color:#3a3; }
r-dragon { color:#f33; }
20 changes: 16 additions & 4 deletions hp/hp.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@

var pre = document.querySelector("pre");

var re = /(>)|([a-z-][a-z0-9 \.,:\(\)-]*[a-z0-9\.:])|(#+)|(\.+)|([+/])|(\$+)|(\^)|(\?)|(=+)|(!)/ig;
var types = ["", "staircase", "text", "wall", "corridor", "door", "money", "trap", "scroll", "water", "potion"];

/// create custom elements

types.forEach(function (value, key) {
document.registerElement("r-" + value);
});


var str = pre.innerHTML;
str = str.replace(re, function(match) {
var types = ["", "staircase", "text", "wall", "corridor", "door", "money", "trap", "scroll", "water", "potion"];
for (var i=1; i<arguments.length-1; i++) {
if (arguments[i]) {
var type = types[i];
var str = "<span class='"+type+"' ";
if (type != "wall" && type != "corridor" && type != "text") { str += "title='"+type+"' "; }
str += ">" + match + "</span>";
var str = "";
if (type == "wall" || type == "corridor" || type == "text") {
str = "<r-" + type + ">" + match + "</r-" + type + ">";
} else {
str = "<r-" + type + " title='"+type+"'>" + match + "</r-" + type + ">";
}
return str;
}
}
Expand Down