angular-read-more icon indicating copy to clipboard operation
angular-read-more copied to clipboard

fix to dom elements truncated with limit

Open sam2x opened this issue 8 years ago • 4 comments

Please review this patch, it fix a very annoying bug.

Bug Explanation: https://github.com/ismarslomic/angular-read-more/issues/6#issuecomment-229992773

Summary:

  • It support plain text (ie: without html inside)
  • Afaik, the patch doesnt break any feautre of the directive (transparent to user)
  • Fix the bug where tags are truncated, which resulted to some content with html not parsed like " style='text-align:center'> Hey this is a long text that would not appear in less part!!!! </span>

Solution of this patch :

  • I use DOMParser recursively parse the content of vm.hmText (ie: data passed to hm-text directive)
  • If a text element is encountered, we take it in account to verify that the limit is not reached
  • If the limit is reached, the parsing is stopped, and the current element text is truncated. The function return the html parsed until the last tag which reached the limit.
  • Plain text are considered as a text element, so no edge case should appear.

sam2x avatar Jul 02 '16 15:07 sam2x

Coverage Status

Coverage remained the same at 100.0% when pulling 8542c3f41ea66aff22b37249a5f05bda420a50ab on sam2x:fix_dom_elements_truncated into 6faff51cb036d6126b3133e59e0067eb7b546f15 on ismarslomic:master.

coveralls avatar Jul 02 '16 15:07 coveralls

Could you also update/add unit tests for this change?

ismarslomic avatar Jul 02 '16 16:07 ismarslomic

Just merge it, I need that fix!

mtebele avatar Sep 19 '16 04:09 mtebele

Note that if you use this fix you cannot have animation transition on text. @ismarslomic i don't know how to add unit test, sry.

sam2x avatar Sep 19 '16 11:09 sam2x