Add Angular filter for wrapping words larger than N characters.

This commit is contained in:
Paulo Reis 2016-08-01 16:35:28 +01:00
parent 18d0c51da9
commit c6334ffab7

View file

@ -0,0 +1,17 @@
define [
"base"
], (App) ->
DEF_MIN_LENGTH = 20
_getWrappedWordsString = (baseStr, wrapperElName, minLength) ->
minLength = minLength || DEF_MIN_LENGTH
findWordsRegEx = new RegExp "\\w{#{minLength},}", "g"
wrappingTemplate = "<#{wrapperElName} style='word-break: break-all;'>$&</#{wrapperElName}>"
baseStr.replace findWordsRegEx, wrappingTemplate
App.filter "wrapLongWords", () ->
(input, minLength) ->
_getWrappedWordsString input, "span", minLength