[Bps-public-commit] rt-extension-announce branch, html-line-count-limit, created. 1.00-6-g715ec75

Craig Kaiser craig at bestpractical.com
Mon Sep 16 17:02:56 EDT 2019


The branch, html-line-count-limit has been created
        at  715ec751154fbafd215132e940b21e37dd17662f (commit)

- Log -----------------------------------------------------------------
commit 5741ee8dd6887a5e2e29baec3bb3341b2613184f
Author: Craig Kaiser <craig at bestpractical.com>
Date:   Wed Aug 28 09:56:03 2019 -0400

    Allow the number of lines displayed in the RT announce banner to be configured

diff --git a/META.yml b/META.yml
index 83d7405..0b65c8a 100644
--- a/META.yml
+++ b/META.yml
@@ -22,6 +22,7 @@ no_index:
     - static
     - xt
 requires:
+  Mojo::Dom: 0
   perl: 5.8.3
 resources:
   license: http://opensource.org/licenses/gpl-license.php
diff --git a/Makefile.PL b/Makefile.PL
index 52c7822..c4a6850 100644
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -2,6 +2,8 @@ use inc::Module::Install;
 
 RTx 'RT-Extension-Announce';
 
+requires 'Mojo::Dom';
+
 repository('https://github.com/bestpractical/rt-extension-announce');
 
 my ($lp) = ($INC{'RT.pm'} =~ /^(.*)[\\\/]/);
diff --git a/README b/README
index e7a409e..7eab172 100644
--- a/README
+++ b/README
@@ -117,6 +117,11 @@ CONFIGURATION
     If set to true, the banner content will be set to 'text/html' and allow
     HTML rendering.
 
+  $RTAnnounceLineCountLimit
+    Set the number of lines that should be displayed in the RT announce
+    banner, if the displayed lines exceed the line limit a scroll box
+    feature will be available.
+
 AUTHOR
     Best Practical Solutions, LLC <modules at bestpractical.com>
 
diff --git a/html/Callbacks/RT-Extension-Announce/Elements/PageLayout/BeforeBody b/html/Callbacks/RT-Extension-Announce/Elements/PageLayout/BeforeBody
index cfd3fee..ecc75fb 100644
--- a/html/Callbacks/RT-Extension-Announce/Elements/PageLayout/BeforeBody
+++ b/html/Callbacks/RT-Extension-Announce/Elements/PageLayout/BeforeBody
@@ -78,12 +78,69 @@
     $content =~ s/\s+$//g; # Remove trailing space
     $content .= chr(8230); # Ellipsis character
   }
+
+  use Mojo::Dom;
+  my $dom = Mojo::DOM->new( $content );
+
+  my @lines;
+  if ( $show_html ) {
+    for my $line ( $dom->find('*')->map('text')->each ) {
+      # We do not care about strings with only white space
+      next unless $line =~ /\S/;
+
+      # Find the HTML element matching our text, not just the text component
+      my $matches = $dom->find('*')->grep(sub { $_->all_text =~ /$line/ });
+      unless ( $matches->size ) {
+        RT::Logger->error("Could not find HTML component matching text content: $line");
+        next;
+      }
+      foreach my $match ( $matches->each ) {
+        # We do not want to grab any parent elements
+        next if $match->children->size;
+        push @lines, $match->to_string;
+
+        # Remove the current node so that we do not end up with duplicates
+        $dom = $match->remove->root;
+        # No need to continue looking for matching elements
+        last;
+      }
+    }
+  } else {
+    # Split just on line breaks
+    @lines = split ( "\n", $content );
+  }
+  my $line_count_limit = RT::Config->Get('RTAnnounceLineCountLimit');
+  if ( $line_count_limit && scalar @lines > $line_count_limit && $show_html ) {
+    # This is our overflow content that will be cutoff in the scroll box
+    my $dom_cutoff = Mojo::DOM->new();
+
+    my $count = 0;
+    for my $line ( @lines ) {
+      if ( $count eq $line_count_limit ) {
+        # Placeholder element to be replaced with overflow CSS div
+        $dom_cutoff = $dom_cutoff->append_content( '<p id="RTAnnounceOverflowStart">' );
+      }
+      $dom_cutoff = $dom_cutoff->append_content( $line );
+      $count = $count + 1;
+    }
+    # Wrap our content in a scrollable div since we have more lines than we want to display
+    $content = $dom_cutoff->content;
+
+    # Replace our placeholder element with the overflow div
+    $content =~ s/\<p id="RTAnnounceOverflowStart"\>\<\/p\>/\<div class="RTAnnounceBannerOverflow overflow-ellipsis"\>/;
+
+    # Close the overflow div at the end of the content
+    $content .= '</div>';
+  }
+
 </%perl>
+<div class="RTAnnounceScrollable">
 % if ( $show_html ) {
   <% $content |n %>
 % } else {
   <% $content %>
 % }
