Reactix.js 1.12 KB
Newer Older
1 2 3
'use strict';

function addRootElement(rootElem) {
4 5 6 7
    document.body.insertBefore(
	rootElem,
	document.body.lastElementChild.nextElementSibling
    );
8 9
}

10
function getSelection(_u) {
11
    return window.getSelection();
12 13
}

14
function stringify(j, indent) {
15
    return JSON.stringify(j, null, indent);
16 17
}

18 19 20 21
function postMessage(obj, msg, src) {
    obj.contentWindow.postMessage(msg, src);
}

22
function setCookie(c) {
23
    document.cookie = c;
24 25
}

26
function domRectFromRect(obj) {
27 28 29 30 31 32 33 34 35 36 37 38 39
    return DOMRectReadOnly.fromRect(obj)
}

function preventDefault(e) {
    return e.preventDefault();
}

function stopPropagation(e) {
    return e.stopPropagation();
}

function blur(el) {
    return el.blur();
40 41
}

42
exports._addRootElement = addRootElement;
43
exports._getSelection = getSelection;
44
exports._stringify = stringify;
45
exports._postMessage = postMessage;
46
exports._setCookie = setCookie;
47
exports._domRectFromRect = domRectFromRect;
48 49 50
exports._preventDefault = preventDefault;
exports._stopPropagation = stopPropagation;
exports._blur = blur;
51 52

exports._keyCode = function(e) {
53 54
    // https://www.w3schools.com/jsref/event_key_keycode.asp
    return e.which || e.keyCode;
55
}