overview
1 year ago
campaign_builder_controller.js
1 year ago
chart_controller.js
2 months ago
chart_interval_controller.js
2 years ago
clipboard_controller.js
1 year ago
copy_report_controller.js
2 years ago
create_report_controller.js
1 year ago
delete_data_controller.js
1 year ago
delete_report_controller.js
2 years ago
easepick_controller.js
2 years ago
examiner_controller.js
2 months ago
examiner_header_controller.js
11 months ago
export_overview_controller.js
9 months ago
export_reports_controller.js
2 years ago
filters_controller.js
6 months ago
group_controller.js
2 years ago
import_reports_controller.js
2 years ago
journey_controller.js
6 months ago
map_controller.js
9 months ago
migration_redirect_controller.js
2 years ago
modal_controller.js
2 years ago
pause_emails_controller.js
6 months ago
pie_chart_controller.js
6 months ago
plugin_group_options_controller.js
1 year ago
pruner_controller.js
5 months ago
quick_stats_controller.js
1 year ago
real_time_controller.js
6 months ago
refresh_overview_controller.js
1 year ago
rename_report_controller.js
2 years ago
report_controller.js
2 months ago
reset_analytics_controller.js
1 year ago
reset_overview_controller.js
1 year ago
save_report_controller.js
2 years ago
select_input_controller.js
2 years ago
set_favorite_report_controller.js
2 years ago
sort_controller.js
2 years ago
sortable_reports_controller.js
2 years ago
table_columns_controller.js
2 years ago
tooltip_controller.js
6 months ago
woocommerce_settings_controller.js
1 year ago
tooltip_controller.js
90 lines
| 1 | import { Controller } from "@hotwired/stimulus"; |
| 2 | |
| 3 | export default class extends Controller { |
| 4 | static values = { text: String }; |
| 5 | |
| 6 | popover = null; |
| 7 | hideTimeout = null; |
| 8 | |
| 9 | connect() { |
| 10 | this.popover = this.getPopoverElement(); |
| 11 | this.element.after(this.popover); |
| 12 | |
| 13 | this.element.addEventListener("focus", this.showTooltip.bind(this)); |
| 14 | this.element.addEventListener("blur", this.hideTooltip.bind(this)); |
| 15 | |
| 16 | this.element.addEventListener("mouseenter", this.showTooltip.bind(this)); |
| 17 | this.element.addEventListener("mouseleave", this.hideTooltip.bind(this)); |
| 18 | |
| 19 | this.popover.addEventListener("mouseenter", this.enterTooltip.bind(this)); |
| 20 | this.popover.addEventListener("mouseleave", this.hideTooltip.bind(this)); |
| 21 | |
| 22 | document.addEventListener("iawp:closeAllTooltips", this.hideTooltipNow.bind(this)); |
| 23 | } |
| 24 | |
| 25 | disconnect() { |
| 26 | this.element.removeEventListener("focus", this.showTooltip.bind(this)); |
| 27 | this.element.removeEventListener("blur", this.hideTooltip.bind(this)); |
| 28 | |
| 29 | this.element.removeEventListener("mouseenter", this.showTooltip.bind(this)); |
| 30 | this.element.removeEventListener("mouseleave", this.hideTooltip.bind(this)); |
| 31 | |
| 32 | this.popover.removeEventListener("mouseenter", this.enterTooltip.bind(this)); |
| 33 | this.popover.removeEventListener("mouseleave", this.hideTooltip.bind(this)); |
| 34 | |
| 35 | document.removeEventListener("iawp:closeAllTooltips", this.hideTooltipNow.bind(this)); |
| 36 | } |
| 37 | |
| 38 | showTooltip() { |
| 39 | clearTimeout(this.hideTimeout); |
| 40 | |
| 41 | document.dispatchEvent(new CustomEvent("iawp:closeAllTooltips")); |
| 42 | |
| 43 | this.popover.showPopover(); |
| 44 | |
| 45 | const rect = this.element.getBoundingClientRect(); |
| 46 | const top = rect.top + window.scrollY - this.popover.offsetHeight + 2; |
| 47 | const left = rect.left + window.scrollX + rect.width / 2 - this.popover.offsetWidth / 2; |
| 48 | |
| 49 | this.popover.style.position = "absolute"; |
| 50 | this.popover.style.margin = "0"; |
| 51 | this.popover.style.inset = `${top}px auto auto ${left}px`; |
| 52 | } |
| 53 | |
| 54 | hideTooltip() { |
| 55 | this.hideTimeout = setTimeout(() => { |
| 56 | this.popover.hidePopover(); |
| 57 | }, 50); |
| 58 | } |
| 59 | |
| 60 | hideTooltipNow() { |
| 61 | this.popover.hidePopover(); |
| 62 | } |
| 63 | |
| 64 | enterTooltip() { |
| 65 | clearTimeout(this.hideTimeout); |
| 66 | } |
| 67 | |
| 68 | getPopoverElement() { |
| 69 | const element = document.createElement("div"); |
| 70 | element.popover = 'manual' |
| 71 | element.classList.add("iawp-tooltip-popover"); |
| 72 | |
| 73 | const tooltip = document.createElement("div"); |
| 74 | tooltip.classList.add("iawp-tooltip"); |
| 75 | |
| 76 | const text = document.createElement("div"); |
| 77 | text.classList.add("iawp-tooltip-text"); |
| 78 | text.textContent = this.textValue; |
| 79 | tooltip.appendChild(text); |
| 80 | |
| 81 | const arrow = document.createElement("div"); |
| 82 | arrow.classList.add("iawp-tooltip-arrow"); |
| 83 | tooltip.appendChild(arrow); |
| 84 | |
| 85 | element.appendChild(tooltip) |
| 86 | |
| 87 | return element |
| 88 | } |
| 89 | } |
| 90 |