From f8397ebe12d6affa44ceeff40abad31d99678767 Mon Sep 17 00:00:00 2001 From: Piyush Dankhara Date: Tue, 5 Jun 2018 21:28:41 -0700 Subject: [PATCH 1/3] [Backport] Trim username on customer account login page --- .../view/frontend/templates/form/login.phtml | 11 ++++ .../view/frontend/web/js/trim-username.js | 65 +++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 app/code/Magento/Customer/view/frontend/web/js/trim-username.js diff --git a/app/code/Magento/Customer/view/frontend/templates/form/login.phtml b/app/code/Magento/Customer/view/frontend/templates/form/login.phtml index 8e7494a417e34..f862bc08607e6 100644 --- a/app/code/Magento/Customer/view/frontend/templates/form/login.phtml +++ b/app/code/Magento/Customer/view/frontend/templates/form/login.phtml @@ -50,3 +50,14 @@ + + + diff --git a/app/code/Magento/Customer/view/frontend/web/js/trim-username.js b/app/code/Magento/Customer/view/frontend/web/js/trim-username.js new file mode 100644 index 0000000000000..69f89cb8fe01f --- /dev/null +++ b/app/code/Magento/Customer/view/frontend/web/js/trim-username.js @@ -0,0 +1,65 @@ +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +define([ + 'jquery' +], function ($) { + 'use strict'; + + $.widget('mage.trimUsername', { + options: { + cache: {}, + formSelector: 'form', + emailSelector: 'input[type="email"]' + }, + + /** + * Widget initialization + * @private + */ + _create: function () { + // We need to look outside the module for backward compatibility, since someone can already use the module. + // @todo Narrow this selector in 2.3 so it doesn't accidentally finds the the email field from the + // newsletter email field or any other "email" field. + this.options.cache.email = $(this.options.formSelector).find(this.options.emailSelector); + this._bind(); + }, + + /** + * Event binding, will monitor change, keyup and paste events. + * @private + */ + _bind: function () { + if (this.options.cache.email.length) { + this._on(this.options.cache.email, { + 'change': this._trimUsername, + 'keyup': this._trimUsername, + 'paste': this._trimUsername + }); + } + }, + + /** + * Trim username + * @private + */ + _trimUsername: function () { + var username = this._getUsername().trim(); + + this.options.cache.email.val(username); + }, + + /** + * Get username value + * @returns {*} + * @private + */ + _getUsername: function () { + return this.options.cache.email.val(); + } + }); + + return $.mage.trimUsername; +}); From 43835fc4ae4cb1322d90bda02ba2726359171cf6 Mon Sep 17 00:00:00 2001 From: Piyush Dankhara Date: Wed, 6 Jun 2018 13:32:39 +0530 Subject: [PATCH 2/3] Remove blank line at eof --- .../Magento/Customer/view/frontend/templates/form/login.phtml | 1 - 1 file changed, 1 deletion(-) diff --git a/app/code/Magento/Customer/view/frontend/templates/form/login.phtml b/app/code/Magento/Customer/view/frontend/templates/form/login.phtml index f862bc08607e6..241ab1451238a 100644 --- a/app/code/Magento/Customer/view/frontend/templates/form/login.phtml +++ b/app/code/Magento/Customer/view/frontend/templates/form/login.phtml @@ -60,4 +60,3 @@ } } - From 14721c7d9bdb228988f8edc9efdaba9f0c241f8b Mon Sep 17 00:00:00 2001 From: Piyush Dankhara Date: Wed, 6 Jun 2018 13:51:37 +0530 Subject: [PATCH 3/3] Update comment in trim-username.js --- app/code/Magento/Customer/view/frontend/web/js/trim-username.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Customer/view/frontend/web/js/trim-username.js b/app/code/Magento/Customer/view/frontend/web/js/trim-username.js index 69f89cb8fe01f..1b6aab6086853 100644 --- a/app/code/Magento/Customer/view/frontend/web/js/trim-username.js +++ b/app/code/Magento/Customer/view/frontend/web/js/trim-username.js @@ -21,7 +21,7 @@ define([ */ _create: function () { // We need to look outside the module for backward compatibility, since someone can already use the module. - // @todo Narrow this selector in 2.3 so it doesn't accidentally finds the the email field from the + // @todo Narrow this selector in 2.3 so it doesn't accidentally finds the email field from the // newsletter email field or any other "email" field. this.options.cache.email = $(this.options.formSelector).find(this.options.emailSelector); this._bind();