Opened 3 years ago

Last modified 3 years ago

#3630 new feature

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 (2)

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

Download all attachments as: .zip

Change History (7)

Changed 3 years ago by ejn

Patch to improve regex matching of OL icon class name

comment:1 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

comment:2 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.

comment:3 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.

comment:4 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.

comment:5 Changed 3 years ago by ejn

CLA sent this morning by e-mail.

Note: See TracTickets for help on using tickets.