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

Conversation

vanithaak
Copy link
Contributor

Fixes #104 (<=== Add issue number here)

Make sure these boxes are checked before your pull request (PR) is ready to be reviewed and merged. Thanks!

  • PR is descriptively titled 📑 and links the original issue above 🔗
  • tests pass -- look for a green checkbox ✔️ a few minutes after opening your PR -- or run tests locally with grunt test
  • code is in uniquely-named feature branch and has no merge conflicts 📁
  • screenshots/GIFs are attached 📎 in case of UI updates
  • @mention the original creator of the issue in a comment below for help or for a review

We're happy to help you get this ready -- don't be afraid to ask for help, and don't be discouraged if your tests fail at first!

If tests do fail, click on the red X to learn why by reading the logs.

Please be sure you've reviewed our contribution guidelines at https://publiclab.org/contributing-to-public-lab-software

Thanks!

@gitpod-io
Copy link

gitpod-io bot commented Oct 27, 2022

@vanithaak
Copy link
Contributor Author

I have added the script and link tags in index.html , triggerred the tooltip in index.js , added attributes in EditAction.js, still I'm not able to see the tooltip when I hover. @jywarren What am I missing?

please review my pr. Thanks!

Copy link
Member

@jywarren jywarren left a comment

Choose a reason for hiding this comment

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

OK, I looked back at my original clarification and although we had been editing inside EditAction back then, at that time, that file contained ALL the tools. If you look higher, we were actually editing the Transparency tool (now called Opacity):

ToggleTransparency = EditOverlayAction.extend({
options: { toolbarIcon: {
html: '<span class="fa fa-adjust"></span>',
tooltip: 'Toggle Image Transparency',
title: 'Toggle Image Transparency'
}},

So we actually need to be editing the tooltip there, in its new file location:

https://github.com/vanithaak/Leaflet.DistortableImage/blob/87ab889f5575adb0248f6e9d55ba80e993812297/src/edit/actions/OpacityAction.js#L17-L22

Notice how most of the actions actually extend EditAction -- EditAction is like the common parent class, and each actual tool is extending it. Does that make sense? So I think the code on line 42 of EditAction is OK. So, let's see if we can get the tooltip text manually...

Yes, I can confirm that the toolbar item shows:

<a class="leaflet-toolbar-icon drag" href="#" role="button" data-bs-toggle="tooltip" data-bs-placement="top" data-bs-title="Drag Image"><svg class="ldi-icon ldi-drag" role="img" focusable="false"><use xlink:href="#drag"></use></svg></a>

Good! data-bs-title is present! And, i tried running new bootstrap.Tooltip(document.getElementsByClassName('leaflet-toolbar-icon drag')[0]) and it worked:

image

So, I wonder if we are failing in line 1 of index.js. Let me dig a bit more.

@@ -95,9 +95,6 @@ <h3 id="offcanvasRightLabel">Images</h3>
form.addEventListener('submit', (event) => {
event.preventDefault();
const url = input.value.replace('details', 'metadata');
let splitUrl = url.split('/');
Copy link
Member

Choose a reason for hiding this comment

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

First, just noting this seems like an unrelated change -- can you try reverting it with:

cd examples
wget https://raw.githubusercontent.com/publiclab/Leaflet.DistortableImage/main/examples/archive.html
cd ../
git add dist
git commit -m 'removed unrelated changes'
git push

@@ -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 : (

@jywarren
Copy link
Member

jywarren commented Nov 2, 2022

I also want to suggest that we include some documentation. We shouldn't make Bootstrap a required dependency. I think this fails gracefully if it's not present, right? The only code that will fail is still in our examples/index.js file, not in the core library. But we can add a line to the README saying that to enable tooltip formatting, you can include a) Bootstrap 5 and b) the lines of code we're adding to index.js, to load these styles. How does that sound?

@vanithaak
Copy link
Contributor Author

Sounds good! I'll start working on it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Display Bootstrap-like tooltips for menu items
2 participants