Ticket #3630 (new feature)

Opened 3 years ago

Last modified 3 years ago

Panel: play nicely with multiple classnames for widgets (e.g. "olControlNavigationItemActive myClass")

Reported by: ejn Owned by:
Priority: minor Milestone: 2.13 Release
Component: Control.Panel Version: 2.11
Keywords: panel widget state Cc:
State:

Description

The current redraw method for Panel (more precisely, the methods iconOn and iconOff) change the class name on the icon using a regular expression which matches ItemInactive$ or ItemActive$ - i.e. at the end of the whole className string.

In cases where multiple class names are applied to the widgets this regex doesn't work - we need to be matching at end of word, not end of string - and so the widget state doesn't get updated.

Use case is e.g. to simplify CSS I wish to add a class "navigationWidget" to all controls on my panel, leaving them with a className string such as "olControlZoomBoxItemInactive navigationControl".

Suggested regex (unfortunately no lookbehinds in JavaScript so slightly clunky) which should be pretty foolproof:

replace(/\b(olControl[^ ]*Item)Inactive\b/, "$1Active")
replace(/\b(olControl[^ ]*Item)Active\b/, "$1Inactive")

The attached patch implements this change.

Attachments

2012-03-05_Control.Panel.patch Download (0.7 KB) - added by ejn 3 years ago.
Patch to improve regex matching of OL icon class name
2012-03-05_Control.Panel.2.patch Download (2.9 KB) - added by ejn 3 years ago.
Corrected patch including unit tests

Change History

Changed 3 years ago by ejn

Patch to improve regex matching of OL icon class name

Changed 3 years ago by erilem

This is a valid request. Your patch would need unit tests. And a pull request in  https://github.com/openlayers/openlayers would be appreciated.

Changed 3 years ago by ejn

Corrected patch including unit tests

Changed 3 years ago by ejn

Added unit tests to patch, and fixed a problem where Control displayName didn't start with olControl.

No current GitHub account, but will look into creating one.

Changed 3 years ago by ejn

See  Pull request. Note that this issue was already more or less fixed in trunk (but I don't seem to be able to close the ticket?) so I just tidied up the regex used and added the unit testing from my patch against the 2.11 release.

Changed 3 years ago by erilem

ejn, do we have a CLA from you? See  http://trac.osgeo.org/openlayers/wiki/HowToContribute if not. Thank you.

Changed 3 years ago by ejn

CLA sent this morning by e-mail.

Note: See TracTickets for help on using tickets.