Permalink
Browse files

Adding a public getImgEl method. Cleaner.

  • Loading branch information...
pgiraud committed Oct 17, 2012
1 parent 55ea9da commit 0b2ea4124d0aae8009f9cd294ea8772a63c25713
Showing with 20 additions and 29 deletions.
  1. +3 −22 examples/legendpanel.js
  2. +17 −7 lib/GeoExt/widgets/LegendImage.js
View
@@ -133,14 +133,8 @@ Ext.onReady(function() {
// here we create a customized LegendImage component. Our goal is to add a label
// for each layer.PARAMS.LAYERS' item.
CustomLegendImage = Ext.extend(GeoExt.LegendImage, {
- /** private: method[initComponent]
- * Initializes the legend image component.
- */
initComponent: function() {
- GeoExt.LegendImage.superclass.initComponent.call(this);
- if(this.defaultImgSrc === null) {
- this.defaultImgSrc = Ext.BLANK_IMAGE_URL;
- }
+ CustomLegendImage.superclass.initComponent.call(this);
this.autoEl = {
tag: "div",
children: [{
@@ -154,21 +148,8 @@ CustomLegendImage = Ext.extend(GeoExt.LegendImage, {
};
},
- /** api: method[setUrl]
- * :param url: ``String`` The new URL.
- *
- * Sets the url of the legend image.
- */
- setUrl: function(url) {
- this.url = url;
- var el = Ext.select('img', false, this.getEl().dom).first();
- if (el) {
- el.un("load", this.onImageLoad, this);
- el.on("load", this.onImageLoad, this, {single: true});
- el.un("error", this.onImageLoadError, this);
- el.on("error", this.onImageLoadError, this, {single: true});
- el.dom.src = url;
- }
+ getImgEl: function() {
+ return Ext.select('img', false, this.getEl().dom).first();
}
});
Ext.reg('custom_legendimage', CustomLegendImage);
@@ -59,14 +59,24 @@ GeoExt.LegendImage = Ext.extend(Ext.BoxComponent, {
};
},
+ /** api: method[getImgEl]
+ * :return: ``Ext.Element`` The image element.
+ *
+ * Returns the image element.
+ * This method is supposed to be overriden in subclasses.
+ */
+ getImgEl: function() {
+ return this.getEl();
+ },
+
/** api: method[setUrl]
* :param url: ``String`` The new URL.
*
* Sets the url of the legend image.
*/
setUrl: function(url) {
this.url = url;
- var el = this.getEl();
+ var el = this.getImgEl();
if (el) {
el.un("load", this.onImageLoad, this);
el.on("load", this.onImageLoad, this, {single: true});
@@ -90,8 +100,8 @@ GeoExt.LegendImage = Ext.extend(Ext.BoxComponent, {
/** private: method[onDestroy]
* Private method called during the destroy sequence.
*/
- onDestroy: function(e, img) {
- var el = Ext.get(img);
+ onDestroy: function() {
+ var el = this.getImgEl();
if(el) {
el.un("load", this.onImageLoad, this);
el.un("error", this.onImageLoadError, this);
@@ -102,17 +112,17 @@ GeoExt.LegendImage = Ext.extend(Ext.BoxComponent, {
/** private: method[onImageLoadError]
* Private method called if the legend image fails loading.
*/
- onImageLoadError: function(e, img) {
- var el = Ext.get(img);
+ onImageLoadError: function() {
+ var el = this.getImgEl(img);
el.addClass(this.noImgCls);
el.dom.src = this.defaultImgSrc;
},
/** private: method[onImageLoad]
* Private method called after the legend image finished loading.
*/
- onImageLoad: function(e, img) {
- var el = Ext.get(img);
+ onImageLoad: function() {
+ var el = this.getImgEl(img);
if (!OpenLayers.Util.isEquivalentUrl(el.dom.src, this.defaultImgSrc)) {
el.removeClass(this.noImgCls);
}

0 comments on commit 0b2ea41

Please sign in to comment.