better counting of line breaks, also hopefullt solves the random collapsing linebreak bug

This commit is contained in:
Hannes Mannerheim 2015-01-26 19:22:05 +01:00
parent 5ffe3faf96
commit 858d87682a
2 changed files with 14 additions and 6 deletions

View File

@ -643,7 +643,9 @@ function qOrAmp(stream) {
function countCharsInQueetBox(src,trgt,btn) {
var $src_txt = $('<div/>').append($.trim(src.text().replace(/^\s+|\s+$/g, '')));
// count linebreaks by converting them to spaces
var $src_txt = $('<div/>').append(src.html().replace(/<br>/g,' '));
$src_txt = $('<div/>').append($.trim($src_txt.text().replace(/\n/g,'').replace(/^\s+|\s+$/g, '')));
var numchars = ($src_txt.text()).length;
// check for long urls and disable/enable url shorten button if present

View File

@ -263,7 +263,6 @@ $(window).load(function() {
// login or not
if(window.loggedIn) {
console.log('logged in user: ' + window.loggedIn.screen_name);
doLogin(getStreamFromUrl());
}
else {
@ -1509,8 +1508,15 @@ $('body').on('click', '.queet-toolbar button',function () {
var queetBox = $(this).parent().parent().siblings('.queet-box');
var queetBoxID = queetBox.attr('id');
var queetText = $.trim(queetBox.text().replace(/^\s+|\s+$/g, ''));
var queetHtml = '<div id="' + tempPostId + '" class="stream-item conversation temp-post" style="opacity:1"><div class="queet"><span class="dogear"></span><div class="queet-content"><div class="stream-item-header"><a class="account-group"><img class="avatar" src="' + $('#user-avatar').attr('src') + '" /><strong class="name">' + $('#user-name').html() + '</strong> <span class="screen-name">@' + $('#user-screen-name').html() + '</span></a><small class="created-at">posting</small></div><div class="queet-text">' + replaceHtmlSpecialChars(queetText.replace(/\n/g,'<br>')) + '</div><div class="stream-item-footer"><ul class="queet-actions"><li class="action-reply-container"><a class="with-icn"><span class="icon sm-reply" title="' + window.sL.replyVerb + '"></span></a></li><li class="action-del-container"><a class="with-icn"><span class="icon sm-trash" title="' + window.sL.deleteVerb + '"></span></a></li></i></li><li class="action-fav-container"><a class="with-icn"><span class="icon sm-fav" title="' + window.sL.favoriteVerb + '"></span></a></li></ul></div></div></div></div>';
// jquery's .text() function is not consistent in converting <br>:s to \n:s,
// so we do this detour to make sure line breaks are preserved
queetBox.html(queetBox.html().replace(/<br>/g, '{{{lb}}}'));
var queetText = $.trim(queetBox.text().replace(/^\s+|\s+$/g, '').replace(/\n/g, ''));
queetText = queetText.replace(/{{{lb}}}/g, "\n");
var queetTempText = replaceHtmlSpecialChars(queetText.replace(/\n/g,'<br>')); // no xss
queetTempText = queetTempText.replace(/&lt;br&gt;/g,'<br>'); // but preserve line breaks
var queetHtml = '<div id="' + tempPostId + '" class="stream-item conversation temp-post" style="opacity:1"><div class="queet"><span class="dogear"></span><div class="queet-content"><div class="stream-item-header"><a class="account-group"><img class="avatar" src="' + $('#user-avatar').attr('src') + '" /><strong class="name">' + $('#user-name').html() + '</strong> <span class="screen-name">@' + $('#user-screen-name').html() + '</span></a><small class="created-at">posting</small></div><div class="queet-text">' + queetTempText + '</div><div class="stream-item-footer"><ul class="queet-actions"><li class="action-reply-container"><a class="with-icn"><span class="icon sm-reply" title="' + window.sL.replyVerb + '"></span></a></li><li class="action-del-container"><a class="with-icn"><span class="icon sm-trash" title="' + window.sL.deleteVerb + '"></span></a></li></i></li><li class="action-fav-container"><a class="with-icn"><span class="icon sm-fav" title="' + window.sL.favoriteVerb + '"></span></a></li></ul></div></div></div></div>';
queetHtml = detectRTL(queetHtml);
// popup reply
@ -1745,7 +1751,7 @@ $('body').on('mouseup', 'div.syntax-two', function(e){
function stripHtmlFromPaste(e) {
e.preventDefault();
var text = replaceHtmlSpecialChars(e.clipboardData.getData("text/plain"));
text = text.replace("\n",'<br>'); // keep line-breaks
text = text.replace(/\n/g,'<br>').replace(/\t/g, '&nbsp;&nbsp;&nbsp;&nbsp;'); // keep line-breaks and tabs
document.execCommand("insertHTML", false, text);
}