Greetings
One of my clients javascript files is failing. I have found the reason, but the discovery has made me REALLY confused as I have never seen anything like it.
The issue is that when the browser reads through the script sources and enters a specific custom .js file which contains 543 lines of code, it only reads to line 502 which is this if (isValidWidthChange) {
but what confuses me is that when I use developer tool in IE and firebug in FireFox and uses their script debug tool, when it hits line 502, the javascript is cut off like so - if (isValidWidthChan
if (isValidWidthChange) {
if (isValidWidthChan
Can anyone give me a logic explanation on WHY this happens?
I can say so much that I was adding a few things to the file, but I took a back-up of the original before starting, and this is actually the error which keeps occuring even after I set the website to use the original file again.
I have tried IISRESET a lot of times. I have tried copying the file from a healthy environment. I have cleared all the caches in my browsers and on the server. Yet it still appears.
I didn't develop it myself, it's a third party product. But this has never happened before.
Codesnippet of where the error occurs
(function($) {
// jQuery autoGrowInput plugin by James Padolsey
// See related thread: http://stackoverflow.com/questions/931207/is-there-a-jquery-autogrow-plugin-for-text-fields
$.fn.autoGrowInput = function(o) {
o = $.extend({
maxWidth: 1000,
minWidth: 0,
comfortZone: 70
}, o);
this.filter('input:text').each(function() {
var minWidth = o.minWidth || $(this).width(),
val = '',
input = $(this),
testSubject = $('<tester/>').css({
position: 'absolute',
top: -9999,
left: -9999,
width: 'auto',
fontSize: input.css('fontSize'),
fontFamily: input.css('fontFamily'),
fontWeight: input.css('fontWeight'),
letterSpacing: input.css('letterSpacing'),
whiteSpace: 'nowrap'
}),
check = function() {
if (val === (val = input.val())) { return; }
// Enter new content into testSubject
var escaped = val.replace(/&/g, '&').replace(/\s/g, ' ').replace(/</g, '<').replace(/>/g, '>');
testSubject.html(escaped);
// Calculate new width + whether to change
var testerWidth = testSubject.width(),
newWidth = (testerWidth + o.comfortZone) >= minWidth ? testerWidth + o.comfortZone : minWidth,
currentWidth = input.width(),
isValidWidthChange = (newWidth < currentWidth && newWidth >= minWidth)
|| (newWidth > minWidth && newWidth < o.maxWidth);
// Animate width
if (isValidWidthChange) { // This is where it stops
input.width(newWidth);
}
};
testSubject.insertAfter(input);
$(this).bind('keyup keydown blur update', check);
});
return this;
};
})(jQuery);