-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1e8b4be
commit 82aa181
Showing
26 changed files
with
207 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
src/main/resources/assets/admin/common/js/dom/util/animateScrollTop.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
export function animateScrollTop( | ||
el: HTMLElement, | ||
targetTop: number, | ||
durationMs: number, | ||
complete: () => void | ||
) { | ||
const startScrollTop = el.scrollTop; | ||
const distance = targetTop - startScrollTop; | ||
const framesPerSecond = 50; | ||
const timeout = 1000 / framesPerSecond; | ||
const intervals = durationMs / timeout; | ||
const step = distance / intervals; | ||
const timer = setInterval(() => { | ||
if (el.scrollTop >= targetTop) { | ||
clearInterval(timer); | ||
if (el.scrollTop > targetTop) { // Handle overshoot (decimals) | ||
el.scrollTop = targetTop; | ||
} | ||
complete(); | ||
} else { | ||
el.scrollTop += step; | ||
} | ||
}, timeout); | ||
} |
2 changes: 2 additions & 0 deletions
2
src/main/resources/assets/admin/common/js/dom/util/elementExists.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export const elementExists = (element: Element) => typeof(element) != 'undefined' && element != null; | ||
|
6 changes: 6 additions & 0 deletions
6
src/main/resources/assets/admin/common/js/dom/util/findElements.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export function findElements( | ||
selector: string, | ||
context: Document | Element = document | ||
) { | ||
return Array.from(context.querySelectorAll(selector)); | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/resources/assets/admin/common/js/dom/util/findHTMLElements.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import {findElements} from './findElements'; | ||
import {isHTMLElement} from './isHTMLElement'; | ||
|
||
export function findHTMLElements( | ||
selector: string, | ||
context: Document | Element = document | ||
): HTMLElement[] { | ||
return findElements(selector, context).filter((el) => isHTMLElement(el)) as HTMLElement[]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export function first( | ||
selector: string, | ||
context: Document | Element = document | ||
) { | ||
return context.querySelector(selector); | ||
} |
3 changes: 3 additions & 0 deletions
3
src/main/resources/assets/admin/common/js/dom/util/getData.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export function getData(el: Element, name: string): string | null { | ||
return el.getAttribute(`data-${name}`); | ||
} |
3 changes: 3 additions & 0 deletions
3
src/main/resources/assets/admin/common/js/dom/util/getInnerHeight.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export function getInnerHeight(el: Element) { | ||
return el.clientHeight; | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/resources/assets/admin/common/js/dom/util/getOffset.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export function getOffset(el: Element) { | ||
const box = el.getBoundingClientRect(); | ||
const docElem = document.documentElement; | ||
return { | ||
top: box.top + window.scrollY - docElem.clientTop, | ||
left: box.left + window.scrollX - docElem.clientLeft | ||
}; | ||
} |
6 changes: 6 additions & 0 deletions
6
src/main/resources/assets/admin/common/js/dom/util/getOffsetParent.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import {isHTMLElement} from './isHTMLElement'; | ||
|
||
export function getOffsetParent(el: HTMLElement): HTMLElement { | ||
const maybeHTMLElement = el.offsetParent; | ||
return isHTMLElement(maybeHTMLElement) ? maybeHTMLElement : el; | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/resources/assets/admin/common/js/dom/util/getOuterHeightWithMargin.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export function getOuterHeightWithMargin(el: Element) { | ||
const style = getComputedStyle(el); | ||
|
||
return ( | ||
el.getBoundingClientRect().height + | ||
parseFloat(style.marginTop) + | ||
parseFloat(style.marginBottom) | ||
); | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/resources/assets/admin/common/js/dom/util/getOuterWidthWithMargin.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export function getOuterWidthWithMargin(el: Element) { | ||
const style = getComputedStyle(el); | ||
|
||
return ( | ||
el.getBoundingClientRect().width + | ||
parseFloat(style.marginLeft) + | ||
parseFloat(style.marginRight) | ||
); | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/resources/assets/admin/common/js/dom/util/getPosition.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export function getPosition(el: Element) { | ||
const {top, left} = el.getBoundingClientRect(); | ||
const {marginTop, marginLeft} = getComputedStyle(el); | ||
return { | ||
top: top - parseInt(marginTop, 10), | ||
left: left - parseInt(marginLeft, 10) | ||
}; | ||
} |
6 changes: 6 additions & 0 deletions
6
src/main/resources/assets/admin/common/js/dom/util/isHTMLElement.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export function isHTMLElement(el: unknown): el is HTMLElement { | ||
if (typeof HTMLElement !== 'object') { | ||
throw new Error('Your browser does not support HTMLElement. Please use a newer browser.'); | ||
} | ||
return el instanceof HTMLElement; | ||
} |
3 changes: 3 additions & 0 deletions
3
src/main/resources/assets/admin/common/js/dom/util/isVisible.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export function isVisible(el: HTMLElement) { | ||
return !!(el.offsetWidth || el.offsetHeight || el.getClientRects().length); | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/resources/assets/admin/common/js/dom/util/selectHTMLElement.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import {isHTMLElement} from './isHTMLElement'; | ||
import {first} from './first'; | ||
|
||
export function selectHTMLElement( | ||
selector: string, | ||
context: Document | Element = document | ||
): HTMLElement | null { | ||
const el = first(selector, context); | ||
return isHTMLElement(el) ? el : null; | ||
} |
4 changes: 4 additions & 0 deletions
4
src/main/resources/assets/admin/common/js/dom/util/setData.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export function setData(el: Element, name: string, value: string) { | ||
el.setAttribute('data-' + name, value); | ||
return el; | ||
} |
4 changes: 4 additions & 0 deletions
4
src/main/resources/assets/admin/common/js/dom/util/setInnerHeight.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export function setInnerHeight(el: HTMLElement, value: string) { | ||
el.style.height = value; | ||
return el; | ||
} |
4 changes: 4 additions & 0 deletions
4
src/main/resources/assets/admin/common/js/dom/util/setInnerHtml.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export function setInnerHtml(el: Element, value: string) { | ||
el.innerHTML = value; | ||
return el; | ||
} |
5 changes: 5 additions & 0 deletions
5
src/main/resources/assets/admin/common/js/dom/util/setOffset.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export function setOffset(el: HTMLElement, {top, left}: {top: number, left: number}) { | ||
el.style.top = `${top}px`; | ||
el.style.left = `${left}px`; | ||
return el; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export function show(el: HTMLElement) { | ||
el.style.display = ''; | ||
return el; | ||
} |
Oops, something went wrong.