text.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /**
  2. * DO NOT EDIT THIS FILE.
  3. * See the following change record for more information,
  4. * https://www.drupal.org/node/2815083
  5. * @preserve
  6. **/
  7. (function ($, Drupal) {
  8. Drupal.behaviors.textSummary = {
  9. attach: function attach(context, settings) {
  10. $(context).find('.js-text-summary').once('text-summary').each(function () {
  11. var $widget = $(this).closest('.js-text-format-wrapper');
  12. var $summary = $widget.find('.js-text-summary-wrapper');
  13. var $summaryLabel = $summary.find('label').eq(0);
  14. var $full = $widget.children('.js-form-type-textarea');
  15. var $fullLabel = $full.find('label').eq(0);
  16. if ($fullLabel.length === 0) {
  17. $fullLabel = $('<label></label>').prependTo($full);
  18. }
  19. var $link = $('<span class="field-edit-link"> (<button type="button" class="link link-edit-summary">' + Drupal.t('Hide summary') + '</button>)</span>');
  20. var $button = $link.find('button');
  21. var toggleClick = true;
  22. $link.on('click', function (e) {
  23. if (toggleClick) {
  24. $summary.hide();
  25. $button.html(Drupal.t('Edit summary'));
  26. $link.appendTo($fullLabel);
  27. } else {
  28. $summary.show();
  29. $button.html(Drupal.t('Hide summary'));
  30. $link.appendTo($summaryLabel);
  31. }
  32. e.preventDefault();
  33. toggleClick = !toggleClick;
  34. }).appendTo($summaryLabel);
  35. if ($widget.find('.js-text-summary').val() === '') {
  36. $link.trigger('click');
  37. }
  38. });
  39. }
  40. };
  41. })(jQuery, Drupal);