1

With custom jQuery Ui widget, you can attach your own callback functions to it by passing options to the plugin. However, if I want to attach one callback to "generate_img" event and later on another different but not mutually exclusive behaviour to the same widget event "generate_img", the later one will replace, instead of adding to the existing behaviour.

Is there a way to solve this problem? Thanks.

Jinghui Niu
  • 990
  • 11
  • 28

1 Answers1

0

You could do something like this (using a dialog Widget and the beforeClose event as an example):

function one(){alert("one");}
function two(){alert("two");}

$( function() {
    $( "#dialog" ).dialog(
        {beforeClose: one}      
    );

    var original = $( "#dialog" ).dialog("option", "beforeClose");
    $( "#dialog" ).dialog("option", "beforeClose", function(){
        original();
        two();
    });    
});
GertG
  • 959
  • 1
  • 8
  • 21
  • Super smart solution! Just one more follow-up question here, do you thinking studying the jQuery `Promise` object will improve in this situation and make it any more elegant? I'm planning to learn that area. Thanks. – Jinghui Niu Mar 23 '17 at 04:30