I'm trying to do some JavaScript manipulation on the page following the two-pass tutorial.
https://www.princexml.com/doc/two-pass/#two-pass
My goal is to manipulate the font size, but it seems the properties scrollWidth and scrollHeight are not supported? I'm also confused why the jQuery.outerWdith() & jQuery.outerHeight() methods return values whereas the DOM properties offsetWidth, offsetHeight and scrollHeight all return "undefined".
Any help would be much appreciated. Below is the template you can use for testing.
https://www.princexml.com/doc/two-pass/#two-pass
My goal is to manipulate the font size, but it seems the properties scrollWidth and scrollHeight are not supported? I'm also confused why the jQuery.outerWdith() & jQuery.outerHeight() methods return values whereas the DOM properties offsetWidth, offsetHeight and scrollHeight all return "undefined".
Any help would be much appreciated. Below is the template you can use for testing.
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<script src="jquery.js"></script>
<style>
.no-resize, .resize {
width: 100px;
height: 50px;
border: 1px solid #000;
color: #000;
margin: 20px 0;
font-size: 15px
}
.nowrap {
width: 250px;
white-space: nowrap;
}
</style>
</head>
<body>
<div class='container'>
<div class='no-resize'>This text won't be resized and will go out of the div.</div>
<div class='resize'>This text will be resized and wont go out of the div.</div>
<div class='no-resize nowrap'>This text won't be resized and will go out of the div.</div>
<div class='resize nowrap'>This text will also be resized and wont go out of the div.</div>
<div id="test" class='resize nowrap'>This text will also be resized and wont go out of the div.<br/>New Line<br/>New Line<br/>New Line<br/>New Line</div>
</div>
<script>
$(document).ready(function()
{
var elements = $('.resize');
if (elements.length < 0)
{
return;
}
elements.each(function(i, element)
{
// Debug: these output values
// $(element).outerWidth();
// $(element).outerHeight();
//
// Debug: these all output "undefined"
// element.offsetWidth
// element.offsetHeight
// element.scrollHeight
while (element.scrollWidth > element.offsetWidth || element.scrollHeight > element.offsetHeight)
{
var newFontSize = (parseFloat($(element).css('font-size').slice(0, -2)) * 0.95) + 'px';
$(element).css('font-size', newFontSize);
}
}
);
}
);
Prince.trackBoxes = true;
Prince.addEventListener("complete", resizeText, false);
function resizeText()
{
var htmlString = document.documentElement.innerHTML;
console.log(htmlString);
}
</script>
</body>
</html>