diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
| commit | 3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch) | |
| tree | a44932296ef4a9b71d5f010906253d8c53727726 /addons/website/static/src/js/show_password.js | |
| parent | 0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff) | |
initial commit 2
Diffstat (limited to 'addons/website/static/src/js/show_password.js')
| -rw-r--r-- | addons/website/static/src/js/show_password.js | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/addons/website/static/src/js/show_password.js b/addons/website/static/src/js/show_password.js new file mode 100644 index 00000000..a27d1812 --- /dev/null +++ b/addons/website/static/src/js/show_password.js @@ -0,0 +1,48 @@ +// +// This file is meant to allow to switch the type of an input #password +// from password to text on mousedown on an input group. +// On mouse down, we see the password in clear text +// On mouse up, we hide it again. +// +odoo.define('website.show_password', function (require) { +'use strict'; + +var publicWidget = require('web.public.widget'); + +publicWidget.registry.ShowPassword = publicWidget.Widget.extend({ + selector: '#showPass', + events: { + 'mousedown': '_onShowText', + 'touchstart': '_onShowText', + }, + + /** + * @override + */ + destroy: function () { + this._super(...arguments); + $('body').off(".ShowPassword"); + }, + + //-------------------------------------------------------------------------- + // Handlers + //-------------------------------------------------------------------------- + + /** + * @private + */ + _onShowPassword: function () { + this.$el.closest('.input-group').find('#password').attr('type', 'password'); + }, + /** + * @private + */ + _onShowText: function () { + $('body').one('mouseup.ShowPassword touchend.ShowPassword', this._onShowPassword.bind(this)); + this.$el.closest('.input-group').find('#password').attr('type', 'text'); + }, +}); + +return publicWidget.registry.ShowPassword; + +}); |
