Skip to content

Commit

Permalink
fix ariatemplates#1474 Better dialog width management depending on th…
Browse files Browse the repository at this point in the history
…e title length
  • Loading branch information
fbasso committed Jun 3, 2015
1 parent b81fe4a commit 6de1d16
Show file tree
Hide file tree
Showing 5 changed files with 271 additions and 8 deletions.
57 changes: 50 additions & 7 deletions src/aria/widgets/container/Dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,7 @@ module.exports = Aria.classDefinition({
this._cfg.title = newValue;
if (this._titleDomElt) {
this._titleDomElt.innerHTML = newValue;
this._onDimensionsChanged();
}
} else if (propertyName === "macro") {
this._cfg.macro = newValue;
Expand Down Expand Up @@ -580,9 +581,12 @@ module.exports = Aria.classDefinition({
var cfg = this._cfg;
var getDomElementChild = ariaUtilsDom.getDomElementChild;
this._domElt = this._popup.domElement;
this._titleBarDomElt = getDomElementChild(this._domElt, 0, true);
this._titleDomElt = getDomElementChild(this._titleBarDomElt, cfg.icon ? 1 : 0);
var titleBarDomElt = this._titleBarDomElt = getDomElementChild(this._domElt, 0, true);
this._titleDomElt = getDomElementChild(titleBarDomElt, cfg.icon ? 1 : 0);
this._onDimensionsChanged();

this._calculatePosition();

if (cfg.modal) {
ariaTemplatesNavigationManager.focusFirst(this._domElt);
}
Expand Down Expand Up @@ -709,6 +713,7 @@ module.exports = Aria.classDefinition({
* @protected
*/
_updateDivSize : function (viewport) {
var cfg = this._cfg;
var math = ariaUtilsMath;

var maxHeight, maxWidth;
Expand All @@ -720,16 +725,54 @@ module.exports = Aria.classDefinition({
maxWidth = math.min(this._cfg.maxWidth, viewport.width);
}

var titleBarDomElt = this._titleBarDomElt;
var titleDomElt = this._titleDomElt;

var isIE7 = aria.core.Browser.isIE7;
if (isIE7) {
// without this, IE 7 gives wrong inner sizes
titleDomElt.style.overflow = "visible";
}

titleDomElt.style.width = "";
var titleWidth = ariaUtilsDom.getGeometry(titleDomElt).width;
var childNodes = this._titleBarDomElt.childNodes;
var iconsWidth = 0;
for (var i = 1, ii = childNodes.length; i < ii; i++) {
iconsWidth += childNodes[i].offsetWidth;
}

// First manage the width of the modal depending on the title bar and the max width
var shadows = this._shadows;
var minWidth = ariaUtilsMath.max(cfg.width, cfg.minWidth);
if (cfg.width == -1) {
minWidth = ariaUtilsMath.max(titleWidth + iconsWidth + shadows.left + shadows.right, minWidth);
}

// if maximized == true, then height|widthMaximized will be used; otherwise normal width and height
this._div.updateSize({
maxHeight : maxHeight,
maxWidth : maxWidth,
height : this._cfg.height,
width : this._cfg.width,
heightMaximized : this._cfg.heightMaximized,
widthMaximized : this._cfg.widthMaximized,
maximized : this._cfg.maximized
minWidth : minWidth,
height : cfg.height,
width : cfg.width,
heightMaximized : cfg.heightMaximized,
widthMaximized : cfg.widthMaximized,
maximized : cfg.maximized
});

var titleBarWidth = ariaUtilsDom.getGeometry(titleBarDomElt).width;

// The manage the title length to manage the text-overflow
if (titleWidth >= titleBarWidth) {
titleDomElt.style.width = (titleBarWidth - iconsWidth - shadows.left - shadows.right) + "px";
}

if (isIE7) {
// Back to overflow hidden mode
titleDomElt.style.overflow = "hidden";
}

},

/**
Expand Down
3 changes: 3 additions & 0 deletions src/aria/widgets/container/DialogStyle.tpl.css
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@
padding-top: 6px;
color:${skinClass.titleColor};
font-weight:bold;
white-space: nowrap;
text-overflow: ellipsis;
overflow: hidden;
}
.xDialog_${skinClassName}_icon {
padding-left: 6px;
Expand Down
2 changes: 1 addition & 1 deletion src/aria/widgets/container/Div.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ module.exports = Aria.classDefinition({
*/
updateSize : function (cfg) {
var hasChanged = false, prefName, newVal;
var prefs = ['maxWidth', 'maxHeight', 'width', 'height'];
var prefs = ['maxWidth', 'maxHeight', 'minWidth', 'width', 'height'];

for (var i = 0, len = prefs.length; i < len; i++) {
prefName = prefs[i];
Expand Down
107 changes: 107 additions & 0 deletions test/aria/widgets/container/dialog/sizes/DialogMaxWidthTestCase.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/*
* Copyright 2012 Amadeus s.a.s.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* Test for issue #10
*/
Aria.classDefinition({
$classpath : "test.aria.widgets.container.dialog.sizes.DialogMaxWidthTestCase",
$extends : "aria.jsunit.TemplateTestCase",
$dependencies : ["aria.utils.Json"],
$constructor : function () {
this.$TemplateTestCase.constructor.call(this);

this.$json = aria.utils.Json;

this.data = {
title: "Short",
width: 150
};

this.setTestEnv({
template : "test.aria.widgets.container.dialog.sizes.DialogMaxWidthTestCaseTpl",
data : this.data
});
},
$prototype : {

checkSizes : function(dialogId, mainWidth) {
var dialog = this.dialogs[dialogId];

var dom = dialog._domElt;
var children = dom.children;
var dlgBody = children[0];
var dlgTitle = children[1];
var dlgTitleText = aria.utils.Dom.getElementsByClassName(dlgTitle, "sDialog_title");
var dlgCloseIcon = aria.utils.Dom.getElementsByClassName(dlgTitle, "sDialog_close");

this.assertEqualsWithTolerance(dlgBody.offsetWidth, mainWidth, 8, dialogId + " width should be %2 instead of %1");
this.assertEqualsWithTolerance(dlgTitle.offsetWidth, mainWidth - 10, 8, dialogId + " title width should be %2 instead of %1");
this.assertEquals(dlgTitleText.offsetTop, dlgCloseIcon.offsetTop, "The close icon should be on teh first line");
},


runTemplateTest : function () {
// The main template is Ready even if it contains a template inside the Dialog, wait
var dialogIds = ["dialog1", "dialog2", "dialog3", "dialog4", "dialog5"];
this.waitFor({
condition : function() {
// Wait for every dialog ready and open
var dialogs = this.dialogs = {};
for (var i = 0; i < dialogIds.length; i += 1) {
var id = dialogIds[i];
var currentInstance = dialogs[id] = this.getWidgetInstance(id);
if (!currentInstance || !currentInstance._popup.isOpen) {
return false;
}
}
return true;
},
callback : {
fn : this.checkWidths,
scope : this
}
});
},

checkWidths : function () {
this.checkSizes("dialog1", 400);
this.checkSizes("dialog2", 400);
this.checkSizes("dialog3", 238);
this.checkSizes("dialog4", 400);

this.changeContainerSize();
},

changeContainerSize : function () {

var data = this.data;
this.checkSizes("dialog5", 200);
this.$json.setValue(data, "title", "This is now a very long title");
this.checkSizes("dialog5", 251);

this.$json.setValue(data, "title", "This is now a very very very very very very very long title");
this.checkSizes("dialog5", 400);

this.$json.setValue(data, "title", "Short again");
this.checkSizes("dialog5", 200);

this.$json.setValue(data, "width", 500);
this.checkSizes("dialog5", 400);

this.end();
}
}
});
110 changes: 110 additions & 0 deletions test/aria/widgets/container/dialog/sizes/DialogMaxWidthTestCaseTpl.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/*
* Copyright 2012 Amadeus s.a.s.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

{Template {
$classpath : "test.aria.widgets.container.dialog.sizes.DialogMaxWidthTestCaseTpl"
}}

{macro main()}

{@aria:Dialog {
visible : true,
macro : "largeContent",
title: "Very very very very very very very very very very very very long title",
id : "dialog1",
maximizable : true,
center : false,
xpos : 20,
ypos : 20,
maxHeight: 350,
maxWidth: 400
}/}

{@aria:Dialog {
visible : true,
macro : "largeContent",
title: "Normal title",
id : "dialog2",
center : false,
xpos : 450,
ypos : 20,
maxHeight: 400,
maxWidth: 400
}/}

{@aria:Dialog {
visible : true,
macro : "smallContent",
title: "Title larger than the content",
id : "dialog3",
center : false,
xpos : 900,
ypos : 20,
maxHeight: 400,
maxWidth: 400
}/}

{@aria:Dialog {
visible : true,
macro : "smallContent",
title: "Very very very very very very very very very very very very long title",
id : "dialog4",
center : false,
xpos : 1150,
ypos : 20,
maxHeight: 400,
maxWidth: 400
}/}

{@aria:Dialog {
visible : true,
macro : "dynamicWidth",
title: "Normal title",
bind: {
title: {
to : "title",
inside : data
}
},
id : "dialog5",
center : false,
xpos : 900,
ypos : 200,
maxHeight: 400,
maxWidth: 400
}/}

{/macro}

{macro largeContent ()}
<div style="width:700px; height: 3000px">Large dialog content</div>
{/macro}
{macro dynamicWidth ()}
{section {
macro: "dynamicWidthContent",
bindRefreshTo: [{
inside: data,
to: "width"
}]
}/}
{/macro}
{macro dynamicWidthContent ()}
<div style="width:${data.width}px; height: 3000px">Large dialog content</div>
{/macro}
{macro smallContent ()}
<div style="padding: 20px">Dialog content</div>
{/macro}

{/Template}

0 comments on commit 6de1d16

Please sign in to comment.