1/* 2 * SimpleModal Login 3 * Theme: default 4 * Copyright 2014 Studio Fuel (http://www.studiofuel.com) 5 */ 6jQuery(function ($) { 7 var SimpleModalLogin = { 8 init: function () { 9 var s = this; 10 s.error = []; 11 12 $('.simplemodal-login, .simplemodal-register, .simplemodal-forgotpw').live('click.simplemodal-login', function (e) { 13 s.login = $('#loginform'), 14 s.lostpw = $('#lostpasswordform'), 15 s.register = $('#registerform'); 16 17 if ($(this).hasClass('simplemodal-login')) { 18 s.form = '#loginform'; 19 s.login.show(); s.lostpw.hide(); s.register.hide(); 20 } 21 else if ($(this).hasClass('simplemodal-register')) { 22 s.form = '#registerform'; 23 s.register.show(); s.login.hide(); s.lostpw.hide(); 24 } 25 else { 26 s.form = '#lostpasswordform'; 27 s.lostpw.show(); s.login.hide(); s.register.hide(); 28 } 29 s.url = this.href; 30 31 if (!$('#simplemodal-login-container').length) { 32 $('#simplemodal-login-form').modal({ 33 overlayId: 'simplemodal-login-overlay', 34 containerId: 'simplemodal-login-container', 35 opacity:85, 36 onShow: SimpleModalLogin.show, 37 position: ['15%', null], 38 zIndex:10000 39 }); 40 } 41 else { 42 SimpleModalLogin.show(); 43 } 44 return false; 45 }); 46 47 if (SimpleModalLoginL10n['shortcut'] === "true") { 48 $(document).bind('keydown.simplemodal-login', SimpleModalLogin.keydown); 49 } 50 }, 51 show: function (obj) { 52 var s = SimpleModalLogin; 53 s.dialog = obj || s.dialog; 54 s.modal = s.modal || this; 55 var form = $(s.form, s.dialog.data[0]), 56 fields = $('.simplemodal-login-fields', form[0]), 57 activity = $('.simplemodal-login-activity', form[0]); 58 59 // update and focus dialog 60 s.dialog.container.css({height:'auto'}); 61 62 // remove any existing errors or messages 63 s.clear(s.dialog.container[0]); 64 65 form.unbind('submit.simplemodal-login').bind('submit.simplemodal-login', function (e) { 66 e.preventDefault(); 67 68 // remove any existing errors or messages 69 s.clear(s.dialog.container[0]); 70 71 if (s.isValid(form)) { 72 fields.hide(); activity.show(); 73 74 if (s.url && s.url.indexOf('redirect_to') !== -1) { 75 var p = s.url.split('='); 76 form.append($('<input type="hidden" name="redirect_to">').val(unescape(p[1]))); 77 } 78 79 $.ajax({ 80 url: form[0].action, 81 data: form.serialize(), 82 type: 'POST', 83 cache: false, 84 success: function (resp) { 85 var data = $(document.createElement('div')).html(resp), 86 redirect = $('#simplemodal-login-redirect', data[0]); 87 88 if (redirect.length) { 89 var href = location.href; 90 if (redirect.html().length) { 91 href = redirect.html(); 92 } 93 window.location = href; 94 } 95 else { 96 var error = $('#login_error', data[0]), 97 message = $('.message', data[0]), 98 loginform = $(s.form, data[0]); 99 100 if (error.length) { 101 error.find('a').addClass('simplemodal-forgotpw'); 102 $('p:first', form[0]).before(error); 103 activity.hide(); fields.show(); 104 } 105 else if (message.length) { 106 if (s.form === '#lostpasswordform' || s.form === '#registerform') { 107 form = s.login; 108 s.lostpw.hide(); s.register.hide(); 109 s.login.show(); 110 } 111 $('p:first', form[0]).before(message); 112 activity.hide(); fields.show(); 113 } 114 else if (loginform.length) { 115 s.showError(form, ['empty_all']); 116 activity.hide(); fields.show(); 117 } 118 } 119 }, 120 error: function (xhr) { 121 $('p:first', form[0]).before( 122 $(document.createElement('div')) 123 .html('<strong>ERROR</strong>: ' + xhr.statusText) 124 .attr('id', 'login_error') 125 ); 126 activity.hide(); fields.show(); 127 } 128 }); 129 } 130 else { 131 s.showError(form, s.error); 132 } 133 }); 134 }, 135 /* utility functions */ 136 clear: function (context) { 137 $('#login_error, .message', context).remove(); 138 }, 139 isValid: function (form) { 140 var log = $('.user_login', form[0]), 141 pass = $('.user_pass', form[0]), 142 email = $('.user_email', form[0]), 143 fields = $(':text, :password', form[0]), 144 valid = true; 145 146 SimpleModalLogin.error = []; 147 148 if (log.length && !$.trim(log.val())) { 149 SimpleModalLogin.error.push('empty_username'); 150 valid = false;
151 } 152 else if (pass.length && !$.trim(pass.val())) { 153 SimpleModalLogin.error.push('empty_password'); 154 valid = false; 155 } 156 else if (email.length && !$.trim(email.val())) { 157 SimpleModalLogin.error.push('empty_email'); 158 valid = false; 159 } 160 161 var empty_count = 0; 162 fields.each(function () { 163 if (!$.trim(this.value)) { 164 empty_count++; 165 } 166 }); 167 if (fields.length > 1 && empty_count === fields.length) { 168 SimpleModalLogin.error = ['empty_all']; 169 valid = false; 170 } 171 172 return valid; 173 }, 174 keydown: function (e) { 175 if (e.altKey && e.ctrlKey && e.keyCode === 76) { 176 if (SimpleModalLoginL10n['logged_in'] === "true") { 177 window.location = SimpleModalLoginL10n['admin_url']; 178 } 179 else { 180 $('.simplemodal-login').trigger('click.simplemodal-login'); 181 } 182 } 183 }, 184 message: function (key) { 185 return SimpleModalLoginL10n[key] ? 186 SimpleModalLoginL10n[key].replace(/>/g, '>').replace(/</g, '<') : 187 key; 188 }, 189 showError: function (form, keys) { 190 keys = $.map(keys, function (key) { 191 return SimpleModalLogin.message(key); 192 }); 193 $('p:first', form[0]) 194 .before($('<div id="login_error"></div>').html( 195 keys.join('<br/>') 196 )); 197 } 198 }; 199 200 SimpleModalLogin.init(); 201});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.