forked from FINAKON/HelpProject
1. Initial Commit - a boiler plate code and POC to realize the concept of context sensitive help 2. Frontend code written in ReactJS 3. Backend code written in Java, Spring Boot Framework 4. Frontend Start: pre-requisites : node, npm npm run dev ==> to start the frontend vite server 5. Backend Start: pre-requisites : java, mvn mvn spring-boot:run ==> to start the backend server 6. Visit http://localhost:5173/ for basic demo of help, press F1 in textboxes 7. Visit http://localhost:5173/editor and enter "admin123" to add/modify texts. Happy Coding !!! Thank you, Bhargava.
54 lines
1.8 KiB
JavaScript
54 lines
1.8 KiB
JavaScript
class Tooltip {
|
|
constructor(quill, boundsContainer) {
|
|
this.quill = quill;
|
|
this.boundsContainer = boundsContainer || document.body;
|
|
this.root = quill.addContainer('ql-tooltip');
|
|
this.root.innerHTML = this.constructor.TEMPLATE;
|
|
if (this.quill.root === this.quill.scrollingContainer) {
|
|
this.quill.root.addEventListener('scroll', () => {
|
|
this.root.style.marginTop = (-1*this.quill.root.scrollTop) + 'px';
|
|
});
|
|
}
|
|
this.hide();
|
|
}
|
|
|
|
hide() {
|
|
this.root.classList.add('ql-hidden');
|
|
}
|
|
|
|
position(reference) {
|
|
let left = reference.left + reference.width/2 - this.root.offsetWidth/2;
|
|
// root.scrollTop should be 0 if scrollContainer !== root
|
|
let top = reference.bottom + this.quill.root.scrollTop;
|
|
this.root.style.left = left + 'px';
|
|
this.root.style.top = top + 'px';
|
|
this.root.classList.remove('ql-flip');
|
|
let containerBounds = this.boundsContainer.getBoundingClientRect();
|
|
let rootBounds = this.root.getBoundingClientRect();
|
|
let shift = 0;
|
|
if (rootBounds.right > containerBounds.right) {
|
|
shift = containerBounds.right - rootBounds.right;
|
|
this.root.style.left = (left + shift) + 'px';
|
|
}
|
|
if (rootBounds.left < containerBounds.left) {
|
|
shift = containerBounds.left - rootBounds.left;
|
|
this.root.style.left = (left + shift) + 'px';
|
|
}
|
|
if (rootBounds.bottom > containerBounds.bottom) {
|
|
let height = rootBounds.bottom - rootBounds.top;
|
|
let verticalShift = reference.bottom - reference.top + height;
|
|
this.root.style.top = (top - verticalShift) + 'px';
|
|
this.root.classList.add('ql-flip');
|
|
}
|
|
return shift;
|
|
}
|
|
|
|
show() {
|
|
this.root.classList.remove('ql-editing');
|
|
this.root.classList.remove('ql-hidden');
|
|
}
|
|
}
|
|
|
|
|
|
export default Tooltip;
|