<commit_before>/* global HTMLTemplateElement, HTMLImports, MutationObserver */

window.addEventListener('HTMLImportsLoaded', function () {
  importTemplates();
});

// NOTE: HTML Imports polyfill must come before we include `vr-markup`.
var hasImports = document.createElement('link').import;
if (!hasImports) {
  require('../lib/vendor/HTMLImports');
}

var VRMarkup = require('@mozvr/vr-markup');
var registerTemplate = require('./lib/register-template');
var utils = require('./lib/utils');

var VRUtils = VRMarkup.utils;

var internals = {};

function importTemplates () {
  if (HTMLImports && !HTMLImports.useNative) {
    Object.keys(HTMLImports.importer.documents).forEach(function (key) {
      var doc = HTMLImports.importer.documents[key];
      utils.$$('template[is="vr-template"]', doc).forEach(function (template) {
        var templateEl = document.importNode(template, true);
        document.body.appendChild(templateEl);
      });
    });
  }
}

document.addEventListener('vr-markup-ready', function () {
  internals.vrMarkupReady = true;
});

module.exports = document.registerElement(
  'vr-template',
  {
    extends: 'template',
    prototype: Object.create(
      HTMLTemplateElement.prototype,
      {
        createdCallback: {
          value: function () {
            var self = this;
            self.placeholders = [];
            if (self.ownerDocument !== document) {
              // TODO: Fix native HTML Imports for Chrome.
              // See https://github.com/MozVR/vr-components/issues/53
              setTimeout(function () {
                document.body.appendChild(self);
              });
            }
          }
        },

        attributeBlacklist: {
          value: {
            name: true,
            id: true
          }
        },

        attachedCallback: {
          value: function () {
            this.sceneEl = utils.$('vr-scene');
            if (internals.vrMarkupReady) {
              this.inject();
              return;
            }
            document.addEventListener('vr-markup-ready', this.attachEventListeners.bind(this));
            this.addEventListener('loaded', this.inject.bind(this));
          }
        },

        detachedCallback: {
          value: function () {
            var self = this;
            self.removeTemplateListener();
            self.placeholders.forEach(function (el) {
              self.sceneEl.remove(el);
            });
          },
          writable: window.debug<commit_msg>add `is` to attribute blacklist for templates<commit_after>/* global HTMLTemplateElement, HTMLImports, MutationObserver */

window.addEventListener('HTMLImportsLoaded', function () {
  importTemplates();
});

// NOTE: HTML Imports polyfill must come before we include `vr-markup`.
var hasImports = document.createElement('link').import;
if (!hasImports) {
  require('../lib/vendor/HTMLImports');
}

var VRMarkup = require('@mozvr/vr-markup');
var registerTemplate = require('./lib/register-template');
var utils = require('./lib/utils');

var VRUtils = VRMarkup.utils;

var internals = {};

function importTemplates () {
  if (HTMLImports && !HTMLImports.useNative) {
    Object.keys(HTMLImports.importer.documents).forEach(function (key) {
      var doc = HTMLImports.importer.documents[key];
      utils.$$('template[is="vr-template"]', doc).forEach(function (template) {
        var templateEl = document.importNode(template, true);
        document.body.appendChild(templateEl);
      });
    });
  }
}

document.addEventListener('vr-markup-ready', function () {
  internals.vrMarkupReady = true;
});

module.exports = document.registerElement(
  'vr-template',
  {
    extends: 'template',
    prototype: Object.create(
      HTMLTemplateElement.prototype,
      {
        createdCallback: {
          value: function () {
            var self = this;
            self.placeholders = [];
            if (self.ownerDocument !== document) {
              // TODO: Fix native HTML Imports for Chrome.
              // See https://github.com/MozVR/vr-components/issues/53
              setTimeout(function () {
                document.body.appendChild(self);
              });
            }
          }
        },

        attributeBlacklist: {
          value: {
            name: true,
            id: true,
            is: true
          }
        },

        attachedCallback: {
          value: function () {
            this.sceneEl = utils.$('vr-scene');
            if (internals.vrMarkupReady) {
              this.inject();
              return;
            }
            document.addEventListener('vr-markup-ready', this.attachEventListeners.bind(this));
            this.addEventListener('loaded', this.inject.bind(this));
          }
        },

        detachedCallback: {
          value: function () {
            var self = this;
            self.removeTemplateListener();
            self.placeholders.forEach(function (el) {
              self.sceneEl.remove(el);
            });
          },
          writable: window.debug
{'fraction_non_alphanumeric': 0.13219531560142914, 'fraction_numerical': 0.0007939658594680428, 'mean_word_length': 2.123992560446373, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5243843', 'n_tokens_mistral': 1358, 'n_tokens_neox': 1347, 'n_words': 247}