<commit_before>// dom.ts - DOM helpers and interface extensions
// Part of Stardazed TX
// (c) 2016 by <NAME> - @zenmumbler

// interface Element {
// 	closest: (selectors: string) => Element;
// }


namespace sd.dom {

	// -- Elements

	export type ElemSelector = string | Object;

	export function $n(sel: string, base?: HTMLElement): HTMLElement[] { return Array.prototype.slice.call((base || document).querySelectorAll(sel), 0); }
	export function $(sel: ElemSelector, base?: HTMLElement) { return (typeof (sel) == 'string') ? $n(<string>sel, base) : seq(sel); }
	export function $1(sel: ElemSelector, base?: HTMLElement): HTMLElement { return $(sel, base)[0]; }

	export function show(sel: ElemSelector, disp?: string) { $(sel).forEach(function(el) { el.style.display = (disp != null) ? disp : "block" }); }
	export function hide(sel: ElemSelector) { $(sel).forEach(function(el) { el.style.display = "none" }); }

	export function setDisabled(sel: ElemSelector, dis: boolean) { $(sel).forEach(function(el) { el.disabled = dis; }); }
	export function enable(sel: ElemSelector) { setDisabled(sel, false); }
	export function disable(sel: ElemSelector) { setDisabled(sel, true); }

	export function closest(sourceSel: ElemSelector, sel: string): HTMLElement {
		var source = <Node>($1(sourceSel));

		if ((<Element>source).closest) {
			return <HTMLElement>(<Element>source).closest(sel);
		}

		do {
			source = source.parentNode;
			if (source.nodeType != Node.ELEMENT_NODE)
				return null;
			var elem = <HTMLElement>source;
			if (elem.matches(sel))
				return elem;
		} while (source);

		return null;
	}

	export function nextElementSibling(elem: HTMLElement): HTMLElement {
		while (elem) {
			elem = <HTMLElement>(elem.nextSibling);
			if (elem && elem.nodeType == Node.ELEMENT_NODE)
				return elem;
		}

		return null;
	}


	// -- Events

	export function on(target: ElemSelector, evt: string, handler: (ev: Event) => any) {
		$(target).forEach(function(tgt) { tgt.addEventListener(evt, handler); });<commit_msg>dom: null annotations<commit_after>// dom.ts - DOM helpers and interface extensions
// Part of Stardazed TX
// (c) 2016 by <NAME> - @zenmumbler

// interface Element {
// 	closest: (selectors: string) => Element;
// }


namespace sd.dom {

	// -- Elements

	export type ElemSelector = string | Object;

	export function $n(sel: string, base?: HTMLElement): HTMLElement[] { return Array.prototype.slice.call((base || document).querySelectorAll(sel), 0); }
	export function $(sel: ElemSelector, base?: HTMLElement) { return (typeof (sel) == 'string') ? $n(<string>sel, base) : seq(sel); }
	export function $1(sel: ElemSelector, base?: HTMLElement): HTMLElement { return $(sel, base)[0]; }

	export function show(sel: ElemSelector, disp?: string) { $(sel).forEach(function(el) { el.style.display = (disp != null) ? disp : "block" }); }
	export function hide(sel: ElemSelector) { $(sel).forEach(function(el) { el.style.display = "none" }); }

	export function setDisabled(sel: ElemSelector, dis: boolean) { $(sel).forEach(function(el) { el.disabled = dis; }); }
	export function enable(sel: ElemSelector) { setDisabled(sel, false); }
	export function disable(sel: ElemSelector) { setDisabled(sel, true); }

	export function closest(sourceSel: ElemSelector, sel: string): HTMLElement | null {
		var source = <Node>($1(sourceSel));

		if ((<Element>source).closest) {
			return <HTMLElement>(<Element>source).closest(sel);
		}

		do {
			source = source.parentNode;
			if (source.nodeType != Node.ELEMENT_NODE)
				return null;
			var elem = <HTMLElement>source;
			if (elem.matches(sel))
				return elem;
		} while (source);

		return null;
	}

	export function nextElementSibling(elem: HTMLElement): HTMLElement | null {
		while (elem) {
			elem = <HTMLElement>(elem.nextSibling);
			if (elem && elem.nodeType == Node.ELEMENT_NODE)
				return elem;
		}

		return null;
	}


	// -- Events

	export function on(target: ElemSelector, evt: string, handler: (ev: Event) => any) {
		$(target).forEach(function(tgt) { tgt.addEventListener(evt, handler); });
{'fraction_non_alphanumeric': 0.15995085995085995, 'fraction_numerical': 0.003931203931203931, 'mean_word_length': 4.435246995994659, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 23, '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': '2034127', 'n_tokens_mistral': 1409, 'n_tokens_neox': 1327, 'n_words': 340}