Dynamically add Dialog button broken

Dynamically add Dialog button broken

The addButton code below no longer works since at least jQuery-UI 10.4. It does work when there's already a button in the dialog.
We are using jQuery (UI) 1.11 JS and CSS.

  1. <div id="messageDialog"></div>

  2. <script type="text/javascript">
  3. var frameHeight = ( $(window).height()*0.85 )-1220;
  4. var frameWidth = $(window).width()*0.85;
  5. if (frameWidth > 920) {

  6. frameWidth = 920;
  7. }

  8. $('#messageDialog').dialog({

  9. html: '<h1>hi</h1>',

  10. autoOpen: true,

  11. height: $(window).height()*0.85,

  12. width: frameWidth,

  13. position: "left+" & frameWidth/2 & "top+40",

  14. modal: true,

  15. resizable: false
  16. });

  17. $.extend($.ui.dialog.prototype, {

  18. 'addButton': function(buttonName, func) {

  19. var buttons = this.element.dialog('option', 'buttons');

  20. buttons[buttonName] = func;

  21. this.element.dialog('option', 'buttons', buttons);

  22. if(buttonName=='Inbox'){

  23. fixPosition();

  24. }

  25. }
  26. });

  27. $.extend($.ui.dialog.prototype, {

  28. 'removeButton': function(buttonName) {

  29. var buttons = this.element.dialog('option', 'buttons');

  30. delete buttons[buttonName];

  31. this.element.dialog('option', 'buttons', buttons);

  32. }
  33. });

  34. function fixPosition(){

  35. // Inbox button to the left

  36. $('.ui-dialog .ui-dialog-buttonpane button span').each(function() {

  37. if($(this).html()=='Inbox'){

  38. $(this).parent().css('float','left');

  39. }

  40. });
  41. }

  42. function newMessage() {

  43. location.href = 'http://www.dummy.com'
  44. }

  45. window.parent.jQuery('#messageDialog').dialog('addButton', 'New message', newMessage);
  46. </script>