lazd / DOMly

The fast template system that creates and clones DOM nodes
MIT License
53 stars 9 forks source link

Browser support? #26

Open curioustechizen opened 9 years ago

curioustechizen commented 9 years ago

From the description, it looks like DOMly's pre-compiled templates will work on IE8 and above (based on info about the use of createElement, DocumentFragment and Node). Is this assumption correct? Is there a browser support list?

lazd commented 9 years ago

DOMly uses the following DOM methods and properties:

This was brought up before and we decided to expose DOMly's compiler so you can easily extend DOMly to support IE < 9 by overriding the setTextContent method:

var domly = require('domly');

// Extend DOMly's compiler
var Compiler = function() {
  domly.Compiler.call(this);
};

Compiler.prototype = Object.create(domly.Compiler.prototype);

/**
  Support: IE < 9
  Use innerText instead of textContent if it's not available
*/
Compiler.prototype.setTextContent = function(elName, text) {
  this.pushStatement(elName+'[typeof '+elName+'.textContent === "undefined" ? "innerText" : "textContent"] = '+this.makeVariableStatement(text)+';');
};

// Export a module that uses our new compiler
module.exports = {
  Compiler: Compiler,
  compile: function(html, options) {
    var compiler = new Compiler(options);
    return compiler.compile(html);
  },
  precompile: function(html, options) {
    var compiler = new Compiler(options);
    return compiler.precompile(html);
  }
};

I'm not interested in adding support for IE < 9 to DOMly itself due to the performance hit and a general desire to push the web forward :). That said, it would be wise to add the above description to a wiki page or markdown file so it's clear to users what browsers are supported as well as how to override DOMly and integrate the overridden version when using grunt-domly and gulp-domly. I'll leave this issue open until that's done.