//MAIN FUNCTIONS AND GOOGLE
if (!navigator.cookieEnabled)
{ window.location = "http://www.constructionmonkey.com/utility/NoCookies.aspx"; }
else
{
document.cookie = "js=1; path=/";
}
//ERROR LOGGING
$.ajaxSetup({
beforeSend: function (xhr, settings) {
xhr.data = settings.data;
xhr.url = settings.url;
},
error: function (xhr, status, error) {
if (xhr.status == 0 || xhr.status == 500) {
var msg = 'Ajax Error
';
msg += 'Webservice called: ' + xhr.url + '
';
msg += 'Webservice data: ' + xhr.data + '
';
msg += 'Error: ' + xhr.statusText;
errorHandler(msg, window.location.href, 'ajax');
}
}
});
window.onerror = function (msg, file, line, col, error) {
// var message = 'Message: ' + msg + '
';
// message += 'Line Number: ' + line;
// errorHandler(message, file, 'javascript');
var callback = function (stackframes) {
var stringifiedStack = stackframes.map(function (sf) {
return sf.toString();
}).join('\n');
errorHandler('msg: ' + msg + ' line: ' + line + ' col: ' + col + ' error: ' + error + ' file:' + file, file, 'javascript');
// alert('msg: ' + msg + ' line: ' + line + ' col: ' + col + ' error: ' + error + ' file:' + file);
};
StackTrace.get().then(callback);
}
function errorHandler(message, url, type) {
var arg = '{"message":"' + escape(message) + '","url":"' + escape(url) + '","type":"' + type + '","userID":' + userID +'}';
$.ajax({
type: "POST",
url: "/webservices/WSError.asmx/LogScriptError",
data: arg,
async: true,
processData: false,
contentType: "application/json; charset=utf-8",
dataType: "json",
error: function (xhr, status, error) {
alert('Error:' + xhr.statusText);
}
});
return true;
}
//MENU
var ww = document.body.clientWidth, mmHTML = $('nav > ul > li:first-child > a:first-child').html();
$(function () {
$("nav > ul li a").each(function () {
if ($(this).next().length > 0) {
$(this).addClass("parent");
};
})
$("nav > ul li > span").each(function () {
if ($(this).next().length > 0) {
$(this).addClass("parent");
};
})
$(".toggleMenu").click(function (e) {
e.preventDefault();
$(this).toggleClass("active");
$("nav > ul").toggle();
});
adjustMenu();
// $('nav > *').removeClass('hover');
// $('nav > *').removeClass('active');
//Setup Forms
$('input').preventDoubleClick();
$('button').preventDoubleClick();
$('form input, form textarea, form select').not(':input[type=button], :input[type=submit], :input[type=reset]').preventEnter();
$('main').css('padding-bottom', $('footer').height() + 'px');
});
$(window).bind('resize orientationchange', function () {
ww = document.body.clientWidth;
adjustMenu();
});
function adjustMenu () {
if (ww <= 768) {
$('nav .right').removeClass('right');
$('nav > ul > li:first-child > a:first-child').html('Main Menu');
$(".toggleMenu").css("display", "block");
if (!$(".toggleMenu").hasClass("active")) {
$("nav > ul").hide();
} else {
$("nav > ul").show();
}
$("nav > ul li").unbind('mouseenter mouseleave');
$("nav > ul li a.parent").unbind('click').bind('click', function (e) {
if (!$(this).parent().hasClass('hover'))
{
// must be attached to anchor element to prevent bubbling
e.preventDefault();
$(this).parent("li").toggleClass("hover");
}
});
$("nav > ul li span.parent").unbind('click').bind('click', function (e) {
// must be attached to anchor element to prevent bubbling
e.preventDefault();
$(this).parent("li").toggleClass("hover");
});
}
else if (ww > 768) {
$('nav > ul > li:first-child > a:first-child').html(mmHTML);
$(".toggleMenu").css("display", "none");
$("nav > ul").show();
$("nav > ul li").removeClass("hover");
$("nav > ul li a").unbind('click');
$("nav > ul li span").unbind('click');
$("nav > ul li").unbind('mouseenter mouseleave').bind('mouseenter mouseleave', function () {
// must be attached to li so that mouseleave is not triggered when hover over submenu
$(this).toggleClass('hover');
});
}
}
jQuery.fn.preventDoubleClick = function () {
$(this).on('click', function (e) {
var $el = $(this);
if ($el.data('clicked')) {
// Previously clicked, stop actions
e.preventDefault();
e.stopPropagation();
} else {
// Mark to ignore next click
$el.data('clicked', true);
// Unmark after 1 second
window.setTimeout(function () {
$el.removeData('clicked');
}, 1000)
}
});
return this;
};
jQuery.fn.preventEnter = function () {
$(this).on('keypress', function (e) {
var keyCode = e.keyCode || e.which;
if (keyCode === 13) {
e.preventDefault();
var inputs = $(this).closest("form").find("input:visible, textarea:visible, select:visible");
var idx = inputs.index(this);
if (idx == inputs.length - 1) {
} else {
inputs[idx + 1].focus(); // handles submit buttons
}
return false;
}
});
return this;
};