Max image width for columns in gridelements - typo3

I have some grids, where i can choose the column width via flexform (33.3% - 33.3% - 33.3% or 25% - 50% - 25%, …)
I get the max-width of the columns by using CASE with the flexform-field value and the max-width of the page:
…
3 < lib.gridelements.defaultGridSetup
3 {
columns {
1 < .default
1.renderObj = COA
1.renderObj {
10 = LOAD_REGISTER
10.colMaxWidth.cObject = CASE
10.colMaxWidth.cObject {
key.data = field:parentgrid_flexform_style
default = TEXT
default.value =
col-1-2-1 = TEXT
col-1-2-1.value = {$maxContentWidth} / 4
col-1-2-1.prioriCalc = 1
col-4-3-3 = TEXT
col-4-3-3.value = {$maxContentWidth} / 10 * 4
col-4-3-3.prioriCalc = 1
col-1-1-1 = TEXT
col-1-1-1.value = {$maxContentWidth} / 3
col-1-1-1.prioriCalc = 1
}
20.textmedia.dataProcessing.20.maxGalleryWidth.stdWrap.data = register:colMaxWidth
30 = RESTORE_REGISTER
}
2 < .1
2 {
renderObj.10.colMaxWidth.cObject {
col-1-2-1.value = {$maxContentWidth} / 2
col-4-3-3.value = {$maxContentWidth} / 10 * 3
}
}
3 < .1
3 {
renderObj.10.colMaxWidth.cObject {
col-4-3-3.value = {$maxContentWidth} / 10 * 3
}
}
}
...
}
}
This will work fine. But I don’t know what to do, if using nested grids? Then I have to get the flexform-values of the parent gridelement.
Or what is your solution to calculate the max—image-width for grid-columns?

be careful with the calculated size. especially if you use responsive layouts. in responsive layouts columns could be wider on a smaller screen as columns may appaer beneath each other than side by side.
in general: you don't have an easy way to calculate the column width of stacked gridelements. you could do very complicated TS configuration, or you might use an userfunc to solve the computation in PHP.

Did you try to use gridelements together with fluidtemplates?
In the meantime I use this in all my defined grid-elements.

Don't do this on the server side, because the server will not get noticed, when a client changes its browser dimensions. The solution to your problem can easily be fixed by using some CSS. Lets assume you do not render the width directly, but use classes for a grid-system like bootstrap and your rendered gridelement HTML structure looks like this:
<div class="row">
<div class="columns column-2"></div>
<div class="columns column-8"><img src="someimage.jpg" width="800" height="400" /></div>
<div class="columns column-2"></div>
</div>
Your column CSS would probably look like this:
.row{
width: 100%;
}
.row:after{
content: '';
clear: both;
height: 0px;
visibility: hidden;
}
.columns{
float: left;
}
.column-2{
width: 33%;
}
.column-8{
width: 66%;
}
Now you want the images inside the columns to resize with the columns themselfes. A simple max-width: 100%; should do that like so:
.columns img{
max-width: 100%;
}

Since you are using registers anyway, you can include the already calculated register to calculate the amount on deeper levels of the nested structure.
Registers are working like a stack, so with each LOAD_REGISTER you will add a new value to the register stack of colMaxWidth, with each RESTORE_REGISTER you will remove that value in favor of the former value in the stack.
While this is not recommendable performancewise, you can still calculate nested amounts by including the register into the calculation as long as the result gets cached.
When you are on highly dynamic pages with more ore less uncacheable results, you should go for another solution though.

Why don't you use the image editor in TYPO3 V7 Media-Tab?
Screenshot of the image-editor — sorry, but in German

Related

ag-grid auto height for entire grid

