From 66898025139362da787c98da474421dcce9d494e Mon Sep 17 00:00:00 2001 From: Mikunj Date: Tue, 20 Nov 2018 13:09:05 +1100 Subject: [PATCH] Truncate text to 15 characters. --- js/views/blocked_number_view.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/js/views/blocked_number_view.js b/js/views/blocked_number_view.js index 3743815d3..03ec264ad 100644 --- a/js/views/blocked_number_view.js +++ b/js/views/blocked_number_view.js @@ -59,14 +59,31 @@ addOne(model) { const number = model.get('number'); if (number) { - this.$el.append(``); + this.$el.append(``); } }, addAll() { this.$el.html(''); this.collection.each(this.addOne, this); }, + truncate(string, limit) { + // Make sure an element and number of items to truncate is provided + if (!string || !limit) return string; + // Get the inner content of the element + let content = string.trim(); + + // Convert the content into an array of words + // Remove any words above the limit + content = content.slice(0, limit); + + // Convert the array of words back into a string + // If there's content to add after it, add it + if (string.length > limit) + content = `${content}...`; + + return content; + }, render() { this.addAll(); return this;