0

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

4

2 回答 2

1

你应该使用:

$(document).ready(function () { ... });

当您说它在加载 DOM 之前触发时,在脚本中您已将整个代码放入文档就绪块中。这些代码中的任何一个都会影响大小吗?

你确定代码没有被破坏?例如,您可以拉出该块并将其绑定到单击事件。

于 2013-07-19T15:53:57.960 回答
0

问题是第三方脚本!!愚蠢的脚本!

于 2013-07-19T16:38:31.227 回答