I can't find a good way to size the grid to fit all rows perfectly.
documentation only points to sizing by % or px.
Since I want it to size based on rows, I came up with the following function. Seem like im re-inventing the wheel, so maybe there is a better way?
getHeight(type:EntityType) {
var c = this.Apis[type] && this.Apis[type].api && this.Apis[type].api.rowModel // get api for current grid
? this.Apis[type].api.rowModel.rowsToDisplay.length
: -1;
return c > 0
? (40+(c*21))+'px' // not perfect but close formula for grid height
: '86%';
}
there has to be a less messy way..
I came across this solution:
https://github.com/ag-grid/ag-grid/issues/801
There are 2 answers to this problem.
1) If you are using anything below v10.1.0, then you can use the following CSS to achieve the problem:
.ag-scrolls {
height: auto !important;
}
.ag-body {
position: relative !important;
top: auto !important;
height: auto !important;
}
.ag-header {
position: relative !important;
}
.ag-floating-top {
position: relative !important;
top: auto !important;
}
.ag-floating-bottom {
position: relative !important;
top: auto !important;
}
.ag-bl-normal-east,
.ag-bl-normal,
.ag-bl-normal-center,
.ag-bl-normal-center-row,
.ag-bl-full-height,
.ag-bl-full-height-center,
.ag-pinned-left-cols-viewport,
.ag-pinned-right-cols-viewport,
.ag-body-viewport-wrapper,
.ag-body-viewport {
height: auto !important;
}
2) Anything above v10.1.0, there is now a property called 'domLayout'.
https://www.ag-grid.com/javascript-grid-width-and-height/#autoHeight
If the following is the markup
<ag-grid-angular
#agGrid
id="myGrid"
class="ag-theme-balham"
[columnDefs]="columnDefs"
[rowData]="rowData"
[domLayout]="domLayout"
[animateRows]="true"
(gridReady)="onGridReady($event)"
></ag-grid-angular>
Note that [domLayout]="domLayout"
set it as this.domLayout = "autoHeight"; and you're done..
Ref:
https://www.ag-grid.com/javascript-grid-width-and-height/
https://next.plnkr.co/edit/Jb1TD7gbA4w7yclU
Hope it helps.
You can now automate grid height by setting the domLayout='autoHeight' property, or by calling api.setDomLayout('autoHeight')
reference Grid Auto Height
Add the following code on onGridReady function for auto width and auto height
onGridReady = params => {
// Following line to make the currently visible columns fit the screen
params.api.sizeColumnsToFit();
// Following line dymanic set height to row on content
params.api.resetRowHeights();
};
reference
Auto Height
Auto width
determineHeight() {
setTimeout(() => {
console.log(this.gridApi.getDisplayedRowCount());
if (this.gridApi.getDisplayedRowCount() < 20) {
this.gridApi.setDomLayout("autoHeight");
}
else {
this.gridApi.setDomLayout("normal");
document.getElementById('myGrid').style.height = "600px";
}
}, 500);
}
You can use ag-grid feature AutoHeight = true in the column Configuration. or if you want to calculate the height dynamically you should use getRowHeight() callback and create DOM elements like div and span, and add your text in it, then the div will give the OffsetHeight for it then you wont see any cropping of data/rows.
Hope this helps.

Html2Canvas is not able to render multiple DIVs properly

Html2Canvas is not able to render multiple DIVs properly when
The number of DIVs increases significantly, OR
The size of each DIV increases significantly (then it fails with fewer number of DIVs)
I am using Html2Canvas Plugin to convert div (containing image) to canvas. I have implemented a recursive function to convert multiple images at a time (see code below).
JavaScript
//counter
var div_number = 0;
function image2canvas() {
var img2canvasObj = {
logging:true,
onrendered: function (canvas) {
canvas.id = "cvs" + div_number;
$("#canvasid").append(canvas);
//incrementing the counter
div_number = div_number + 1;
if (div_number <= 18) {
html2canvas($("#tempDivforpublishplan" + div_number), img2canvasObj);
}
if (div_number === 19) {
<Some Ajax Call>
}
}
};
html2canvas($("#Content_to_convert" + div_number), img2canvasObj);
}
The HTML for multiple images (which I am converting to canvas) is as follows. Note that I am using images as background of div elements. Each of these elements have a base64 string appended to the image URL which is used to convert the image to canvas.
HTML:
<div id="tempDivforpublishplan0" style='background: url("data:image/png;base64,iVBORw0KGgo…..") 0% 0% / 634px 2266.26px; width: 634px; height: 2266.26px; position: relative; cursor: auto;'> </div>
<div id="tempDivforpublishplan1" style='background: url("data:image/png;base64,iVBORw0KGgo…..") 0% 0% / 634px 2266.26px; width: 634px; height: 2266.26px; position: relative; cursor: auto;'> </div>
.
.
.
<div id="tempDivforpublishplan19" style='background: url("data:image/png;base64,iVBORw0KGgo…..") 0% 0% / 634px 2266.26px; width: 634px; height: 2266.26px; position: relative; cursor: auto;'> </div>
When image count is more, or the size and resolution of images is high, only few images are converted properly. Remaining images are either converted partially or not converted at all. Is there any workaround which can be used to fix this issue?
i have achieved this using callback and delay....
before calling your recursive function use delay and use callback as html2canvas is asynchronous call
I think you are having this trouble because you reach CanvasRenderer height limit during rendering. Assuming all your divs your page height is more than 40000px. Html2Canvas renders your page completely and then crops your div from it according to your div's position. You can see how big your canvas object is if you take a look throw your console having 'logging: true' in html2canvas options. Here is some more info about this subject: Maximum size of a <canvas> element

