Page 1 of 1

[CHAT BUG FIX] word wrap on too long words

PostPosted: Sat Oct 22, 2011 12:25 pm
by Zougi
Hey!

As you certainly know, when someone post a long string on the chat like "fooooooooooooooooooooooooooooooooo", a horizontal scroll bar appears and the chat becomes nearly unreadable and ugly.

To prevent this, my solution is to cut the word and add a '-', the new line character and another '-':
e.g:
"foooooooooooooooooooooooo-
-ooooooooo"

Here is the fix:
Open the file [install_directory]/subsonic/jetty/xxxx/webapp/WEB-INF/jsp/right.jsp
After the below tags (line 79 for me):
Code: Select all
<c:if test="${model.showChat}">
    <script type="text/javascript">

add this function:
Code: Select all
            function split_long_word(text, limit)
            {
                var t = '';
                var j = 0;
                for (var i = 0; i < text.length; i++)
                {
                        if (text[i] == ' ')
                        {
                                j = i;
                        }
                        if (i > j + limit)
                        {
                                t += "-\n-";
                                j = i;
                        }
                        t += text[i];
                }
                return t;
            }


Now search the following (line 136 for me):
Code: Select all
dwr.util.setValue("content" + id, message.content);

and replace it with:
Code: Select all
dwr.util.setValue("content" + id, split_long_word(message.content, 25));

25 means it will split the word on the 25th character, obviously you can modify this number if you want.

I hope Sindre Mehus, the developer of subsonic, will maybe see my post and correct this bug.

Zougi.

Re: [CHAT BUG FIX] word wrap on too long words

PostPosted: Sun Jun 17, 2012 3:54 am
by neodawg
This seems to work well, I do have one suggestion and that is dont put in any "-" because if someone puts in a hyperlink and it adds in the hyphens it breaks the link if they do a direct copy-paste.


Thanks,
neodawg