Explorar o código

Add Angular filter for wrapping words larger than N characters.

Paulo Reis %!s(int64=10) %!d(string=hai) anos
pai
achega
c6334ffab7
Modificáronse 1 ficheiros con 17 adicións e 0 borrados
  1. 17 0
      services/web/public/coffee/filters/wrapLongWords.coffee

+ 17 - 0
services/web/public/coffee/filters/wrapLongWords.coffee

@@ -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