+
diff --git a/js/interface_common.js b/js/interface_common.js
index c25f340..5e26403 100644
--- a/js/interface_common.js
+++ b/js/interface_common.js
@@ -293,7 +293,7 @@ function openConversationClick(e) {
e.stopPropagation();
e.preventDefault();
- var postData = $(this).parents('.module.post.original.open .module.post.original .post-data');
+ var postData = $(this).closest(e.data.feeder);
window.location.hash = '#conversation?post=' + postData.attr('data-screen-name') +
':post' + postData.attr('data-id');
@@ -379,13 +379,25 @@ function reTwistPopup(e) {
return;
}
- openModal({
+ var modal = openModal({
classBase: '.prompt-wrapper',
classAdd: 'reTwist',
title: polyglot.t('retransmit_this')
- })
- .content
- .append(postToElem($.evalJSON($(this).parents('.post-data').attr('data-userpost')), ''));
+ });
+
+ modal.content
+ .append(postToElem($.evalJSON($(this).parents('.post-data').attr('data-userpost')), ''))
+ .append($('#reply-modal-template').children().clone(true)) // FIXME retwist-reply-modal-template
+ ;
+
+ var replyArea = modal.content.find('.post-area .post-area-new');
+ var textArea = replyArea.find('textarea');
+ var textAreaPostInline = modal.content.find('.post .post-area-new textarea');
+ $.each(['placeholder', 'data-reply-to'], function(i, attribute) {
+ textArea.attr(attribute, textAreaPostInline.attr(attribute));
+ });
+
+ replyArea.find('.post-submit').addClass('with-reference');
}
// Expande Área do Novo post
@@ -399,16 +411,16 @@ function replyInitPopup(e, post) {
getFullname(post.userpost.n, modal.self.find('h3 .fullname'));
modal.content
- .append($('#reply-modal-template').children().clone(true))
.append(postToElem(post, ''))
+ .append($('#reply-modal-template').children().clone(true))
;
// FIXME passing data through attributes may result in a mess like following
var replyArea = modal.content.find('.post-area .post-area-new').addClass('open');
- var replyText = replyArea.find('textarea');
- var postInlineReplyText = modal.content.find('.post .post-area-new textarea');
+ var textArea = replyArea.find('textarea');
+ var textAreaPostInline = modal.content.find('.post .post-area-new textarea');
$.each(['placeholder', 'data-reply-to'], function(i, attribute) {
- replyText.attr(attribute, postInlineReplyText.attr(attribute));
+ textArea.attr(attribute, textAreaPostInline.attr(attribute));
});
composeNewPost(e, replyArea);
@@ -587,7 +599,7 @@ function posPostPreview(event) {
- postPreview.css('padding-left') - postPreview.css('padding-right'));
}
if (textArea[0].value.length)
- postPreview.html(htmlFormatMsg(textArea[0].value, [])).show();
+ postPreview.html(htmlFormatMsg(textArea[0].value).html).show();
else
postPreview.hide();
textArea.before(postPreview);
@@ -698,7 +710,7 @@ function replyTextInput(event) {
if ($.Options.postPreview.val) {
if (textArea[0].value.length)
- textAreaForm.find('#post-preview').html(htmlFormatMsg(textArea[0].value, [])).show();
+ textAreaForm.find('#post-preview').html(htmlFormatMsg(textArea[0].value).html).show();
else
textAreaForm.find('#post-preview').html('').hide();
}
@@ -1202,82 +1214,95 @@ function undoLastUnicode(e) {
}
function postSubmit(e, oldLastPostId) {
+ var btnPostSubmit;
+
if (e instanceof $) {
- var $this = e;
+ btnPostSubmit = e;
//check if previous part was sent...
if (oldLastPostId === lastPostId) {
- setTimeout(postSubmit, 1000, $this, oldLastPostId);
+ setTimeout(postSubmit, 1000, btnPostSubmit, oldLastPostId);
return;
}
} else {
e.stopPropagation();
e.preventDefault();
- var $this = $(this);
+ btnPostSubmit = $(this);
}
- $.MAL.disableButton($this);
+ $.MAL.disableButton(btnPostSubmit);
- var $replyText = $this.closest('.post-area-new').find('textarea');
+ var textArea = btnPostSubmit.closest('.post-area-new').find('textarea');
- $replyText.siblings('#post-preview').hide();
+ textArea.siblings('#post-preview').hide();
- var $postOrig = $this.closest('.post-data');
- if (!$postOrig.length) {
- $postOrig = $this.closest('.modal-content').find('.post-data');
+ var postData = btnPostSubmit.closest('.post-data');
+ if (!postData.length) {
+ postData = btnPostSubmit.closest('.modal-content').find('.post-data');
}
- if (splitedPostsCount > 1) {
- if ($replyText.length < splitedPostsCount) {
- //current part will be sent as reply to the previous part...
- $postOrig = $('');
+ if (btnPostSubmit.hasClass('with-reference')) {
+ var doSubmitPost = function (postText, postData) {
+ newRtMsg(postData, postText);
+ }
+ } else {
+ if (splitedPostsCount > 1) {
+ if (textArea.length < splitedPostsCount) {
+ //current part will be sent as reply to the previous part...
+ postData = $('');
+ }
+ }
+
+ var doSubmitPost = function (postText, postData) {
+ newPostMsg(postText, postData);
}
}
- if ($replyText.length <= 1) {
+ if (textArea.length <= 1) {
if (splitedPostsCount > 1) {
- var postxt = '';
- var reply_to = $replyText.attr('data-reply-to');
- var val = $replyText.val();
+ var postText = '';
+ var reply_to = textArea.attr('data-reply-to');
+ var val = textArea.val();
if (typeof reply_to === 'undefined' || checkPostForMentions(val, reply_to, 140))
- postxt = val + ' (' + splitedPostsCount.toString() + '/' + splitedPostsCount.toString() + ')';
+ postText = val + ' (' + splitedPostsCount.toString() + '/' + splitedPostsCount.toString() + ')';
else
- postxt = reply_to + val + ' (' + splitedPostsCount.toString() + '/' + splitedPostsCount.toString() + ')';
+ postText = reply_to + val + ' (' + splitedPostsCount.toString() + '/' + splitedPostsCount.toString() + ')';
- newPostMsg(postxt, $postOrig);
+ doSubmitPost(postText, postData);
} else
- newPostMsg($replyText.val(), $postOrig);
+ doSubmitPost(textArea.val(), postData);
splitedPostsCount = 1;
} else {
- var postxt = '';
- var reply_to = $replyText.attr('data-reply-to');
- var val = $replyText[0].value;
+ var postText = '';
+ var reply_to = textArea.attr('data-reply-to');
+ var val = textArea[0].value;
if (typeof reply_to === 'undefined' || checkPostForMentions(val, reply_to, 140))
- postxt = val + ' (' + (splitedPostsCount - $replyText.length + 1).toString() + '/' + splitedPostsCount.toString() + ')';
+ postText = val + ' (' + (splitedPostsCount - textArea.length + 1).toString() + '/' + splitedPostsCount.toString() + ')';
else
- postxt = reply_to + val + ' (' + (splitedPostsCount - $replyText.length + 1).toString() + '/' + splitedPostsCount.toString() + ')';
+ postText = reply_to + val + ' (' + (splitedPostsCount - textArea.length + 1).toString() + '/' + splitedPostsCount.toString() + ')';
- $($replyText[0]).remove();
+ $(textArea[0]).remove();
oldLastPostId = lastPostId;
- newPostMsg(postxt, $postOrig);
- setTimeout(postSubmit, 1000, $this, oldLastPostId);
+ doSubmitPost(postText, postData);
+ setTimeout(postSubmit, 1000, btnPostSubmit, oldLastPostId);
return;
}
- $replyText.val('').attr('placeholder', polyglot.t('Your message was sent!'));
- var tweetForm = $this.parents('form');
- var remainingCount = tweetForm.find('.post-area-remaining');
- remainingCount.text(140);
-
- if ($this.parents('.prompt-wrapper').length)
+ if (btnPostSubmit.parents('.prompt-wrapper').length)
closeModalHandler('.prompt-wrapper');
-
- if ($this.closest('.post-area,.post-reply-content')) {
- $('.post-area-new').removeClass('open').find('textarea').blur();
- };
- $replyText.data('unicodeConversionStack', []);
- $replyText.data('disabledUnicodeRules', []);
+ else {
+ textArea.val('').attr('placeholder', polyglot.t('Your message was sent!'));
+ var tweetForm = btnPostSubmit.parents('form');
+ var remainingCount = tweetForm.find('.post-area-remaining');
+ remainingCount.text(140);
+
+ if (btnPostSubmit.closest('.post-area,.post-reply-content')) {
+ $('.post-area-new').removeClass('open').find('textarea').blur();
+ };
+ textArea.data('unicodeConversionStack', []);
+ textArea.data('disabledUnicodeRules', []);
+ }
}
function retweetSubmit(e) {
@@ -1402,7 +1427,8 @@ function initInterfaceCommon() {
;
$('.post-submit').on('click', postSubmit);
$('.modal-propagate').on('click', retweetSubmit);
- $('.expanded-content .show-more').on('click', openConversationClick);
+ $('.expanded-content .show-more').on('click',
+ {feeder: '.module.post.original.open .module.post.original .post-data'}, openConversationClick);
if ($.Options.unicodeConversion.val === 'disable')
$('.undo-unicode').on('click', undoLastUnicode).css('display', 'none');
diff --git a/js/options.js b/js/options.js
index b047087..6941387 100644
--- a/js/options.js
+++ b/js/options.js
@@ -373,7 +373,7 @@ function tickOptionsPostPreview() {
var imgPreviewCont = elem.find('.preview-container');
elem.children().first().html(htmlFormatMsg(
- polyglot.t('post_preview_dummy', {logo: '/img/twister_mini.png', site: 'http://twister.net.co'}), []));
+ polyglot.t('post_preview_dummy', {logo: '/img/twister_mini.png', site: 'http://twister.net.co'})).html);
if ($.Options.displayPreview.val === 'enable') {
imgPreviewCont.empty();
diff --git a/js/tmobile.js b/js/tmobile.js
index 32603a6..24a0b00 100644
--- a/js/tmobile.js
+++ b/js/tmobile.js
@@ -488,6 +488,15 @@ function handleAvatarFileSelectMobile(evt) {
}
}
+function openConversationClick(event) {
+ event.stopPropagation();
+ event.preventDefault();
+
+ var userpost = $(event.target).closest(event.data.feeder).attr('data-userpost');
+
+ $.mobile.showPageLoadingMsg();
+ $.mobile.navigate('#post?userpost=' + encodeURIComponent(userpost));
+}
function clearProfilePage() {
diff --git a/js/twister_actions.js b/js/twister_actions.js
index e5ea597..e6b6061 100644
--- a/js/twister_actions.js
+++ b/js/twister_actions.js
@@ -263,30 +263,60 @@ function newPostMsg(msg, $postOrig) {
}
}
-function newRtMsg($postOrig) {
- var content_to_rt = $postOrig.attr('data-content_to_rt');
- var content_to_sigrt = $postOrig.attr('data-content_to_sigrt');
+function newRtMsg(postData, msg) {
+ var userpost = $.evalJSON(postData.attr('data-content_to_rt'));
+ var sig_userpost;
+
+ if (userpost.rt) {
+ if (parseInt(twisterVersion) <= 93000) {
+ alert(polyglot.t('error',
+ {error: 'can\'t handle retwisting of commented retwisted twists with daemon version '
+ + twisterDisplayVersion + ' and below of that. please upgrade it.'}
+ ));
+
+ return;
+ } else {
+ // dropping of rt to avoid overquoting
+ sig_userpost = userpost.sig_wort;
+ userpost.rt = undefined;
+ userpost.sig_rt = undefined;
+ }
+ } else {
+ sig_userpost = postData.attr('data-content_to_sigrt');
+ }
- var sig_userpost = String(content_to_sigrt);
- var userpost = $.evalJSON(String(content_to_rt));
- var rtObj = { sig_userpost :sig_userpost, userpost : userpost };
+ if (typeof sig_userpost === 'undefined') {
+ alert(polyglot.t('error',
+ {error: 'can\'t sig_userpost is not deifned'}
+ ));
- if( lastPostId != undefined ) {
- if ( typeof _sendedPostIDs !== 'undefined' )
+ return;
+ }
+
+ userpost.sig_wort = undefined;
+
+ var rtObj = {sig_userpost: sig_userpost, userpost: userpost};
+
+ if (typeof lastPostId !== 'undefined') {
+ if (typeof _sendedPostIDs !== 'undefined')
_sendedPostIDs.push(lastPostId + 1);
- var params = [defaultScreenName, lastPostId+1, rtObj]
+ var params = [defaultScreenName, lastPostId + 1, rtObj];
- twisterRpc("newrtmsg", params,
- function(arg, ret) { incLastPostId(); }, null,
- function(arg, ret) { var msg = ("message" in ret) ? ret.message : ret;
- alert(polyglot.t("ajax_error", { error: msg })); }, null);
+ if (typeof msg !== 'undefined')
+ params.push(msg);
+
+ twisterRpc('newrtmsg', params,
+ function(arg, ret) {incLastPostId();}, null,
+ function(arg, ret) {var msg = ('message' in ret) ? ret.message : ret;
+ alert(polyglot.t('ajax_error', {error: msg}));
+ }, null
+ );
} else {
- alert(polyglot.t("Internal error: lastPostId unknown (following yourself may fix!)"));
+ alert(polyglot.t('Internal error: lastPostId unknown (following yourself may fix!)'));
}
}
-
function updateProfileData(profileModalContent, username) {
//profileModalContent.find("a").attr("href",$.MAL.userUrl(username));
diff --git a/js/twister_formatpost.js b/js/twister_formatpost.js
index 52adcad..c09a9f5 100644
--- a/js/twister_formatpost.js
+++ b/js/twister_formatpost.js
@@ -3,12 +3,18 @@
//
// Format JSON posts and DMs to HTML.
+var _templatePostRtReference
+var _templatePostRtBy
var _htmlFormatMsgLinkTemplateExternal;
var _htmlFormatMsgLinkTemplateUser;
var _htmlFormatMsgLinkTemplateHashtag;
$(document).ready(function() {
// we're setting it here for perfomance improvement purpose // to not search and prepare it for for every post every time
+ _templatePostRtReference = $('#post-rt-reference-template').children().clone(true);
+ _templatePostRtReference.find('.post-text')
+ .on('click', {feeder: '.post-rt-reference'}, openConversationClick);
+ _templatePostRtBy = $('#post-retransmited-by-template').children().clone(true);
_htmlFormatMsgLinkTemplateExternal = $('#external-page-link-template')
if (_htmlFormatMsgLinkTemplateExternal.length) {
_htmlFormatMsgLinkTemplateExternal = _htmlFormatMsgLinkTemplateExternal[0].cloneNode();
@@ -28,7 +34,19 @@ $(document).ready(function() {
// format "userpost" to html element
// kind = "original"/"ancestor"/"descendant"
-function postToElem( post, kind, promoted ) {
+function postToElem(post, kind, promoted) {
+
+ function setPostCommon(elem, username, time) {
+ var postInfoName = elem.find('.post-info-name')
+ .text(username).attr('href', $.MAL.userUrl(username));
+
+ getFullname(username, postInfoName);
+ //elem.find('.post-info-tag').text("@" + username); // FIXME
+ getAvatar(username, elem.find('.avatar'));
+
+ elem.find('.post-info-time').text(timeGmtToText(time)).attr('title', timeSincePost(time));
+ }
+
/*
"userpost" :
{
@@ -50,115 +68,153 @@ function postToElem( post, kind, promoted ) {
"sig_userpost" : signature by userpost.n
*/
+ var username, k, time, msg, rt, content_to_rt, content_to_sigrt, retweeted_by;
+
// Obtain data from userpost
- var postJson = $.toJSON(post);
- var userpost = post["userpost"];
- if( "rt" in userpost ) {
- var rt = userpost["rt"];
- var n = rt["n"];
- var k = rt["k"];
- var t = rt["time"];
- var msg = rt["msg"];
- var content_to_rt = $.toJSON(rt);
- var content_to_sigrt = userpost["sig_rt"];
- var retweeted_by = userpost["n"];
+ var userpost = post.userpost;
+
+ if (post.sig_wort)
+ userpost.sig_wort = post.sig_wort;
+
+ if (userpost.rt) {
+ rt = userpost.rt;
+ if (userpost.msg) {
+ username = userpost.n;
+ k = userpost.k;
+ time = userpost.time;
+ msg = userpost.msg;
+ content_to_rt = $.toJSON(userpost);
+ content_to_sigrt = post.sig_userpost;
+ } else {
+ username = rt.n;
+ k = rt.k;
+ time = rt.time;
+ msg = rt.msg;
+ content_to_rt = $.toJSON(rt);
+ content_to_sigrt = userpost.sig_rt;
+ }
+ retweeted_by = userpost.n;
} else {
- var n = userpost["n"];
- var k = userpost["k"];
- var t = userpost["time"];
- var msg = userpost["msg"]
- var content_to_rt = $.toJSON(userpost);
- var content_to_sigrt = post["sig_userpost"];
- var retweeted_by = undefined;
+ username = userpost.n;
+ k = userpost.k;
+ time = userpost.time;
+ msg = userpost.msg;
+ content_to_rt = $.toJSON(userpost);
+ content_to_sigrt = post.sig_userpost;
}
// Now create the html elements
var elem = $.MAL.getPostTemplate().clone(true);
elem.removeAttr('id')
.addClass(kind)
- .attr('data-time', t)
+ .attr('data-time', time)
;
- if( post['isNew'] )
+ if (post.isNew)
elem.addClass('new');
var postData = elem.find('.post-data');
postData.addClass(kind)
- .attr('data-userpost', postJson)
+ .attr('data-userpost', $.toJSON(post))
.attr('data-content_to_rt', content_to_rt)
.attr('data-content_to_sigrt', content_to_sigrt)
- .attr('data-screen-name', n)
+ .attr('data-screen-name', username)
.attr('data-id', k)
- .attr('data-lastk', userpost["lastk"])
+ .attr('data-lastk', userpost.lastk)
.attr('data-text', msg)
;
- if( 'reply' in userpost ) {
+ if (userpost.reply) {
postData.attr('data-replied-to-screen-name', userpost.reply.n)
.attr('data-replied-to-id', userpost.reply.k)
.find('.post-expand').text(polyglot.t('Show conversation'))
;
- } else if ( 'rt' in userpost && 'reply' in userpost.rt ) {
+ } else if (userpost.rt && userpost.rt.reply) {
postData.attr('data-replied-to-screen-name', userpost.rt.reply.n)
.attr('data-replied-to-id', userpost.rt.reply.k)
.find('.post-expand').text(polyglot.t('Show conversation'))
;
}
- var postInfoName = elem.find('.post-info-name');
- postInfoName.text(n).attr('href', $.MAL.userUrl(n));
- getFullname( n, postInfoName );
- //elem.find('.post-info-tag').text("@" + n);
- getAvatar( n, elem.find('.avatar') );
- elem.find('.post-info-time').text(timeGmtToText(t)).attr('title', timeSincePost(t));
+ setPostCommon(elem, username, time);
- var mentions = [];
- elem.find('.post-text').html(htmlFormatMsg(msg, mentions));
- postData.attr('data-text-mentions', mentions);
-
- var replyTo = '';
- if( n !== defaultScreenName )
- replyTo += '@' + n + ' ';
- for (var i = 0; i < mentions.length; i++) {
- if (mentions[i] !== n && mentions[i] !== defaultScreenName)
- replyTo += '@' + mentions[i] + ' ';
+ msg = htmlFormatMsg(msg);
+ elem.find('.post-text').html(msg.html);
+ postData.attr('data-text-mentions', msg.mentions.join()); // FIXME no idea why do we need this attribute since we don't use it but use data-reply-to instead
+
+ if (username !== defaultScreenName) {
+ if (msg.mentions.indexOf(username) === -1)
+ msg.mentions.splice(0, 0, username);
}
+ for (var i = msg.mentions.indexOf(defaultScreenName); i !== -1; i = msg.mentions.indexOf(defaultScreenName))
+ msg.mentions.splice(i, 1);
+
+ if (msg.mentions.length)
+ var replyTo = '@' + msg.mentions.join(' @') + ' ';
+ else
+ var replyTo = '';
var postTextArea = elem.find('.post-area-new textarea');
postTextArea.attr('data-reply-to', replyTo);
+
if (!defaultScreenName)
postTextArea.attr('placeholder', polyglot.t('You have to log in to post replies.'));
else
- postTextArea.attr('placeholder', polyglot.t('reply_to', { fullname: replyTo })+ '...');
+ postTextArea.attr('placeholder', polyglot.t('reply_to', {fullname: replyTo})+ '...');
postData.attr('data-reply-to', replyTo);
- if( retweeted_by != undefined ) {
- elem.find('.post-context').show();
- elem.find('.post-retransmited-by')
- .attr('href', $.MAL.userUrl(retweeted_by))
- .text('@' + retweeted_by)
- ;
+ if (typeof retweeted_by !== 'undefined') {
+ var postContext = elem.find('.post-context');
+ if (userpost.msg) {
+ postContext.append(_templatePostRtReference.clone(true))
+ .find('.post-rt-reference')
+ .attr('data-screen-name', rt.n)
+ .attr('data-id', rt.k)
+ .attr('data-userpost', $.toJSON({userpost: rt, sig_userpost: userpost.sig_rt}))
+ .find('.post-text').html(htmlFormatMsg(rt.msg).html)
+ ;
+ setPostCommon(postContext, rt.n, rt.time);
+ } else {
+ postContext.append(_templatePostRtBy.clone(true))
+ .find('.post-retransmited-by')
+ .attr('href', $.MAL.userUrl(retweeted_by)).text('@' + retweeted_by)
+ ;
+ }
+ postContext.show();
}
- if (typeof(promoted) !== 'undefined' && promoted) {
+ if (typeof promoted !== 'undefined' && promoted) {
elem.find('.post-propagate').remove();
postData.attr('data-promoted', 1);
- postData.attr('data-screen-name', '!' + n);
+ postData.attr('data-screen-name', '!' + username);
} else {
- setPostInfoSent(userpost["n"], userpost["k"], elem.find('.post-info-sent'));
+ setPostInfoSent(userpost.n, userpost.k, elem.find('.post-info-sent'));
if ($.Options.filterLang.val !== 'disable' && $.Options.filterLangSimulate.val) {
// FIXME it's must be stuff from template actually
- if (typeof(post['langFilter']) !== 'undefined') {
- if (typeof(post['langFilter']['prob'][0]) !== 'undefined')
- var mlm = ' // '+polyglot.t('Most possible language: this', {'this': ''+post['langFilter']['prob'][0].toString()+''});
+ if (typeof post.langFilter !== 'undefined') {
+ if (typeof post.langFilter.prob[0] !== 'undefined')
+ var mlm = ' // ' + polyglot.t('Most possible language: this',
+ {'this': '' + post.langFilter.prob[0].toString() + ''});
else
var mlm = '';
- elem.append('
'+polyglot.t('This post is treated by language filter', {'treated': ''+((post['langFilter']['pass']) ? polyglot.t('passed') : polyglot.t('blocked'))+''})+'