+</div>
 %if( $show_ticket_links{$ticket->Id} ){
  (<a class="announcements_detail" href="<% RT->Config->Get('WebPath') %>/Ticket/Display.html?id=<% $ticket->Id %>">more</a>)
 %}
diff --git a/lib/RT/Extension/Announce.pm b/lib/RT/Extension/Announce.pm
index 44bc8c3..afdb509 100644
--- a/lib/RT/Extension/Announce.pm
+++ b/lib/RT/Extension/Announce.pm
@@ -224,6 +224,11 @@ the regular privileged RT page.
 
 If set to true, the banner content will be set to 'text/html' and allow HTML rendering.
 
+=head2 C<$RTAnnounceLineCountLimit>
+
+Set the number of lines that should be displayed in the RT announce banner, if the displayed lines exceed
+the line limit a scroll box feature will be available.
+
 =head1 AUTHOR
 
 Best Practical Solutions, LLC E<lt>modules at bestpractical.comE<gt>
diff --git a/static/css/announce.css b/static/css/announce.css
index 022eac9..1052ec5 100644
--- a/static/css/announce.css
+++ b/static/css/announce.css
@@ -82,3 +82,12 @@ table.announce td.date {
   font-size: smaller;
   color: #777;
 }
+
+.RTAnnounceBannerOverflow {
+  height: 0px;
+  white-space: nowrap;
+}
+
+.RTAnnounceScrollable {
+  overflow: auto;
+}

commit b9a863195210c665c9772b3fd2bd376c90b83926
Author: Craig Kaiser <craig at bestpractical.com>
Date:   Wed Sep 4 17:16:31 2019 -0400

    Add "AdvancedMode" config option to manually set banner overflow"

diff --git a/README b/README
index 7eab172..d756e87 100644
--- a/README
+++ b/README
@@ -122,6 +122,12 @@ CONFIGURATION
     banner, if the displayed lines exceed the line limit a scroll box
     feature will be available.
 
+  $RTAnnounceAdvancedMode
+    When this configuration is enabled the $RTAnnounceLineCountLimit will
+    not be taken into account, instead the following opening and
+    corresponding closing '<div class="RTAnnounceBannerOverflow"></div>'
+    should be used to wrap the overflow content.
+
 AUTHOR
     Best Practical Solutions, LLC <modules at bestpractical.com>
 
diff --git a/html/Callbacks/RT-Extension-Announce/Elements/PageLayout/BeforeBody b/html/Callbacks/RT-Extension-Announce/Elements/PageLayout/BeforeBody
index ecc75fb..335c540 100644
--- a/html/Callbacks/RT-Extension-Announce/Elements/PageLayout/BeforeBody
+++ b/html/Callbacks/RT-Extension-Announce/Elements/PageLayout/BeforeBody
@@ -69,6 +69,7 @@
   $txns->RowsPerPage(1);
 
   my $show_html = RT::Config->Get('RTAnnounceAllowHTML') || 0;
