From 649b6d83843c9f7b1716e7b284514f9fe13882d6 Mon Sep 17 00:00:00 2001 From: RaNaN Date: Wed, 10 Jul 2013 21:15:37 +0200 Subject: new hoster links, fixed manifest --- pyload/web/app/scripts/helpers/truncate.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 pyload/web/app/scripts/helpers/truncate.js (limited to 'pyload/web/app/scripts/helpers/truncate.js') diff --git a/pyload/web/app/scripts/helpers/truncate.js b/pyload/web/app/scripts/helpers/truncate.js new file mode 100644 index 000000000..fb351b776 --- /dev/null +++ b/pyload/web/app/scripts/helpers/truncate.js @@ -0,0 +1,25 @@ +require(['underscore','handlebars'], function(_, Handlebars) { + 'use strict'; + + function truncate(fullStr, options) { + var strLen = 30; + if (_.isNumber(options)) + strLen = options; + + if (fullStr.length <= strLen) return fullStr; + + var separator = options.separator || '…'; + + var sepLen = separator.length, + charsToShow = strLen - sepLen, + frontChars = Math.ceil(charsToShow / 2), + backChars = Math.floor(charsToShow / 2); + + return fullStr.substr(0, frontChars) + + separator + + fullStr.substr(fullStr.length - backChars); + } + + Handlebars.registerHelper('truncate', truncate); + return truncate; +}); \ No newline at end of file -- cgit v1.2.3