-
Notifications
You must be signed in to change notification settings - Fork 167
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Get biggest z index of element #1437
Conversation
* @param element the parent element | ||
* @returns | ||
*/ | ||
export default function getBiggestZIndex(element: HTMLElement) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is now only used by image edit plugin, so let's put it there and no need to export, to reduce the size of dom package
const parent: HTMLElement | null = child?.parentElement; | ||
if (parent) { | ||
const parentZIndex = parent.style?.zIndex ? parseInt(parent.style.zIndex) : 0; | ||
if (parentZIndex > zIndex) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no, what we need is not the largest z index, but the last z index. e.g.
<body>
<div zIndex = 1>
<div zIndex = 100>
...
Although 1 < 100, but since 1 is the last zindex, we use it instead of 100
this.editor.getDocument().body.appendChild(this.zoomWrapper); | ||
} | ||
|
||
private getEditorDiv(editor: IEditor) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's try to avoid getting editor div directly. Plugin should not know editor DIV at all.
You can use editor.getScrollContainer() as the first element.
@@ -0,0 +1,22 @@ | |||
import { getTagOfNode } from 'roosterjs-editor-dom'; | |||
|
|||
/** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
*/ | ||
export default function getLatestZIndex(editorDiv: HTMLElement) { | ||
let child: HTMLElement | null = editorDiv; | ||
let zIndex = child.style.zIndex ? parseInt(child.style.zIndex) : 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can simplify this to something like:
let zIndex = 0;
while (child && getTagOfNode(child) != 'BODY') {
if (child.style.zIndex) {
zIndex = parseInt(child.style.zIndex);
}
child = child.parentElement;
}
Add
getBiggestZIndex
api that search from an elements to it's root for the biggest z-index value.In ImageEdit use
getBiggestZIndex
api to find the biggest index above the editor and add it plus one to the image wrapper.