[wp-hackers] Javascript callback upon Widget save

John Gadbois jgadbois at gmail.com
Thu Sep 9 21:52:42 UTC 2010


That should work perfectly.  I didn't know there was a generic ajaxSuccess
event.  I'll try it out....

On Thu, Sep 9, 2010 at 4:26 PM, Mohammad Jangda <batmoo at gmail.com> wrote:

> >
> > Is there a Javascript callback that I can hook into when saving a widget
> in
> > the admin screen?  Since the widget Save button reloads the contents of
> the
> > widget panel, I'm losing some event handlers that I'd like to set back
> up.
> >
>
> You can hook into the jQuery's ajaxSuccess event (
> http://api.jquery.com/ajaxSuccess/). It's not the nicest solution but it
> works (I actually use the same approach to hook into post autosaves).
>
> Below is a crude example that triggers anytime a "mywidget" instance is
> added or saved. Just change the value of widget_id_base to the id of your
> widget and you're set.
>
> (If you want it nicely formatted, find it on gisthub:
> http://gist.github.com/572482)
>
> jQuery(document).ajaxSuccess(function(e, xhr, settings) {
>        var widget_id_base = 'mywidget';
>
>        if(settings.data.search('action=save-widget') != -1 &&
> settings.data.search('id_base=' + widget_id_base) != -1) {
>                alert('yay!');
>                // do other stuff
>        }
>
> });
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>


More information about the wp-hackers mailing list