From 3751379f1e9a4c215fb6eb898b4ccc67659b9ace Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Tue, 10 May 2022 21:51:50 +0700 Subject: initial commit 2 --- addons/website/static/src/js/show_password.js | 48 +++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 addons/website/static/src/js/show_password.js (limited to 'addons/website/static/src/js/show_password.js') 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; + +}); -- cgit v1.2.3