In my script, the function in question is at the end of
$(jquery).ready(function(){...});
For some reason it is firing before the DOM is loaded. I'll post the whole script below. I am interested in what happens at lines 246-248.
THIS IS THE BUGGY PART:
alert(listObj.listOffset);
listObj.allLists.offset({ left: listObj.listOffset });
listObj.allLists[listIndex].focus();
A Little More Detail
This particular part of the script is trying to put the focus on today. There is a layout object that should enable this process. It needs to run after the DOM loads, so that it can calculate layout offset variables. When it loads early, the offset ends up being 15000px instead of 400ish.
If you can offer some things to look for, that might help me figure it out, even if you can't pinpoint the solution. I understand this is a lot of code. This is an enterprise app with a lot of hands working on it.
MY SCRIPT SECTION OF DOCUMENT
// bind listeners to time input fields
$('.timeBlock').on("blur", validateHrs);
$('.timeBlock').keyup(function () {
var listObj = new LayoutObj();
listObj.tabNav();
});
// bind listeners to prev/next buttons
$('.previous, .next').on("click", function () {
var str = $(this).attr('class');
var obj = new LayoutObj();
obj.navDates(str);
});
// calculate totals for stored inputs
totalHrs();
// highlight today's date
var today = new Date();
var thisMonth = today.getMonth();
var thisDate = today.getDate();
var dateStr = '';
var splitDates = new Array();
var fullDates = new Array();
var listIndex;
var listObj;
fullDates = $('.dateNum');
fullDates.each(function (index) {
splitDates[index] = $(this).text().split('/');
});
for (var i = 0; i < splitDates.length; i++) {
if (thisMonth === (parseInt(splitDates[i][0], 10) - 1) && thisDate === parseInt(splitDates[i][1], 10)) {
thisMonth += 1;
thisMonth += '';
thisDate += '';
if (thisMonth.length < 2) {
dateStr = "0" + thisMonth + "/";
}
else {
dateStr = thisMonth + "/";
}
if (thisDate.length < 2) {
dateStr += "0" + thisDate;
}
else {
dateStr += thisDate;
}
fullDates[i].parentNode.setAttribute('class', 'date today');
listIndex = i;
}
//The following code will shift the job lists to reveal today's date ///////, if it is not in the view on load.
}
var listObj = new LayoutObj();
listObj.listOffset = listObj.cellWidth * (listIndex + 1);
//alert(listObj.listOffset);
listObj.allLists.offset({ left: listObj.listOffset });
listObj.allLists[listIndex].focus();
});
LayoutObj