Opened 11 years ago
Closed 11 years ago
#28702 closed enhancement (wontfix)
using jQuery.on binding for catching the click in custom-header.js
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 4.0 |
Component: | Customize | Keywords: | has-patch close |
Focuses: | Cc: |
Description
I ran into this while building a theme that allows for images in it's custom widgets. The problem:
I want to use wp-admin/js/custom-header.js to bind to my
<a id="choose-from-library-link"> ... </a>
,
but because a widget form is loaded through AJAX, the element does not exist in the DOM yet, when the click is caught.
I propose changing line 18 of wp-admin/js/custom-header.js to
$(document).on('click', '#choose-from-library-link', function( event ) {
.
Attachments (1)
Change History (5)
Note: See
TracTickets for help on using
tickets.
I don't see a problem with making this change per se, but I would not recommend using an admin-specific file that's liable to change and, in this case, possibly even be removed (see #25571), in a theme or plugin. And this change isn't necessary for this file to function as intended for core.
If you want similar functionality to what that file does, copy it into a new, appropriately named file bundled with your theme/plugin and tweak it to fit your needs. Or, look at a tutorial on using the media library in themes and plugins. Also, you shouldn't use an id like that in a widget, as multiple instances of the widget will result in duplicate ids.