How to access height of div set in HTML document from within jquery theme script file? - galleria

I'm currently creating a theme for the popular jquery gallery script, Galleria.
Here's a link to the documentation on creating a theme.
My theme is based on the default theme, "Classic", and here's what I need to do.
The Galleria script takes images within a div called "galleria" and makes a slideshow out of them. A basic requirement is that you set the height of this div in CSS.
Rather than setting this in an associated CSS file, I have set the height of the "galleria" div using Javascript within the HTML doc that picks up the browser window's height. The reason I did this (instead of merely setting height as 100%) can be seen in full here, but essentially it's because I need content below this div, but still want the page to show a fullscreen gallery when scrolled all the way up.
The above is great, but now I need to set the position of various elements created by the Galleria script, as a value that depends on this calculated height.
In my theme.js, how do I fetch the height of the "galleria" div as calculated above? And how do I then set the position of another element within the Galleria DOM structure depending on this?

Using a library like jQuery this becomes pretty easy.
To get the height of the galleria element:
val galleria_height = $("#galleria");
To position an element inside the galleria element (assuming absolute positioning):
val galleria_offset = $("#galleria").offset()
val relativeTop = 10;
val relativeLeft = 10;
// Position the element at (10, 10) relative to galleria
$("#some_element").offset({
top: galleria_offset.top + relativeTop,
left: galleria_offset.left + relativeLeft
});

Related

Determine rendered height in a PDF document for drawing dynamic-sized page footers, on macOS

