Make WordPress Core

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: daanmeijer's profile DaanMeijer 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)

28702.patch (465 bytes) - added by chriseverson 11 years ago.

Download all attachments as: .zip

Change History (5)

#1 @SergeyBiryukov
11 years ago

  • Component changed from Administration to Customize
  • Keywords needs-patch added
  • Milestone changed from Awaiting Review to Future Release

@chriseverson
11 years ago

#2 @chriseverson
11 years ago

  • Keywords has-patch added; needs-patch removed

#3 @celloexpressions
11 years ago

  • Keywords close added

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.

#4 @celloexpressions
11 years ago

  • Milestone Future Release deleted
  • Resolution set to wontfix
  • Status changed from new to closed

Per previous comment, this isn't really needed for core and facilitates invalid use of this file.

Note: See TracTickets for help on using tickets.