[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 21:42:08 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:  JavaScript   |     Version:  2.8                                                 
 Severity:  normal       |    Keywords:  widgets, javascript, admin, events, hooks, callbacks
-------------------------+--------------------------------------------------
Changes (by azaozz):

  * component:  Widgets => JavaScript


Comment:

 Since most widgets are multi-instance chances are that there will be more
 than one of each on the screen. So html IDs cannot be used anywhere in the
 widgets (that would break any js). In that terms using the ID of the
 widgets is not recommended as it needs to change for each widget added to
 a sidebar.

 We could add a callback to wpWidgets.addEvents() however in js it's very
 easy to overwrite this (like you've already done):
 {{{
 wpWidgets._addEvents = wpWidgets.addEvents;
 wpWidgets.addEvents = function(scope) {...}
 }}}

 Other notes:
  * Returning "false" for an event doesn't stop other listeners attached to
 it, propagation or bubbling. Copying the widget's html and inserting it in
 a sidebar removes all previously attached events. Also when a widget is
 saved, the html is reloaded from the ajax return.

  * Unless you need some (quite) advanced functionality like ajax loading
 an arbitrary number of tabs, etc. it's better not to use ui.tabs. The
 basic tab switching/hiding/disabling is easily done directly with jQuery
 (and won't break next time they decide to change ui.tabs).

  * You can use the jQuery.live() (new in 1.3) to attach the functions to
 all tabs at once, including tabs that are loaded after a widget has been
 saved. Then you can get the current ID (if you still need it) by doing
 `jQuery(this).parents('.widget').attr('id')`.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/10426#comment:1>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list