Roo/bootstrap/Modal.js
[roojs1] / Roo / bootstrap / Modal.js
index d5515a3..57f4424 100644 (file)
@@ -17,6 +17,7 @@
  * @cfg {Boolean} allow_close default true
  * @cfg {Boolean} fitwindow default false
  * @cfg {String} size (sm|lg) default empty
+ * @cfg {Number} max_width set the max width of modal
  *
  *
  * @constructor
@@ -81,7 +82,10 @@ Roo.extend(Roo.bootstrap.Modal, Roo.bootstrap.Component,  {
     closeEl:  false,
 
     size: '',
-
+    
+    max_width: 0,
+    
+    fit_content: false,
 
     onRender : function(ct, position)
     {
@@ -119,8 +123,7 @@ Roo.extend(Roo.bootstrap.Modal, Roo.bootstrap.Component,  {
         this.footerEl = this.el.select('.modal-footer',true).first();
 
         this.maskEl = Roo.DomHelper.append(document.body, {tag: "div", cls:"x-dlg-mask"}, true);
-        this.maskEl.enableDisplayMode("block");
-        this.maskEl.hide();
+        
         //this.el.addClass("x-dlg-modal");
 
         if (this.buttons.length) {
@@ -160,9 +163,8 @@ Roo.extend(Roo.bootstrap.Modal, Roo.bootstrap.Component,  {
 
     },
 
-    getAutoCreate : function(){
-
-
+    getAutoCreate : function()
+    {
         var bdy = {
                 cls : 'modal-body',
                 html : this.html || ''
@@ -259,12 +261,42 @@ Roo.extend(Roo.bootstrap.Modal, Roo.bootstrap.Component,  {
 
     resize : function()
     {
-        this.maskEl.setSize(Roo.lib.Dom.getViewWidth(true),  Roo.lib.Dom.getViewHeight(true));
+        this.maskEl.setSize(
+            Roo.lib.Dom.getViewWidth(true),
+            Roo.lib.Dom.getViewHeight(true)
+        );
+        
         if (this.fitwindow) {
-            var w = this.width || Roo.lib.Dom.getViewportWidth(true) - 30;
-            var h = this.height || Roo.lib.Dom.getViewportHeight(true) - 60;
-            this.setSize(w,h);
+            this.setSize(
+                this.width || Roo.lib.Dom.getViewportWidth(true) - 30,
+                this.height || Roo.lib.Dom.getViewportHeight(true) - 60
+            );
+            return;
         }
+        
+        if(this.max_width !== 0) {
+            
+            var w = Math.min(this.max_width, Roo.lib.Dom.getViewportWidth(true) - 30);
+            
+            if(this.height) {
+                this.setSize(w, this.height);
+                return;
+            }
+            
+            if(!this.fit_content) {
+                this.setSize(w, Roo.lib.Dom.getViewportHeight(true) - 60);
+                return;
+            }
+            
+            var body_childs = this.bodyEl.dom.childNodes;
+            var full_height = this.headerEl.getHeight() + this.footerEl.getHeight();
+            for(var i = 0; i < body_childs.length; i++) {
+                full_height += body_childs[i].offsetHeight;
+            }
+            
+            this.setSize(w, Math.min(full_height, Roo.lib.Dom.getViewportHeight(true) - 60));
+        }
+        
     },
 
     setSize : function(w,h)
@@ -282,6 +314,7 @@ Roo.extend(Roo.bootstrap.Modal, Roo.bootstrap.Component,  {
         }
 
         //this.el.setStyle('display', 'block');
+        this.el.removeClass('hideing');        
         this.el.addClass('show');
  
         if(this.animate){  // element has 'fade'  - so stuff happens after .3s ?- not sure why the delay?
@@ -291,7 +324,6 @@ Roo.extend(Roo.bootstrap.Modal, Roo.bootstrap.Component,  {
             }).defer(50, this);
         }else{
             this.el.addClass('in');
-
         }
 
         // not sure how we can show data in here..
@@ -303,7 +335,7 @@ Roo.extend(Roo.bootstrap.Modal, Roo.bootstrap.Component,  {
         
         this.maskEl.setSize(Roo.lib.Dom.getViewWidth(true),   Roo.lib.Dom.getViewHeight(true));
         this.maskEl.setStyle('z-index', Roo.bootstrap.Modal.zIndex++);
-        this.maskEl.show();
+        this.maskEl.addClass('show');
         
         this.resize();
         
@@ -323,7 +355,7 @@ Roo.extend(Roo.bootstrap.Modal, Roo.bootstrap.Component,  {
     hide : function()
     {
         if(this.fireEvent("beforehide", this) !== false){
-            this.maskEl.hide();
+            this.maskEl.removeClass('show');
             Roo.get(document.body).removeClass("x-body-masked");
             this.el.removeClass('in');
             this.el.select('.modal-dialog', true).first().setStyle('transform','');
@@ -331,8 +363,11 @@ Roo.extend(Roo.bootstrap.Modal, Roo.bootstrap.Component,  {
             if(this.animate){ // why
                 this.el.addClass('hideing');
                 (function(){
-                     this.el.removeClass('show');
-                     this.el.removeClass('hideing');
+                    if (!this.el.hasClass('hideing')) {
+                        return; // it's been shown again...
+                    }
+                    this.el.removeClass('show');
+                    this.el.removeClass('hideing');
                 }).defer(150,this);
                 
             }else{