diff --git a/css/diff.general.css b/css/diff.general.css index 87942ee..dd2e2c2 100644 --- a/css/diff.general.css +++ b/css/diff.general.css @@ -47,7 +47,13 @@ .diff-revision__item { display: table-cell; padding: 0.3em 1em; - white-space: nowrap; +} +.diff-revision__item__content.show-less { + height: 1.538em; + overflow-y: hidden; +} +.diff-revision__item__content.show-more { + height: auto; } @media screen and (min-width: 920px) { @@ -66,6 +72,12 @@ .diff-revision { width: 75%; } + .diff-revision__item { + white-space: nowrap; + } + .diff-revision__item-message { + white-space: normal; + } .diff-navigation__link.next-link { float: left; diff --git a/diff.libraries.yml b/diff.libraries.yml index b12374a..867d695 100644 --- a/diff.libraries.yml +++ b/diff.libraries.yml @@ -5,6 +5,8 @@ diff.general: css/diff.general.css: {} js: js/diff.js: {} + dependencies: + - core/jquery.once diff.double_column: version: 1.x diff --git a/js/diff.js b/js/diff.js index 0ed2a55..c4aa950 100644 --- a/js/diff.js +++ b/js/diff.js @@ -63,4 +63,41 @@ } }; + /** + * For revision messages that are bigger then one line add more/less UI logic. + * + * @type {Drupal~behavior} + */ + Drupal.behaviors.diffRevisionMessages = { + attach: function (context, settings) { + $('.diff-revision__item-message', context).once('diff-message').each(function () { + var $this = $(this); + var $thisMsg = $this.find('.diff-revision__item__content'); + var height = $thisMsg.height(); + // For line height we are getting px value so we need to convert to int. + var lineHeight = parseInt($thisMsg.css('lineHeight'), 10); + + // If height is bigger then line height for revision message then we + // have vertical overflow and we will apply more/less UI logic. + if (height > lineHeight) { + $thisMsg.addClass('show-less'); + + // Create a more/less link. + var $link = $('' + Drupal.t('more') + ''); + $link.click(function () { + if ($thisMsg.hasClass('show-less')) { + $thisMsg.removeClass('show-less'); + $link.text(Drupal.t('less')); + } + else { + $thisMsg.addClass('show-less'); + $link.text(Drupal.t('more')); + } + }); + $link.insertAfter($thisMsg); + } + }); + } + }; + })(jQuery, Drupal, drupalSettings); diff --git a/src/DiffLayoutBase.php b/src/DiffLayoutBase.php index e27cd1c..14785d2 100644 --- a/src/DiffLayoutBase.php +++ b/src/DiffLayoutBase.php @@ -203,8 +203,8 @@ abstract class DiffLayoutBase extends PluginBase implements DiffLayoutInterface, if ($revision_log) { $revision_link['message'] = [ '#type' => 'markup', - '#prefix' => '
', + '#prefix' => '', '#markup' => $revision_log, ]; }