Widget GUI in WordPress admin is one of the oldest ones that uses a lot of AJAX. Users learn to use it quickly and get the grasp of the widget-sidebar workflow without any problems. That's why a lot of developers love to create widgets and as they become more and more complicate so do their interfaces. More JavaScript means a better experience for users but also more problems for the AJAX driven interface. These jQuery events will help you immensely if you ever had problem initializing or reinitializing your JS code on widget creation or update. Do I need this? What's the problem all about? Honestly, probably not. Most things can be solved by properly utilizing jQuery's live() method, or on() to be more precise. The (potential) problem lies in the fact that each time you save a WP widget the complete interface (of that widget) gets regenerated by PHP by using the widget's form function and, via AJAX, sent to the browser to replace the existing HTML. That means that the JS that does dynamic stuff with that HTML has to be reinitialized as well. Why? Because technically it's new HTML and new elements, so you need to re-hook all actions and events on them. For simple things such as click
Share This