Is it possible to write a specific query in typoscript

my question may seem trivial, sorry if it is! I am currently learning typo3 and typoscript. I want to create a template with a dynamic background image. This image is stored in a directory. I would like to get the image name from the table tt_content. However, the way this works confuses me a bit and i don't know if my take on it is the right one.
The code looks like this:
20 = CONTENT
20.table = tt_content
20.select{
where = pid = 79
}
20.headerImagePath = COA
20.headerImagePath {
10 = TEXT
10.stdWrap.field = image
10.stdWrap.wrap = <div class="background-media" style="background-image: url('|'); background-repeat: no-repeat; background-size: cover; background-attachment: fixed; background-position: 50%;" data-start="background-position:50% 50%"
data-70-top-bottom="background-position:50% 70%">
</div>
}
I'd like to store the information about the image (the div part in the code) in a variable and put it into my template. The template part of my code looks like this:
<f:format.raw>{headerimage}</f:format.raw>
or
<f:cObject typoscriptObjectPath="headerimage" />
So my question would be, is the way i am selecting things from the database and storing into a variable correct and is the way i am calling them in the template correct? If the way above should work but i have some little errors, is it good practice or should i do things differently?
Kind Regards
Adi
your snippet will not work, because your structure is very wrong.
On
20.headerImagePath = COA
you try to create a new CONTENT OBJECT ARRAY on a CONTENT OBJECT.
20 = CONTENT
This will not work.
But the CONTENT Object has a property called renderObj.
Look at following example:
UNTESTED
Try it like this:
lib.headerImagePath = CONTENT
lib.headerImagePath {
# first call the content you need
table = tt_content
select {
# Add your colPos
# In this example i store my header image in colpos 9
where = colPos = 9
# PID from current field or define your own
# pidInList = 123
pidInList.field = uid
languageField = sys_language_uid
}
renderObj = COA
renderObj {
# FILES object was introduced in TYPO3 6.x
10 = FILES
10 {
# Set a reference to let the file object know, where we will get the images
references {
table = tt_content
uid.field = uid
fieldName = image
}
# make sure we only get the first image in set
maxItems = 1
renderObj = COA
renderObj {
# We only need the url and not the complete image. So we need a IMG_RESOURCE and not an IMAGE Object
10 = IMG_RESOURCE
10 {
stdWrap {
wrap = <div class="background-media" style="background-image: url('|'); background-repeat: no-repeat; background-size: cover; background-attachment: fixed; background-position: 50%;" data-start="background-position:50% 50%" data-70-top-bottom="background-position:50% 70%"></div>
required = 1
}
# Import file from current object
# and treat the id as a reference (TYPO3 File Abstraction Layer)
file {
import.data = file:current:uid
treatIdAsReference = 1
}
}
}
}
}
}
Also look at this examples:
Here they get the header image directly from the MEDIA Element in the page properties:
http://wiki.typo3.org/TypoScript_Header_Image
to get header image as backgound us,its working also in multilanguage work with typo 6.x
page.cssInline {
10 = FILES
10 {
references.data = levelmedia:-1, slide
references.listNum = 0
renderObj = TEXT
renderObj.data = file:current:publicUrl
renderObj.wrap (
.title-1 {
background-image: url(../|) !important;
}
)
}
}
thanks to http://www.derhansen.de/2013/02/using-fal-media-in-typo3-60-for-inline.html

