So I am pretty new to using Google Compiler and am running into a few issues. The first is that in my preprocessed code I am setting an empty array to a variable which will be populated later on, but when compiling it removes the variable altogether so that it becomes undefined when trying to use it later on.
Here is the code I have slightly modified. Line 19 ends up being removed so therefore rowDivs is showing up as undefined on line 44:
/**
* Equal Heights
*
* @see https://css-tricks.com/equal-height-blocks-in-rows/
*/
goog.provide('EqualHeights');
(function($) {
// = Equalize columns on load and resize
equal_heights();
$(window).resize(function() {
equal_heights();
})
var currentTallest = 0;
var currentRowStart = 0;
var rowDivs = new Array();
function setConformingHeight(el, newHeight) {
// set the height to something new, but remember the original height in case things change
el.data("originalHeight", (el.data("originalHeight") == undefined) ? (el.height()) : (el.data("originalHeight")));
el.height(newHeight);
}
function getOriginalHeight(el) {
// if the height has changed, send the originalHeight
return (el.data("originalHeight") == undefined) ? (el.height()) : (el.data("originalHeight"));
}
function equal_heights() {
// find the tallest DIV in the row, and set the heights of all of the DIVs to match it.
$('[data-equalizer-watch]').each(function() {
// "caching"
var $el = $(this);
var topPosition = $el.position().top;
if (currentRowStart != topPosition) {
// we just came to a new row. Set all the heights on the completed row
for(currentDiv = 0 ; currentDiv < rowDivs.length ; currentDiv++) setConformingHeight(rowDivs[currentDiv], currentTallest);
// set the variables for the new row
rowDivs.length = 0;
// empty the array
currentRowStart = topPosition;
currentTallest = getOriginalHeight($el);
rowDivs.push($el);
}
else {
// another div on the current row. Add it to the list and check if it's taller
rowDivs.push($el);
currentTallest = (currentTallest < getOriginalHeight($el)) ? (getOriginalHeight($el)) : (currentTallest);
}
});
// do the last row
for (currentDiv = 0 ; currentDiv < rowDivs.length ; currentDiv++) {
setConformingHeight(rowDivs[currentDiv], currentTallest);
}
}
})(jQuery);
For the compiler settings, I am using the following flags. Note that I am not even using the advanced optimizations complication level:
--closure_entry_point main.js
--externs node_modules/google-closure-compiler/contrib/externs/jquery-1.9.js
--language_in ECMASCRIPTS5
--warning_level: VERBOSE
I am probably missing something obvious, but just want to get on the right track. Thanks.