Opened 15 years ago
Closed 10 years ago
#13019 closed defect (bug) (fixed)
Allow multiple category widget dropdowns
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 4.2 | Priority: | low |
Severity: | minor | Version: | 3.0 |
Component: | Widgets | Keywords: | has-patch needs-testing |
Focuses: | Cc: |
Description
Although this may be a somewhat trivial and silly use of category widgets, currently placing two category widgets onto the same page with the dropdown option set results in having duplicate javascript and duplicative identified select boxes.
Whilst the instance of each widget is unique, the select boxes displayed at not given unique IDs or Names, resulting in valid markup, and resulting in only the secondary select box operating correctly. The JS var gets redeclared by the duplicative script, which gives precedence to the second dropdown.
One use case would be a page that lists long archives and shows a jump menu at both the top and bottom of the page. This would have to be done directly in the template due to the widget restrictions at present.
I am attaching a patch that adds a static counter into the category widget function, and gives each dropdown a unique identifier ID/Name, allowing simultaneous use of several category dropdowns, the JS function is updated appropriately to.
Code tested on IE7 and FF3, functionality remains the same as the original code, minus the limitation mentioned above.
Feedback is appreciated, and please do re-tag if necessary.
Attachments (3)
Change History (11)
#1
@
15 years ago
- Milestone changed from 3.1 to Unassigned
Not sure 3.1 milestone was appropriate, simple patch/enhancement, changed Milestone to Unassigned, to let you folks decide when it's relevant for.
#2
@
15 years ago
Instead of the static counter use $this->number
Defined in the WP_Widget class:
var $number = false; Unique ID number of the current instance.
#3
@
15 years ago
My silly typo aside, i've attached a patch using the $number var for the counter as suggested.
#4
@
15 years ago
- Milestone changed from Awaiting Review to Future Release
Instead of spitting out the same JS multiple times, I'm wondering if this would be a better take:
- One JS function, takes one argument, the ID of the dropdown.
- static variable in widget() keeps track of how many times it's been called. If more than once, the JS function is not reprinted, and only the function call and event assignment is.
#5
@
15 years ago
Would welcome a new patch..
I like the idea, using a function that accepts the ID of the dropdown..
+1 if anyone wants to provide a patch to do just that.. (JS is not my strongest area)..
#6
@
15 years ago
Didn't see this ticket and submitted a duplicate of this last night. Patch is attached that changes the function to accept a dropdown ID and only output the JS function once using a static counter inside widget(). Used the widget ID as part of the dropdown ID so uniqueness is absolutely ensured.
Tested in IE 7, Firefox and Chrome.
Adds counter to allow simultaneous use of category widget dropdown jump menus