<commit_before>/* global Node */

import _default from "ember-views/views/states/default";
import { create } from "ember-metal/platform";
import merge from "ember-metal/merge";

/**
@module ember
@submodule ember-views
*/
var preRender = create(_default);

var containsElement;
if (typeof Node === 'object') {
  containsElement = Node.prototype.contains;

  if (!containsElement && Node.prototype.compareDocumentPosition) {
    // polyfill for older Firefox.
    // http://compatibility.shwups-cms.ch/en/polyfills/?&id=52
    containsElement = function(node){
      return !!(this.compareDocumentPosition(node) & 16);
    };
  }
} else {
  containsElement = function(element) {
    return this.contains(element);
  };
}

merge(preRender, {
  // a view leaves the preRender state once its element has been
  // created (createElement).
  insertElement: function(view, fn) {
    view.createElement();
    var viewCollection = view.viewHierarchyCollection();

    viewCollection.trigger('willInsertElement');

    fn.call(view);

    // We transition to `inDOM` if the element exists in the DOM
    var element = view.get('element');
    if (containsElement.call(document.body, element)) {
      viewCollection.transitionTo('inDOM', false);
      viewCollection.trigger('didInsertElement');
    }
  },

  renderToBufferIfNeeded: function(view, buffer) {
    view.renderToBuffer(buffer);
    return true;
  },

  empty: Ember.K,

  setElement: function(view, value) {
    if (value !== null) {
      view._transitionTo('hasElement');
    }
    return value;
  }
});
<commit_msg>[BUGFIX beta] Use the jQuery polyfill for Node.prototype.contains rather than playing whackamole with browsers<commit_after>/* global Node */

import _default from "ember-views/views/states/default";
import { create } from "ember-metal/platform";
import merge from "ember-metal/merge";
import jQuery from "ember-views/system/jquery";

/**
@module ember
@submodule ember-views
*/
var preRender = create(_default);

merge(preRender, {
  // a view leaves the preRender state once its element has been
  // created (createElement).
  insertElement: function(view, fn) {
    view.createElement();
    var viewCollection = view.viewHierarchyCollection();

    viewCollection.trigger('willInsertElement');

    fn.call(view);

    // We transition to `inDOM` if the element exists in the DOM
    var element = view.get('element');
    if (jQuery.contains(document.body, element)) {
      viewCollection.transitionTo('inDOM', false);
      viewCollection.trigger('didInsertElement');
    }
  },

  renderToBufferIfNeeded: function(view, buffer) {
    view.renderToBuffer(buffer);
    return true;
  },

  empty: Ember.K,

  setElement: function(view, value) {
    if (value !== null) {
      view._transitionTo('hasElement');
    }
    return value;
  }
});

{'fraction_non_alphanumeric': 0.12995750708215298, 'fraction_numerical': 0.00141643059490085, 'mean_word_length': 3.763912310286678, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, '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': '5895022', 'n_tokens_mistral': 844, 'n_tokens_neox': 818, 'n_words': 207}