Comments on: “wordwrap” for JavaScript https://j11y.io/snippets/wordwrap-for-javascript/ Sun, 22 Mar 2015 15:39:22 +0000 hourly 1 https://wordpress.org/?v=5.0.13 By: Tim https://j11y.io/snippets/wordwrap-for-javascript/#comment-1046 Wed, 17 Feb 2010 22:46:31 +0000 https://j11y.io/?p=968#comment-1046 This is far more elegant than alot of scripts that do the same thing. Only I dont want to word wrap just cut the string on the specified length and append the break “…”.

If I set to false or true this script still cuts it up into lines?

Any idea how to just return the string with specified length with brk appended?

]]>
By: carobbins https://j11y.io/snippets/wordwrap-for-javascript/#comment-1045 Fri, 13 Nov 2009 17:02:25 +0000 https://j11y.io/?p=968#comment-1045 Hey just wanted to let you know I found the issue and created this work around for Mirth:
brk = (brk ? brk :’n’);
width = (width ? width : 75);
cut = (cut ? cut : false);

Thank you for this function it is great.

]]>
By: carobbins https://j11y.io/snippets/wordwrap-for-javascript/#comment-1044 Fri, 13 Nov 2009 16:39:22 +0000 https://j11y.io/?p=968#comment-1044 Thank you for this function. It works great in the browser environment. However, I am trying to use it in Mirth (a java based application that runs javascript) and it keeps putting a brk anywhere there is a space in the string. Is there some variation that is possible to prevent this.

]]>
By: zm https://j11y.io/snippets/wordwrap-for-javascript/#comment-1043 Sun, 05 Jul 2009 14:50:32 +0000 https://j11y.io/?p=968#comment-1043 ‘|\S+?(\s|$)’ do you mean ‘|(\S+)?(\s|$)’ ?
i can not understant the ‘+?’, could you tell me what this for ?
thanks alot 🙂

]]>
By: James https://j11y.io/snippets/wordwrap-for-javascript/#comment-1042 Fri, 26 Jun 2009 17:31:56 +0000 https://j11y.io/?p=968#comment-1042 @unscriptable, I haven’t really considered any uses for this yet (on the client-side). I clicked a link to another solution yesterday and it dissapointed me; I thought this could be done more gracefully; so, I wrote my own.

]]>
By: unscriptable https://j11y.io/snippets/wordwrap-for-javascript/#comment-1041 Fri, 26 Jun 2009 14:03:20 +0000 https://j11y.io/?p=968#comment-1041 Hi James,

Nice use of regular expressions to remove the computationally heavy bits out of Javascript. My first rule of performant Javascript is to not use Javascript if there’s a built-in method. (However, Safari 4, FF 3.5, and Chrome 2 make this less of a strict rule than it was even a few months ago.)

I am having trouble figuring out why I’d need this in a real app, though. Why not let the browser word-wrap using CSS? In what scenarios have you used this?

— John

]]>