better char counting and don't collapse queet box when content is too long

This commit is contained in:
Hannes Mannerheim 2014-10-17 17:08:14 +02:00
parent 4876a6a853
commit 387ecc59f4
3 changed files with 13 additions and 4 deletions

View File

@ -842,7 +842,9 @@ function expand_queet(q,doScrolling) {
if(q.hasClass('expanded') && !q.hasClass('collapsing')) {
var sel = getSelection().toString();
if(!sel && !q.find('.queet-button').children('button').hasClass('enabled')) { // don't collapse if text is selected, or if queet has an active queet button
if(!sel
&& !q.find('.queet-button').children('button').hasClass('enabled')
&& !q.find('.queet-button').children('button').hasClass('too-long')) { // don't collapse if text is selected, or if queet has an active queet button, or if queet text is too long
// remove some things right away
q.find('.inline-reply-caret').remove();

View File

@ -514,8 +514,8 @@ function qOrAmp(stream) {
function countCharsInQueetBox(src,trgt,btn) {
var $src_txt = $('<div/>').append($.trim(src.html()).replace(/&nbsp;/gi,' ').replace(/<br>/i,'').replace(/<br>/gi,"x"));
var numchars = ($.trim($src_txt.text())).length;
var $src_txt = $('<div/>').append($.trim(src.text().replace(/^\s+|\s+$/g, '')));
var numchars = ($src_txt.text()).length;
// check for long urls and disable/enable url shorten button if present
var longurls = 0;
@ -535,6 +535,7 @@ function countCharsInQueetBox(src,trgt,btn) {
if(numchars > 0 && numchars < window.textLimit+1) {
btn.removeClass('disabled');
btn.addClass('enabled');
btn.removeClass('too-long');
// deactivate button if it's equal to the start text
var queetBox = btn.closest('.inline-reply-queetbox').children('.queet-box-syntax');
@ -546,9 +547,15 @@ function countCharsInQueetBox(src,trgt,btn) {
}
}
}
else if(numchars > window.textLimit){
btn.removeClass('enabled');
btn.addClass('disabled');
btn.addClass('too-long');
}
else {
btn.removeClass('enabled');
btn.addClass('disabled');
btn.removeClass('too-long');
}

View File

@ -1376,7 +1376,7 @@ $('body').on('click', '.queet-toolbar button',function () {
var queetBox = $(this).parent().parent().siblings('.queet-box');
var queetBoxID = queetBox.attr('id');
var queetText = $.trim(queetBox.html().replace(/\n/g,'').replace(/<br>/g,"\n"));
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">' + queetText.replace(/\n/g,'<br>') + '</div><div class="stream-item-footer"><span class="stream-item-expand">&nbsp;</span></div></div></div></div>';
queetHtml = detectRTL(queetHtml);