Commit 02c6617d authored by Cecilia Vela Gurovic's avatar Cecilia Vela Gurovic
Browse files

Bug 1813987: resizing block when expandig collapsible inside block

fixes failed step in resume_page.feature
fixes in timeline view to expand a block to fit content

behatnotneeded

Change-Id: I1d187f338c0c36795efff40bbe8d9447b2d66124
parent fb0adb74
...@@ -57,8 +57,13 @@ function loadGrid(grid, blocks) { ...@@ -57,8 +57,13 @@ function loadGrid(grid, blocks) {
// images need time to load before height can be properly calculated // images need time to load before height can be properly calculated
window.setTimeout(function(){ window.setTimeout(function(){
updateBlockSizes(); // no need to update the blocksizes for hidden timeline views
var id = $(grid.container).attr('id');
if (typeof id === 'undefined') {
updateBlockSizes();
}
}, 300); }, 300);
} }
function initJs() { function initJs() {
...@@ -70,6 +75,41 @@ function initJs() { ...@@ -70,6 +75,41 @@ function initJs() {
if (typeof viewmenuInit !== "undefined") { if (typeof viewmenuInit !== "undefined") {
viewmenuInit(); viewmenuInit();
} }
$(window).on('colresize', function(e) {
var grid = $(e.target).closest('.grid-stack');
var id = grid.attr('id');
//check we are not in timeline view
if (typeof id === 'undefined') {
updateBlockSizes();
}
else {
// on timeline view
grid.gridstack();
updateBlockSizes(grid);
}
});
$(window).on('shown.bs.collapse', function(e) {
var grid = $(e.target).closest('.grid-stack');
var id = grid.attr('id');
//check we are not in timeline view
if (typeof id === 'undefined') {
updateBlockSizes();
}
else {
// on timeline view
grid.gridstack();
updateBlockSizes(grid);
}
});
$(window).on('timelineviewresizeblocks', function() {
var grid = $('.lineli.selected .grid-stack');
grid = grid.gridstack();
updateBlockSizes(grid);
});
} }
function updateTranslatedGridRows(blocks) { function updateTranslatedGridRows(blocks) {
...@@ -132,25 +172,27 @@ function updateTranslatedGridRows(blocks) { ...@@ -132,25 +172,27 @@ function updateTranslatedGridRows(blocks) {
moveBlocks(updatedGrid); moveBlocks(updatedGrid);
} }
function updateBlockSizes() { function updateBlockSizes(grid) {
$.each($('.grid-stack').children(), function(index, element) { if (typeof grid == 'undefined') {
grid = $('.grid-stack');
}
$.each(grid.children(), function(index, element) {
if (!$(element).hasClass('staticblock')) { if (!$(element).hasClass('staticblock')) {
var width = $($('.grid-stack-item')[index]).attr('data-gs-width'), var width = $(element).attr('data-gs-width'),
prevHeight = $($('.grid-stack-item')[index]).attr('data-gs-height'), prevHeight = $(element).attr('data-gs-height'),
height = Math.ceil( height = Math.ceil(
( (
$('.grid-stack-item-content')[index].scrollHeight + $(element).find('.grid-stack-item-content')[0].scrollHeight +
$('.grid-stack').data('gridstack').opts.verticalMargin grid.data('gridstack').opts.verticalMargin
) )
/ /
( (
$('.grid-stack').data('gridstack').cellHeight() + grid.data('gridstack').cellHeight() +
$('.grid-stack').data('gridstack').opts.verticalMargin grid.data('gridstack').opts.verticalMargin
) )
); );
//height = height.toString(); if (+prevHeight < height) {
if (+prevHeight != height) { grid.data('gridstack').resize(element, +width, height);
$('.grid-stack').data('gridstack').resize($('.grid-stack-item')[index], +width, height);
} }
} }
}); });
...@@ -172,7 +214,11 @@ function addNewWidget(blockContent, blockId, dimensions, grid, blocktypeclass, m ...@@ -172,7 +214,11 @@ function addNewWidget(blockContent, blockId, dimensions, grid, blocktypeclass, m
// images need time to load before height can be properly calculated // images need time to load before height can be properly calculated
window.setTimeout(function(){ window.setTimeout(function(){
updateBlockSizes(); // no need to update sizes for timeline views that are hidden
var id = $(grid.container).attr('id');
if (typeof id == 'undefined') {
updateBlockSizes();
}
}, 300); }, 300);
return el; return el;
...@@ -245,10 +291,6 @@ function gridInit() { ...@@ -245,10 +291,6 @@ function gridInit() {
serializeWidgetMap(items); serializeWidgetMap(items);
}); });
$(window).on('colresize', function() {
updateBlockSizes();
});
} }
function gridRemoveEvents() { function gridRemoveEvents() {
......
...@@ -295,6 +295,7 @@ ...@@ -295,6 +295,7 @@
selectedContent.removeClass('enter-left enter-right'); selectedContent.removeClass('enter-left enter-right');
selectedContent.addClass('selected'); selectedContent.addClass('selected');
evdone = true; evdone = true;
$(window).trigger('timelineviewresizeblocks');
} }
}); });
// height of the version changes after it becomes visible // height of the version changes after it becomes visible
...@@ -431,6 +432,7 @@ ...@@ -431,6 +432,7 @@
timeline.find('.cd-timeline-navigation').find('.next').addClass('inactive'); timeline.find('.cd-timeline-navigation').find('.next').addClass('inactive');
} }
}); });
$(window).trigger('timelineviewresizeblocks');
} }
else { else {
$(obj).html("Error fetching data"); $(obj).html("Error fetching data");
......
...@@ -41,7 +41,7 @@ ...@@ -41,7 +41,7 @@
formatSubTitle: function (subTitle, obj) { return '<div class="metadata">' + subTitle + '</div>'; }, formatSubTitle: function (subTitle, obj) { return '<div class="metadata">' + subTitle + '</div>'; },
formatBodyContent: function (bodyCnt, obj) { formatBodyContent: function (bodyCnt, obj) {
if (obj.gridlayout) { if (obj.gridlayout) {
var grid = $('<div class="grid-stack"></div>'); var grid = $('<div id="grid_' + obj.assignID + '" class="grid-stack"></div>');
var options = { var options = {
verticalMargin: 10, verticalMargin: 10,
float: true, float: true,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment