vue-grid-layout-v3
Version:
A draggable and resizable grid layout, as a Vue component.
52 lines (41 loc) • 1.21 kB
JavaScript
// let currentDir: "ltr" | "rtl" | "auto" = "auto";
let currentDir = 'auto';
function hasDocument() {
return (typeof document !== 'undefined');
}
function hasWindow() {
return (typeof window !== 'undefined');
}
export function getDocumentDir() {
if (!hasDocument()) {
return currentDir;
}
const direction = (typeof document.dir !== 'undefined')
? document.dir
: document.getElementsByTagName('html')[0].getAttribute('dir');
return direction;
}
// export function setDocumentDir(dir: "ltr" | "rtl" | "auto"){
export function setDocumentDir(dir) {
if (!hasDocument) {
currentDir = dir;
return;
}
const html = document.getElementsByTagName('html')[0];
html.setAttribute('dir', dir);
}
const cb = () => {};
// export function addWindowEventListener(event:string, callback: () => mixed){
export function addWindowEventListener(event, callback = cb) {
if (!hasWindow) {
callback();
return;
}
window.addEventListener(event, callback);
}
export function removeWindowEventListener(event, callback = cb) {
if (!hasWindow) {
return;
}
window.removeEventListener(event, callback);
}