Assuming I print a small amount of text into a PDF document, I like to know how much of the page is actually used by the text.
For example, if I render a short text paragraph into a PDF document, I like to learn the content height of only that text, not of the entire A4 (letter) page.
Background
I need to render a long HTML page into a PDF document that uses a smaller page size. The result is that the content gets rendered into several PDF pages. I currently use NSPrintOperation for this.
The challenge is that I also need to render a footer page into each page. For this, I need to dynamically determine the height of that footer so that I can set the page's bottom margin accordingly, resulting in the footer area be kept free when rendering the main (body) HTML content. Once that's finished, I can then add the footer to each page in a separate step (using CGPDFDocument).
I wish there was a simpler way, but it seems that the macOS HTML renderer cannot handle html footers when printing multiple pages.
I found a solution, though that's a bit ugly:
Generate the PDF with the footer content, so that it renders at the top of the page (margins set to 0).
Read the PDF into NSPDFImageRepMBS
Create a NSImageMBS and add the imageRep to it with addRepresentation:
Now the image has a size of the original PDF page, but contains only the drawable region of the footer content - the rest of the image is clear.
By scanning the image's lines from bottom towards the top, looking for a non-clear line, the height of the footer content can be determined.
With the footer height known, I can now render the main content to a PDF with the bottom margin set to keep free the footer area
Finally, I create a new CGPDFDocument, going over each page of the main PDF, drawing thes main pages along with the footer (offset into the page's footer area) into each page.

How to "disable" FullPage on smartphones and display sections as a long page?

I am using FullPage JS to display a few sections. On the desktop, it works perfectly.
However, Some sections have quite an amount of content. On smartphones, part of the content of these sections is covered. Put another way, I am only able to see part of the content of these sections when I scroll (I already used media queries to reduce content display on smartphones, but these sections do have more content than what a full screen can display on smartphones).
I need the usual FullPage JS to work for me on the desktop. However, can I disable full screen display on smartphones and simply display a list of sections as a long page on smartphones? Did anyone do this before?
fullpage.js provides options for it such as responsiveWidth and responsiveHeight that will turn off auto scrolling under a given value in px.
Combine those with the class fp-auto-height-responsive and you'll get what you want.
All of this is detailed in the docs.
Responsive auto height sections
A responsive auto height can be applied by using the class fp-auto-height-responsive. This way sections will be full height until the responsive mode gets fired.
responsiveWidth: (default 0) A normal scroll (autoScrolling:false) will be used under the defined width in pixels. A class fp-responsive is added to the body tag in case the user wants to use it for his own responsive CSS. For example, if set to 900, whenever the browser's width is less than 900 the plugin will scroll like a normal site.
responsiveHeight: (default 0) A normal scroll (autoScrolling:false) will be used under the defined height in pixels. A class fp-responsive is added to the body tag in case the user wants to use it for his own responsive CSS. For example, if set to 900, whenever the browser's height is less than 900 the plugin will scroll like a normal site.

Make Responsive Svg inside angular-gridster item

I want to make Gridster grid responsive according to grid resize as well as window resize. Currently I am using DC.js to render charts inside the gridster grid, but if the screen resolution changes from bigger to smaller , the value of the item stored previously for the width for svg remain too big for the screen.
Any tips how to make it responsive. How to set the width of gridster item , it looks to me it injected through java-script.
I found out the answer. Angular Gridster have a event "gridster-resized" , whenever this event happens try to resize the items in the gridster.

jqgrid column resize after manually width change

i have a function where i manually set the width of a jqgrid column. If I after this want to use the resize handle, it adds or substracts relative from the original width size. So it doesn't see my new width to take as a base. I have tried putting the width and withOrg in the colModel without success.
I have a click handler inwhich i resize a column to a certain width on click. i set the width of the th trought JS. After this i would like to be able to use the .ui-jqgrid-resize element for resizing the column.
a short version of my code, say the th is 200px wide:
$('th').dblclick(function(){
$(this).width('100px');
});
after the user doubleclicked, and the th went smaller in size to 100px, the user uses the resize handle to widen the th 10px. The expected result is a th of 110px wide, but the thjumps to 210px wide. It adds the 10px the user wanted to add to the original state, not the state i have set with the doubleclick.
I would recommend you to use setColWidth method, from the plugin which I wrote before (see the answer), to change the width of the grid column. You can download the current version of the plugin from github.
If you trying to set the width of columns based on the width of the content of the column then I would recommend you to take a look at the demo created for the answer and read the answer too. I don't see the suggested code as final solution, but the demos shows my view on the problem and the ways to implement "autowidth" functionality.

How to find pixel height of a div with a consistent result between FF and Chrome

Back story: I have an SVG canvas with some polylines on it. I also have some HTML <span> and <textarea> elements that need to be positioned precisely in relation to those polylines.
I started by putting the HTML elements in the SVG in <foreignElement> tags, but I had a problem there because IE doesn't see them at all and Firefox doesn't see the <textarea>s. So I took them out of the SVG and now every browser sees them.
So far so good. Now the only way I know to make sure they position correctly with the polylines is to give both the HTML elements and the SVG canvas absolute positions with CSS.
Here's my problem. Above all these elements is a header div. I want the whole SVG business to sit at a reasonable distance below the header. Say 15px. But since the SVG is absolutely positioned, I need to know the height of that header div to get the SVG and related HTML elements into the right place.
I've tried jQuery's .height() method and some related methods. The problem with all of them is that Firefox and Chrome give two different results. I know this doesn't reflect a real pixel height difference between the two, because I can see visually that the header is slightly taller in FF, yet FF gives a smaller height reading.
How can I get a browser-consistent height reading for my header div? Or at least one that I can use to absolutely position other elements at the same distance below it in every browser.
You could try with this function
function getHeight() {
return Math.min(
Math.min(document.body.scrollHeight, document.documentElement.scrollHeight),
Math.min(document.body.offsetHeight, document.documentElement.offsetHeight),
Math.min(document.body.clientHeight, document.documentElement.clientHeight)
);
}
or simply with document.documentElement.clientHeight, which usually does the trick for me in all the browsers I use for testing (Chrome, Firefox, Safari and Opera)
[edit] The function above returns the width and height of the body, in order to use it for any div, use this one
function getHeight(div) {
return Math.min(div.scrollHeight, div.offsetHeight, div.clientHeight);
}
You can use it like this
var myDiv = document.getElementById('myDivId');
console.log('the height is ' + getHeight(myDiv));
[edit2]Keep in mind that the divs might actually have a different size depending on the browser.
Let's say this is google chrome and the green bar at top is the navigation bar, with a height of 75px. You have it at 100%, filling up your screen, who has 1000px height, and you place an 100 pixels div to the top and also stick an 100px div to the bottom of the screen (with blue). The purple div between them will have an 725px height.
And this below is firefox. It's placed on the same 1000px screen, also at 100%, but its navigation bar has 100px height. With the same 100px blue divs to the top and the bottom, the purple div will have a height of 700px here, different from chrome.
Of course, this is a very, very simple example and I doubt this is your case. But you might have a similar problem with div placements and it's something you should try to check.

Resources