Skip to content

Instantly share code, notes, and snippets.

@matthewp
Created June 19, 2012 19:08

Revisions

  1. @matthewpblog matthewpblog created this gist Jun 19, 2012.
    23 changes: 23 additions & 0 deletions rel-template.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    (function() {
    "use strict";

    Object.defineProperty(HTMLLinkElement.prototype, 'template', {
    get: function() {
    if(!/template/i.test(this.rel)) {
    return "";
    }

    var req = new XMLHttpRequest();
    req.open('GET', this.href, false);
    req.setRequestHeader('Accept', this.type || "*/*");
    req.send();

    if(req.status !== 200) {
    throw "Unable to retrieve the template.";
    } else {
    return req.responseText;
    }
    }
    });

    })();