diff --git a/.gitignore b/.gitignore index 861b5f712724f8e645fd9d72df1ea61077268458..1d06131cf38a82bea76ff07efda13499e0a6fb20 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,5 @@ # Ignore compiled files. source -js # Ignore directories images/images diff --git a/js/user-login-min.js b/js/user-login-min.js new file mode 100644 index 0000000000000000000000000000000000000000..5365d9382e7ef1134927a5113998f75603d68fba --- /dev/null +++ b/js/user-login-min.js @@ -0,0 +1 @@ +!function(l,i){i.behaviors.uwFdsuThemeRespUserLogin={attach:function(i,n){l("#edit-simplesamlphp-auth-login-link").length&&(l("#user-login-form").css("display","none"),l("#user-login-form").after('<button id="adfs-login-link" class="button--primary">Log in via ADFS</button> <button id="local-login-link" class="button--medium">Log in locally</button>'),l("#edit-submit").val("Log in locally"),l("#local-login-link").click(function(){l("#user-login-form").css("display","block"),l("#local-login-link").css("display","none"),l("#adfs-login-link").css("display","none"),l("#edit-name").focus()}),l("#adfs-login-link").click(function(){l("#edit-simplesamlphp-auth-login-link")[0].click()}))}}}(jQuery,Drupal); diff --git a/js/user-login.js b/js/user-login.js new file mode 100644 index 0000000000000000000000000000000000000000..c0f36da198dae9910c29099567cc49f3f022d698 --- /dev/null +++ b/js/user-login.js @@ -0,0 +1,28 @@ +(function ($, Drupal) { + Drupal.behaviors.uwFdsuThemeRespUserLogin = { + attach: function (context, settings) { + // Don't do anything if SimpleSAML isn't enabled. + if ($('#edit-simplesamlphp-auth-login-link').length) + { + // Hide the normal login form. + $('#user-login-form').css('display', 'none'); + // Add buttons (using JS because they don't work without JS) + $('#user-login-form').after('<button id="adfs-login-link" class="button--primary">Log in via ADFS</button> <button id="local-login-link" class="button--medium">Log in locally</button>'); + // Update the existing login form's link text. + $('#edit-submit').val('Log in locally'); + // If the local login link is clicked, show the normal login form and hide the buttons. + // Be nice to the user, and put focus on the name field so they can just start typing. + $('#local-login-link').click(function () { + $('#user-login-form').css('display', 'block'); + $('#local-login-link').css('display', 'none'); + $('#adfs-login-link').css('display', 'none'); + $('#edit-name').focus(); + }); + // If the ADFS login link is clicked, click on the original log in with ADFS link. + $('#adfs-login-link').click(function () { + $('#edit-simplesamlphp-auth-login-link')[0].click(); + }); + } + } + }; +})(jQuery, Drupal); diff --git a/uw_fdsu_theme_resp.libraries.yml b/uw_fdsu_theme_resp.libraries.yml index 15fa558a7d4f097a84c71c3ffa6da154d2681351..a93569a34bf72efac187c3790596b23e35af3737 100644 --- a/uw_fdsu_theme_resp.libraries.yml +++ b/uw_fdsu_theme_resp.libraries.yml @@ -21,3 +21,6 @@ uw_dashboards: css: theme: ../../modules/custom/uw_wcms_gesso/css/uw-dashboards.min.css: {} +user.login: + js: + js/user-login-min.js: {} diff --git a/uw_fdsu_theme_resp.theme b/uw_fdsu_theme_resp.theme index bbfca39ffdf629b14c492ef2c8653dcc590a0cef..2a553dcc6654879f0505b0d47c656e9b2bb1f086 100644 --- a/uw_fdsu_theme_resp.theme +++ b/uw_fdsu_theme_resp.theme @@ -36,6 +36,12 @@ function uw_fdsu_theme_resp_preprocess_html(&$variables) { $variables['uw_admin_page'] = \Drupal::service('uw_cfg_common.uw_analytics')->administrationPage(); _uw_fdsu_theme_resp_add_favicons($variables); + + // Add Javascript only on the user login page. + $route_name = \Drupal::routeMatch()->getRouteName(); + if ($route_name == 'user.login') { + $variables['#attached']['library'][] = 'uw_fdsu_theme_resp/user.login'; + } } /**