[wp-trac] [WordPress Trac] #10426: Should introduce JavaScript hooks/events/callback after a widget has been added from the admin interface
WordPress Trac
wp-trac at lists.automattic.com
Thu Jul 16 19:18:09 UTC 2009
#10426: Should introduce JavaScript hooks/events/callback after a widget has been
added from the admin interface
-------------------------+--------------------------------------------------
Reporter: godfreykfc | Owner: azaozz
Type: enhancement | Status: new
Priority: normal | Milestone: Unassigned
Component: Widgets | Version: 2.8
Severity: normal | Keywords: widgets, javascript, admin, events, hooks, callbacks
-------------------------+--------------------------------------------------
The new widget interface provides a very nice experience for the end-
users, but not so much for the developers.
As a developer, you will often find the need to use JavaScript in your
widget controls, such as creating the tabs in our section widget (see:
[http://wordpress.org/extend/plugins/section-widget/screenshots/]). This,
however, is really a lot more tricky than it should have been. When WP
loads the widgets interface, it will create some "stub" widgets on the
left. In the "stub" widgets, all HTML IDs will include a placeholder like
section-widget-___i___. When the user drags the stub widget to the
sidebar, WP will copy its content and then do a search and replace of all
the IDs so it will look like section-widget-1 in the end.
This ID change causes a lot of problem for other JS code. For instance, if
you tab-ify your divs on document.ready using jQueryUI Tabs, it would no
longer work after the stub widget is copied over to the sidebar, because
the actions it uses are dependent on the actual IDs of the divs. You might
think that adding an event listener for the onClick event on the expand
button will solve the problem, but it won't work because WP already
attached a listen to that event, which unfortunately returns "false" -
which stops the event from bubbling up.
Currently, it requires a lot of hacking to get around this problem, (see:
[http://svn.wp-plugins.org/section-widget/trunk/section-widget.dev.js]) so
I am suggesting we should either: a) provide a way to register JS
callbacks when a widget has been added to the sidebar, or b) trigger a
custom event on the widget after it has been added to the sidebar.
--
Ticket URL: <http://core.trac.wordpress.org/ticket/10426>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list