From 93df9c4dfd68017a1b49793a3e2d1ecfc0d30757 Mon Sep 17 00:00:00 2001 From: elitsa Date: Fri, 13 Sep 2019 12:03:33 +0200 Subject: [PATCH 1/4] Renamed angular filter so it doesn't collide with the "truncate" one in Forms. --- .../{truncate.filter.js => advancedtruncate.filter.js} | 6 +++--- .../src/views/common/overlays/itempicker/itempicker.html | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) rename src/Umbraco.Web.UI.Client/src/common/filters/{truncate.filter.js => advancedtruncate.filter.js} (86%) diff --git a/src/Umbraco.Web.UI.Client/src/common/filters/truncate.filter.js b/src/Umbraco.Web.UI.Client/src/common/filters/advancedtruncate.filter.js similarity index 86% rename from src/Umbraco.Web.UI.Client/src/common/filters/truncate.filter.js rename to src/Umbraco.Web.UI.Client/src/common/filters/advancedtruncate.filter.js index 5efe0f5fff..266c444fe5 100644 --- a/src/Umbraco.Web.UI.Client/src/common/filters/truncate.filter.js +++ b/src/Umbraco.Web.UI.Client/src/common/filters/advancedtruncate.filter.js @@ -1,7 +1,7 @@ /** * @ngdoc filter - * @name umbraco.filters.filter:truncate - * @namespace truncateFilter + * @name umbraco.filters.filter:advancedTruncate + * @namespace advancedTruncateFilter * * param {any} wordwise if true, the string will be cut after last fully displayed word. * param {any} max max length of the outputtet string @@ -10,7 +10,7 @@ * @description * Limits the length of a string, if a cut happens only the string will be appended with three dots to indicate that more is available. */ -angular.module("umbraco.filters").filter('truncate', +angular.module("umbraco.filters").filter('advancedTruncate', function () { return function (value, wordwise, max, tail) { if (!value) return ''; diff --git a/src/Umbraco.Web.UI.Client/src/views/common/overlays/itempicker/itempicker.html b/src/Umbraco.Web.UI.Client/src/views/common/overlays/itempicker/itempicker.html index a9f57fe304..1594d6139e 100644 --- a/src/Umbraco.Web.UI.Client/src/views/common/overlays/itempicker/itempicker.html +++ b/src/Umbraco.Web.UI.Client/src/views/common/overlays/itempicker/itempicker.html @@ -24,7 +24,7 @@ - {{ pasteItem.name | truncate:true:36 }} + {{ pasteItem.name | advancedTruncate:true:36 }} From 2c18a125c6e8178a221700dbf05ea8755fdccacc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20Lyngs=C3=B8?= Date: Fri, 13 Sep 2019 13:46:15 +0200 Subject: [PATCH 2/4] Revert "Renamed angular filter so it doesn't collide with the "truncate" one in Forms." This reverts commit f1cb89b249bdea3faf4b6d6ccf248f64b2056040. --- .../{advancedtruncate.filter.js => truncate.filter.js} | 6 +++--- .../src/views/common/overlays/itempicker/itempicker.html | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) rename src/Umbraco.Web.UI.Client/src/common/filters/{advancedtruncate.filter.js => truncate.filter.js} (86%) diff --git a/src/Umbraco.Web.UI.Client/src/common/filters/advancedtruncate.filter.js b/src/Umbraco.Web.UI.Client/src/common/filters/truncate.filter.js similarity index 86% rename from src/Umbraco.Web.UI.Client/src/common/filters/advancedtruncate.filter.js rename to src/Umbraco.Web.UI.Client/src/common/filters/truncate.filter.js index 266c444fe5..5efe0f5fff 100644 --- a/src/Umbraco.Web.UI.Client/src/common/filters/advancedtruncate.filter.js +++ b/src/Umbraco.Web.UI.Client/src/common/filters/truncate.filter.js @@ -1,7 +1,7 @@ /** * @ngdoc filter - * @name umbraco.filters.filter:advancedTruncate - * @namespace advancedTruncateFilter + * @name umbraco.filters.filter:truncate + * @namespace truncateFilter * * param {any} wordwise if true, the string will be cut after last fully displayed word. * param {any} max max length of the outputtet string @@ -10,7 +10,7 @@ * @description * Limits the length of a string, if a cut happens only the string will be appended with three dots to indicate that more is available. */ -angular.module("umbraco.filters").filter('advancedTruncate', +angular.module("umbraco.filters").filter('truncate', function () { return function (value, wordwise, max, tail) { if (!value) return ''; diff --git a/src/Umbraco.Web.UI.Client/src/views/common/overlays/itempicker/itempicker.html b/src/Umbraco.Web.UI.Client/src/views/common/overlays/itempicker/itempicker.html index 1594d6139e..a9f57fe304 100644 --- a/src/Umbraco.Web.UI.Client/src/views/common/overlays/itempicker/itempicker.html +++ b/src/Umbraco.Web.UI.Client/src/views/common/overlays/itempicker/itempicker.html @@ -24,7 +24,7 @@ - {{ pasteItem.name | advancedTruncate:true:36 }} + {{ pasteItem.name | truncate:true:36 }} From 3d9c2fee7c99399e32c35c7590c509dce85fdead Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20Lyngs=C3=B8?= Date: Fri, 13 Sep 2019 14:55:52 +0200 Subject: [PATCH 3/4] new Angular Truncate Filter, that supports Legacy version from Umbraco Forms, plus updated code for even prettier truncated content. --- .../src/common/filters/truncate.filter.js | 38 +++++++++++++++---- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/common/filters/truncate.filter.js b/src/Umbraco.Web.UI.Client/src/common/filters/truncate.filter.js index 5efe0f5fff..395300014d 100644 --- a/src/Umbraco.Web.UI.Client/src/common/filters/truncate.filter.js +++ b/src/Umbraco.Web.UI.Client/src/common/filters/truncate.filter.js @@ -4,28 +4,52 @@ * @namespace truncateFilter * * param {any} wordwise if true, the string will be cut after last fully displayed word. - * param {any} max max length of the outputtet string - * param {any} tail option tail, defaults to: ' ...' - * + * param {any} max where to cut the string. + * param {any} tail option tail, defaults to: '…' + * + * Legacy version: + * parameter noOfChars(wordwise) Where to cut the string. + * parameter appendDots(max) If true dots will be appended in the end. + * * @description * Limits the length of a string, if a cut happens only the string will be appended with three dots to indicate that more is available. */ angular.module("umbraco.filters").filter('truncate', function () { return function (value, wordwise, max, tail) { + if (!value) return ''; + + // Overload-fix to support Forms Legacy Version: + if (typeof(wordwise) !== 'boolean') { + // switch arguments around to fit Forms version. + if (max !== true) { + tail = ''; + } + max = wordwise; + wordwise = false; + } + // !end of overload fix. + max = parseInt(max, 10); if (!max) return value; if (value.length <= max) return value; - + + tail = (!tail && tail !== '') ? '…' : tail; + + if (wordwise && value.substr(max, 1) === ' ') { + max++; + } value = value.substr(0, max); + if (wordwise) { var lastspace = value.lastIndexOf(' '); - if (lastspace != -1) { - value = value.substr(0, lastspace); + if (lastspace !== -1) { + value = value.substr(0, lastspace+1); } } - return value + (tail || (wordwise ? ' …' : '…')); + + return value + tail; }; } ); From 759c8b8b98f5ebeb7064f8fb6671dad4a8aa8bf1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20Lyngs=C3=B8?= Date: Thu, 26 Sep 2019 15:55:35 +0200 Subject: [PATCH 4/4] updated comment --- .../src/common/filters/truncate.filter.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Umbraco.Web.UI.Client/src/common/filters/truncate.filter.js b/src/Umbraco.Web.UI.Client/src/common/filters/truncate.filter.js index 395300014d..37c560b519 100644 --- a/src/Umbraco.Web.UI.Client/src/common/filters/truncate.filter.js +++ b/src/Umbraco.Web.UI.Client/src/common/filters/truncate.filter.js @@ -20,7 +20,13 @@ angular.module("umbraco.filters").filter('truncate', if (!value) return ''; - // Overload-fix to support Forms Legacy Version: + /* + Overload-fix to support Forms Legacy Version: + + We are making this hack to support the old Forms version of the truncate filter. + The old version took different attributes, this code block checks if the first argument isnt a boolean, meaning its not the new version, meaning that the filter is begin used in the old way. + Therefor we use the second argument(max) to indicate wether we want a tail (…) and using the first argument(wordwise) as the second argument(max amount of characters) + */ if (typeof(wordwise) !== 'boolean') { // switch arguments around to fit Forms version. if (max !== true) {