.rej 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. --- logintoboggan.permissions.js
  2. +++ logintoboggan.permissions.js
  3. @@ -1,77 +1,25 @@
  4. /**
  5. - * This is a custom implementation of user.permissions.js, which is necessary
  6. - * because LoginToboggan needs its pre-auth role to not be explicitly tied to
  7. - * the auth role. The change is minor -- simply exclude the pre-auth role from
  8. - * all the auto-checking as the anon and auth user roles are.
  9. + * LoginToboggan needs its pre-auth role to not be explicitly tied to
  10. + * the auth role.
  11. */
  12. -
  13. (function ($) {
  14. /**
  15. * Shows checked and disabled checkboxes for inherited permissions.
  16. */
  17. -Drupal.behaviors.permissions = {
  18. - attach: function (context) {
  19. - var self = this;
  20. - $('table#permissions').once('permissions', function () {
  21. - // On a site with many roles and permissions, this behavior initially has
  22. - // to perform thousands of DOM manipulations to inject checkboxes and hide
  23. - // them. By detaching the table from the DOM, all operations can be
  24. - // performed without triggering internal layout and re-rendering processes
  25. - // in the browser.
  26. - var $table = $(this);
  27. - if ($table.prev().length) {
  28. - var $ancestor = $table.prev(), method = 'after';
  29. - }
  30. - else {
  31. - var $ancestor = $table.parent(), method = 'append';
  32. - }
  33. - $table.detach();
  34. -
  35. - // Create dummy checkboxes. We use dummy checkboxes instead of reusing
  36. - // the existing checkboxes here because new checkboxes don't alter the
  37. - // submitted form. If we'd automatically check existing checkboxes, the
  38. - // permission table would be polluted with redundant entries. This
  39. - // is deliberate, but desirable when we automatically check them.
  40. - var $dummy = $('<input type="checkbox" class="dummy-checkbox" disabled="disabled" checked="checked" />')
  41. - .attr('title', Drupal.t("This permission is inherited from the authenticated user role."))
  42. - .hide();
  43. -
  44. - $('input[type=checkbox]', this).not('.rid-2, .rid-1, .rid-' + Drupal.settings.LoginToboggan.preAuthID).addClass('real-checkbox').each(function () {
  45. - $dummy.clone().insertAfter(this);
  46. +Drupal.behaviors.LoginTobogganPermissions = {
  47. + attach: function (context, settings) {
  48. + // Revert changes made by modules/user/user.permissions.js
  49. + $('table#permissions', context).once('tobogganPermissions', function () {
  50. + $('input[type=checkbox]', this).filter('.rid-' + settings.LoginToboggan.preAuthID).removeClass('real-checkbox').each(function () {
  51. + $(this).next().filter('.dummy-checkbox').remove();
  52. + $('input.rid-' + settings.LoginToboggan.preAuthID).each(function () {
  53. + this.style.display = '';
  54. + });
  55. });
  56. -
  57. - // Initialize the authenticated user checkbox.
  58. - $('input[type=checkbox].rid-2', this)
  59. - .bind('click.permissions', self.toggle)
  60. - // .triggerHandler() cannot be used here, as it only affects the first
  61. - // element.
  62. - .each(self.toggle);
  63. -
  64. - // Re-insert the table into the DOM.
  65. - $ancestor[method]($table);
  66. });
  67. },
  68. -
  69. - /**
  70. - * Toggles all dummy checkboxes based on the checkboxes' state.
  71. - *
  72. - * If the "authenticated user" checkbox is checked, the checked and disabled
  73. - * checkboxes are shown, the real checkboxes otherwise.
  74. - */
  75. - toggle: function () {
  76. - var authCheckbox = this, $row = $(this).closest('tr');
  77. - // jQuery performs too many layout calculations for .hide() and .show(),
  78. - // leading to a major page rendering lag on sites with many roles and
  79. - // permissions. Therefore, we toggle visibility directly.
  80. - $row.find('.real-checkbox').each(function () {
  81. - this.style.display = (authCheckbox.checked ? 'none' : '');
  82. - });
  83. - $row.find('.dummy-checkbox').each(function () {
  84. - this.style.display = (authCheckbox.checked ? '' : 'none');
  85. - });
  86. - }
  87. };
  88. })(jQuery);