<commit_before>define([ 'jquery' ], function(jquery) {
	var hi5 = {
		version : "0.7.0"
	};
	var grammar = {};

	grammar["Application"] = function($e) {
		handleUIElements($e);
	};

	grammar["TrimmedWindow"] = function($e) {
		handleUIElements($e);
		handleUIElements($e, ".Menu");
		handleUIElements($e, ".TrimBar");
	};

	grammar["Menu"] = function($e) {
		var $menuTrigger = $("<span class='w3-opennav w3-xlarge w3-right w3-margin-right'>&#9776;</span>");
		$menuTrigger.click(function() {
			// show the menu panel configured below
			$e.show();
		});
		// add to container of the menu
		$e.parent().prepend($menuTrigger);

		// the menu panel which will be shown if the menu trigger is pressed
		$e.addClass("w3-sidenav w3-white w3-card-2 w3-animate-right");
		$e.hide();
		$e.css("right", "0");

		var $closeItem = $("<a href='javascript:void(0)' class='w3-closenav w3-light-grey'>"
				+ "Close<span class='w3-right w3-large w3-margin-right'>&times;</span></a>");
		$e.prepend($closeItem);
		$closeItem.click(function() {
			$e.hide();
		});

		handleUIElements($e, ".MenuItem");
	};

	grammar["MenuItem"] = function($e) {
		// TODO handle sub menus
		handleUIElements($e, ".MenuItem");
	};

	grammar["DirectMenuItem"] = function($e) {
		processDirectItem($e, true, true);
	};
	grammar["DirectToolItem"] = function($e) {
		processDirectItem($e, false, false);
	}

	grammar["GenericStack"] = function($e, stackElementsType) {
		if (stackElementsType == null) {
			stackElementsType = $e.children().eq(0).attr("etype");
		}

		var $ul = $("<ul class='w3-navbar w3-white'></ul>");
		$e.children("." + stackElementsType).hide().each(function() {
			var $p = $(this);
			var $a = $("<a href='#'>" + $p.attr("label") + "</a>");

			var iconSpanHtml = getIconSpanHtml($p, $p.attr("iconURI"));
			if (iconSpanHtml) {
				$a.prepend(iconSpanHtml);
			}

			var $li = $("<li></li>");
			var clickHandler = function() {
				var $pers = $e.children("." + stackElementsType);
				$pers.hide();
				$pers.eq($li.index()).show();
				$ul.children().attr("active", "false");
				$li.attr("active", "true");
			};
			$a.click(clickHandler);
			// install click handler also for stack element
			// to allow to programmatically show it
			$p.click(clickHandler);
			$li.append($a);
			$ul.append($li);
		});
		$e.prepend($ul);
		handleUIElements($e);
		// select first stack element
		$ul.find("a").eq(0).trigger('click');
	};

	grammar["PerspectiveStack"] = function($e) {
		grammar["GenericStack"]($e, "Perspective");
	};

	grammar["Perspective"] = function($e) {
		handleUIElements($e);
	};

	grammar["PartStack"] = function($e) {
		grammar["GenericStack"]($e, "Part");
	};

	grammar["Part"] = function($e) {
		$("[tags~='ViewMenu']", $e).each(function() {
			handleUIElements($e, ".Menu");
		});
		handleUIElements($e, ".ToolBar");

		$e.addClass("w3-panel");
		$e.addClass("w3-border");
		var contribution = $e.attr("contributionuri");

		if (!contribution) {
			contribution = $e.attr("state_index");
		}

		var url = toUrl($e, contribution);
		var $contents = $("<div class='w3-container'></div>");
		$e.append($contents);
		$contents.load(url);
	};

	grammar["TrimBar"] = function($e) {
		var dir = $e.attr("direction");
		handleUIElements($e);
	};

	grammar["ToolBar"] = function($e) {
		$e.addClass("w3-right");
		handleUIElements($e);
	};

	grammar["HandledToolItem"] = function($e) {
		$e.html("<button class='w3-btn w3-white'><img src='" + toUrl($e, $e.attr("iconURI")) + "'></img><br>"
				+ $e.attr("label") + "</button>");
		$e.css("float", "left");
	};

	function applyRule($e) {
		var etype = $e.attr("etype");
		var rule = grammar[etype];

		if (rule == null) {
			console.error("No rule found for: " + etype);
		} else {
			rule($e);
		}
	}

	function processDirectItem($e, hideParentOnClick, showLabel) {
		var $a = $("<a  href='#' class='w3-btn w3-white w3-round'></a>");

		var label = $e.attr("label");
		if (showLabel) {
			if (label !== "") {
				$a.text(label);
			}
		} else {
			$a.attr("title", label);
		}

		var iconSpanHtml = getIconSpanHtml($e, $e.attr("iconURI"));
		if (iconSpanHtml) {
			if (!showLabel) {
				iconSpanHtml.removeClass("w3-margin-right");
			}
			$a.prepend(iconSpanHtml);
		}

		$e.prepend($a);
		var requireModule = toUrl($e, $e.attr("contributionuri"));
		$a.click(function() {
			// hide the menu panel
			if (hideParentOnClick) {
				$e.parent().hide();
			}
			require([ requireModule ], function(handler) {
				if (typeof handler.execute === 'function') {
					if (typeof handler.canExecute === 'function' && !handler.canExecute()) {
						return;
					}
					handler.execute();
				}
			});
		})
	}

	function getIconSpanHtml($e, iconURI) {
		if (iconURI) {
			if (iconURI.startsWith('fa-')) {
				return $("<span class='w3-margin-right fa " + iconURI + "'></span>");
			} else {
				return toUrl($e, iconURI);
			}
		}
		return false;
	}

	function handleUIElements($e, filter) {
		$e.children(".UIElement " + (filter == null ? "" : filter)).each(function() {
			applyRule($(this));
		});
	}

	function toUrl($e, relativePath) {
		return $e.attr("contributoruri") + "/" + relativePath;
	}

	function getParamNames(fn) {
		var fstr = fn.toString();
		return fstr.match(/\(.*?\)/)[0].replace(/[()]/gi, '').replace(/\s/gi, '').split(',');
	}

	var PartService = function($context) {
		this.$context = $context;
	};
	PartService.prototype.loadUIElement = function(id, fn) {
		this.$context.load("hi5/ws/model/element/" + id, function() {
			$uiElement = $("[elementid='" + id + "']", this);
			applyRule($uiElement);
			if (typeof fn === 'function') {
				fn();
			}
		});
	};
	PartService.prototype.showPerspective = function(id, callback) {
		$(document).find(".Perspective[elementid='" + id + "']").each(function() {
			var $this = $(this);
			// each stack element knows how to show itself when clicked on,
			// see GenericStack rule
			$this.trigger('click');
			callback.apply($this);
		});
	};
	PartService.prototype.select = function(selector) {
		// first find the enclosing Part div, then start searching from that
		// context downwards
		return this.$context.closest(".Part").find(selector);
	};

	$.fn.hi5 = function(fn) {
		var names = getParamNames(fn);
		this.each(function() {
			var $this = $(this);
			var context = {
				partService : new PartService($this)
			};

			var args = new Array();

			for (var i = 0; i < names.length; i++) {
				var name = names[i];
				var arg = context[name];
				args.push(arg);
			}

			fn.apply(this, args);
		})
	};

	return hi5;
});<commit_msg>switched direct item rendering from <a> to <span><commit_after>define([ 'jquery' ], function(jquery) {
	var hi5 = {
		version : "0.7.0"
	};
	var grammar = {};

	grammar["Application"] = function($e) {
		handleUIElements($e);
	};

	grammar["TrimmedWindow"] = function($e) {
		handleUIElements($e);
		handleUIElements($e, ".Menu");
		handleUIElements($e, ".TrimBar");
	};

	grammar["Menu"] = function($e) {
		var $menuTrigger = $("<span class='w3-opennav w3-xlarge w3-right w3-margin-right'>&#9776;</span>");
		$menuTrigger.click(function() {
			// show the menu panel configured below
			$e.show();
		});
		// add to container of the menu
		$e.parent().prepend($menuTrigger);

		// the menu panel which will be shown if the menu trigger is pressed
		$e.addClass("w3-sidenav w3-white w3-card-2 w3-animate-right");
		$e.hide();
		$e.css("right", "0");

		var $closeItem = $("<a href='javascript:void(0)' class='w3-closenav w3-light-grey'>"
				+ "Close<span class='w3-right w3-large w3-margin-right'>&times;</span></a>");
		$e.prepend($closeItem);
		$closeItem.click(function() {
			$e.hide();
		});

		handleUIElements($e, ".MenuItem");
	};

	grammar["MenuItem"] = function($e) {
		// TODO handle sub menus
		handleUIElements($e, ".MenuItem");
	};

	grammar["DirectMenuItem"] = function($e) {
		processDirectItem($e, true, true);
	};
	grammar["DirectToolItem"] = function($e) {
		processDirectItem($e, false, false);
	}

	grammar["GenericStack"] = function($e, stackElementsType) {
		if (stackElementsType == null) {
			stackElementsType = $e.children().eq(0).attr("etype");
		}

		var $ul = $("<ul class='w3-navbar w3-white'></ul>");
		$e.children("." + stackElementsType).hide().each(function() {
			var $p = $(this);
			var $a = $("<a href='#'>" + $p.attr("label") + "</a>");

			var iconSpanHtml = getIconSpanHtml($p, $p.attr("iconURI"));
			if (iconSpanHtml) {
				$a.prepend(iconSpanHtml);
			}

			var $li = $("<li></li>");
			var clickHandler = function() {
				var $pers = $e.children("." + stackElementsType);
				$pers.hide();
				$pers.eq($li.index()).show();
				$ul.children().attr("active", "false");
				$li.attr("active", "true");
			};
			$a.click(clickHandler);
			// install click handler also for stack element
			// to allow to programmatically show it
			$p.click(clickHandler);
			$li.append($a);
			$ul.append($li);
		});
		$e.prepend($ul);
		handleUIElements($e);
		// select first stack element
		$ul.find("a").eq(0).trigger('click');
	};

	grammar["PerspectiveStack"] = function($e) {
		grammar["GenericStack"]($e, "Perspective");
	};

	grammar["Perspective"] = function($e) {
		handleUIElements($e);
	};

	grammar["PartStack"] = function($e) {
		grammar["GenericStack"]($e, "Part");
	};

	grammar["Part"] = function($e) {
		$("[tags~='ViewMenu']", $e).each(function() {
			handleUIElements($e, ".Menu");
		});
		handleUIElements($e, ".ToolBar");

		$e.addClass("w3-panel");
		$e.addClass("w3-border");
		var contribution = $e.attr("contributionuri");

		if (!contribution) {
			contribution = $e.attr("state_index");
		}

		var url = toUrl($e, contribution);
		var $contents = $("<div class='w3-container'></div>");
		$e.append($contents);
		$contents.load(url);
	};

	grammar["TrimBar"] = function($e) {
		var dir = $e.attr("direction");
		handleUIElements($e);
	};

	grammar["ToolBar"] = function($e) {
		$e.addClass("w3-right");
		handleUIElements($e);
	};

	grammar["HandledToolItem"] = function($e) {
		$e.html("<button class='w3-btn w3-white'><img src='" + toUrl($e, $e.attr("iconURI")) + "'></img><br>"
				+ $e.attr("label") + "</button>");
		$e.css("float", "left");
	};

	function applyRule($e) {
		var etype = $e.attr("etype");
		var rule = grammar[etype];

		if (rule == null) {
			console.error("No rule found for: " + etype);
		} else {
			rule($e);
		}
	}

	function processDirectItem($e, hideParentOnClick, showLabel) {
		var $a = $("<span class='w3-btn w3-white w3-round'></span>");

		var label = $e.attr("label");
		if (showLabel) {
			if (label !== "") {
				$a.text(label);
			}
		} else {
			$a.attr("title", label);
		}

		var iconSpanHtml = getIconSpanHtml($e, $e.attr("iconURI"));
		if (iconSpanHtml) {
			if (!showLabel) {
				iconSpanHtml.removeClass("w3-margin-right");
			}
			$a.prepend(iconSpanHtml);
		}

		$e.prepend($a);
		var requireModule = toUrl($e, $e.attr("contributionuri"));
		$a.click(function() {
			// hide the menu panel
			if (hideParentOnClick) {
				$e.parent().hide();
			}
			require([ requireModule ], function(handler) {
				if (typeof handler.execute === 'function') {
					if (typeof handler.canExecute === 'function' && !handler.canExecute()) {
						return;
					}
					handler.execute();
				}
			});
		})
	}

	function getIconSpanHtml($e, iconURI) {
		if (iconURI) {
			if (iconURI.startsWith('fa-')) {
				return $("<span class='w3-margin-right fa " + iconURI + "'></span>");
			} else {
				return toUrl($e, iconURI);
			}
		}
		return false;
	}

	function handleUIElements($e, filter) {
		$e.children(".UIElement " + (filter == null ? "" : filter)).each(function() {
			applyRule($(this));
		});
	}

	function toUrl($e, relativePath) {
		return $e.attr("contributoruri") + "/" + relativePath;
	}

	function getParamNames(fn) {
		var fstr = fn.toString();
		return fstr.match(/\(.*?\)/)[0].replace(/[()]/gi, '').replace(/\s/gi, '').split(',');
	}

	var PartService = function($context) {
		this.$context = $context;
	};
	PartService.prototype.loadUIElement = function(id, fn) {
		this.$context.load("hi5/ws/model/element/" + id, function() {
			$uiElement = $("[elementid='" + id + "']", this);
			applyRule($uiElement);
			if (typeof fn === 'function') {
				fn();
			}
		});
	};
	PartService.prototype.showPerspective = function(id, callback) {
		$(document).find(".Perspective[elementid='" + id + "']").each(function() {
			var $this = $(this);
			// each stack element knows how to show itself when clicked on,
			// see GenericStack rule
			$this.trigger('click');
			callback.apply($this);
		});
	};
	PartService.prototype.select = function(selector) {
		// first find the enclosing Part div, then start searching from that
		// context downwards
		return this.$context.closest(".Part").find(selector);
	};

	$.fn.hi5 = function(fn) {
		var names = getParamNames(fn);
		this.each(function() {
			var $this = $(this);
			var context = {
				partService : new PartService($this)
			};

			var args = new Array();

			for (var i = 0; i < names.length; i++) {
				var name = names[i];
				var arg = context[name];
				args.push(arg);
			}

			fn.apply(this, args);
		})
	};

	return hi5;
});
{'fraction_non_alphanumeric': 0.20899897405833212, 'fraction_numerical': 0.006448776198153305, 'mean_word_length': 3.1279491833030852, 'pattern_counts': {'":': 0, '<': 53, '<?xml version=': 0, '>': 51, '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': '518439', 'n_tokens_mistral': 5459, 'n_tokens_neox': 4727, 'n_words': 898}