Settings for truncate and add-ellipsis

Created on 5 April 2017, over 7 years ago
Updated 1 August 2023, over 1 year ago

My customer (and me too) like to see more than 30 characters in the "Menu link weight" box.
I took a look and noticed the 30 is hard wired in the calls to Unicode::truncate() (in menu_link_weight.module).
Also the add-ellipsis option of truncate() is hard wired to FALSE.

So I propose settings for both - see patch in #12.

(At the time of first posting there were no settings for menu_link_weight at all, so the first patches included the whole settings form.)

Feature request
Status

Needs review

Version

1.0

Component

User interface

Created by

🇩🇪Germany gngn

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇩🇪Germany gngn

    Trying to sort out the diffs between #19, #20, #21, #22

    • @JurgenR wrote in #20
      Patch #19 can't apply on 8.x-1.0-beta4.
      This is caused by changed line numbers, I've updated the patch to work against 8.x-1.0-beta4.

      But #20 differs from #19 by missing the following change in #19 in js/menu_link_weight.js:

               // Checking and unchecking the checkbox may also update the link title.
               $checkbox.on('change', function() {
                 if ($checkbox.is(':checked') && !$link_title.data('menuLinkAutomaticTitleOverridden')) {
                   if ($title.val() !== undefined) {
      -              $current_selection.html($title.val().substring(0, 30));
      +              $current_selection.html(Drupal.menu_truncate($title.val(), $truncate, $add_ellipsis));
                   }
                 }
               });

      So #20 drops the support for "Checking and unchecking the checkbox" (by keeping the hardcoded 30).

    • 8.x-1.0-beta5 added a check $title.val() !== undefined) to the same part:
      <             $current_selection.html($title.val().substring(0, 30));
      ---
      >             if ($title.val() !== undefined) {
      >               $current_selection.html($title.val().substring(0, 30));
      >             }

      This change made it into #21 (meant for 8.x-1.0-beta4):

               // Checking and unchecking the checkbox may also update the link title.
               $checkbox.on('change', function() {
                 if ($checkbox.is(':checked') && !$link_title.data('menuLinkAutomaticTitleOverridden')) {
      -            $current_selection.html($title.val().substring(0, 30));
      +            if ($title.val() !== undefined) {
      +              $current_selection.html($title.val().substring(0, 30));
      +            }
                 }
               });
             });

      which still keeps the hardcoded 30.

      #21 also changes the behavoiur of Drupal.menu_truncate - I think that is meant by

      ellipsis behaviour was not working as expected when dealing with long words
      • #19 and #20 had:
        +  Drupal.menu_truncate = function (title, max_length, add_ellipsis) {
        +    var truncated = jQuery.trim(title).substring(0, max_length);
        +    if (add_ellipsis) {
        +      // Thanx to
        +      // https://stackoverflow.com/questions/2248742/jquery-text-truncation-read-more-style/2249591#2249591
        +      truncated = truncated.split(" ") // separate characters into an array of words
        +        .slice(0, -1)  // remove the last full or partial wordc
        +        .join(" ") + "..."; // remove the last full or partial word
        +    }
        +    return truncated;
        +  }
      • #21 has:
        +  Drupal.menu_truncate = function (title, max_length, add_ellipsis) {
        +    var ellipsis = add_ellipsis ? "..." : "";
        +    return jQuery.trim(title).length > max_length ? title.slice(0, max_length) + ellipsis : title;
        +  };

      I did not test this change.

    • #22 is #21 applied to 8.x-1.0-beta5 (I think).
      Since 8.x-1.0-beta5 added the mentioned check $title.val() !== undefined) #22 does not include this change.

    So I think we should

    1. Reintroduce the mentioned use of Drupal.menu_truncate() (introduced in #19, dropped in #20, #21, #22).
    2. Decide wether ellipsis behaviour is better handled in #19 or in #21.
      @JurgenR can you name an example for ?

    Patch coming.

  • 🇧🇪Belgium jurgenr

    Updated patch against the latest rc1 release.

  • Open in Jenkins → Open on Drupal.org →
    Core: 10.0.7 + Environment: PHP 7.3 & MySQL 5.7
    last update over 1 year ago
    Composer error. Unable to continue.
  • 🇧🇪Belgium jurgenr

    Updated patch against the latest rc1 release.

Production build 0.71.5 2024