[wp-trac] [WordPress Trac] #19587: WordPress widget admin bug

WordPress Trac wp-trac at lists.automattic.com
Sat Feb 25 00:17:23 UTC 2012


#19587: WordPress widget admin bug
-------------------------------+------------------------------
 Reporter:  ciprian_vb         |       Owner:
     Type:  defect (bug)       |      Status:  new
 Priority:  normal             |   Milestone:  Awaiting Review
Component:  Widgets            |     Version:
 Severity:  normal             |  Resolution:
 Keywords:  reporter-feedback  |
-------------------------------+------------------------------

Comment (by o----o):

 hello,

 The javascript in the widget is pretty confusing still, at least for me.
 In order to run the javascript when we need it, we have to run through
 many triggers.

 When we need the script it has to be ready when:
 1. The widget is dropped on the place
 2. When the admin widget page is loaded and the widget is already in the
 place
 3. On some action inside the the widget (and only for that widget)
 4. When the widget is saved

 I'll show you step by step what I do for each state, because I haven't
 found anywhere how to do it at once, or easier.


 {{{
 jQuery(document).ready(function($){
   // 1. when dropped in
   $('div.widgets-sortables').bind('sortstop',function(event,ui){
     console.log('just dropped in');
   });
   // 2. do some stuff on load
   console.log('onLoad');
   // 3. on action
   $(document).delegate('.our_widget_class', 'change', function(ev) {
     // you have to find the parent widget here,
     // and do something for it. And this is not easy
     // because the widget shouldn't have it's ID yet, but still possible.
     // This is actually the safest part of the whole process (maybe just
 for me)
     console.log('the element changed');
   });
   // 4. on save
   $('body').ajaxSuccess(function(evt, request, settings) {
     console.log('saved');
   });
 });
 }}}

 (The script is located outside of the widget php code)

 And still, this is not a perfect solution. When the widget is dropped in
 the place, the widget goes at least through a mix of these states. I think
 it goes through state 1. 2. 4. .. But we know, that the widget could not
 undergo the step 4. it is not really saved yet. If it has been saved then
 it should have it's ID already, right?

 I'm sure I do something wrong. But this example and also the fact that
 there are not many widget with
 Javascript inside, shows how uneasy this actually is in the WP now.

 I'm sorry but I haven't found any better description of this problem than
 here, so I hope Scribu might clarified it.

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


More information about the wp-trac mailing list