2020-04-23 17:13:56 +08:00
|
|
|
export function getDom(element) {
|
2020-06-03 23:11:02 +08:00
|
|
|
if (!element) {
|
|
|
|
element = document.body;
|
|
|
|
} else if (typeof element === 'string') {
|
2020-07-23 22:51:02 +08:00
|
|
|
if (element === 'document') {
|
|
|
|
return document;
|
|
|
|
}
|
2020-06-03 23:11:02 +08:00
|
|
|
element = document.querySelector(element);
|
|
|
|
}
|
|
|
|
return element;
|
2020-03-11 16:49:25 +08:00
|
|
|
}
|
2020-03-10 15:25:29 +08:00
|
|
|
|
2020-03-11 16:49:25 +08:00
|
|
|
export function getDomInfo(element) {
|
2020-06-03 23:11:02 +08:00
|
|
|
var result = {};
|
2020-03-10 15:25:29 +08:00
|
|
|
|
2020-06-03 23:11:02 +08:00
|
|
|
var dom = getDom(element);
|
2020-03-11 16:49:25 +08:00
|
|
|
|
2020-06-03 23:11:02 +08:00
|
|
|
result["offsetTop"] = dom.offsetTop || 0;
|
|
|
|
result["offsetLeft"] = dom.offsetLeft || 0;
|
|
|
|
result["offsetWidth"] = dom.offsetWidth || 0;
|
|
|
|
result["offsetHeight"] = dom.offsetHeight || 0;
|
|
|
|
result["scrollHeight"] = dom.scrollHeight || 0;
|
|
|
|
result["scrollWidth"] = dom.scrollWidth || 0;
|
|
|
|
result["scrollLeft"] = dom.scrollLeft || 0;
|
|
|
|
result["scrollTop"] = dom.scrollTop || 0;
|
|
|
|
result["clientTop"] = dom.clientTop || 0;
|
|
|
|
result["clientLeft"] = dom.clientLeft || 0;
|
|
|
|
result["clientHeight"] = dom.clientHeight || 0;
|
|
|
|
result["clientWidth"] = dom.clientWidth || 0;
|
2020-11-12 16:53:14 +08:00
|
|
|
var absolutePosition = getElementAbsolutePos(dom);
|
|
|
|
result["absoluteTop"] = Math.round(absolutePosition.y);
|
|
|
|
result["absoluteLeft"] = Math.round(absolutePosition.x);
|
2020-05-03 17:22:33 +08:00
|
|
|
|
2020-06-03 23:11:02 +08:00
|
|
|
return result;
|
2020-03-10 15:25:29 +08:00
|
|
|
}
|
|
|
|
|
2020-11-12 16:53:14 +08:00
|
|
|
function getElementAbsolutePos(element) {
|
|
|
|
var res:any = new Object();
|
|
|
|
res.x = 0; res.y = 0;
|
|
|
|
if (element !== null) {
|
|
|
|
if (element.getBoundingClientRect) {
|
|
|
|
var viewportElement = document.documentElement;
|
|
|
|
var box = element.getBoundingClientRect();
|
|
|
|
var scrollLeft = viewportElement.scrollLeft;
|
|
|
|
var scrollTop = viewportElement.scrollTop;
|
|
|
|
|
|
|
|
res.x = box.left + scrollLeft;
|
|
|
|
res.y = box.top + scrollTop;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-07-02 14:08:51 +08:00
|
|
|
export function addFileClickEventListener(btn) {
|
2020-09-02 15:15:59 +08:00
|
|
|
if ((btn as HTMLElement).addEventListener) {
|
|
|
|
(btn as HTMLElement).addEventListener("click", fileClickEvent);
|
|
|
|
}
|
2020-07-02 14:08:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export function removeFileClickEventListener(btn) {
|
2020-09-02 15:15:59 +08:00
|
|
|
(btn as HTMLElement).removeEventListener("click", fileClickEvent);
|
2020-07-02 14:08:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export function fileClickEvent() {
|
|
|
|
var fileId = this.attributes["data-fileid"].nodeValue;
|
|
|
|
var element = document.getElementById(fileId);
|
|
|
|
(element as HTMLInputElement).click();
|
|
|
|
}
|
|
|
|
|
2020-07-01 06:49:51 +08:00
|
|
|
export function clearFile(element) {
|
|
|
|
element.setAttribute("type", "input");
|
|
|
|
element.value = '';
|
|
|
|
element.setAttribute("type", "file");
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getFileInfo(element) {
|
|
|
|
if (element.files && element.files.length > 0) {
|
2020-07-21 00:16:02 +08:00
|
|
|
var fileInfo = [];
|
|
|
|
for (var i = 0; i < element.files.length; i++) {
|
|
|
|
var file = element.files[i];
|
|
|
|
var objectUrl = getObjectURL(element);
|
|
|
|
fileInfo.push({
|
|
|
|
fileName: file.name,
|
|
|
|
size: file.size,
|
|
|
|
objectURL: objectUrl,
|
|
|
|
type: file.type
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-07-01 06:49:51 +08:00
|
|
|
return fileInfo;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getObjectURL(element) {
|
|
|
|
var url = null;
|
|
|
|
var file = element.files[0];
|
|
|
|
if (window.URL != undefined) {
|
|
|
|
url = window.URL.createObjectURL(file);
|
|
|
|
} else if (window.webkitURL != undefined) {
|
|
|
|
url = window.webkitURL.createObjectURL(file);
|
|
|
|
}
|
|
|
|
return url;
|
|
|
|
}
|
|
|
|
|
2020-07-21 15:50:38 +08:00
|
|
|
export function uploadFile(element, index, data, headers, fileId, url, name, instance, percentMethod, successMethod, errorMethod) {
|
2020-07-01 06:49:51 +08:00
|
|
|
let formData = new FormData();
|
2020-07-21 00:16:02 +08:00
|
|
|
var file = element.files[index];
|
2020-07-01 06:49:51 +08:00
|
|
|
var size = file.size;
|
2020-07-21 15:50:38 +08:00
|
|
|
formData.append(name, file);
|
|
|
|
if (data != null) {
|
|
|
|
for (var key in data) {
|
|
|
|
formData.append(key, data[key]);
|
|
|
|
}
|
|
|
|
}
|
2020-07-01 06:49:51 +08:00
|
|
|
const req = new XMLHttpRequest()
|
|
|
|
req.onreadystatechange = function () {
|
|
|
|
if (req.readyState === 4) {
|
2020-07-13 11:54:53 +08:00
|
|
|
if (req.status != 200) {
|
|
|
|
instance.invokeMethodAsync(errorMethod, fileId, `{"status": ${req.status}}`);
|
2020-07-01 06:49:51 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
instance.invokeMethodAsync(successMethod, fileId, req.responseText);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
req.upload.onprogress = function (event) {
|
|
|
|
var percent = Math.floor(event.loaded / size * 100);
|
|
|
|
instance.invokeMethodAsync(percentMethod, fileId, percent);
|
|
|
|
}
|
|
|
|
req.onerror = function (e) {
|
|
|
|
instance.invokeMethodAsync(errorMethod, fileId, "error");
|
|
|
|
}
|
|
|
|
req.open('post', url, true)
|
|
|
|
if (headers != null) {
|
|
|
|
for (var header in headers) {
|
|
|
|
req.setRequestHeader(header, headers[header]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
req.send(formData)
|
|
|
|
}
|
|
|
|
|
|
|
|
export function triggerEvent(element, eventType, eventName) {
|
2020-07-02 14:08:51 +08:00
|
|
|
var dom = element as HTMLInputElement;
|
2020-07-01 06:49:51 +08:00
|
|
|
var evt = document.createEvent(eventType);
|
|
|
|
evt.initEvent(eventName);
|
|
|
|
return dom.dispatchEvent(evt);
|
|
|
|
}
|
|
|
|
|
2020-03-10 15:25:29 +08:00
|
|
|
export function getBoundingClientRect(element) {
|
2020-06-03 23:11:02 +08:00
|
|
|
let dom = getDom(element);
|
2020-10-14 13:56:59 +08:00
|
|
|
if (dom && dom.getBoundingClientRect) {
|
2020-07-21 00:16:02 +08:00
|
|
|
return dom.getBoundingClientRect();
|
|
|
|
}
|
|
|
|
return null;
|
2020-03-10 15:25:29 +08:00
|
|
|
}
|
|
|
|
|
2020-03-11 16:49:25 +08:00
|
|
|
export function addDomEventListener(element, eventName, invoker) {
|
2020-06-03 23:11:02 +08:00
|
|
|
let callback = args => {
|
|
|
|
const obj = {};
|
|
|
|
for (let k in args) {
|
|
|
|
obj[k] = args[k];
|
|
|
|
}
|
|
|
|
let json = JSON.stringify(obj, (k, v) => {
|
|
|
|
if (v instanceof Node) return 'Node';
|
|
|
|
if (v instanceof Window) return 'Window';
|
|
|
|
return v;
|
|
|
|
}, ' ');
|
|
|
|
invoker.invokeMethodAsync('Invoke', json);
|
|
|
|
};
|
|
|
|
|
|
|
|
if (element == 'window') {
|
|
|
|
if (eventName == 'resize') {
|
|
|
|
window.addEventListener(eventName, debounce(() => callback({ innerWidth: window.innerWidth, innerHeight: window.innerHeight }), 200, false));
|
2020-05-10 22:43:58 +08:00
|
|
|
} else {
|
2020-06-03 23:11:02 +08:00
|
|
|
window.addEventListener(eventName, callback);
|
2020-04-22 19:37:06 +08:00
|
|
|
}
|
2020-06-03 23:11:02 +08:00
|
|
|
} else {
|
|
|
|
let dom = getDom(element);
|
|
|
|
(dom as HTMLElement).addEventListener(eventName, callback);
|
|
|
|
}
|
2020-03-10 15:25:29 +08:00
|
|
|
}
|
|
|
|
|
2020-03-15 23:54:48 +08:00
|
|
|
export function matchMedia(query) {
|
2020-06-03 23:11:02 +08:00
|
|
|
return window.matchMedia(query).matches;
|
2020-03-10 15:25:29 +08:00
|
|
|
}
|
|
|
|
|
2020-03-12 16:35:23 +08:00
|
|
|
function fallbackCopyTextToClipboard(text) {
|
2020-06-03 23:11:02 +08:00
|
|
|
var textArea = document.createElement("textarea");
|
|
|
|
textArea.value = text;
|
|
|
|
|
|
|
|
// Avoid scrolling to bottom
|
|
|
|
textArea.style.top = "0";
|
|
|
|
textArea.style.left = "0";
|
|
|
|
textArea.style.position = "fixed";
|
|
|
|
|
|
|
|
document.body.appendChild(textArea);
|
|
|
|
textArea.focus();
|
|
|
|
textArea.select();
|
2020-03-12 16:35:23 +08:00
|
|
|
|
2020-06-03 23:11:02 +08:00
|
|
|
try {
|
|
|
|
var successful = document.execCommand('copy');
|
|
|
|
var msg = successful ? 'successful' : 'unsuccessful';
|
|
|
|
console.log('Fallback: Copying text command was ' + msg);
|
|
|
|
} catch (err) {
|
|
|
|
console.error('Fallback: Oops, unable to copy', err);
|
|
|
|
}
|
|
|
|
|
|
|
|
document.body.removeChild(textArea);
|
2020-03-12 16:35:23 +08:00
|
|
|
}
|
|
|
|
export function copy(text) {
|
2020-06-03 23:11:02 +08:00
|
|
|
if (!navigator.clipboard) {
|
|
|
|
fallbackCopyTextToClipboard(text);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
navigator.clipboard.writeText(text).then(function () {
|
|
|
|
console.log('Async: Copying to clipboard was successful!');
|
|
|
|
}, function (err) {
|
|
|
|
console.error('Async: Could not copy text: ', err);
|
|
|
|
});
|
2020-03-11 16:49:25 +08:00
|
|
|
}
|
2020-03-12 13:00:54 +08:00
|
|
|
|
2020-03-25 00:32:26 +08:00
|
|
|
export function focus(selector) {
|
2020-06-03 23:11:02 +08:00
|
|
|
let dom = getDom(selector);
|
|
|
|
dom.focus();
|
2020-03-25 00:32:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export function blur(selector) {
|
2020-06-03 23:11:02 +08:00
|
|
|
let dom = getDom(selector);
|
|
|
|
dom.blur();
|
2020-03-25 00:32:26 +08:00
|
|
|
}
|
|
|
|
|
2020-03-12 13:00:54 +08:00
|
|
|
export function log(text) {
|
2020-06-03 23:11:02 +08:00
|
|
|
console.log(text);
|
2020-03-27 17:24:16 +08:00
|
|
|
}
|
|
|
|
|
2020-10-09 10:59:52 +08:00
|
|
|
export function BackTop(target: string) {
|
|
|
|
let dom = getDom(target);
|
|
|
|
if (dom) {
|
|
|
|
slideTo(dom.scrollTop);
|
|
|
|
} else {
|
|
|
|
slideTo(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function slideTo(targetPageY) {
|
|
|
|
var timer = setInterval(function () {
|
|
|
|
var currentY = document.documentElement.scrollTop || document.body.scrollTop;
|
|
|
|
var distance = targetPageY > currentY ? targetPageY - currentY : currentY - targetPageY;
|
|
|
|
var speed = Math.ceil(distance / 10);
|
|
|
|
if (currentY == targetPageY) {
|
|
|
|
clearInterval(timer);
|
|
|
|
} else {
|
|
|
|
window.scrollTo(0, targetPageY > currentY ? currentY + speed : currentY - speed);
|
|
|
|
}
|
|
|
|
}, 10);
|
2020-05-03 17:22:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export function getFirstChildDomInfo(element) {
|
2020-06-03 23:11:02 +08:00
|
|
|
var dom = getDom(element);
|
|
|
|
return getDomInfo(dom.firstElementChild);
|
2020-05-03 17:22:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export function addClsToFirstChild(element, className) {
|
2020-06-03 23:11:02 +08:00
|
|
|
var dom = getDom(element);
|
|
|
|
if (dom.firstElementChild) {
|
|
|
|
dom.firstElementChild.classList.add(className);
|
|
|
|
}
|
2020-05-03 17:22:33 +08:00
|
|
|
}
|
|
|
|
|
2020-12-03 12:28:02 +08:00
|
|
|
export function removeClsFromFirstChild(element, className) {
|
|
|
|
var dom = getDom(element);
|
|
|
|
if (dom.firstElementChild) {
|
|
|
|
dom.firstElementChild.classList.remove(className);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-03 17:22:33 +08:00
|
|
|
export function addDomEventListenerToFirstChild(element, eventName, invoker) {
|
2020-06-03 23:11:02 +08:00
|
|
|
var dom = getDom(element);
|
2020-05-03 17:22:33 +08:00
|
|
|
|
2020-06-03 23:11:02 +08:00
|
|
|
if (dom.firstElementChild) {
|
|
|
|
addDomEventListener(dom.firstElementChild, eventName, invoker);
|
|
|
|
}
|
2020-05-03 17:22:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export function getAbsoluteTop(e) {
|
2020-06-03 23:11:02 +08:00
|
|
|
var offset = e.offsetTop;
|
|
|
|
if (e.offsetParent != null) {
|
|
|
|
offset += getAbsoluteTop(e.offsetParent);
|
|
|
|
}
|
|
|
|
return offset;
|
2020-05-03 17:22:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export function getAbsoluteLeft(e) {
|
2020-06-03 23:11:02 +08:00
|
|
|
var offset = e.offsetLeft;
|
|
|
|
if (e.offsetParent != null) {
|
|
|
|
offset += getAbsoluteLeft(e.offsetParent);
|
|
|
|
}
|
|
|
|
return offset;
|
2020-05-10 22:43:58 +08:00
|
|
|
}
|
2020-05-03 17:22:33 +08:00
|
|
|
|
|
|
|
export function addElementToBody(element) {
|
2020-06-03 23:11:02 +08:00
|
|
|
document.body.appendChild(element);
|
2020-05-03 17:22:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export function delElementFromBody(element) {
|
2020-06-03 23:11:02 +08:00
|
|
|
document.body.removeChild(element);
|
2020-04-23 17:13:56 +08:00
|
|
|
}
|
2020-05-09 11:09:07 +08:00
|
|
|
|
|
|
|
export function addElementTo(addElement, elementSelector) {
|
2020-06-03 23:11:02 +08:00
|
|
|
let parent = getDom(elementSelector);
|
|
|
|
if (parent && addElement) {
|
|
|
|
parent.appendChild(addElement);
|
|
|
|
}
|
2020-05-09 11:09:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export function delElementFrom(delElement, elementSelector) {
|
2020-06-03 23:11:02 +08:00
|
|
|
let parent = getDom(elementSelector);
|
|
|
|
if (parent && delElement) {
|
|
|
|
parent.removeChild(delElement);
|
|
|
|
}
|
2020-06-02 14:25:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export function getActiveElement() {
|
2020-06-03 23:11:02 +08:00
|
|
|
let element = document.activeElement;
|
|
|
|
let id = element.getAttribute("id") || "";
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function focusDialog(selector: string, count: number = 0) {
|
|
|
|
let ele = <HTMLElement>document.querySelector(selector);
|
|
|
|
if (ele && !ele.hasAttribute("disabled")) {
|
|
|
|
setTimeout(() => {
|
|
|
|
ele.focus();
|
|
|
|
let curId = "#" + getActiveElement();
|
|
|
|
if (curId !== selector) {
|
|
|
|
if (count < 10) {
|
|
|
|
focusDialog(selector, count + 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, 10);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getWindow() {
|
|
|
|
return {
|
|
|
|
innerWidth: window.innerWidth,
|
|
|
|
innerHeight: window.innerHeight
|
|
|
|
};
|
2020-06-02 14:25:44 +08:00
|
|
|
}
|
2020-06-03 23:11:02 +08:00
|
|
|
|
|
|
|
function debounce(func, wait, immediate) {
|
|
|
|
var timeout;
|
|
|
|
return () => {
|
|
|
|
const context = this, args = arguments;
|
|
|
|
const later = () => {
|
|
|
|
timeout = null;
|
|
|
|
if (!immediate) func.apply(this, args);
|
|
|
|
};
|
|
|
|
const callNow = immediate && !timeout;
|
|
|
|
clearTimeout(timeout);
|
|
|
|
timeout = setTimeout(later, wait);
|
|
|
|
if (callNow) func.apply(context, args);
|
|
|
|
};
|
2020-06-04 17:03:13 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
export function css(element: HTMLElement, name: string | object, value: string | null = null) {
|
|
|
|
if (typeof name === 'string') {
|
|
|
|
element.style[name] = value;
|
|
|
|
} else {
|
|
|
|
for (let key in name) {
|
|
|
|
if (name.hasOwnProperty(key)) {
|
|
|
|
element.style[key] = name[key];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export function addCls(selector: Element | string, clsName: string | Array<string>) {
|
|
|
|
let element = getDom(selector);
|
|
|
|
|
|
|
|
if (typeof clsName === "string") {
|
|
|
|
element.classList.add(clsName);
|
|
|
|
} else {
|
|
|
|
element.classList.add(...clsName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export function removeCls(selector: Element | string, clsName: string | Array<string>) {
|
|
|
|
let element = getDom(selector);
|
|
|
|
|
|
|
|
if (typeof clsName === "string") {
|
|
|
|
element.classList.remove(clsName);
|
|
|
|
} else {
|
|
|
|
element.classList.remove(...clsName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-27 13:13:26 +08:00
|
|
|
export function elementScrollIntoView(selector: Element | string) {
|
|
|
|
let element = getDom(selector);
|
|
|
|
|
|
|
|
if(!element)
|
|
|
|
return;
|
|
|
|
|
|
|
|
element.scrollIntoView({ behavior: 'smooth', block: 'nearest', inline: 'start' });
|
|
|
|
}
|
|
|
|
|
2020-07-21 22:32:54 +08:00
|
|
|
const oldBodyCacheStack = [];
|
2020-07-11 23:41:27 +08:00
|
|
|
|
2020-07-22 22:24:58 +08:00
|
|
|
const hasScrollbar = () => {
|
|
|
|
let overflow = document.body.style.overflow;
|
|
|
|
if (overflow && overflow === "hidden") return false;
|
|
|
|
return document.body.scrollHeight > (window.innerHeight || document.documentElement.clientHeight);
|
|
|
|
}
|
|
|
|
|
2020-06-04 17:03:13 +08:00
|
|
|
export function disableBodyScroll() {
|
2020-07-11 23:41:27 +08:00
|
|
|
let body = document.body;
|
2020-07-21 22:32:54 +08:00
|
|
|
const oldBodyCache = {};
|
2020-07-11 23:41:27 +08:00
|
|
|
["position", "width", "overflow"].forEach((key) => {
|
|
|
|
oldBodyCache[key] = body.style[key];
|
|
|
|
});
|
2020-07-21 22:32:54 +08:00
|
|
|
oldBodyCacheStack.push(oldBodyCache);
|
2020-07-11 23:41:27 +08:00
|
|
|
css(body,
|
2020-06-04 17:03:13 +08:00
|
|
|
{
|
|
|
|
"position": "relative",
|
2020-07-22 22:24:58 +08:00
|
|
|
"width": hasScrollbar() ? "calc(100% - 17px)" : null,
|
2020-06-04 17:03:13 +08:00
|
|
|
"overflow": "hidden"
|
|
|
|
});
|
|
|
|
addCls(document.body, "ant-scrolling-effect");
|
|
|
|
}
|
|
|
|
|
2020-09-05 16:09:58 +08:00
|
|
|
export function enableBodyScroll() {
|
|
|
|
let oldBodyCache = oldBodyCacheStack.length > 0 ? oldBodyCacheStack.pop() : {};
|
2020-06-04 17:03:13 +08:00
|
|
|
|
2020-09-05 16:09:58 +08:00
|
|
|
css(document.body,
|
|
|
|
{
|
|
|
|
"position": oldBodyCache["position"] ?? null,
|
|
|
|
"width": oldBodyCache["width"] ?? null,
|
|
|
|
"overflow": oldBodyCache["overflow"] ?? null
|
|
|
|
});
|
|
|
|
removeCls(document.body, "ant-scrolling-effect");
|
2020-06-10 21:44:21 +08:00
|
|
|
}
|
|
|
|
|
2020-11-18 16:01:31 +08:00
|
|
|
export function destroyAllDialog() {
|
|
|
|
document.querySelectorAll('.ant-modal-root')
|
|
|
|
.forEach(e => document.body.removeChild(e.parentNode));
|
|
|
|
}
|
|
|
|
|
2020-06-10 21:44:21 +08:00
|
|
|
export function createIconFromfontCN(scriptUrl) {
|
|
|
|
if (document.querySelector(`[data-namespace="${scriptUrl}"]`)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const script = document.createElement('script');
|
|
|
|
script.setAttribute('src', scriptUrl);
|
|
|
|
script.setAttribute('data-namespace', scriptUrl);
|
|
|
|
document.body.appendChild(script);
|
2020-06-14 18:54:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export function getScroll() {
|
2020-07-01 06:49:51 +08:00
|
|
|
return { x: window.pageXOffset, y: window.pageYOffset };
|
2020-06-14 18:54:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export function getInnerText(element) {
|
2020-07-01 06:49:51 +08:00
|
|
|
let dom = getDom(element);
|
|
|
|
return dom.innerText;
|
2020-06-14 18:54:14 +08:00
|
|
|
}
|
2020-07-11 01:46:35 +08:00
|
|
|
|
2020-10-14 17:24:26 +08:00
|
|
|
export function getMaxZIndex() {
|
|
|
|
return [...document.all].reduce((r, e) => Math.max(r, +window.getComputedStyle(e).zIndex || 0), 0)
|
|
|
|
}
|
|
|
|
|
2020-07-11 01:46:35 +08:00
|
|
|
const objReferenceDict = {};
|
|
|
|
export function disposeObj(objReferenceName) {
|
2020-07-21 00:16:02 +08:00
|
|
|
delete objReferenceDict[objReferenceName];
|
2020-07-11 01:46:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//#region mentions
|
|
|
|
|
2020-08-26 07:28:44 +08:00
|
|
|
import getOffset from "./modules/Caret";
|
2020-07-11 01:46:35 +08:00
|
|
|
|
|
|
|
export function getCursorXY(element, objReference) {
|
2020-07-21 00:16:02 +08:00
|
|
|
objReferenceDict["mentions"] = objReference;
|
|
|
|
window.addEventListener("click", mentionsOnWindowClick);
|
2020-07-11 01:46:35 +08:00
|
|
|
|
2020-07-21 00:16:02 +08:00
|
|
|
var offset = getOffset(element);
|
2020-07-11 01:46:35 +08:00
|
|
|
|
2020-07-21 00:16:02 +08:00
|
|
|
return [offset.left, offset.top + offset.height + 14];
|
2020-07-11 01:46:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function mentionsOnWindowClick(e) {
|
2020-07-21 00:16:02 +08:00
|
|
|
let mentionsObj = objReferenceDict["mentions"];
|
|
|
|
if (mentionsObj) {
|
|
|
|
mentionsObj.invokeMethodAsync("CloseMentionsDropDown");
|
|
|
|
} else {
|
|
|
|
window.removeEventListener("click", mentionsOnWindowClick);
|
|
|
|
}
|
2020-07-11 01:46:35 +08:00
|
|
|
}
|
|
|
|
|
2020-08-26 07:28:44 +08:00
|
|
|
//#endregion
|
|
|
|
|
|
|
|
export { enableDraggable, disableDraggable, resetModalPosition } from "./modules/dragHelper";
|