Skip to content
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

Display Bootstrap-like tooltips for menu items #1249

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions dist/leaflet.distortableimage.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions examples/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@
<link rel="stylesheet" href="../dist/vendor.css">
<link rel="stylesheet" href="../dist/leaflet.distortableimage.css" media="screen" title="no title">
<link rel="stylesheet" href="https://unpkg.com/leaflet-control-geocoder/dist/Control.Geocoder.css" />
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-Zenh87qX5JnK2Jl0vWa8Ck2rdkQ2Bzep5IDxbcnCeuOxjzrPF/et3URy9Bv1WTRi" crossorigin="anonymous">

<script src="../node_modules/leaflet/dist/leaflet.js" type="text/javascript" charset="utf-8"></script>
<script src="../dist/vendor.js"></script>
<script src="../dist/leaflet.distortableimage.js"></script>
<script src="./js/index.js" defer></script>
<script src="https://maps.googleapis.com/maps/api/js?key=<key>&libraries=places"></script>
<script src="https://unpkg.com/leaflet-control-geocoder/dist/Control.Geocoder.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/dist/umd/popper.min.js" integrity="sha384-oBqDVmMz9ATKxIep9tiCxS/Z9fNfEXiDAYTujMAeBAsjFuCZSmKbSSUnQlmh/jp3" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js" integrity="sha384-IDwe1+LCz02ROU9k972gdyvl+AESN10+x7tBKgc9I5HFtuNz0wWnPclzo6p9vxnk" crossorigin="anonymous"></script>
</head>
<body style="margin:0;">
<form id="test_form">
Expand Down
2 changes: 2 additions & 0 deletions examples/js/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const tooltipTriggerList = document.querySelectorAll('[data-bs-toggle="top"]')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, here is I think the issue. tooltipTriggerList evaluates to an empty NodeList. I think we're running this code too early. If you want to run it AFTER page JS activity is complete, we can put it under the (function() { line. That defers execution until the page is ready. Can we do that? We may need to define it with global scope above, then set it once the page is ready.

Copy link
Contributor Author

@vanithaak vanithaak Nov 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, I tried what you suggested

let tooltipTriggerList;
let tooltipList;
let map;

(function() {
  map = L.map('map').setView([51.505, -0.09], 13);
  map.addGoogleMutant();

  map.whenReady(function() {
    tooltipTriggerList = document.querySelectorAll('[data-bs-toggle="tooltip"]')
    tooltipList = [...tooltipTriggerList].map(tooltipTriggerEl => new bootstrap.Tooltip(tooltipTriggerEl))
    img = L.distortableImageOverlay('example.jpg', {
      selected: true,
      fullResolutionSrc: 'large.jpg',
    }).addTo(map);
  });
})();

L.Control.geocoder().addTo(map);

This is how it looks like now. I'm still not able to see the tooltip : (

const tooltipList = [...tooltipTriggerList].map(tooltipTriggerEl => new bootstrap.Tooltip(tooltipTriggerEl))
let map;

(function() {
Expand Down
5 changes: 4 additions & 1 deletion src/edit/actions/EditAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,11 @@ L.EditAction = L.Toolbar2.Action.extend({
}

this._link.setAttribute('href', '#');
this._link.setAttribute('title', iconOptions.tooltip);
// this._link.setAttribute('title', iconOptions.tooltip);
this._link.setAttribute('role', 'button');
this._link.setAttribute('data-bs-toggle', 'tooltip');
this._link.setAttribute('data-bs-placement', 'top');
this._link.setAttribute('data-bs-title', iconOptions.tooltip);

L.DomUtil.addClass(this._link, this.constructor.baseClass);

Expand Down