sync
[roojs1] / Roo / bootstrap / Img.js
index c0e87df..0226544 100644 (file)
@@ -36,7 +36,13 @@ Roo.bootstrap.Img = function(config){
          * The img click event for the img.
          * @param {Roo.EventObject} e
          */
-        "click" : true
+        "click" : true,
+        /**
+         * @event load
+         * The when any image loads
+         * @param {Roo.EventObject} e
+         */
+        "load" : true
     });
 };
 
@@ -44,7 +50,7 @@ Roo.extend(Roo.bootstrap.Img, Roo.bootstrap.Component,  {
     
     imgResponsive: true,
     border: '',
-    src: '',
+    src: 'about:blank',
     href: false,
     target: false,
     xsUrl: '',
@@ -55,8 +61,6 @@ Roo.extend(Roo.bootstrap.Img, Roo.bootstrap.Component,  {
     getAutoCreate : function()
     {   
         if(this.src || (!this.xsUrl && !this.smUrl && !this.mdUrl && !this.lgUrl)){
-            Roo.log('run?????????????????????');
-            Roo.log(this.src);
             return this.createSingleImg();
         }
         
@@ -64,45 +68,55 @@ Roo.extend(Roo.bootstrap.Img, Roo.bootstrap.Component,  {
             tag: 'div',
             cls: 'roo-image-responsive-group',
             cn: []
-        }
-        Roo.log('run?????????????????????');
-        Roo.each(['xsUrl', 'smUrl', 'mdUrl', 'lgUrl'], function(size){
-            if(!this[size]){
+        };
+        var _this = this;
+        
+        Roo.each(['xs', 'sm', 'md', 'lg'], function(size){
+            
+            if(!_this[size + 'Url']){
                 return;
             }
             
             var img = {
                 tag: 'img',
-                cls: (this.imgResponsive) ? 'img-responsive' : '',
-                html: this.html || cfg.html,
-                src: this[size]
-            }
+                cls: (_this.imgResponsive) ? 'img-responsive' : '',
+                html: _this.html || cfg.html,
+                src: _this[size + 'Url']
+            };
             
             img.cls += ' roo-image-responsive-' + size;
             
-            if (['rounded','circle','thumbnail'].indexOf(this.border)>-1) {
-                cfg.cls += ' img-' + this.border;
+            var s = ['xs', 'sm', 'md', 'lg'];
+            
+            s.splice(s.indexOf(size), 1);
+            
+            Roo.each(s, function(ss){
+                img.cls += ' hidden-' + ss;
+            });
+            
+            if (['rounded','circle','thumbnail'].indexOf(_this.border)>-1) {
+                cfg.cls += ' img-' + _this.border;
             }
             
-            if(this.alt){
-                cfg.alt = this.alt;
+            if(_this.alt){
+                cfg.alt = _this.alt;
             }
             
-            if(this.href){
+            if(_this.href){
                 var a = {
                     tag: 'a',
-                    href: this.href,
+                    href: _this.href,
                     cn: [
                         img
                     ]
-                }
+                };
 
                 if(this.target){
-                    a.target = this.target;
+                    a.target = _this.target;
                 }
             }
             
-            cfg.cn.push((this.href) ? a : img);
+            cfg.cn.push((_this.href) ? a : img);
             
         });
         
@@ -114,8 +128,9 @@ Roo.extend(Roo.bootstrap.Img, Roo.bootstrap.Component,  {
         var cfg = {
             tag: 'img',
             cls: (this.imgResponsive) ? 'img-responsive' : '',
-            html : null
-        }
+            html : null,
+            src : 'about:blank'  // just incase src get's set to undefined?!?
+        };
         
         cfg.html = this.html || cfg.html;
         
@@ -134,9 +149,9 @@ Roo.extend(Roo.bootstrap.Img, Roo.bootstrap.Component,  {
                 tag: 'a',
                 href: this.href,
                 cn: [
-                   cfg
-               ]
-            }
+                    cfg
+                ]
+            };
             
             if(this.target){
                 a.target = this.target;
@@ -147,18 +162,43 @@ Roo.extend(Roo.bootstrap.Img, Roo.bootstrap.Component,  {
         return (this.href) ? a : cfg;
     },
     
-    initEvents: function() {
-        
+    initEvents: function() 
+    {
         if(!this.href){
             this.el.on('click', this.onClick, this);
         }
+        this.el.select('img', true).on('load', this.onImageLoad, this);
     },
     
     onClick : function(e)
     {
         Roo.log('img onclick');
         this.fireEvent('click', this, e);
+    },
+    onImageLoad: function(e)
+    {
+        Roo.log('img load');
+        this.fireEvent('load', this, e);
+    },
+    
+    /**
+     * Sets the url of the image - used to update it
+     * @param {String} url the url of the image
+     */
+    
+    setSrc : function(url)
+    {
+        this.src =  url;
+        
+        if(this.src || (!this.xsUrl && !this.smUrl && !this.mdUrl && !this.lgUrl)){
+            this.el.dom.src =  url;
+            return;
+        }
+        
+        this.el.select('img', true).first().dom.src =  url;
     }
+    
+    
    
 });