Code coverage report for lib/components/unsafe.js

Statements: 11.11% (3 / 27)      Branches: 0% (0 / 16)      Functions: 0% (0 / 2)      Lines: 11.11% (3 / 27)      Ignored: none     

All files » lib/components/ » unsafe.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 631         1             1                                                                                                    
var BaseComponent  = require("./base");
 
/**
 */
 
function EscapeComponent(options) {
  BaseComponent.call(this, options);
}
 
/**
 */
 
module.exports = BaseComponent.extend(EscapeComponent, {
 
  /**
   */
 
  update: function() {
 
    var value = this.attributes.html;
 
    // dirty check if is a binding
    if (typeof value === "object" && value.evaluate) {
      value = void 0;
    }
 
    // has a remove script
    if (this.currentValue && this.currentValue.remove) {
      this.currentValue.remove();
    }
 
    this.currentValue = value;
 
    if (!value) {
      return this.section.removeAll();
    }
 
    var node;
 
    if (value.render) {
 
      value.remove();
      node = value.render();
    } else if (value.nodeType != null) {
      node = value;
    } else {
      if (this.document !== global.document) {
        node = this.document.createTextNode(String(value));
      } else {
        var div = this.document.createElement("div");
        div.innerHTML = String(value);
        node = this.document.createDocumentFragment();
        var cn = Array.prototype.slice.call(div.childNodes);
        for (var i = 0, n = cn.length; i < n; i++) {
          node.appendChild(cn[i]);
        }
      }
    }
 
    this.section.replaceChildNodes(node);
  }
});