ソースを参照

Hide footer if there is no button

Dante 11 年 前
コミット
ae21008379
2 ファイル変更18 行追加5 行削除
  1. 5 2
      examples/index.html
  2. 13 3
      js/bootstrap-dialog.js

+ 5 - 2
examples/index.html

@@ -6,7 +6,7 @@
 <script src="assets/bootstrap/js/bootstrap.min.js"></script>
 <script src="assets/prettify/run_prettify.js"></script>
 <link href="assets/bootstrap-dialog/css/bootstrap-dialog.min.css" rel="stylesheet" type="text/css" />
-<script src="assets/bootstrap-dialog/js/bootstrap-dialog.min.js"></script>
+<script src="../js/bootstrap-dialog.js"></script>
 <meta charset="utf-8" />
 <title>BootstrapDialog examples</title>
 <style>
@@ -75,7 +75,10 @@
             }, {
                 label: 'Title 2',
                 action: function(dialog) {
-                    dialog.setTitle('Title 2');
+                    dialog.setButtons([{
+                        label: 'Something',
+                        cssClass: 'btn-warning'
+                    }]);
                 }
             }]
         });

+ 13 - 3
js/bootstrap-dialog.js

@@ -309,6 +309,7 @@
         },
         setButtons: function(buttons) {
             this.options.buttons = buttons;
+            this.updateButtons();
 
             return this;
         },
@@ -334,6 +335,17 @@
 
             return '';
         },
+        updateButtons: function() {
+            if (this.isRealized()) {
+                if (this.getButtons().length === 0) {
+                    this.getModalFooter().hide();
+                } else {
+                    this.getModalFooter().find('.' + this.getNamespace('footer')).html('').append(this.createFooterButtons());
+                }
+            }
+
+            return this;
+        },
         isAutodestroy: function() {
             return this.options.autodestroy;
         },
@@ -394,9 +406,6 @@
             var $container = $('<div></div>');
             $container.addClass(this.getNamespace('footer'));
 
-            // Buttons
-            $container.append(this.createFooterButtons());
-
             return $container;
         },
         createFooterButtons: function() {
@@ -679,6 +688,7 @@
             this.makeModalDraggable();
             this.handleModalEvents();
             this.setRealized(true);
+            this.updateButtons();
             this.updateTitle();
             this.updateMessage();
             this.updateClosable();