diff --git a/anchor.js b/anchor.js new file mode 100644 index 00000000..e801b6d1 --- /dev/null +++ b/anchor.js @@ -0,0 +1,14 @@ +function anchorArgument(argument, defaultValue) { + args = []; + pairs = window.location.hash.slice(1).split("&"); + for (var i = 0, len = pairs.length; i < len; i++) { + pair = pairs[i]; + eq = pair.indexOf("="); + if(eq) { + key = decodeURIComponent(pair.slice(0, eq)); + value = decodeURIComponent(pair.slice(eq + 1)); + args[key] = value; + } + } + return args[argument] ? args[argument] : defaultValue; +} diff --git a/font.js b/font.js new file mode 100644 index 00000000..462a01b8 --- /dev/null +++ b/font.js @@ -0,0 +1,68 @@ +// Manage rendering text from this skin's text.bmp file +Font = function() { + + this.setNodeToString = function(node, string) { + stringElement = this.stringNode(string); + node.innerHTML = ''; + node.appendChild(stringElement); + } + + this.stringNode = function(string) { + parentDiv = document.createElement('div'); + for (var i = 0, len = string.length; i < len; i++) { + char = string[i].toLowerCase(); + parentDiv.appendChild(this.characterNode(char)); + } + return parentDiv; + } + + this.characterNode = function(char) { + return this.displayCharacterInNode(char, document.createElement('div')); + } + + this.displayCharacterInNode = function(character, node) { + position = this.charPosition(character); + row = position[0]; + column = position[1]; + verticalOffset = row * 6; + horizontalOffset = column * 5; + + x = '-' + horizontalOffset + 'px'; + y = '-' + verticalOffset + 'px' + node.style.backgroundPosition = x + ' ' + y; + node.classList.add('character'); + + // Spaces cause a strange issue with inline-block elements + if(character == ' ') character = ' '; + + node.innerHTML = character; + return node; + } + + this.charPosition = function(char) { + position = this.fontLookup[char]; + if(!position) { + return this.fontLookup[' ']; + } + + return position; + } + + /* XXX There are too many " " and "_" characters */ + this.fontLookup = { + "a": [0,0], "b": [0,1], "c": [0,2], "d": [0,3], "e": [0,4], "f": [0,5], + "g": [0,6], "h": [0,7], "i": [0,8], "j": [0,9], "k": [0,10], + "l": [0,11], "m": [0,12], "n": [0,13], "o": [0,14], "p": [0,15], + "q": [0,16], "r": [0,17], "s": [0,18], "t": [0,19], "u": [0,20], + "v": [0,21], "w": [0,22], "x": [0,23], "y": [0,24], "z": [0,25], + "\"": [0,26], "@": [0,27], " ": [0,29], "0": [1,0], "1": [1,1], + "2": [1,2], "3": [1,3], "4": [1,4], "5": [1,5], "6": [1,6], "7": [1,7], + "8": [1,8], "9": [1,9], " ": [1,10], "_": [1,11], ":": [1,12], + "(": [1,13], ")": [1,14], "-": [1,15], "'": [1,16], "!": [1,17], + "_": [1,18], "+": [1,19], "\\": [1,20], "/": [1,21], "[": [1,22], + "]": [1,23], "^": [1,24], "&": [1,25], "%": [1,26], ".": [1,27], + "=": [1,28], "$": [1,29], "#": [1,30], "Å": [2,0], "Ö": [2,1], + "Ä": [2,2], "?": [2,3], "*": [2,4], " ": [2,5], "<": [1,22], + ">": [1,23], "{": [1,22], "}": [1,23] + }; +} diff --git a/index.html b/index.html index 451df486..28fafa00 100755 --- a/index.html +++ b/index.html @@ -70,6 +70,10 @@

by @captbaritone - GitHub

+ + + + diff --git a/media.js b/media.js new file mode 100644 index 00000000..51ae6969 --- /dev/null +++ b/media.js @@ -0,0 +1,76 @@ +/* Helpful wrapper for the native