Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

feat #276 custom image for Iconbutton

  • Loading branch information...
commit fc797d038e6b8006703f804a3fa02cb659699b5a 1 parent e0b0913
Srinath M smadapathi authored piuccio committed
3  build/config/urlmap.json
View
@@ -28,7 +28,8 @@
"Link.js" : "aria/pack-widgets1.js",
"LinkStyle.tpl.css" : "aria/pack-widgets1.js",
"SortIndicator.js" : "aria/pack-widgets2.js",
- "SortIndicatorStyle.tpl.css" : "aria/pack-widgets2.js"
+ "SortIndicatorStyle.tpl.css" : "aria/pack-widgets2.js",
+ "IconButton.js" : "aria/pack-widgets2.js"
},
"calendar" : {
"*" : "aria/pack-widgets1.js"
42 src/aria/widgets/CfgBeans.js
View
@@ -946,6 +946,27 @@ Aria.beanDefinitions({
$type : "json:String",
$description : "The name of the sprite and the icon that is to be used in the form sprite:icon",
$default : null
+ },
+ "sourceImage" : {
+ $type : "json:Object",
+ $description : "Configuration for custom image",
+ $properties : {
+ "path" : {
+ $type : "json:String",
+ $description : "Path of the image",
+ $default : null
+ },
+ "width" : {
+ $type : "json:Integer",
+ $description : "Width of the image",
+ $default : 16
+ },
+ "height" : {
+ $type : "json:Integer",
+ $description : "Height of the image",
+ $default : 16
+ }
+ }
}
}
},
@@ -1031,6 +1052,27 @@ Aria.beanDefinitions({
$type : "json:String",
$description : "The name of the sprite and the icon that is to be used in the form sprite:icon",
$default : null
+ },
+ "sourceImage" : {
+ $type : "json:Object",
+ $description : "Configuration for custom image",
+ $properties : {
+ "path" : {
+ $type : "json:String",
+ $description : "Path of the image",
+ $default : null
+ },
+ "width" : {
+ $type : "json:Integer",
+ $description : "Width of the image",
+ $default : 16
+ },
+ "height" : {
+ $type : "json:Integer",
+ $description : "Height of the image",
+ $default : 16
+ }
+ }
}
}
},
23 src/aria/widgets/Icon.js
View
@@ -63,8 +63,16 @@ Aria.classDefinition({
* @param {aria.templates.MarkupWriter} out the html output writer
*/
writeMarkup : function (out) {
- var cfg = this._cfg, id = this._domId, tooltip = cfg.tooltip, iconInfo;
- iconInfo = this._getIconInfo(cfg.icon);
+ var cfg = this._cfg;
+ var id = this._domId;
+ var tooltip = cfg.tooltip;
+ var sourceImage = cfg.sourceImage;
+ var iconInfo = sourceImage ? {
+ "imageURL" : sourceImage.path,
+ "width" : sourceImage.width,
+ "height" : sourceImage.height
+ } : this._getIconInfo(cfg.icon);
+
if (!iconInfo) {
tooltip = this.ERROR_ICON_TITLE.replace('%', cfg.icon);
iconInfo = this._getErrIcon();
@@ -156,10 +164,13 @@ Aria.classDefinition({
} else if (iconInfo.margins != null) {
margins = iconInfo.margins;
}
-
- return [margins, ';padding:0;background-position:-', iconInfo.iconLeft, 'px -', iconInfo.iconTop,
- 'px;width:', iconInfo.width, 'px;height:', iconInfo.height, 'px;', vAlign].join('');
-
+ if (cfg.sourceImage) {
+ return [margins, ';padding:0;background:url(', iconInfo.imageURL, ') no-repeat; width:',
+ iconInfo.width, 'px;height:', iconInfo.height, 'px;', vAlign].join('');
+ } else {
+ return [margins, ';padding:0;background-position:-', iconInfo.iconLeft, 'px -', iconInfo.iconTop,
+ 'px;width:', iconInfo.width, 'px;height:', iconInfo.height, 'px;', vAlign].join('');
+ }
},
/**
3  src/aria/widgets/action/IconButton.js
View
@@ -34,7 +34,8 @@ Aria.classDefinition({
* @protected
*/
this._icon = new aria.widgets.Icon({
- icon : cfg.icon
+ icon : cfg.icon,
+ sourceImage : cfg.sourceImage
}, ctxt, lineNumber);
},
$destructor : function () {
1  test/aria/widgets/WidgetsTestSuite.js
View
@@ -34,5 +34,6 @@ Aria.classDefinition({
this.addTests("test.aria.widgets.environment.WidgetSettings");
this.addTests("test.aria.widgets.errorlist.ErrorListControllerTest");
this.addTests("test.aria.widgets.form.FormTestSuite");
+ this.addTests("test.aria.widgets.action.iconbutton.issue276.IconButtonTestCase");
}
});
32 test/aria/widgets/action/iconbutton/issue276/IconButtonTestCase.js
View
@@ -0,0 +1,32 @@
+Aria.classDefinition({
+ $classpath : "test.aria.widgets.action.iconbutton.issue276.IconButtonTestCase",
+ $extends : "aria.jsunit.TemplateTestCase",
+ $constructor : function () {
+ this.$TemplateTestCase.constructor.call(this);
+
+ this.setTestEnv({
+ template : "test.aria.widgets.action.iconbutton.issue276.TemplateIconBtn"
+ });
+
+ },
+
+ $prototype : {
+ runTemplateTest : function () {
+ var iconBtnId = this.getWidgetInstance("myid")._domId;
+ var domUtil = aria.utils.Dom;
+ // for getting iconbutton image style
+ var iconBtnElement = domUtil.getDomElementsChildByTagName(domUtil.getElementById(iconBtnId), 'span')[4];
+ var width = domUtil.getStyle(iconBtnElement, "width");
+ var height = domUtil.getStyle(iconBtnElement, "height");
+ // Background url is different for different browsers, so just checking image name
+ var imageURL = domUtil.getStyle(iconBtnElement, "background").split(' ')[0].replace(/("|')/g, "");
+ var imagename = imageURL.substring(imageURL.lastIndexOf('/') + 1, imageURL.lastIndexOf(')'));;
+
+ this.assertEquals(width, "42px", "Width is not proper");
+ this.assertEquals(height, "16px", "Height is not proper");
+ this.assertEquals(imagename, "icon-check.png", "Image is not proper");
+
+ this.end();
+ }
+ }
+});
19 test/aria/widgets/action/iconbutton/issue276/TemplateIconBtn.tpl
View
@@ -0,0 +1,19 @@
+{Template {
+ $classpath:'test.aria.widgets.action.iconbutton.issue276.TemplateIconBtn',
+ $hasScript:false
+}}
+
+ {macro main()}
+
+ {@aria:IconButton {
+ id:"myid",
+ sourceImage:{ path:aria.core.DownloadMgr.resolveURL("test/aria/widgets/action/iconbutton/issue276/icon-check.png"), width:42},
+ label:"mybutton"
+ } /}
+ <br/>
+ <br/>
+
+
+ {/macro}
+
+{/Template}
BIN  test/aria/widgets/action/iconbutton/issue276/icon-check.png
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Please sign in to comment.
Something went wrong with that request. Please try again.