+  my $advanced_mode = RT::Config->Get('RTAnnounceAdvancedMode') || 0;
   my $content = $show_html ? $txns->First->Content(Type => 'text/html') : $txns->First->Content(Type => 'text/plain');
 
   if( length $content > $MaxMessageLength ){
@@ -83,58 +84,60 @@
   my $dom = Mojo::DOM->new( $content );
 
   my @lines;
-  if ( $show_html ) {
-    for my $line ( $dom->find('*')->map('text')->each ) {
-      # We do not care about strings with only white space
-      next unless $line =~ /\S/;
-
-      # Find the HTML element matching our text, not just the text component
-      my $matches = $dom->find('*')->grep(sub { $_->all_text =~ /$line/ });
-      unless ( $matches->size ) {
-        RT::Logger->error("Could not find HTML component matching text content: $line");
-        next;
-      }
-      foreach my $match ( $matches->each ) {
-        # We do not want to grab any parent elements
-        next if $match->children->size;
-        push @lines, $match->to_string;
-
-        # Remove the current node so that we do not end up with duplicates
-        $dom = $match->remove->root;
-        # No need to continue looking for matching elements
-        last;
+  # We do not mess with line counts if advanced mode enabled
+  unless ( $advanced_mode ) {
+    if ( $show_html ) {
+      for my $line ( $dom->find('*')->map('text')->each ) {
+        # We do not care about strings with only white space
+        next unless $line =~ /\S/;
+
+        # Find the HTML element matching our text, not just the text component
+        my $matches = $dom->find('*')->grep(sub { $_->all_text =~ /$line/ });
+        unless ( $matches->size ) {
+          RT::Logger->error("Could not find HTML component matching text content: $line");
+          next;
+        }
+        foreach my $match ( $matches->each ) {
+          # We do not want to grab any parent elements
+          next if $match->children->size;
+          push @lines, $match->to_string;
+
+          # Remove the current node so that we do not end up with duplicates
+          $dom = $match->remove->root;
+          # No need to continue looking for matching elements
+          last;
+        }
       }
+    } else {
+      # Split just on line breaks
+      @lines = split ( "\n", $content );
     }
-  } else {
-    # Split just on line breaks
-    @lines = split ( "\n", $content );
-  }
-  my $line_count_limit = RT::Config->Get('RTAnnounceLineCountLimit');
-  if ( $line_count_limit && scalar @lines > $line_count_limit && $show_html ) {
-    # This is our overflow content that will be cutoff in the scroll box
-    my $dom_cutoff = Mojo::DOM->new();
-
-    my $count = 0;
-    for my $line ( @lines ) {
-      if ( $count eq $line_count_limit ) {
-        # Placeholder element to be replaced with overflow CSS div
-        $dom_cutoff = $dom_cutoff->append_content( '<p id="RTAnnounceOverflowStart">' );
+    my $line_count_limit = RT::Config->Get('RTAnnounceLineCountLimit');
+    if ( $line_count_limit && scalar @lines > $line_count_limit && $show_html ) {
+      # This is our overflow content that will be cutoff in the scroll box
+      my $dom_cutoff = Mojo::DOM->new();
+
+      my $count = 0;
+      for my $line ( @lines ) {
+        if ( $count eq $line_count_limit ) {
+          # Placeholder element to be replaced with overflow CSS div
+          $dom_cutoff = $dom_cutoff->append_content( '<p id="RTAnnounceOverflowStart">' );
+        }
+        $dom_cutoff = $dom_cutoff->append_content( $line );
+        $count = $count + 1;
       }
-      $dom_cutoff = $dom_cutoff->append_content( $line );
-      $count = $count + 1;
-    }
-    # Wrap our content in a scrollable div since we have more lines than we want to display
-    $content = $dom_cutoff->content;
+      # Wrap our content in a scrollable div since we have more lines than we want to display
+      $content = $dom_cutoff->content;
 
-    # Replace our placeholder element with the overflow div
-    $content =~ s/\<p id="RTAnnounceOverflowStart"\>\<\/p\>/\<div class="RTAnnounceBannerOverflow overflow-ellipsis"\>/;
+      # Replace our placeholder element with the overflow div
+      $content =~ s/\<p id="RTAnnounceOverflowStart"\>\<\/p\>/\<div class="RTAnnounceBannerOverflow"\>/;
 
-    # Close the overflow div at the end of the content
-    $content .= '</div>';
+      # Close the overflow div at the end of the content
+      $content .= '</div>';
+    }
   }
-
 </%perl>
-<div class="RTAnnounceScrollable">
+<div id="RTAnnounceScrollable" class="RTAnnounceScrollable">
 % if ( $show_html ) {
   <% $content |n %>
 % } else {
diff --git a/lib/RT/Extension/Announce.pm b/lib/RT/Extension/Announce.pm
index afdb509..147ee8a 100644
--- a/lib/RT/Extension/Announce.pm
+++ b/lib/RT/Extension/Announce.pm
@@ -229,6 +229,12 @@ If set to true, the banner content will be set to 'text/html' and allow HTML ren
 Set the number of lines that should be displayed in the RT announce banner, if the displayed lines exceed
 the line limit a scroll box feature will be available.
 
+=head2 C<$RTAnnounceAdvancedMode>
+
+When this configuration is enabled the C<$RTAnnounceLineCountLimit> will not be taken into account, instead the
+following opening and corresponding closing '<div class="RTAnnounceBannerOverflow"></div>' should be used to wrap the
+overflow content.
+
 =head1 AUTHOR
 
 Best Practical Solutions, LLC E<lt>modules at bestpractical.comE<gt>

commit 715ec751154fbafd215132e940b21e37dd17662f
Author: Craig Kaiser <craig at bestpractical.com>
Date:   Wed Sep 4 17:24:06 2019 -0400

    Hide banner scrollbar

diff --git a/static/css/announce.css b/static/css/announce.css
index 1052ec5..9d86ad1 100644
--- a/static/css/announce.css
+++ b/static/css/announce.css
@@ -86,8 +86,17 @@ table.announce td.date {
 .RTAnnounceBannerOverflow {
   height: 0px;
   white-space: nowrap;
+  margin-right: -5px;
 }
 
 .RTAnnounceScrollable {
   overflow: auto;
+  -ms-overflow-style: none; /* IE 11 */
+  scrollbar-width: none; /* Firefox 64 */
+}
+
+/* Chrome */
+.RTAnnounceScrollable::-webkit-scrollbar {
+  width: 0px;  /* Remove scrollbar space */
+  background: transparent;  /* Optional: just make scrollbar invisible */
 }

-----------------------------------------------------------------------


More information about the Bps-public-commit mailing list