var Login = function () { var handleLogin = function() { $('.login-form').validate({ errorElement: 'span', //default input error message container errorClass: 'help-block', // default input error message class focusInvalid: false, // do not focus the last invalid input rules: { email: { required: true }, pwd: { required: true } }, messages: { email: { required: "Inserisci il nome utente" }, pwd: { required: "Inserisci la password" } }, invalidHandler: function (event, validator) { //display error alert on form submit $('.alert-error', $('.login-form')).show(); }, highlight: function (element) { // hightlight error inputs $(element) .closest('.form-group').addClass('has-error'); // set error class to the control group }, success: function (label) { label.closest('.form-group').removeClass('has-error'); label.remove(); }, errorPlacement: function (error, element) { error.insertAfter(element.closest('.input-icon')); }, submitHandler: function (form) { form.submit(); } }); $('.login-form input').keypress(function (e) { if (e.which == 13) { if ($('.login-form').validate().form()) { $('.login-form').submit(); } return false; } }); } var handleForgetPassword = function () { $('.forget-form').validate({ errorElement: 'span', //default input error message container errorClass: 'help-block', // default input error message class focusInvalid: false, // do not focus the last invalid input ignore: "", rules: { email: { required: true, email: true } }, messages: { email: { required: "Scrivi l'indirizzo email" } }, invalidHandler: function (event, validator) { //display error alert on form submit }, highlight: function (element) { // hightlight error inputs $(element) .closest('.form-group').addClass('has-error'); // set error class to the control group }, success: function (label) { label.closest('.form-group').removeClass('has-error'); label.remove(); }, errorPlacement: function (error, element) { error.insertAfter(element.closest('.input-icon')); }, submitHandler: function (form) { form.submit(); } }); $('.forget-form input').keypress(function (e) { if (e.which == 13) { if ($('.forget-form').validate().form()) { $('.forget-form').submit(); } return false; } }); jQuery('#forget-password').click(function () { jQuery('.login-form').hide(); jQuery('.forget-form').show(); }); jQuery('#back-btn').click(function () { jQuery('.login-form').show(); jQuery('.forget-form').hide(); }); } return { //main function to initiate the module init: function () { handleLogin(); handleForgetPassword(); $.backstretch([ "assets/img/bg/1.jpg", "assets/img/bg/2.jpg", "assets/img/bg/3.jpg", "assets/img/bg/4.jpg" ], { fade: 1000, duration: 8000 }); } }; }();