openid.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. (function ($) {
  2. Drupal.behaviors.openid = {
  3. attach: function (context) {
  4. var loginElements = $('.form-item-name, .form-item-pass, li.openid-link');
  5. var openidElements = $('.form-item-openid-identifier, li.user-link');
  6. var cookie = $.cookie('Drupal.visitor.openid_identifier');
  7. // This behavior attaches by ID, so is only valid once on a page.
  8. if (!$('#edit-openid-identifier.openid-processed').length) {
  9. if (cookie) {
  10. $('#edit-openid-identifier').val(cookie);
  11. }
  12. if ($('#edit-openid-identifier').val() || location.hash == '#openid-login') {
  13. $('#edit-openid-identifier').addClass('openid-processed');
  14. loginElements.hide();
  15. // Use .css('display', 'block') instead of .show() to be Konqueror friendly.
  16. openidElements.css('display', 'block');
  17. }
  18. }
  19. $('li.openid-link:not(.openid-processed)', context)
  20. .addClass('openid-processed')
  21. .click(function () {
  22. loginElements.hide();
  23. openidElements.css('display', 'block');
  24. // Remove possible error message.
  25. $('#edit-name, #edit-pass').removeClass('error');
  26. $('div.messages.error').hide();
  27. // Set focus on OpenID Identifier field.
  28. $('#edit-openid-identifier')[0].focus();
  29. return false;
  30. });
  31. $('li.user-link:not(.openid-processed)', context)
  32. .addClass('openid-processed')
  33. .click(function () {
  34. openidElements.hide();
  35. loginElements.css('display', 'block');
  36. // Clear OpenID Identifier field and remove possible error message.
  37. $('#edit-openid-identifier').val('').removeClass('error');
  38. $('div.messages.error').css('display', 'block');
  39. // Set focus on username field.
  40. $('#edit-name')[0].focus();
  41. return false;
  42. });
  43. }
  44. };
  45. })(jQuery);