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

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

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

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

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

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

26
export function _domRectFromRect(obj) {
27 28 29
    return DOMRectReadOnly.fromRect(obj)
}

30
export function _preventDefault(e) {
31 32 33
    return e.preventDefault();
}

34
export function _stopPropagation(e) {
35 36 37
    return e.stopPropagation();
}

38
export function _blur(el) {
39
    return el.blur();
40 41
}

42
export function _triggerEvent(el, evtType) {
43 44 45 46 47 48 49 50 51
  // https://stackoverflow.com/questions/8789423/trigger-onchange-event
  var event = new UIEvent(evtType, {
    view: window,
    bubbles: true,
    cancelable: true
  });
  el.dispatchEvent(event);
}

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