1

I create custom widget with select option image but first time selected option image are not showing after saving this function work perfectly,I need this function only load after Drag in sidebar then load function?

jQuery(document).ready(function() {
    jQuery('body').on('change', '.selector', change_image);     
    function change_image(){
        var $path = jQuery(this).find('option:selected').val();
        jQuery('.image_path').attr('src',$path);
    }
});
1
  • 1
    Please elaborate, drag in which context? Using which code? Which ID precisely?
    – Rarst
    Commented Dec 31, 2013 at 17:17

1 Answer 1

0

My jquery function working perfectly in sidebar :). Jquery Enable after Dragging widget in sidebar .

jQuery( document ).ajaxComplete( function( event, XMLHttpRequest, ajaxOptions ) {
    var request = {}, pairs = ajaxOptions.data.split('&'), i, split, widget;
    for( i in pairs ) {
        split = pairs[i].split( '=' );
        request[decodeURIComponent( split[0] )] = decodeURIComponent( split[1] );
    }

    if( request.action && ( request.action === 'save-widget' ) ) {

        widget = jQuery('input.widget-id[value="' + request['widget-id'] + '"]').parents('.widget');
        if( !XMLHttpRequest.responseText ) 
            wpWidgets.save(widget, 0, 1, 0);
        else
          jQuery('.selector').on('change', change_image);   

        function change_image(){

                var $path = jQuery(this).find('option:selected').val();
                jQuery('.image_path').attr('src',$path);
        }   

    }
});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.