var isChanged = false; $(function() { $(window).scroll(updateStickyFooter).trigger("scroll"); function updateStickyFooter() { if($('footer').length){ if($(document).scrollTop() + window.innerHeight < $('footer').offset().top){ $('.navbar').css('bottom', '0px'); }else{ $('.navbar').css('bottom', (window.innerHeight - ($('footer').offset().top - $(document).scrollTop()) )+'px'); } } } $('.panel-collapse').on('hidden.bs.collapse', function () { updateStickyFooter(); }); $('.panel-collapse').on('shown.bs.collapse', function () { updateStickyFooter(); }); $(':input').change(function() { isChanged = true; }); $(".infoTextIcon").click(function() { $('#infoText').slideToggle(300); $(".infoTextIcon").toggle(); }); $(".infoTextStyle").click(function() { $('#infoText').slideToggle(300); $(".infoTextIcon").toggle(); }); // Municipality picker $('.ui-chkbox-box').click(function() { isChanged = true; }); $.fn.focusNextInputField = function() { return this.each(function() { var fields = $(this).parents('form:eq(0),body').find('button,input,textarea,select:not([onchange])'); var index = fields.index( this ); if ( index > -1 && ( index + 1 ) < fields.length ) { fields.eq( index + 1 ).focus(); } return false; }); }; $.fn.focusPreviousInputField = function() { return this.each(function() { var fields = $(this).parents('form:eq(0),body').find('button,input,textarea,select:not([onchange])'); var index = fields.index( this ); if ( index > -1 && ( index + 1 ) < fields.length ) { fields.eq( index - 1 ).focus(); } return false; }); }; //hijack tabkey $(":input").on("keydown", function (event) { if(event.shiftKey && event.keyCode == 9) { event.preventDefault(); $(event.target).focusPreviousInputField(); } else if(event.keyCode == 9) { event.preventDefault(); $(event.target).focusNextInputField(); } }); }); //avoid undefined error on pages without primefaces.js if (typeof PrimeFaces === 'object') { // extend calendar close PrimeFaces.widget.Calendar.prototype.fireDateSelectEvent = (function(old) { function extendsFireDateSelectEvent() { old.apply(this, null); $(this.input.selector).focus(); } return extendsFireDateSelectEvent; })(PrimeFaces.widget.Calendar.prototype.fireDateSelectEvent); PrimeFaces.widget.SelectOneMenu.prototype.hide = (function(old) { function extendsHide() { old.apply(this, null); $(this.focusInput.selector).focus; } return extendsHide; })(PrimeFaces.widget.SelectOneMenu.prototype.hide); } function showSaveDialog(message) { if(isChanged) { return confirm(message); } else { return true; } } function showSaveDlgOrBlockUI(msg, loadMsg, opts) { if(!showSaveDialog(msg)){ return false; } blockUIWhileLoading(loadMsg, {fadeIn: 0}); } function setChanged(){ isChanged = true; } function resetChanged() { isChanged = false; } function resetAfterSave(data) { if (data.status === "success") { isChanged = false; } } function limitTextArea(element, limit, strMessage) { var newLineCount = (element.value.match(/\r\n|\n/g) || []).length; if ((element.value.length + newLineCount) > limit) { element.value = element.value.substring(0, limit - newLineCount); } } function textAreaCount(textField, target, maxLimit){ var newlineCount = (textField.value.match(/(\r\n|\n|\r)/g) || []).length; var fullCount = textField.value.length + newlineCount; document.getElementById(target).innerHTML = fullCount + " / " + maxLimit; } function blockUIWhileLoading(message, opts) { $.blockUI.defaults.baseZ = 2000; opts = typeof opts !== 'undefined' ? opts : {}; var htmlMessage = "
"+message+"
"; opts["message"] = htmlMessage; $.blockUI(opts); } var currentFocus = null; var currentValue1 = null; //ugly fix, consider refactor. currentValue1 and currentValue2 were introduced as a fix var currentValue2 = null; //for a bug that caused cursor issue when tabbing to next input field, that caused incorrect input. function setFocus(data) { if(data.status === "complete") { currentFocus = $(':focus').attr('id'); if (currentFocus !== undefined) { currentValue1 = $("#"+currentFocus.replace(/:/g,"\\:")).val(); } } if(data.status === "success") { if(currentFocus !== undefined) { currentValue2 = $("#"+currentFocus.replace(/:/g,"\\:")).val(); if(currentValue1 === currentValue2) { $("#"+currentFocus.replace(/:/g,"\\:")).select(); } else { $("#"+currentFocus.replace(/:/g,"\\:")).focus(); $("#"+currentFocus.replace(/:/g,"\\:")).val(''); $("#"+currentFocus.replace(/:/g,"\\:")).val(currentValue1); } } } } function refresh(data) { setFocus(data); } function hideNavBar() { $('.navbar-fixed-bottom').css("z-index","50"); } function showNavBar() { $('.navbar-fixed-bottom').css("z-index","1030"); }