[Commits] r712 - sandbox/bartvde/legend/geoext/lib/GeoExt/widgets/legend

commits at geoext.org commits at geoext.org
Wed May 13 10:25:12 CEST 2009


Author: bartvde
Date: 2009-05-13 10:25:12 +0200 (Wed, 13 May 2009)
New Revision: 712

Modified:
   sandbox/bartvde/legend/geoext/lib/GeoExt/widgets/legend/Image.js
Log:
updates for basic legend image box component including api docs

Modified: sandbox/bartvde/legend/geoext/lib/GeoExt/widgets/legend/Image.js
===================================================================
--- sandbox/bartvde/legend/geoext/lib/GeoExt/widgets/legend/Image.js	2009-05-13 07:56:24 UTC (rev 711)
+++ sandbox/bartvde/legend/geoext/lib/GeoExt/widgets/legend/Image.js	2009-05-13 08:25:12 UTC (rev 712)
@@ -1,50 +1,66 @@
+/* Copyright (C) 2008-2009 The Open Source Geospatial Foundation
+ * Published under the BSD license.
+ * See http://geoext.org/svn/geoext/core/trunk/license.txt for the full text
+ * of the license.
+ * 
+ * pending approval */
+
+/** api: (define)
+ *  module = GeoExt.legend
+ *  class = Image
+ */
+
 Ext.namespace('GeoExt', 'GeoExt.legend');
 
+/** api: constructor
+ *  .. class:: Image(config)
+ *
+ *  Show a legend image in a BoxComponent and make sure load errors are dealt
+ *  with.
+ */
 GeoExt.legend.Image = Ext.extend(Ext.BoxComponent, {
 
+    /** api: config[url]
+     *  ``String``  The url of the image to load
+     */
     url: null,
 
-    /**
-     * Constructor: GeoExt.legend.Image
-     * 
-     * Parameters:
-     * config - {Object}
+    /** api: config[imgCls]
+     *  ``String``  Optional css class to apply to img tag
      */
-    constructor: function(config) {
-        GeoExt.legend.Image.superclass.constructor.apply(this, arguments);
-    },
+    imgCls: null,
 
+    /** private: method[initComponent]
+     *  Initializes the legend image component. 
+     */
     initComponent: function() {
         GeoExt.legend.Image.superclass.initComponent.call(this);
-        this.el = this.createImage(this.url);
+        this.autoEl = {tag: 'img',
+            'class': this.imgCls, src: this.url};
     },
-    
-    /**
-     * Method: onImageLoadError
-     *     When the image fails loading (e.g. when the server returns an XML
-     *     exception) we need to set the src to a blank image otherwise IE
-     *     will show the infamous red cross.
+
+    /** private: method[onRender]
+     *  Private method called when the legend image component is being
+     *  rendered.
      */
-    onImageLoadError: function() {
-        this.src = Ext.BLANK_IMAGE_URL;
+    onRender: function(ct, position) {
+        GeoExt.legend.Image.superclass.onRender.call(this, ct, position);
+        this.getEl().on('error', this.onImageLoadError, this);
     },
 
-    /**
-     * Method: createImage
-     *     Create an image object for the legend image
-     *
-     * Parameters:
-     * src - {String} the source of the image (url)
-     *
-     * Returns:
-     * {DOMElement}
+    /** private: method[onDestroy]
+     *  Private method called during the destroy sequence.
      */
-    createImage: function(src) {
-        var legendImage = document.createElement("img");
-        Ext.EventManager.addListener(legendImage, 'error', 
-            this.onImageLoadError, legendImage);
-        legendImage.src = src;
-        return legendImage;
+    onDestroy: function() {
+        this.getEl().un('error', this.onImageLoadError, this);
+        GeoExt.legend.Image.superclass.onDestroy.apply(this, arguments);
+    },
+    
+    /** private: method[onImageLoadError]
+     *  Private method called if the legend image fails loading.
+     */
+    onImageLoadError: function() {
+        this.getEl().dom.src = Ext.BLANK_IMAGE_URL;
     }
-    
+
 });



More information about the Commits mailing list