Drupal investigation

escapeAdmin.js 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /**
  2. * @file
  3. * Replaces the home link in toolbar with a back to site link.
  4. */
  5. (function ($, Drupal, drupalSettings) {
  6. 'use strict';
  7. var pathInfo = drupalSettings.path;
  8. var escapeAdminPath = sessionStorage.getItem('escapeAdminPath');
  9. var windowLocation = window.location;
  10. // Saves the last non-administrative page in the browser to be able to link
  11. // back to it when browsing administrative pages. If there is a destination
  12. // parameter there is not need to save the current path because the page is
  13. // loaded within an existing "workflow".
  14. if (!pathInfo.currentPathIsAdmin && !/destination=/.test(windowLocation.search)) {
  15. sessionStorage.setItem('escapeAdminPath', windowLocation);
  16. }
  17. /**
  18. * Replaces the "Home" link with "Back to site" link.
  19. *
  20. * Back to site link points to the last non-administrative page the user
  21. * visited within the same browser tab.
  22. *
  23. * @type {Drupal~behavior}
  24. *
  25. * @prop {Drupal~behaviorAttach} attach
  26. * Attaches the replacement functionality to the toolbar-escape-admin element.
  27. */
  28. Drupal.behaviors.escapeAdmin = {
  29. attach: function () {
  30. var $toolbarEscape = $('[data-toolbar-escape-admin]').once('escapeAdmin');
  31. if ($toolbarEscape.length && pathInfo.currentPathIsAdmin) {
  32. if (escapeAdminPath !== null) {
  33. $toolbarEscape.attr('href', escapeAdminPath);
  34. }
  35. else {
  36. $toolbarEscape.text(Drupal.t('Home'));
  37. }
  38. $toolbarEscape.closest('.toolbar-tab').removeClass('hidden');
  39. }
  40. }
  41. };
  42. })(jQuery, Drupal, drupalSettings);