Archive for August, 2011

Adapt to HTML5

I’ve written some quick example code that takes a page containing HTML5 equivalent class names (ie. .nav) and replaces the node with a HTML5 node that matches (ie. ).

//Adapt page to HTML5
    function changeNodeName(element, newNodeName) {
        var oldNode = element,
			    newNode = document.createElement(newNodeName),
			    node,
			    nextNode;

        node = oldNode.firstChild;
        while (node) {
            nextNode = node.nextSibling;
            newNode.appendChild(node);
            node = nextNode;
        }
        for (var i = 0; i < oldNode.attributes.length; i++) {
            newNode.setAttribute(oldNode.attributes[i].name, oldNode.attributes[i].value);
        }

        oldNode.parentNode.replaceChild(newNode, oldNode);
    }
    try {
        var theBody = document.getElementsByTagName("body")[0];
        var classNames = ["article", "aside", "command", "details", "summary", "figure", "figcaption", "footer", "header", "mark", "meter", "nav", "progress", "ruby", "rt", "rp", "section", "time", "wbr"];
        for (var i = 0; i < classNames.length; i++) {
            htmlFourElements = document.getElementsByClassName(classNames[i], theBody);
            for (var ii = 0; ii < htmlFourElements.length; ii++) {
                changeNodeName(htmlFourElements[ii], classNames[i]);
            }
        }
    } catch(e) {
        console.error(e.message);
    }
Advertisements

SASS and Visual Studio

Quick guide to perfect tools for using SASS in Visual Studio

Syntax highlighting, creating new files and compiling all without Ruby can be done with Mindscape Web Workbench.

Converting CSS to SASS can be done with the sass-convert foo.css foo.scss command or this online tool. Of course the sass-convert command will always be more up to date as it’s part of SASS. But of course you will need SASS and Ruby install to run it.

Code formatting isn’t a problem if you’re used to Ruby. If you’re not the default formatting from any converter is horrible. To convert it to a more ECMAScript style first remove all whitespace (you can leave the line breaks if you like). I use Notepad++ and just remove the indents with shift + tab. Then you can use any CSS cleaning/formatting tool such as Tabifier.