Browse Source

added mention support for post spliting while replying, removed its warning at options page

master
erqan 11 years ago
parent
commit
09d9719094
  1. 134
      js/interface_common.js
  2. 2
      js/interface_localization.js
  3. 10
      js/options.js
  4. 1
      options.html

134
js/interface_common.js

@ -24,8 +24,8 @@ function openModal( modalClass )
//escondo o overflow da tela //escondo o overflow da tela
var $body = $( "body" ); var $body = $( "body" );
$body.css({ $body.css({
"overflow": "hidden", "overflow": "hidden"
}) });
} }
//fecha o modal removendo o conteúdo por detach //fecha o modal removendo o conteúdo por detach
@ -533,7 +533,6 @@ var unfocusThis = function()
$this.removeClass( "open" ); $this.removeClass( "open" );
} }
var splitedPosts = [""];
var splitedPostsCount = 1; var splitedPostsCount = 1;
var usePostSpliting = false; var usePostSpliting = false;
@ -546,74 +545,79 @@ function replyTextKeypress(e) {
$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 (usePostSpliting) {
if (splitedPosts.length == 0)
splitedPosts = [""];
var $tas = tweetForm.find("textarea"); var $tas = tweetForm.find("textarea");
if ($tas.length > 1 && $tas[$tas.length - 1].value.length === 0) { if ($tas.length > 1 && $tas[$tas.length - 1].value.length === 0) {
$tas[$tas.length - 1].value = $tas[$tas.length - 2].value; $tas[$tas.length - 1].value = $tas[$tas.length - 2].value;
$($tas[$tas.length - 2]).remove(); $($tas[$tas.length - 2]).remove();
splitedPosts.splice(0, 1);
} }
splitedPosts[splitedPosts.length - 1] = $tas[$tas.length - 1].value; var reply_to = $this.attr('data-reply-to');
for (var i = 0; i < $tas.length - 1; i++) { for (var i = 0; i < $tas.length - 1; i++) {
var pml = 140 - i.toString().length - $tas.length.toLocaleString().length - 6; var pml = 140 - (i+1).toString().length - $tas.length.toString().length - 6;
//if mention exists, we shouldn't add it while posting.
if (typeof(reply_to) !== 'undefined' &&
!(new RegExp('^.{0,' + (pml - reply_to.length).toString() + '}' + reply_to).test($tas[i].value))) {
pml -= reply_to.length;
}
if ($tas[i].value.length > pml) { if ($tas[i].value.length > pml) {
var ci = $tas[i].value.lastIndexOf(" ", pml); var ci = $tas[i].value.lastIndexOf(" ", pml);
ci = (ci == -1 ? pml : ci); ci = (ci == -1 ? pml : ci);
$tas[i + 1].value = $tas[i].value.substr(ci) + $tas[i + 1].value; $tas[i + 1].value = $tas[i].value.substr(ci) + $tas[i + 1].value;
$tas[i].value = $tas[i].value.substr(0, ci); $tas[i].value = $tas[i].value.substr(0, ci);
splitedPosts[i+1] = $tas[i + 1].value;
} else if ($tas[i].value.length === 0) { } else if ($tas[i].value.length === 0) {
$($tas[i]).remove(); $($tas[i]).remove();
splitedPosts[i] = '';
continue;
} }
splitedPosts[i] = $tas[i].value;
} }
for (var i = splitedPosts.length-1; i > 0; i--) {
if (splitedPosts[i].length == 0) splitedPostsCount = $tas.length;
splitedPosts.splice(i, 1); c = 140 - $this.val().length - (2 * splitedPostsCount.toString().length) - 6;
} if (typeof(reply_to) !== 'undefined' &&
splitedPostsCount = splitedPosts.length; !(new RegExp('^.{0,' + (c - reply_to.length).toString() + '}' + reply_to).test(this.value)))
c = 140 - splitedPosts[splitedPosts.length - 1].length; c -= reply_to.length;
} }
var remainingCount = tweetForm.find(".post-area-remaining"); var remainingCount = tweetForm.find(".post-area-remaining");
if( c < 0 ) { if( c < 0 ) {
if (usePostSpliting){ if (usePostSpliting){
var pml = 140 - (2*splitedPosts.length.toLocaleString().length) - 6; var pml = 140 - (2 * splitedPostsCount.toString().length) - 6;
var cp = splitedPosts[splitedPosts.length-1]; var reply_to = $this.attr('data-reply-to');
//if mention exists, we shouldn't add it while posting.
if (typeof(reply_to) !== 'undefined' &&
!(new RegExp('^.{0,' + (pml - reply_to.length).toString() + '}' + reply_to).test(this.value))) {
pml -= reply_to.length;
}
var cp = this.value;
var ci = cp.lastIndexOf(" ", pml); var ci = cp.lastIndexOf(" ", pml);
ci = (ci == -1 ? pml : ci); ci = (ci == -1 ? pml : ci);
splitedPosts[splitedPosts.length-1] = cp.substr(0, ci); this.value = cp.substr(0, ci);
splitedPosts.push(cp.substr(ci)); splitedPostsCount++;
splitedPostsCount = splitedPosts.length;
var $newta = $this.clone(true);
var reply_to = $this.attr('data-reply-to');
$this.on("click", function(e) {e.stopPropagation()});
$this.on("blur", replyTextKeypress);
$this.addClass('splited-post');
tweetForm.find(".textcomplete-wrapper").append($newta);
$newta.val(cp.substr(ci));
$newta.focus();
if ($newta[0].setSelectionRange)
$newta[0].setSelectionRange($newta.val().length, $newta.val().length);
else if ($newta[0].createTextRange)
$newta[0].createTextRange().moveEnd('character', $newta.val().length);
c += ci - 1; c += ci - 1;
} else } else
remainingCount.addClass("warn"); remainingCount.addClass("warn");
} else } else
remainingCount.removeClass("warn"); remainingCount.removeClass("warn");
if (usePostSpliting) { if (usePostSpliting)
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()); remainingCount.text(splitedPostsCount.toString() + ". post: " + c.toString());
} else else
remainingCount.text(c.toString()); remainingCount.text(c.toString());
var tweetAction = tweetForm.find(".post-submit"); var tweetAction = tweetForm.find(".post-submit");
@ -1107,44 +1111,60 @@ function undoLastUnicode(e) {
var postSubmit = function(e) var postSubmit = function(e)
{ {
if (!(e instanceof $)) { var $this = $( this );
if (e instanceof $)
$this = e;
else {
e.stopPropagation(); e.stopPropagation();
e.preventDefault(); e.preventDefault();
} }
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");
} }
if (splitedPostsCount > 1) { if (splitedPostsCount > 1) {
if (splitedPosts.length < splitedPostsCount) { if ($replyText.length < splitedPostsCount) {
//current part will be sent as reply to the previous part... //current part will be sent as reply to the previous part...
$postOrig = $("<div data-id='" + lastPostId + "' data-screen-name='" + defaultScreenName + "'></div>"); $postOrig = $("<div data-id='" + lastPostId + "' data-screen-name='" + defaultScreenName + "'></div>");
} }
} }
if (splitedPosts.length <= 1) { if ($replyText.length <= 1) {
if (splitedPostsCount > 1) if (splitedPostsCount > 1) {
newPostMsg("(" + splitedPostsCount.toString() + "/" + splitedPostsCount.toString() + ") " + splitedPosts[0], $postOrig); var postxt = "";
else var reply_to = $replyText.attr('data-reply-to');
var val = $replyText.val();
if (typeof(reply_to) === 'undefined' || val.indexOf(reply_to) > 0)
postxt = "(" + splitedPostsCount.toString() + "/" + splitedPostsCount.toString() + ") " + val;
else if (val.indexOf(reply_to) === 0)
postxt = val.replace(reply_to, reply_to + "(" + splitedPostsCount.toString() + "/" + splitedPostsCount.toString() + ") ");
else
postxt = reply_to + "(" + splitedPostsCount.toString() + "/" + splitedPostsCount.toString() + ") " + val;
newPostMsg(postxt, $postOrig);
} else
newPostMsg($replyText.val(), $postOrig); newPostMsg($replyText.val(), $postOrig);
splitedPosts[0] = '';
splitedPostsCount = 1; splitedPostsCount = 1;
} else { } else {
var $twistform = $replyText.parents("form"); var postxt = "";
var $tas = $twistform.find("textarea"); var reply_to = $replyText.attr('data-reply-to');
$($tas[0]).remove(); var val = $replyText[0].value;
if (typeof(reply_to) === 'undefined' || val.indexOf(reply_to) > 0)
postxt = "(" + (splitedPostsCount - $replyText.length + 1).toString() + "/" + splitedPostsCount.toString() + ") " + val;
else if (val.indexOf(reply_to) === 0) {
postxt = val.replace(reply_to, reply_to + "(" + (splitedPostsCount - $replyText.length + 1).toString() + "/" + splitedPostsCount.toString() + ") ");
//splitedPosts.shift();
} else
postxt = reply_to + "(" + (splitedPostsCount - $replyText.length + 1).toString() + "/" + splitedPostsCount.toString() + ") " + val;
$($replyText[0]).remove();
newPostMsg("(" + (splitedPostsCount-splitedPosts.length+1).toString() + "/" + splitedPostsCount.toString() + ") " + splitedPosts.shift() + " + ", $postOrig); newPostMsg(postxt + " +", $postOrig);
setTimeout(postSubmit, 1000, $tas); setTimeout(postSubmit, 1000, $this);
return; return;
} }

2
js/interface_localization.js

@ -207,7 +207,6 @@ 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 only new post": "Split only new post",
"Split all": "Split all", "Split all": "Split all",
"Don't split": "Don't split", "Don't split": "Don't split",
@ -1852,7 +1851,6 @@ if(preferredLanguage == "tr"){
"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.", "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 only new post": "Sadece yeni postaları böl",
"Split all": "Hepsini böl", "Split all": "Hepsini böl",
"Don't split": "Bölme", "Don't split": "Bölme",

10
js/options.js

@ -250,18 +250,8 @@ var TwisterOptions = function()
this.setSplitPostsOpt = function () { this.setSplitPostsOpt = function () {
$('#splitPosts')[0].value = this.getSplitPostsOpt(); $('#splitPosts')[0].value = this.getSplitPostsOpt();
if (this.getSplitPostsOpt() === 'enable')
$("#splitPostWarning")[0].style.display = "inline";
else
$("#splitPostWarning")[0].style.display = "none";
$('#splitPosts').on('change', function () { $('#splitPosts').on('change', function () {
$.Options.setOption(this.id, this.value); $.Options.setOption(this.id, this.value);
if (this.value === 'enable')
$("#splitPostWarning")[0].style.display = "inline";
else
$("#splitPostWarning")[0].style.display = "none";
}); });
} }

1
options.html

@ -252,7 +252,6 @@
<option value="enable">Split all</option> <option value="enable">Split all</option>
<option value="only-new">Split only new post</option> <option value="only-new">Split only new post</option>
</select> </select>
<span style="display:none" class="label" id="splitPostWarning">Mentions at replies aren't handled!</span>
</form> </form>
</div> </div>
</div> </div>

Loading…
Cancel
Save