diff --git a/css/style.css b/css/style.css index bd8b662..795c8f9 100644 --- a/css/style.css +++ b/css/style.css @@ -1489,6 +1489,26 @@ input.userMenu-search-field:focus::-ms-input-placeholder { margin-left: -20px; margin-bottom: 10px; } +textarea.splited-post { + box-shadow: none!important; + animation-name: sent-part; + animation-duration: 0,5s; + animation-easing-function: linear; + -webkit-animation-name: sent-part; + -webkit-animation-duration: 0.5s; + -webkit-animation-easing-function: linear; + -moz-animation-name: sent-part; + -moz-animation-duration: 0.5s; + -moz-animation-easing-function: linear; +} +@keyframes sent-part { + from { + height: 0px; + } + to { + height: 80px; + } +} .highlight { background: #fff; padding: 3px 5px; @@ -2049,6 +2069,11 @@ input.userMenu-search-field:focus::-ms-input-placeholder { margin-top: 10px; font-size: 12px; } +#splitPostWarning { + font-size: 12px; + font-style: italic; + margin-left: 10px; +} /* Following page */ .following ol.following-list > li{ display: inline-block; @@ -2091,69 +2116,4 @@ input.userMenu-search-field:focus::-ms-input-placeholder { font: 12px "Open Sans", sans-serif; display: block; float: right; -} - -/* Autocomplite*/ -.textcomplete-wrapper textarea { - display: inline; -} -ul.dropdown-menu { - position: absolute; - top: 23px; - left: 170px; - z-index: 100; - display: block; - float: left; - min-width: 160px; - padding: 5px 0; - margin: 2px 0 0; - list-style: none; - background-color: #fff; - border: 1px solid rgba(0,0,0, .2); - border-radius: 6px; - -webkit-border-radius: 6px; - -moz-border-radius: 6px; - -webkit-box-shadow: 0 5px 10px rgba(0,0,0, .2); - -moz-box-shadow: 0 5px 10px rgba(0,0,0, .2); - box-shadow: 0 5px 10px rgba(0,0,0, .2); - -} -ul.dropdown-menu li { - line-height: 20px; - -} -ul.dropdown-menu > .active > a { - color: #fff; - text-decoration: none; - background-color: #7691ce; - background-image: linear-gradient(to bottom, #6f88c1, #7e9bdb); - background-repeat: repeat-x; - -} -ul.dropdown-menu > li > a { - display: block; - padding: 3px 20px; - clear: both; - font: 13px/20px "Open Sans", sans-serif; - white-space: nowrap; - cursor: pointer; - -webkit-transition: all 200ms; - -moz-transition: all 200ms; - -ms-transition: all 200ms; - -o-transition: all 200ms; - transition: all 200ms; -} -ul.dropdown-menu img { - width: 25px; - height: 25px; - margin-right: 10px; - -} -p.post-text img { - width: 20px; - height: 20px; -} - -.reply textarea{ - margin-top: 20px; } \ No newline at end of file diff --git a/js/interface_common.js b/js/interface_common.js index aadfabe..4ce23ec 100644 --- a/js/interface_common.js +++ b/js/interface_common.js @@ -382,7 +382,23 @@ var composeNewPost = function( e, postAreaNew ) if( !postAreaNew.hasClass("open") ) { postAreaNew.addClass( "open" ); //se o usuário clicar fora é pra fechar - postAreaNew.clickoutside( unfocusThis ) + postAreaNew.clickoutside( unfocusThis ); + + if ($.Options.getOption('splitPosts', 'disable') === "enable") + usePostSpliting = true; + else if ($.Options.getOption('splitPosts', 'disable') === "only-new") { + var $postOrig = postAreaNew.closest(".post-data"); + + if (!$postOrig.length) { + $postOrig = postAreaNew.closest(".modal-content").find(".post-data"); + } + + if ($postOrig.length) + usePostSpliting = false; + else + usePostSpliting = true; + } else + usePostSpliting = false; } var textArea = postAreaNew.find("textarea"); @@ -399,16 +415,73 @@ var unfocusThis = function() $this.removeClass( "open" ); } +var splitedPosts = [""]; +var splitedPostsCount = 1; +var usePostSpliting = false; + function replyTextKeypress(e) { var e = e || event; var $this = $( this ); var tweetForm = $this.parents("form"); if( tweetForm != undefined ) { var c = 140 - $this.val().length; + if (usePostSpliting) { + if (splitedPosts.length == 0) + splitedPosts = [""]; + + var $tas = tweetForm.find("textarea"); + splitedPosts[splitedPosts.length - 1] = $tas[$tas.length - 1].value; + + for (var i = 0; i < $tas.length - 1; i++) { + if ($tas[i].value.length > 131) { + var ci = $tas[i].value.lastIndexOf(" ", 131); + ci = (ci == -1 ? 131 : ci); + $tas[i + 1].value = $tas[i].value.substr(ci) + $tas[i + 1].value; + $tas[i].value = $tas[i].value.substr(0, ci); + splitedPosts[i+1] = $tas[i + 1].value; + }else if ($tas[i].value.length === 0) { + $($tas[i]).remove(); + splitedPosts.splice(i, 1); + } + splitedPosts[i] = $tas[i].value; + } + c = 140 - splitedPosts[splitedPosts.length - 1].length; + } + var remainingCount = tweetForm.find(".post-area-remaining"); - remainingCount.text(c); - if( c < 0 ) remainingCount.addClass("warn"); - else remainingCount.removeClass("warn"); + + if( c < 0 ) { + if (usePostSpliting){ + var cp = splitedPosts[splitedPosts.length-1]; + var ci = cp.lastIndexOf(" ", 131); + ci = (ci == -1 ? 131 : ci); + splitedPosts[splitedPosts.length-1] = cp.substr(0, ci); + splitedPosts.push(cp.substr(ci)); + splitedPostsCount = splitedPosts.length; + c += ci - 1; + } else + remainingCount.addClass("warn"); + } else + remainingCount.removeClass("warn"); + + if (usePostSpliting) { + //var np = ""; + var $tas = tweetForm.find("textarea"); + + if ($tas.length < splitedPosts.length){ + tweetForm.prepend(""); + $tas = tweetForm.find("textarea"); + $($tas[0]).on("click", function(e) {e.stopPropagation()}); + $tas.on("blur", replyTextKeypress); + } + + for (var i = 0; i < splitedPosts.length; i++) { + $tas[i].value = splitedPosts[i]; + } + + remainingCount.text(splitedPostsCount.toString() + ". post: " + c.toString()); + } else + remainingCount.text(c.toString()); var tweetAction = tweetForm.find(".post-submit"); if( !tweetAction.length ) tweetAction = tweetForm.find(".dm-submit"); @@ -447,19 +520,48 @@ var replyTextSendKeys = function(e) { } var postSubmit = function(e) -{ - e.stopPropagation(); - e.preventDefault(); +{ + if (!(e instanceof $)) { + e.stopPropagation(); + e.preventDefault(); + } var $this = $( this ); var $replyText = $this.closest(".post-area-new").find("textarea"); + if (!$replyText.length) + $replyText = e; + var $postOrig = $this.closest(".post-data"); if (!$postOrig.length) { $postOrig = $this.closest(".modal-content").find(".post-data"); } - - newPostMsg($replyText.val(), $postOrig); + + if (splitedPostsCount > 1) { + if (splitedPosts.length < splitedPostsCount) { + //current part will be sent as reply to the previous part... + $postOrig = $("
"); + } + } + + if (splitedPosts.length == 1) { + if (splitedPostsCount > 1) + newPostMsg("(" + splitedPostsCount.toString() + "/" + splitedPostsCount.toString() + ") " + splitedPosts[0], $postOrig); + else + newPostMsg($replyText.val(), $postOrig); + + splitedPosts[0] = ''; + splitedPostsCount = 1; + } else { + var $twistform = $replyText.parents("form"); + var $tas = $twistform.find("textarea"); + $($tas[0]).remove(); + + newPostMsg("(" + (splitedPostsCount-splitedPosts.length+1).toString() + "/" + splitedPostsCount.toString() + ") " + splitedPosts.shift() + " + ", $postOrig); + setTimeout(postSubmit, 1000, $tas); + + return; + } $replyText.val(""); $replyText.attr("placeholder", polyglot.t("Your message was sent!")); diff --git a/js/options.js b/js/options.js index 91050b4..1e6afed 100644 --- a/js/options.js +++ b/js/options.js @@ -131,7 +131,27 @@ var TwisterOptions = function() $('input[type="checkbox"]').on('click', function(){ $.Options.setOption(this.name, this.checked) }) - } + + this.splitPostsOpt = function (){ + $('#splitPosts').val($.Options.getOption('splitPosts', 'disable')) + + if ($.Options.getOption('splitPosts', 'disable') === 'enable'){ + $("#splitPostWarning").css('display', 'inline') + }else{ + $("#splitPostWarning").css('display', 'none') + } + + $('#splitPosts').on('change', function (){ + $.Options.setOption(this.id, this.value); + + if (this.value === 'enable'){ + $("#splitPostWarning").css('display', 'inline'); + }else{ + $("#splitPostWarning").css('display', 'none'); + } + }); + } +} this.initOptions = function() { this.soundNotifOptions(); @@ -139,6 +159,7 @@ var TwisterOptions = function() this.keysSend(); this.locLang(); this.showPreviewOpt(); + this.splitPostsOpt(); } } diff --git a/js/twister_formatpost.js b/js/twister_formatpost.js index e70552e..071d99e 100644 --- a/js/twister_formatpost.js +++ b/js/twister_formatpost.js @@ -269,7 +269,9 @@ function htmlFormatMsg( msg, output, mentions ) { function _formatText(msg) { msg = $.emotions(msg); - msg = msg.replace(/\n/g, '
'); + msg = msg + .replace(/(\r?\n){2,}/g, '\n\n') + .replace(/\n/g, '
'); return msg; } diff --git a/options.html b/options.html index cb07fd9..2cc5b54 100644 --- a/options.html +++ b/options.html @@ -126,6 +126,16 @@ +
+

Split long posts

+ + +
+