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.
- <div id="messageDialog"></div>
-
- <script type="text/javascript">
- var frameHeight = ( $(window).height()*0.85 )-1220;
- var frameWidth = $(window).width()*0.85;
- if (frameWidth > 920) {
-
- frameWidth = 920;
- }
-
-
- $('#messageDialog').dialog({
-
- html: '<h1>hi</h1>',
-
- autoOpen: true,
-
- height: $(window).height()*0.85,
-
- width: frameWidth,
-
- position: "left+" & frameWidth/2 & "top+40",
-
- modal: true,
-
- resizable: false
- });
-
- $.extend($.ui.dialog.prototype, {
-
- 'addButton': function(buttonName, func) {
-
- var buttons = this.element.dialog('option', 'buttons');
-
- buttons[buttonName] = func;
-
- this.element.dialog('option', 'buttons', buttons);
-
- if(buttonName=='Inbox'){
-
- fixPosition();
-
- }
-
- }
- });
-
- $.extend($.ui.dialog.prototype, {
-
- 'removeButton': function(buttonName) {
-
- var buttons = this.element.dialog('option', 'buttons');
-
- delete buttons[buttonName];
-
- this.element.dialog('option', 'buttons', buttons);
-
- }
- });
-
- function fixPosition(){
-
- // Inbox button to the left
-
- $('.ui-dialog .ui-dialog-buttonpane button span').each(function() {
-
- if($(this).html()=='Inbox'){
-
- $(this).parent().css('float','left');
-
- }
-
- });
- }
-
- function newMessage() {
-
- location.href = 'http://www.dummy.com'
- }
-
- window.parent.jQuery('#messageDialog').dialog('addButton', 'New message', newMessage);
- </script>