-
Notifications
You must be signed in to change notification settings - Fork 47
/
persistent_login.js
89 lines (82 loc) · 2.81 KB
/
persistent_login.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/**
* Plugin which provides a persistent login functionality.
* Also known as "remembery me" or "stay logged in" function.
*
* The rendererd form needs to provide at least:
* - <input type="checkbox" name="_ifpl" id="_ifpl" value="1">
*
* @version @package_version@
* @author insaneFactory, Manuel Freiholz
* @website http://manuel.insanefactory.com/
* @requires Client side: ECMAScript 6 (ES6)
*/
$(document).ready(function () {
if (window.rcmail) {
rcmail.addEventListener('init', function () {
var html = '';
var parentElementSelector = 'form';
var skin = window.rcmail.env.skin;
// Insert different HTML for different skins.
if (skin == 'classic' || skin == 'larry') {
parentElementSelector = '#login-form form table tbody';
html = `
<tr>
<td class="title">` + rcmail.gettext('ifpl_rememberme', 'persistent_login') + `</td>
<td><input type="checkbox" id="_ifpl" name="_ifpl" value="1"></td>
</tr>
<tr id="ifpl-hint" style="display: none;">
<td></td>
<td class="ifpl-hint" style="padding: 5px;">` + rcmail.gettext('ifpl_rememberme_hint', 'persistent_login') + `</td>
</tr>
`;
}
else if (skin == 'elastic') {
parentElementSelector = '#login-form table tbody';
html = `
<tr class="form-group row">
<td class="title" style="display: none;">
<label for="rcmloginuser">Username</label>
</td>
<td class="input input-group input-group-lg">
<div class="custom-control custom-switch">
<input type="checkbox" class="custom-control-input" id="_ifpl" name="_ifpl" value="1">
<label class="custom-control-label" for="_ifpl">` + rcmail.gettext('ifpl_rememberme', 'persistent_login') + `</label>
</div>
</td>
</tr>
<tr id="ifpl-hint" class="form-group row" style="display: none;">
<td class="ifpl-hint" colspan="2">` + rcmail.gettext('ifpl_rememberme_hint', 'persistent_login') + `</td>
</tr>
`;
}
// The default HTML content, for all unknown skins.
else {
html = `
<div id="ifplcontainer">
<input id="_ifpl" name="_ifpl" type="checkbox" value="1">
<label for="_ifpl" style="display: inline-block;">` + rcmail.gettext('ifpl_rememberme', 'persistent_login') + `</label>
<p id="ifpl-hint" class="ifpl-hint" style="display: none;">` + rcmail.gettext('ifpl_rememberme_hint', 'persistent_login') + `</p>
</div>
`;
}
// apppend "html" with checkbox to document.
var element = $(parentElementSelector);
if (element && element.length !== 0) {
element.append(html);
}
else {
$('form').append(html);
}
// show hint.
$('#_ifpl').click(function () {
var t = $(this);
if (t.is(':checked')) {
$('#ifpl-hint').show();
}
else {
$('#ifpl-hint').hide();
}
});
});
} // if (window.rcmail)
});