[bf47591] | 1 | (function($) { |
---|
| 2 | "use strict"; |
---|
| 3 | |
---|
| 4 | // Options for Message |
---|
| 5 | //---------------------------------------------- |
---|
| 6 | var options = { |
---|
| 7 | 'btn-loading': '<i class="fa fa-spinner fa-pulse"></i>', |
---|
| 8 | 'btn-success': '<i class="fa fa-check"></i>', |
---|
| 9 | 'btn-error': '<i class="fa fa-remove"></i>', |
---|
| 10 | 'msg-success': 'All Good! Redirecting...', |
---|
| 11 | 'msg-error': 'Wrong login credentials!', |
---|
| 12 | //'useAJAX': true, |
---|
| 13 | }; |
---|
| 14 | |
---|
| 15 | // Login Form |
---|
| 16 | //---------------------------------------------- |
---|
| 17 | // Validation |
---|
| 18 | $("#login-form").validate({ |
---|
| 19 | rules: { |
---|
| 20 | usuario: "required", |
---|
| 21 | contrasena: "required", |
---|
| 22 | captcha_1: "required", |
---|
| 23 | }, |
---|
| 24 | errorClass: "form-invalid" |
---|
| 25 | }); |
---|
| 26 | |
---|
| 27 | // Form Submission |
---|
| 28 | $("#login-form").submit(function() { |
---|
| 29 | remove_loading($(this)); |
---|
| 30 | |
---|
| 31 | if(options['useAJAX'] == true) |
---|
| 32 | { |
---|
| 33 | // Dummy AJAX request (Replace this with your AJAX code) |
---|
| 34 | // If you don't want to use AJAX, remove this |
---|
| 35 | dummy_submit_form($(this)); |
---|
| 36 | |
---|
| 37 | // Cancel the normal submission. |
---|
| 38 | // If you don't want to use AJAX, remove this |
---|
| 39 | return false; |
---|
| 40 | } |
---|
| 41 | }); |
---|
| 42 | |
---|
| 43 | // Register Form |
---|
| 44 | //---------------------------------------------- |
---|
| 45 | // Validation |
---|
| 46 | $("#register-form").validate({ |
---|
| 47 | rules: { |
---|
| 48 | reg_username: "required", |
---|
| 49 | reg_password: { |
---|
| 50 | required: true, |
---|
| 51 | minlength: 5 |
---|
| 52 | }, |
---|
| 53 | reg_password_confirm: { |
---|
| 54 | required: true, |
---|
| 55 | minlength: 5, |
---|
| 56 | equalTo: "#register-form [name=contrasena]" |
---|
| 57 | }, |
---|
| 58 | reg_email: { |
---|
| 59 | required: true, |
---|
| 60 | email: true |
---|
| 61 | }, |
---|
| 62 | reg_agree: "required", |
---|
| 63 | }, |
---|
| 64 | errorClass: "form-invalid", |
---|
| 65 | errorPlacement: function( label, element ) { |
---|
| 66 | if( element.attr( "type" ) === "checkbox" || element.attr( "type" ) === "radio" ) { |
---|
| 67 | element.parent().append( label ); // this would append the label after all your checkboxes/labels (so the error-label will be the last element in <div class="controls"> ) |
---|
| 68 | } |
---|
| 69 | else { |
---|
| 70 | label.insertAfter( element ); // standard behaviour |
---|
| 71 | } |
---|
| 72 | } |
---|
| 73 | }); |
---|
| 74 | |
---|
| 75 | // Form Submission |
---|
| 76 | $("#register-form").submit(function() { |
---|
| 77 | remove_loading($(this)); |
---|
| 78 | |
---|
| 79 | if(options['useAJAX'] == true) |
---|
| 80 | { |
---|
| 81 | // Dummy AJAX request (Replace this with your AJAX code) |
---|
| 82 | // If you don't want to use AJAX, remove this |
---|
| 83 | dummy_submit_form($(this)); |
---|
| 84 | |
---|
| 85 | // Cancel the normal submission. |
---|
| 86 | // If you don't want to use AJAX, remove this |
---|
| 87 | return false; |
---|
| 88 | } |
---|
| 89 | }); |
---|
| 90 | |
---|
| 91 | // Forgot Password Form |
---|
| 92 | //---------------------------------------------- |
---|
| 93 | // Validation |
---|
| 94 | $("#forgot-password-form").validate({ |
---|
| 95 | rules: { |
---|
| 96 | fp_email: "required", |
---|
| 97 | }, |
---|
| 98 | errorClass: "form-invalid" |
---|
| 99 | }); |
---|
| 100 | |
---|
| 101 | // Form Submission |
---|
| 102 | $("#forgot-password-form").submit(function() { |
---|
| 103 | remove_loading($(this)); |
---|
| 104 | |
---|
| 105 | if(options['useAJAX'] == true) |
---|
| 106 | { |
---|
| 107 | // Dummy AJAX request (Replace this with your AJAX code) |
---|
| 108 | // If you don't want to use AJAX, remove this |
---|
| 109 | dummy_submit_form($(this)); |
---|
| 110 | |
---|
| 111 | // Cancel the normal submission. |
---|
| 112 | // If you don't want to use AJAX, remove this |
---|
| 113 | return false; |
---|
| 114 | } |
---|
| 115 | }); |
---|
| 116 | |
---|
| 117 | // Loading |
---|
| 118 | //---------------------------------------------- |
---|
| 119 | function remove_loading($form) |
---|
| 120 | { |
---|
| 121 | $form.find('[type=submit]').removeClass('error success'); |
---|
| 122 | $form.find('.login-form-main-message').removeClass('show error success').html(''); |
---|
| 123 | } |
---|
| 124 | |
---|
| 125 | function form_loading($form) |
---|
| 126 | { |
---|
| 127 | $form.find('[type=submit]').addClass('clicked').html(options['btn-loading']); |
---|
| 128 | } |
---|
| 129 | |
---|
| 130 | function form_success($form) |
---|
| 131 | { |
---|
| 132 | $form.find('[type=submit]').addClass('success').html(options['btn-success']); |
---|
| 133 | $form.find('.login-form-main-message').addClass('show success').html(options['msg-success']); |
---|
| 134 | } |
---|
| 135 | |
---|
| 136 | function form_failed($form) |
---|
| 137 | { |
---|
| 138 | $form.find('[type=submit]').addClass('error').html(options['btn-error']); |
---|
| 139 | $form.find('.login-form-main-message').addClass('show error').html(options['msg-error']); |
---|
| 140 | } |
---|
| 141 | |
---|
| 142 | // Dummy Submit Form (Remove this) |
---|
| 143 | //---------------------------------------------- |
---|
| 144 | // This is just a dummy form submission. You should use your AJAX function or remove this function if you are not using AJAX. |
---|
| 145 | function dummy_submit_form($form) |
---|
| 146 | { |
---|
| 147 | if($form.valid()) |
---|
| 148 | { |
---|
| 149 | form_loading($form); |
---|
| 150 | |
---|
| 151 | setTimeout(function() { |
---|
| 152 | form_success($form); |
---|
| 153 | }, 2000); |
---|
| 154 | } |
---|
| 155 | } |
---|
| 156 | |
---|
| 157 | })(jQuery); |
---|