<commit_before> /**
  * @module decorator
  * @desc Basic decoration facilities.
  * @author <NAME>
  * @license MPL 2.0
  * @copyright 2013, 2014 Mangalam Research Center for Buddhist Languages
  */
define(/** @lends module:decorator */ function (require, exports, module) {
'use strict';

var util = require("./util");
var $ = require("jquery");
var domutil = require("./domutil");
var closestByClass = domutil.closestByClass;
var transformation = require("./transformation");
var tooltip = require("./gui/tooltip").tooltip;
var action_context_menu = require("./gui/action_context_menu");
var dloc = require("./dloc");

var _indexOf = Array.prototype.indexOf;

/**
 * @classdesc A decorator is responsible for adding decorations to a
 * tree of DOM elements. Decorations are GUI elements.
 *
 * @constructor
 * @param {module:domlistener~Listener} domlistener The listener that
 * the decorator must use to know when the DOM tree has changed and
 * must be redecorated.
 * @param {module:wed~Editor} editor The editor instance for which
 * this decorator was created.
 * @param {module:gui_updater~GUIUpdater} gui_updater The updater to
 * use to modify the GUI tree. All modifications to the GUI must go
 * through this updater.
*/
function Decorator(domlistener, editor, gui_updater) {
    this._domlistener = domlistener;
    this._editor = editor;
    this._gui_updater = gui_updater;
}

exports.Decorator = Decorator;

/**
 * Request that the decorator add its event handlers to its listener.
 */
Decorator.prototype.addHandlers = function () {
    this._domlistener.addHandler(
        "added-element",
        "._real, ._phantom, ._phantom_wrap",
        this.contentEditableHandler.bind(this));
};

/**
 * Start listening to changes to the DOM tree.
 *
 * @param {jQuery} $root The DOM root that this decorator listens
 * to. This must be the same root as the root that the this
 * decorator's domlistener listens on and the same root as the root
 * which the GUI updater updates.
 */
Decorator.prototype.startListening = function ($root) {
    var root = $root[0];
    var contents = Array.prototype.slice.call(root.childNodes);
    while(root.firstChild)
        root.removeChild(root.firstChild);
    this._domlistener.startListening();
    this._gui_updater.insertAt(root, 0, contents);
};

/**
 * This function adds a separator between each child element of the
 * element passed as <code>el</code>. The function only considers
 * "._real" elements.
 *
 * @param {Node} el The element to decorate.
 * @param {string|Node} sep A separator.
 */
Decorator.prototype.listDecorator = function (el, sep) {
    // We expect to work with a homogeneous list. That is, all
    // children the same element.
    var name_map = {};
    var child = el.firstElementChild;
    while(child) {
        if (child.classList.contains("_real"))
            name_map[util.getOriginalName(child)] = 1;
        child = child.nextElementSibling;
    }

    var tags = Object.keys(name_map);
    if (tags.length > 1)
        throw new Error("calling listDecorator on a non-homogeneous list.");

    if (tags.length === 0)<commit_msg>Removed an old pointless bit of code.<commit_after> /**
  * @module decorator
  * @desc Basic decoration facilities.
  * @author <NAME>
  * @license MPL 2.0
  * @copyright 2013, 2014 Mangalam Research Center for Buddhist Languages
  */
define(/** @lends module:decorator */ function (require, exports, module) {
'use strict';

var util = require("./util");
var $ = require("jquery");
var domutil = require("./domutil");
var closestByClass = domutil.closestByClass;
var transformation = require("./transformation");
var tooltip = require("./gui/tooltip").tooltip;
var action_context_menu = require("./gui/action_context_menu");
var dloc = require("./dloc");

var _indexOf = Array.prototype.indexOf;

/**
 * @classdesc A decorator is responsible for adding decorations to a
 * tree of DOM elements. Decorations are GUI elements.
 *
 * @constructor
 * @param {module:domlistener~Listener} domlistener The listener that
 * the decorator must use to know when the DOM tree has changed and
 * must be redecorated.
 * @param {module:wed~Editor} editor The editor instance for which
 * this decorator was created.
 * @param {module:gui_updater~GUIUpdater} gui_updater The updater to
 * use to modify the GUI tree. All modifications to the GUI must go
 * through this updater.
*/
function Decorator(domlistener, editor, gui_updater) {
    this._domlistener = domlistener;
    this._editor = editor;
    this._gui_updater = gui_updater;
}

exports.Decorator = Decorator;

/**
 * Request that the decorator add its event handlers to its listener.
 */
Decorator.prototype.addHandlers = function () {
    this._domlistener.addHandler(
        "added-element",
        "._real, ._phantom, ._phantom_wrap",
        this.contentEditableHandler.bind(this));
};

/**
 * Start listening to changes to the DOM tree.
 *
 * @param {jQuery} $root The DOM root that this decorator listens
 * to. This must be the same root as the root that the this
 * decorator's domlistener listens on and the same root as the root
 * which the GUI updater updates.
 */
Decorator.prototype.startListening = function ($root) {
    this._domlistener.startListening();
};

/**
 * This function adds a separator between each child element of the
 * element passed as <code>el</code>. The function only considers
 * "._real" elements.
 *
 * @param {Node} el The element to decorate.
 * @param {string|Node} sep A separator.
 */
Decorator.prototype.listDecorator = function (el, sep) {
    // We expect to work with a homogeneous list. That is, all
    // children the same element.
    var name_map = {};
    var child = el.firstElementChild;
    while(child) {
        if (child.classList.contains("_real"))
            name_map[util.getOriginalName(child)] = 1;
        child = child.nextElementSibling;
    }

    var tags = Object.keys(name_map);
    if (tags.length > 1)
        throw new Error("calling listDecorator on a non-homogeneous list.");

    if (tags.length === 0)
{'fraction_non_alphanumeric': 0.11241333773522615, 'fraction_numerical': 0.00462198745460548, 'mean_word_length': 3.6751543209876543, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, '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': '7279417', 'n_tokens_mistral': 1821, 'n_tokens_neox': 1774, 'n_words': 604}