<commit_before>/*global kontext: true, Condition: true*/
/**
 *  Add conditional display of element based on MongoDB query syntax
 *  @name	  Conditional
 *  @package  Kontext
 */
(function(kontext) {
	'use strict';

	//@include ../lib/condition

	//  construct the Condiction module once, as it does not contain state, it can be re-used
	var condition = new Condition();

	/**
	 *  The actual extension which will be registered to Kontext
	 *  @name    extension
	 *  @access  internal
	 *  @param   DOMNode  element
	 *  @param   Object   model
	 *  @param   mixed    config
	 *  @note    the extension function will receive the condition instance as property
	 */
	function extension(element, model, config, options) {
		var anchor;

		/**
		 *  Update the element state based on the provided conditions
		 *  @name    update
		 *  @access  internal
		 *  @return  void
		 */
		function update() {
			if (condition.evaluate(config, model)) {
				if (!element.parentNode) {
					anchor.parentNode.insertBefore(element, anchor);
				}
			}
			else if (element.parentNode) {
				element.parentNode.removeChild(element);
			}
		}

		//  tell Kontext not to traverse into the children of the element
		options.stopDescend();

		if (element.parentNode) {
			//  create the anchor node, consisting of an empty text node
			anchor = element.parentNode.insertBefore(document.createTextNode(''), element);

			//  if there are no childNodes, we don't need to bind the model to them
			if (element.firstChild) {
				kontext.bind(model, element.childNodes);
			}
		}

		//  let all model updates flow through the update function
		//  as it is returned by `on`, we can invoke it immediately
		model.on('update', update)();
	}

	/**
	 *  Evaluate a condition
	 *  @name    evaluate
	 *  @access  public
	 *  @param   mixed   condition
	 *  @param   Object  object to apply the condition on
	 *  @return  bool    matches
	 */
	extension.evaluate = function(config, target) {
		return condition.evaluate(config, target);
	};

	//  register the extension als 'conditional'
	kontext.extension('conditional', extension);

})(kontext);<commit_msg>Reduced overhead, which is already taken care of<commit_after>/*global kontext: true, Condition: true*/
/**
 *  Add conditional display of element based on MongoDB query syntax
 *  @name	  Conditional
 *  @package  Kontext
 */
(function(kontext) {
	'use strict';

	//@include ../lib/condition

	//  construct the Condiction module once, as it does not contain state, it can be re-used
	var condition = new Condition();

	/**
	 *  The actual extension which will be registered to Kontext
	 *  @name    extension
	 *  @access  internal
	 *  @param   DOMNode  element
	 *  @param   Object   model
	 *  @param   mixed    config
	 *  @note    the extension function will receive the condition instance as property
	 */
	function extension(element, model, config, options) {
		var anchor;

		/**
		 *  Update the element state based on the provided conditions
		 *  @name    update
		 *  @access  internal
		 *  @return  void
		 */
		function update() {
			if (condition.evaluate(config, model)) {
				if (!element.parentNode) {
					anchor.parentNode.insertBefore(element, anchor);
				}
			}
			else if (element.parentNode) {
				element.parentNode.removeChild(element);
			}
		}

		//  tell Kontext not to traverse into the children of the element
		options.stopDescend();

		if (element.parentNode) {
			//  create the anchor node, consisting of an empty text node
			anchor = element.parentNode.insertBefore(document.createTextNode(''), element);

			kontext.bind(model, element.childNodes);
		}

		//  let all model updates flow through the update function
		//  as it is returned by `on`, we can invoke it immediately
		model.on('update', update)();
	}

	/**
	 *  Evaluate a condition
	 *  @name    evaluate
	 *  @access  public
	 *  @param   mixed   condition
	 *  @param   Object  object to apply the condition on
	 *  @return  bool    matches
	 */
	extension.evaluate = function(config, target) {
		return condition.evaluate(config, target);
	};

	//  register the extension als 'conditional'
	kontext.extension('conditional', extension);

})(kontext);
{'fraction_non_alphanumeric': 0.10174349176021018, 'fraction_numerical': 0.0, 'mean_word_length': 3.046376811594203, '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': '3690294', 'n_tokens_mistral': 1336, 'n_tokens_neox': 1171, 'n_words': 416}