From d26f2b44bd11d57e58924d338fcc1379b4a94007 Mon Sep 17 00:00:00 2001 From: Marko Strukelj Date: Tue, 28 Mar 2017 18:04:22 +0200 Subject: [PATCH] KEYCLOAK-4496 Strange truncation of Client information when creating a new client - Added polyfill from https://github.com/tbosch/autofill-event --- .../main/resources/theme/base/admin/index.ftl | 1 + .../autofill-event/autofill-event-1.0.0.js | 117 ++++++++++++++++++ 2 files changed, 118 insertions(+) create mode 100644 themes/src/main/resources/theme/keycloak/common/resources/lib/autofill-event/autofill-event-1.0.0.js diff --git a/themes/src/main/resources/theme/base/admin/index.ftl b/themes/src/main/resources/theme/base/admin/index.ftl index a845f148e7..82150bc40d 100755 --- a/themes/src/main/resources/theme/base/admin/index.ftl +++ b/themes/src/main/resources/theme/base/admin/index.ftl @@ -39,6 +39,7 @@ + diff --git a/themes/src/main/resources/theme/keycloak/common/resources/lib/autofill-event/autofill-event-1.0.0.js b/themes/src/main/resources/theme/keycloak/common/resources/lib/autofill-event/autofill-event-1.0.0.js new file mode 100644 index 0000000000..7013c6d9ff --- /dev/null +++ b/themes/src/main/resources/theme/keycloak/common/resources/lib/autofill-event/autofill-event-1.0.0.js @@ -0,0 +1,117 @@ +/** + * Autofill event polyfill ##version:1.0.0## + * (c) 2014 Google, Inc. + * License: MIT + */ +(function(window) { + var $ = window.jQuery || window.angular.element; + var rootElement = window.document.documentElement, + $rootElement = $(rootElement); + + addGlobalEventListener('change', markValue); + addValueChangeByJsListener(markValue); + + $.prototype.checkAndTriggerAutoFillEvent = jqCheckAndTriggerAutoFillEvent; + + // Need to use blur and not change event + // as Chrome does not fire change events in all cases an input is changed + // (e.g. when starting to type and then finish the input by auto filling a username) + addGlobalEventListener('blur', function(target) { + // setTimeout needed for Chrome as it fills other + // form fields a little later... + window.setTimeout(function() { + findParentForm(target).find('input').checkAndTriggerAutoFillEvent(); + }, 20); + }); + + window.document.addEventListener('DOMContentLoaded', function() { + // The timeout is needed for Chrome as it auto fills + // login forms some time after DOMContentLoaded! + window.setTimeout(function() { + $rootElement.find('input').checkAndTriggerAutoFillEvent(); + }, 200); + }, false); + + return; + + // ---------- + + function jqCheckAndTriggerAutoFillEvent() { + var i, el; + for (i=0; i 0) { + forEach(this, function(el) { + listener(el, newValue); + }); + } + return res; + } + } + + function addGlobalEventListener(eventName, listener) { + // Use a capturing event listener so that + // we also get the event when it's stopped! + // Also, the blur event does not bubble. + rootElement.addEventListener(eventName, onEvent, true); + + function onEvent(event) { + var target = event.target; + listener(target); + } + } + + function findParentForm(el) { + while (el) { + if (el.nodeName === 'FORM') { + return $(el); + } + el = el.parentNode; + } + return $(); + } + + function forEach(arr, listener) { + if (arr.forEach) { + return arr.forEach(listener); + } + var i; + for (i=0; i