mirror of
https://github.com/tenrok/OverlayScrollbars.git
synced 2026-06-23 01:00:36 +03:00
improve code
This commit is contained in:
@@ -75,9 +75,13 @@
|
|||||||
background: transparent !important;
|
background: transparent !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
[data-overlayscrollbars~='host'],
|
[data-overlayscrollbars],
|
||||||
.os-padding {
|
.os-padding {
|
||||||
position: relative;
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
[data-overlayscrollbars~='host'],
|
||||||
|
.os-padding {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: row !important;
|
flex-direction: row !important;
|
||||||
flex-wrap: nowrap !important;
|
flex-wrap: nowrap !important;
|
||||||
|
|||||||
+43
-11
@@ -15,19 +15,24 @@ const startBtn: HTMLButtonElement | null = document.querySelector('#start');
|
|||||||
const targetRoot: HTMLElement | null = document.querySelector('#targetRoot');
|
const targetRoot: HTMLElement | null = document.querySelector('#targetRoot');
|
||||||
const targetA: HTMLElement | null = document.querySelector('#targetA');
|
const targetA: HTMLElement | null = document.querySelector('#targetA');
|
||||||
const targetB: HTMLElement | null = document.querySelector('#targetB');
|
const targetB: HTMLElement | null = document.querySelector('#targetB');
|
||||||
|
const targetC: HTMLElement | null = document.querySelector('#targetC');
|
||||||
const updatesRootSlot: HTMLElement | null = document.querySelector('#updatesRoot');
|
const updatesRootSlot: HTMLElement | null = document.querySelector('#updatesRoot');
|
||||||
const updatesASlot: HTMLElement | null = document.querySelector('#updatesA');
|
const updatesASlot: HTMLElement | null = document.querySelector('#updatesA');
|
||||||
const updatesBSlot: HTMLElement | null = document.querySelector('#updatesB');
|
const updatesBSlot: HTMLElement | null = document.querySelector('#updatesB');
|
||||||
|
const updatesCSlot: HTMLElement | null = document.querySelector('#updatesC');
|
||||||
const resizeRoot: HTMLElement | null = document.querySelector('#resizeRoot');
|
const resizeRoot: HTMLElement | null = document.querySelector('#resizeRoot');
|
||||||
const resizeA: HTMLElement | null = document.querySelector('#resizeA');
|
const resizeA: HTMLElement | null = document.querySelector('#resizeA');
|
||||||
const resizeB: HTMLElement | null = document.querySelector('#resizeB');
|
const resizeB: HTMLElement | null = document.querySelector('#resizeB');
|
||||||
|
const resizeC: HTMLElement | null = document.querySelector('#resizeC');
|
||||||
const resizeBetweenRoot: HTMLElement | null = document.createElement('div');
|
const resizeBetweenRoot: HTMLElement | null = document.createElement('div');
|
||||||
const resizeBetweenA: HTMLElement | null = document.createElement('div');
|
const resizeBetweenA: HTMLElement | null = document.createElement('div');
|
||||||
const resizeBetweenB: HTMLElement | null = document.createElement('div');
|
const resizeBetweenB: HTMLElement | null = document.createElement('div');
|
||||||
|
const resizeBetweenC: HTMLElement | null = document.createElement('div');
|
||||||
|
|
||||||
let rootUpdateCount = 0;
|
let rootUpdateCount = 0;
|
||||||
let aUpdateCount = 0;
|
let aUpdateCount = 0;
|
||||||
let bUpdateCount = 0;
|
let bUpdateCount = 0;
|
||||||
|
let cUpdateCount = 0;
|
||||||
const rootInstance = OverlayScrollbars(
|
const rootInstance = OverlayScrollbars(
|
||||||
{ target: targetRoot!, padding: true },
|
{ target: targetRoot!, padding: true },
|
||||||
{},
|
{},
|
||||||
@@ -75,8 +80,11 @@ const bInstance = OverlayScrollbars(
|
|||||||
{},
|
{},
|
||||||
{
|
{
|
||||||
initialized() {
|
initialized() {
|
||||||
addClass(resizeBetweenB, 'resize resizeBetween');
|
requestAnimationFrame(() => {
|
||||||
targetB!.append(resizeBetweenB);
|
addClass(bInstance.elements().content, 'flex');
|
||||||
|
addClass(resizeBetweenB, 'resize resizeBetween');
|
||||||
|
targetB!.append(resizeBetweenB);
|
||||||
|
});
|
||||||
},
|
},
|
||||||
updated() {
|
updated() {
|
||||||
bUpdateCount++;
|
bUpdateCount++;
|
||||||
@@ -88,24 +96,44 @@ const bInstance = OverlayScrollbars(
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
OverlayScrollbars(
|
||||||
|
{ target: targetC!, viewport: targetC! },
|
||||||
|
{},
|
||||||
|
{
|
||||||
|
initialized() {
|
||||||
|
addClass(resizeBetweenC, 'resize resizeBetween');
|
||||||
|
targetC!.append(resizeBetweenC);
|
||||||
|
},
|
||||||
|
updated() {
|
||||||
|
cUpdateCount++;
|
||||||
|
requestAnimationFrame(() => {
|
||||||
|
if (updatesCSlot) {
|
||||||
|
updatesCSlot.textContent = `${cUpdateCount}`;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
resize(resizeRoot!);
|
resize(resizeRoot!);
|
||||||
resize(resizeA!);
|
resize(resizeA!);
|
||||||
resize(resizeB!);
|
resize(resizeB!);
|
||||||
|
resize(resizeC!);
|
||||||
resize(resizeBetweenRoot!);
|
resize(resizeBetweenRoot!);
|
||||||
resize(resizeBetweenA!);
|
resize(resizeBetweenA!);
|
||||||
resize(resizeBetweenB!);
|
resize(resizeBetweenB!);
|
||||||
|
resize(resizeBetweenC!);
|
||||||
|
|
||||||
const resizeBetween = async (betweenElm: HTMLElement) => {
|
const resizeBetween = async (betweenElm: HTMLElement) => {
|
||||||
const styleObj = {
|
const styleObj = {
|
||||||
width: parseInt(style(betweenElm, 'width'), 10) + 50,
|
width: parseInt(style(betweenElm, 'width'), 10) + 50,
|
||||||
height: parseInt(style(betweenElm, 'height'), 10) + 50,
|
height: parseInt(style(betweenElm, 'height'), 10) + 50,
|
||||||
};
|
};
|
||||||
const updateCountsBefore = [rootUpdateCount, aUpdateCount, bUpdateCount];
|
const updateCountsBefore = [rootUpdateCount, aUpdateCount, bUpdateCount, cUpdateCount];
|
||||||
style(betweenElm, styleObj);
|
style(betweenElm, styleObj);
|
||||||
|
|
||||||
await timeout(250);
|
await timeout(250);
|
||||||
const updateCountsAfter = [rootUpdateCount, aUpdateCount, bUpdateCount];
|
const updateCountsAfter = [rootUpdateCount, aUpdateCount, bUpdateCount, cUpdateCount];
|
||||||
|
|
||||||
should.equal(
|
should.equal(
|
||||||
JSON.stringify(updateCountsBefore),
|
JSON.stringify(updateCountsBefore),
|
||||||
@@ -120,11 +148,11 @@ const resizeResize = async (resizeElm: HTMLElement) => {
|
|||||||
width: parseInt(style(resizeElm, 'width'), 10) - 10,
|
width: parseInt(style(resizeElm, 'width'), 10) - 10,
|
||||||
height: parseInt(style(resizeElm, 'height'), 10) - 10,
|
height: parseInt(style(resizeElm, 'height'), 10) - 10,
|
||||||
};
|
};
|
||||||
const updateCountsBefore = [rootUpdateCount, aUpdateCount, bUpdateCount];
|
const updateCountsBefore = [rootUpdateCount, aUpdateCount, bUpdateCount, cUpdateCount];
|
||||||
style(resizeElm, styleObj);
|
style(resizeElm, styleObj);
|
||||||
|
|
||||||
await timeout(250);
|
await timeout(250);
|
||||||
const updateCountsAfter = [rootUpdateCount, aUpdateCount, bUpdateCount];
|
const updateCountsAfter = [rootUpdateCount, aUpdateCount, bUpdateCount, cUpdateCount];
|
||||||
|
|
||||||
should.equal(
|
should.equal(
|
||||||
JSON.stringify(updateCountsBefore),
|
JSON.stringify(updateCountsBefore),
|
||||||
@@ -162,11 +190,15 @@ const testBetweenElements = async () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const testResizeElements = async () => {
|
const testResizeElements = async () => {
|
||||||
await waitForOrFailTest(async () => {
|
await waitForOrFailTest(
|
||||||
await resizeResize(resizeRoot!);
|
async () => {
|
||||||
await resizeResize(resizeA!);
|
await resizeResize(resizeRoot!);
|
||||||
await resizeResize(resizeB!);
|
await resizeResize(resizeA!);
|
||||||
});
|
await resizeResize(resizeB!);
|
||||||
|
await resizeResize(resizeC!);
|
||||||
|
},
|
||||||
|
{ timeout: 5000 }
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const start = async () => {
|
const start = async () => {
|
||||||
|
|||||||
@@ -6,6 +6,9 @@
|
|||||||
<div id="targetRoot" class="container">
|
<div id="targetRoot" class="container">
|
||||||
<div id="targetA" class="container">
|
<div id="targetA" class="container">
|
||||||
<div id="targetB" class="container">
|
<div id="targetB" class="container">
|
||||||
|
<div id="targetC" class="container">
|
||||||
|
<div id="resizeC" class="resize">UpdatesC: <span id="updatesC"></span></div>
|
||||||
|
</div>
|
||||||
<div id="resizeB" class="resize">UpdatesB: <span id="updatesB"></span></div>
|
<div id="resizeB" class="resize">UpdatesB: <span id="updatesB"></span></div>
|
||||||
</div>
|
</div>
|
||||||
<div id="resizeA" class="resize">UpdatesA: <span id="updatesA"></span></div>
|
<div id="resizeA" class="resize">UpdatesA: <span id="updatesA"></span></div>
|
||||||
|
|||||||
+9
-1
@@ -22,7 +22,7 @@ body {
|
|||||||
|
|
||||||
.container {
|
.container {
|
||||||
border: 1px solid red;
|
border: 1px solid red;
|
||||||
width: 60%;
|
width: 75%;
|
||||||
height: 60%;
|
height: 60%;
|
||||||
padding: 10px;
|
padding: 10px;
|
||||||
margin: 10px;
|
margin: 10px;
|
||||||
@@ -64,6 +64,14 @@ body {
|
|||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#targetC {
|
||||||
|
height: auto;
|
||||||
|
}
|
||||||
|
|
||||||
.flex {
|
.flex {
|
||||||
display: flex;
|
display: flex;
|
||||||
|
|
||||||
|
& > .resize {
|
||||||
|
width: 80px;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+13
-1
@@ -1,7 +1,14 @@
|
|||||||
import './index.scss';
|
import './index.scss';
|
||||||
import 'styles/overlayscrollbars.scss';
|
import 'styles/overlayscrollbars.scss';
|
||||||
import should from 'should';
|
|
||||||
|
// test viewport inheritted attrs (tabindex) for multiple and single element init
|
||||||
|
// test appear & resize for multiple and single element init
|
||||||
|
// test children changing attr according to dom observer
|
||||||
|
|
||||||
|
/*
|
||||||
import { OverlayScrollbars } from 'overlayscrollbars';
|
import { OverlayScrollbars } from 'overlayscrollbars';
|
||||||
|
|
||||||
|
import should from 'should';
|
||||||
import { resize } from '@/testing-browser/Resize';
|
import { resize } from '@/testing-browser/Resize';
|
||||||
import { timeout } from '@/testing-browser/timeout';
|
import { timeout } from '@/testing-browser/timeout';
|
||||||
import { setTestResult, waitForOrFailTest } from '@/testing-browser/TestResult';
|
import { setTestResult, waitForOrFailTest } from '@/testing-browser/TestResult';
|
||||||
@@ -11,6 +18,10 @@ OverlayScrollbars.env().setDefaultOptions({
|
|||||||
nativeScrollbarsOverlaid: { initialize: true },
|
nativeScrollbarsOverlaid: { initialize: true },
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
const startBtn: HTMLButtonElement | null = document.querySelector('#start');
|
const startBtn: HTMLButtonElement | null = document.querySelector('#start');
|
||||||
const target: HTMLElement | null = document.querySelector('#target');
|
const target: HTMLElement | null = document.querySelector('#target');
|
||||||
const updatesSlot: HTMLElement | null = document.querySelector('#update');
|
const updatesSlot: HTMLElement | null = document.querySelector('#update');
|
||||||
@@ -45,3 +56,4 @@ const start = async () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
startBtn?.addEventListener('click', start);
|
startBtn?.addEventListener('click', start);
|
||||||
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user