Bug #6196
Wt::WAbstractArea::id() is not returning the ID used in HTML
Status:
New
Priority:
Normal
Assignee:
-
Target version:
-
Start date:
01/08/2018
Due date:
% Done:
0%
Estimated time:
Description
I wanted to modify the area of a img with some javascript (maphilight jquery plugin) but it seems
that the ID returned by Wt::WAbstractArea::id() is one behind the ID used within HTML.
Sample code:
requireJQuery(Wt::WApplication::resourcesUrl() + "jQuery/jquery.min.js"); // https://github.com/kemayo/maphilight wApp->require(Wt::WApplication::resourcesUrl() + "MapHilite/jquery.maphilight.min.js"); auto imageWidget = new Wt::WImage{imageContainer}; imageWidget->setResource(new Wt::WFileResource{"res/foobar.png", imageWidget}); imageWidget->addArea(new Wt::WRectArea{0, 0, 10, 10}); imageWidget->addArea(new Wt::WRectArea{0, 10, 10, 10}); imageWidget->addArea(new Wt::WRectArea{10, 0, 10, 10}); auto hilitearea = new Wt::WRectArea{10, 10, 10, 10}; imageWidget->addArea(hilitearea); auto js = "$('#" + imageWidget->id() + " img').maphilight({alwaysOn: true, fill: true, fillColor: '000000', strokeColor: '000000', shadow: true});\n" + "$('#" + hilitearea->id() + "').data('maphilight').fillColor = '0000ff'"; // this fails imageWidget->doJavaScript(js);
Wt-Version: 3.3.7
jQuery: 1.12.4
Files
Updated by Marco Kinski over 4 years ago
I workarounded this by using a collection of Wt::Absolute positioned Wt::WContainers instead of Wt::WRectArea.