Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat #276 custom image for Iconbutton #324

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions src/aria/widgets/CfgBeans.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
}
},
Expand Down Expand Up @@ -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
}
}
}
}
},
Expand Down
23 changes: 17 additions & 6 deletions src/aria/widgets/Icon.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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('');
}
},

/**
Expand Down
3 changes: 2 additions & 1 deletion src/aria/widgets/action/IconButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
3 changes: 3 additions & 0 deletions test/aria/templates/TemplatesTestSuite.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ Aria.classDefinition({
this.addTests("test.aria.templates.issue142.HtmlStyleTemplateTestCase");
this.addTests("test.aria.templates.issue279.ButtonSpacingTestCase");

this.addTests("test.aria.templates.issue276.IconButtonTestCase");


this.addTests("test.aria.templates.statements.StatementsTestSuite");

}
Expand Down
38 changes: 38 additions & 0 deletions test/aria/templates/issue276/IconButtonTestCase.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
Aria.classDefinition({
$classpath : "test.aria.templates.issue276.IconButtonTestCase",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You've created a test case file but haven't added it to any test suite. Please reference this test in TemplatesTestSuite.js.

$extends : "aria.jsunit.TemplateTestCase",
$constructor : function () {
this.$TemplateTestCase.constructor.call(this);

this.setTestEnv({
template : "test.aria.templates.issue276.TemplateIconBtn"
});

},

$prototype : {
runTemplateTest : function () {
this.__checkIconButtonProperties();
this.__finishTest();
},
__checkIconButtonProperties : 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");

},
__finishTest : function () {
this.notifyTemplateTestEnd();
}
}
});
19 changes: 19 additions & 0 deletions test/aria/templates/issue276/TemplateIconBtn.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{Template {
$classpath:'test.aria.templates.issue276.TemplateIconBtn',
$hasScript:false
}}

{macro main()}

{@aria:IconButton {
id:"myid",
sourceImage:{ path:aria.core.DownloadMgr.resolveURL("test/aria/templates/issue276/icon-check.png"), width:42},
label:"mybutton"
} /}
<br/>
<br/>


{/macro}

{/Template}
Binary file added test/aria/templates/issue276/icon-check.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.