Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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);
    }
});
share|improve this question
1  
Please elaborate, drag in which context? Using which code? Which ID precisely? –  Rarst Dec 31 '13 at 17:17

1 Answer 1

up vote 0 down vote accepted

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);
        }   

    }
});
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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