浏览代码

Make default options configurable

Dante 11 年之前
父节点
当前提交
bbd8c50085
共有 2 个文件被更改,包括 34 次插入17 次删除
  1. 6 0
      examples/index.html
  2. 28 17
      js/bootstrap-dialog.js

+ 6 - 0
examples/index.html

@@ -15,6 +15,12 @@
     }
 </style>
 </head>
+<script>
+    BootstrapDialog.configDefaultOptions({
+        type: BootstrapDialog.TYPE_WARNING,
+        title: 'DDD'
+    });
+</script>
 <body style="padding-bottom: 100px;">
 <div class="container">
     <h2>Make use of Bootstrap's modal more monkey-friendly.</h2>

+ 28 - 17
js/bootstrap-dialog.js

@@ -14,23 +14,7 @@
     "use strict";
 
     var BootstrapDialog = function(options) {
-        this.defaultOptions = {
-            id: BootstrapDialog.newGuid(),
-            type: BootstrapDialog.TYPE_PRIMARY,
-            size: BootstrapDialog.SIZE_NORMAL,
-            cssClass: '',
-            title: null,
-            message: null,
-            nl2br: true,
-            buttons: [],
-            closable: true,
-            spinicon: BootstrapDialog.ICON_SPINNER,
-            data: {},
-            onshow: null,
-            onhide: null,
-            autodestroy: true,
-            draggable: false
-        };
+        this.defaultOptions = $.extend(true, {}, BootstrapDialog.defaultOptions);
         this.indexedButtons = {};
         this.registeredButtonHotkeys = {};
         this.draggableData = {
@@ -73,6 +57,33 @@
     BootstrapDialog.ICON_SPINNER = 'glyphicon glyphicon-asterisk';
 
     /**
+     * Default options.
+     */
+    BootstrapDialog.defaultOptions = {
+        type: BootstrapDialog.TYPE_PRIMARY,
+        size: BootstrapDialog.SIZE_NORMAL,
+        cssClass: '',
+        title: null,
+        message: null,
+        nl2br: true,
+        buttons: [],
+        closable: true,
+        spinicon: BootstrapDialog.ICON_SPINNER,
+        data: {},
+        onshow: null,
+        onhide: null,
+        autodestroy: true,
+        draggable: false
+    };
+
+    /**
+     * Config default options.
+     */
+    BootstrapDialog.configDefaultOptions = function(options) {
+        BootstrapDialog.defaultOptions = $.extend(true, BootstrapDialog.defaultOptions, options);
+    };
+
+    /**
      * Open / Close all created dialogs all at once.
      */
     BootstrapDialog.dialogs = {};