浏览代码

Make BootstrapDialog.show() BootstrapDialog.alert() BootstrapDialog.confirm() return the created dialog instance.

Dante 12 年之前
父节点
当前提交
d67fe3601e
共有 3 个文件被更改,包括 22 次插入13 次删除
  1. 7 7
      examples/assets/bootstrap-dialog/js/bootstrap-dialog.js
  2. 9 0
      examples/index.html
  3. 6 6
      js/bootstrap-dialog.js

+ 7 - 7
examples/assets/bootstrap-dialog/js/bootstrap-dialog.js

@@ -224,7 +224,7 @@ var BootstrapDialog = null;
         getCssClass: function() {
             return this.options.cssClass;
         },
-        setCssClass: function(cssClass){
+        setCssClass: function(cssClass) {
             this.options.cssClass = cssClass;
 
             return this;
@@ -590,10 +590,10 @@ var BootstrapDialog = null;
      * Shortcut function: show
      * 
      * @param {type} options
-     * @returns {undefined}
+     * @returns the created dialog instance
      */
     BootstrapDialog.show = function(options) {
-        new BootstrapDialog(options).open();
+        return new BootstrapDialog(options).open();
     };
 
     /**
@@ -601,10 +601,10 @@ var BootstrapDialog = null;
      * 
      * @param {type} message
      * @param {type} callback
-     * @returns {undefined}
+     * @returns the created dialog instance
      */
     BootstrapDialog.alert = function(message, callback) {
-        new BootstrapDialog({
+        return new BootstrapDialog({
             message: message,
             data: {
                 'callback': callback
@@ -625,10 +625,10 @@ var BootstrapDialog = null;
      * 
      * @param {type} message
      * @param {type} callback
-     * @returns {undefined}
+     * @returns the created dialog instance
      */
     BootstrapDialog.confirm = function(message, callback) {
-        new BootstrapDialog({
+        return new BootstrapDialog({
             title: 'Confirmation',
             message: message,
             closable: false,

+ 9 - 0
examples/index.html

@@ -114,6 +114,15 @@
             .open();
         -->
     </div>
+    <p>In fact BootstrapDialog.show(...) will also return the created dialog instance.</p>
+    <div class="source-code runnable">
+        <!--
+        // You can use dialogInstance later.
+        var dialogInstance = BootstrapDialog.show({
+            message: 'Hello Banana!'
+        });
+        -->
+    </div>
     
     <h3>Open / Close multiple dialogs</h3>
     <p>This example demonstrates opening and closing a batch of dialogs at one time. <br />Dialog that created by BootstrapDialog will be in a container <strong>BootstrapDialog.dialogs</strong> before it's closed and destroyed, iterate <strong>BootstrapDialog.dialogs</strong> to find all dialogs that havn't been destroyed.</p>

+ 6 - 6
js/bootstrap-dialog.js

@@ -590,10 +590,10 @@ var BootstrapDialog = null;
      * Shortcut function: show
      * 
      * @param {type} options
-     * @returns {undefined}
+     * @returns the created dialog instance
      */
     BootstrapDialog.show = function(options) {
-        new BootstrapDialog(options).open();
+        return new BootstrapDialog(options).open();
     };
 
     /**
@@ -601,10 +601,10 @@ var BootstrapDialog = null;
      * 
      * @param {type} message
      * @param {type} callback
-     * @returns {undefined}
+     * @returns the created dialog instance
      */
     BootstrapDialog.alert = function(message, callback) {
-        new BootstrapDialog({
+        return new BootstrapDialog({
             message: message,
             data: {
                 'callback': callback
@@ -625,10 +625,10 @@ var BootstrapDialog = null;
      * 
      * @param {type} message
      * @param {type} callback
-     * @returns {undefined}
+     * @returns the created dialog instance
      */
     BootstrapDialog.confirm = function(message, callback) {
-        new BootstrapDialog({
+        return new BootstrapDialog({
             title: 'Confirmation',
             message: message,
             closable: false,