Browse Source

Merge pull request #140 from erqan/split-long-posts

Split long posts
master
miguelfreitas 11 years ago
parent
commit
415572ac5f
  1. 20
      css/style.css
  2. 118
      js/interface_common.js
  3. 13
      js/interface_localization.js
  4. 23
      js/options.js
  5. 12
      options.html

20
css/style.css

@ -548,6 +548,26 @@ button.disabled:hover
border: solid 1px rgba( 227, 79, 66, .5 ); border: solid 1px rgba( 227, 79, 66, .5 );
box-shadow: 0 0 10px rgba(0, 0, 0, .3 ); box-shadow: 0 0 10px rgba(0, 0, 0, .3 );
} }
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;
}
}
.post-area-extras .post-area-extras
{ {
overflow: hidden; overflow: hidden;

118
js/interface_common.js

@ -417,7 +417,23 @@ var composeNewPost = function( e, postAreaNew )
if( !postAreaNew.hasClass("open") ) { if( !postAreaNew.hasClass("open") ) {
postAreaNew.addClass( "open" ); postAreaNew.addClass( "open" );
//se o usuário clicar fora é pra fechar //se o usuário clicar fora é pra fechar
postAreaNew.clickoutside( unfocusThis ) postAreaNew.clickoutside( unfocusThis );
if ($.Options.getSplitPostsOpt() === "enable")
usePostSpliting = true;
else if ($.Options.getSplitPostsOpt() === "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"); var textArea = postAreaNew.find("textarea");
@ -434,6 +450,10 @@ var unfocusThis = function()
$this.removeClass( "open" ); $this.removeClass( "open" );
} }
var splitedPosts = [""];
var splitedPostsCount = 1;
var usePostSpliting = false;
function replyTextKeypress(e) { function replyTextKeypress(e) {
e = e || event; e = e || event;
var $this = $( this ); var $this = $( this );
@ -442,10 +462,63 @@ function replyTextKeypress(e) {
if ($.Options.getUnicodeConversionOpt() !== "disable") if ($.Options.getUnicodeConversionOpt() !== "disable")
$this.val(convert2Unicodes($this.val(), $this)); $this.val(convert2Unicodes($this.val(), $this));
var c = 140 - $this.val().length; 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"); var remainingCount = tweetForm.find(".post-area-remaining");
remainingCount.text(c);
if( c < 0 ) remainingCount.addClass("warn"); if( c < 0 ) {
else remainingCount.removeClass("warn"); 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.find(".textcomplete-wrapper").prepend("<textarea class='splited-post'></textarea>");
$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"); var tweetAction = tweetForm.find(".post-submit");
if( !tweetAction.length ) tweetAction = tweetForm.find(".dm-submit"); if( !tweetAction.length ) tweetAction = tweetForm.find(".dm-submit");
@ -938,18 +1011,47 @@ function undoLastUnicode(e) {
var postSubmit = function(e) var postSubmit = function(e)
{ {
e.stopPropagation(); if (!(e instanceof $)) {
e.preventDefault(); e.stopPropagation();
e.preventDefault();
}
var $this = $( this ); var $this = $( this );
var $replyText = $this.closest(".post-area-new").find("textarea"); var $replyText = $this.closest(".post-area-new").find("textarea");
if (!$replyText.length)
$replyText = e;
var $postOrig = $this.closest(".post-data"); var $postOrig = $this.closest(".post-data");
if (!$postOrig.length) { if (!$postOrig.length) {
$postOrig = $this.closest(".modal-content").find(".post-data"); $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 = $("<div data-id='" + lastPostId + "' data-screen-name='" + defaultScreenName + "'></div>");
}
}
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.val("");
$replyText.attr("placeholder", polyglot.t("Your message was sent!")); $replyText.attr("placeholder", polyglot.t("Your message was sent!"));

13
js/interface_localization.js

@ -207,6 +207,11 @@ if(preferredLanguage == "en"){
"Use proxy for image preview only": "Use proxy for image preview only", "Use proxy for image preview only": "Use proxy for image preview only",
"Use external links behind a proxy": "Use external links behind a proxy", "Use external links behind a proxy": "Use external links behind a proxy",
"There aren't any posts with this hashtag.": "There aren't any posts with this hashtag.", "There aren't any posts with this hashtag.": "There aren't any posts with this hashtag.",
"Mentions at replies aren't handled!": "Mentions at replies aren't handled!",
"Split only new post": "Split only new post",
"Split all": "Split all",
"Don't split": "Don't split",
"Split long posts": "Split long posts"
}; };
} }
if(preferredLanguage == "es"){ if(preferredLanguage == "es"){
@ -1811,7 +1816,13 @@ if(preferredLanguage == "tr"){
"No one can mention you because you are not logged in.": "Giriş yapmadığınız için kimse adınıza mesaj gönderemiyor.", "No one can mention you because you are not logged in.": "Giriş yapmadığınız için kimse adınıza mesaj gönderemiyor.",
"You don't have any profile because you are not logged in.": "Giriş yapmadığınız için profiliniz yok.", "You don't have any profile because you are not logged in.": "Giriş yapmadığınız için profiliniz yok.",
"Use proxy for image preview only": "Vekil sunucuyu sadece resim ön izleme için kullan", "Use proxy for image preview only": "Vekil sunucuyu sadece resim ön izleme için kullan",
"Use external links behind a proxy": "Harici bağlantılar için vekil sunucu kullan" "Use external links behind a proxy": "Harici bağlantılar için vekil sunucu kullan",
"There aren't any posts with this hashtag.": "Bu etiketle ilgili gönderi yok.",
"Mentions at replies aren't handled!": "Cevaplardaki isimler yönetilmiyor!",
"Split only new post": "Sadece yeni postaları böl",
"Split all": "Hepsini böl",
"Don't split": "Bölme",
"Split long posts": "Uzun gönderileri böl"
}; };
} }

23
js/options.js

@ -243,6 +243,28 @@ var TwisterOptions = function()
}); });
} }
this.getSplitPostsOpt = function (){
return $.Options.getOption('splitPosts', 'disable');
}
this.setSplitPostsOpt = function (){
$('#splitPosts')[0].value = this.getSplitPostsOpt();
if (this.getSplitPostsOpt() === 'enable')
$("#splitPostWarning")[0].style.display = "inline";
else
$("#splitPostWarning")[0].style.display = "none";
$('#splitPosts').on('change', function (){
$.Options.setOption(this.id, this.value);
if (this.value === 'enable')
$("#splitPostWarning")[0].style.display = "inline";
else
$("#splitPostWarning")[0].style.display = "none";
});
}
this.InitOptions = function() { this.InitOptions = function() {
this.soundNotifOptions(); this.soundNotifOptions();
this.volumeControl(); this.volumeControl();
@ -258,6 +280,7 @@ var TwisterOptions = function()
this.setConvertFractionsOpt(); this.setConvertFractionsOpt();
this.setUseProxyOpt(); this.setUseProxyOpt();
this.setUseProxyForImgOnlyOpt(); this.setUseProxyForImgOnlyOpt();
this.setSplitPostsOpt();
} }
} }

12
options.html

@ -213,6 +213,18 @@
</div> </div>
</form> </form>
</div> </div>
<br/>
<div>
<form action="" id="splitPostsOpt">
<p class="label">Split long posts</p>
<select name="" id="splitPosts">
<option value="disable">Don't split</option>
<option value="enable">Split all</option>
<option value="only-new">Split only new post</option>
</select>
<span style="display:none" class="label" id="splitPostWarning">Mentions at replies aren't handled!</span>
</form>
</div>
</div> </div>
</div> </div>

Loading…
Cancel
Save