Methods can be invoked on non-mapster supported/initialized elements
Describe the bug ImageMapster currently has sporadic behavior when invoking a method on an element. For example:
- Methods can be called on elements that are not yet been initialized - In some cases, the method returns without error (e.g.
select) and in some cases there is an error (e.g.,keys) but the error is not meaningful (e.g.Uncaught Can't access data until binding complete.). - Methods can be called on unsupported elements (e.g.
div)
To Reproduce Steps to reproduce the behavior:
- Open tooltips example
- Execute
$('.navmenu').mapster('select')in console - Method completes successfully even though
divis not a valid target and mapster cannot be applied to it - Execute
$('.navmenu').mapster('keys')in console - Method encounters
Uncaught Can't access data until binding complete.exception even thoughdivis not a valid target and mapster cannot be applied to it. - Add the following HTML to the example page
<img
id="testimage"
src="images/beatles_basic.jpg"
usemap="#beatles-map"
/>
- Execute
$('#testimage').mapster('select') - Method completes successfully even though mapster is not initialized
- Execute
$('#testimage').mapster('keys')in console - Method encounters
Uncaught Can't access data until binding complete.which is misleading because mapster is not even initialized
Expected behavior Mapster should only support img/area elements, track initialization and provide meaningful error messages based on situation. Additionally, mapster creates internal elements and there is code in-place that "ignore" these elements during method execution - this additional processing overhead can be avoided by ensuring that mapster is only called on "valid" (user created img/area & initialized) elements.
Screenshots N/A
Desktop (please complete the following information): N/A
Smartphone (please complete the following information): N/A
Additional context While technically a bug, fixing this properly would result in a breaking change for existing code that uses IM that doesn't follow standard jQuery usage guidelines (wrt to selectors) so it should be saved for next major release and marked as a breaking change.