How to: Fixed Table Header with ONE table (no jQuery)

I know, there are at least 3 dozen questions like this on stackoverflow and still, I could not make this happen:
A simple table where thead is sticked/fixed at the top, and the tbody is scrolled.
I tried so much in the past days and now I ended up here crying for help.
A solution should work in IE8+ and newest FF, Chrome & Safari.
The difference to other "possible duplicates like this one is that I don't want to use two nested tables or jQuery (plain javascript is fine though).
Demo of what I want:
http://www.imaputz.com/cssStuff/bigFourVersion.html.
Problem is it doesn't work in IE, and I would be fine to use some JS.
Ok i got it:
You need to wrap the table in two DIVs:
<div class="outerDIV">
<div class="innerDIV">
<table></table>
</div>
</div>
The CSS for the DIVs is this:
.outerDIV {
position: relative;
padding-top: 20px; //height of your thead
}
.innerDIV {
overflow-y: auto;
height: 200px; //the actual scrolling container
}
The reason is, that you basically make the inner DIV scrollable, and pull the THEAD out of it by sticking it to the outer DIV.
Now stick the thead to the outerDIV by giving it
table thead {
display: block;
position: absolute;
top: 0;
left: 0;
}
The tbody needs to have display: block as well.
Now you'll notice that the scrolling works, but the widths are completely messep up. That's were Javascript comes in.
You can choose on your own how you want to assign it. I for myself gave the TH's in the table fixed widths and built a simple script which takes the width and assigns them to the first TD-row in the tbody.
Something like this should work:
function scrollingTableSetThWidth(tableId)
{
var table = document.getElementById(tableId);
ths = table.getElementsByTagName('th');
tds = table.getElementsByTagName('td');
if(ths.length > 0) {
for(i=0; i < ths.length; i++) {
tds[i].style.width = getCurrentComputedStyle(ths[i], 'width');
}
}
}
function getCurrentComputedStyle(element, attribute)
{
var attributeValue;
if (window.getComputedStyle)
{ // class A browsers
var styledeclaration = document.defaultView.getComputedStyle(element, null);
attributeValue = styledeclaration.getPropertyValue(attribute);
} else if (element.currentStyle) { // IE
attributeValue = element.currentStyle[vclToCamelCases(attribute)];
}
return attributeValue;
}
With jQuery of course this would be a lot easier but for now i was not allowed to use a third party library for this project.
Maybe we should change a method to archieve this goal.Such as:
<div><ul><li>1</li><li>2</li></ul></div> //make it fixed
<table>
<thead>
<tr><th>1</th><th>2</th></tr>
</thead>
<tfoot></tfoot>
<tbody></tbody>
</table>
Of course, this is not good to sematic.But it is the simplest way without js or jq.
Don't you think so?

Custom Element Preset => Form Field: Images

I tried to create a typo3 template with a special div-tag.
The editors should have the possibility to add images to the page-element. The goal should be the following code:
<div id="special_div_tag_in_template">
<img src="first_image_from_editor_in_page_element.png" />
<img src="second_image_from_editor_in_page_element.png" />
<img src="third_image_from_editor_in_page_element.png" />
</div>
Is there a possibility to create a custom element preset / form field?
I hope some one has a hint how to solve with this problem.
Thanks, Andreas
You can use the media field of the page properties:
lib.headerImage = COA
lib.headerImage {
wrap = <div id="special_div_tag_in_template">|</div>
10 = IMAGE
10 {
file {
import = uploads/media/
import {
field = media
listNum = 0
}
// set the dimensions if you want
height = 200
width = 100m
}
}
// create a copy and select 2nd image
20 < .10
20.file.import.listNum = 1
// create a copy and select 3rd image
30 < .10
30.file.import.listNum = 2
}
Take a look at the TYPO3 Wiki for more examples of header images.
A different approach would be to create DS/TO in TemplaVoila and insert this as a flexible content element (FCE)