Browse Source

rewrite a post's template related stuff

readme-update
Simon Grim 6 years ago
parent
commit
fa79bc595c
  1. 7
      home.html
  2. 48
      js/interface_common.js
  3. 2
      js/interface_home.js
  4. 14
      js/mobile_abstract.js
  5. 15
      js/tmobile.js
  6. 7
      js/twister_formatpost.js
  7. 12
      tmobile.html

7
home.html

@ -185,7 +185,6 @@
<!-- END postboard-top --> <!-- END postboard-top -->
<ol id="posts" class="postboard-posts"> <ol id="posts" class="postboard-posts">
<!-- use "post-template" here -->
</ol> </ol>
<div class="postboard-loading" style="display: none;"> <div class="postboard-loading" style="display: none;">
@ -349,7 +348,8 @@
<a class="shorten-uri">shorten URL</a> <a class="shorten-uri">shorten URL</a>
</div> </div>
<li id="post-template" class="module post" data-time=""> <div id="template-post">
<li class="module post" data-time="">
<div class="post-data" data-userpost="" data-content_to_rt="" data-content_to_sigrt="" <div class="post-data" data-userpost="" data-content_to_rt="" data-content_to_sigrt=""
data-screen-name="" data-id="" data-text="" data-text-mentions=""> data-screen-name="" data-id="" data-text="" data-text-mentions="">
<div class="post-photo"><img class="avatar" src="img/grayed_avatar_placeholder_24.png" alt="user-photo"/></div> <div class="post-photo"><img class="avatar" src="img/grayed_avatar_placeholder_24.png" alt="user-photo"/></div>
@ -391,7 +391,8 @@
</div> <!-- expanded-content --> </div> <!-- expanded-content -->
<div class="new-replies-available"><button></button></div> <div class="new-replies-available"><button></button></div>
</div> <!-- post-data --> </div> <!-- post-data -->
</li> <!-- post-template --> </li>
</div>
<div id="template-post-rt-reference"> <div id="template-post-rt-reference">
<div class="post-rt-reference"> <div class="post-rt-reference">

48
js/interface_common.js

@ -2775,25 +2775,8 @@ function initInterfaceCommon() {
$('.module.mini-profile .open-followers').on('mouseup', {route: '#followers'}, routeOnClick); $('.module.mini-profile .open-followers').on('mouseup', {route: '#followers'}, routeOnClick);
$('.post-text').on('click', 'a', muteEvent); $('.post-text').on('click', 'a', muteEvent);
$('.post-reply').on('click', postReplyClick);
$('.post-propagate').on('click', reTwistPopup);
$('.post-favorite').on('click', favPopup);
$('.userMenu-config').clickoutside(closeThis.bind($('.config-menu'))); $('.userMenu-config').clickoutside(closeThis.bind($('.config-menu')));
$('.userMenu-config-dropdown').on('click', dropDownMenu); $('.userMenu-config-dropdown').on('click', dropDownMenu);
$('#post-template.module.post').on('click', function (event) {
if (event.button === 0 && window.getSelection() == 0)
postExpandFunction(event, $(this));
})
.find('.new-replies-available button').hide()
.on('click', function (event) {
event.stopPropagation();
$(event.target).hide()
.closest('li.post').next('.post-replies').find('.post.pending')
.removeClass('pending').slideDown('fast')
;
})
.closest('.post-data').find('.post-stats').hide()
;
$('.post-area-new') $('.post-area-new')
.on('click', function (e) {composeNewPost(e, $(this));}) .on('click', function (e) {composeNewPost(e, $(this));})
.clickoutside(unfocusPostAreaNew) .clickoutside(unfocusPostAreaNew)
@ -2809,10 +2792,6 @@ function initInterfaceCommon() {
$('.modal-propagate').on('click', retweetSubmit); $('.modal-propagate').on('click', retweetSubmit);
$('.modal-fav-public').on('click', favSubmit); $('.modal-fav-public').on('click', favSubmit);
$('.modal-fav-private').on('click', favSubmit); $('.modal-fav-private').on('click', favSubmit);
$('.expanded-content .show-more').on('mouseup',
{feeder: '.module.post.original.open .module.post.original .post-data'}, handleClickOpenConversation)
.on('click', muteEvent) // to prevent post collapsing
;
if ($.Options.unicodeConversion.val === 'disable') if ($.Options.unicodeConversion.val === 'disable')
$('.undo-unicode').on('click', undoLastUnicode).css('display', 'none'); $('.undo-unicode').on('click', undoLastUnicode).css('display', 'none');
else else
@ -2897,6 +2876,33 @@ function initInterfaceCommon() {
} }
) )
; ;
twister.tmpl.post = extractTemplate('#template-post')
.on('click', function (event) {
if (event.button === 0 && window.getSelection() == 0)
postExpandFunction(event, $(this));
})
;
twister.tmpl.post.find('.post-reply').on('click', postReplyClick);
twister.tmpl.post.find('.post-propagate').on('click', reTwistPopup);
twister.tmpl.post.find('.post-favorite').on('click', favPopup);
twister.tmpl.post.find('.expanded-content .show-more')
.on('mouseup',
{feeder: '.module.post.original.open .module.post.original .post-data'},
handleClickOpenConversation
)
.on('click', muteEvent) // to prevent post collapsing
;
twister.tmpl.post.find('.new-replies-available button').hide()
.on('click', function (event) {
event.stopPropagation();
$(event.target).hide()
.closest('li.post').next('.post-replies').find('.post.pending')
.removeClass('pending').slideDown('fast')
;
})
;
twister.tmpl.post.find('.post-stats').hide();
} }
function extractTemplate(selector) { function extractTemplate(selector) {

2
js/interface_home.js

@ -51,7 +51,7 @@ var InterfaceFunctions = function() {
if (!defaultScreenName) { if (!defaultScreenName) {
$('.userMenu-profile > a').attr('href', '#/login').text(polyglot.t('Login')); $('.userMenu-profile > a').attr('href', '#/login').text(polyglot.t('Login'));
$(".post-area-new > textarea").attr("placeholder",polyglot.t("You have to log in to post messages.")); $(".post-area-new > textarea").attr("placeholder",polyglot.t("You have to log in to post messages."));
$('.post-area-new > textarea').prop('disabled', true); getElem('.post-area-new > textarea', true).prop('disabled', true);
$miniProfile.find(".mini-profile-name").text("guest"); $miniProfile.find(".mini-profile-name").text("guest");
$miniProfile.find(".posts-count").text("0"); $miniProfile.find(".posts-count").text("0");
$miniProfile.find(".following-count").text("0"); $miniProfile.find(".following-count").text("0");

14
js/mobile_abstract.js

@ -140,20 +140,6 @@ var MAL = function()
} }
} }
this.setPostTemplate = function(p) {
if( $.hasOwnProperty("mobile") ) {
this.postTemplate = p;
}
}
this.getPostTemplate = function() {
if( $.hasOwnProperty("mobile") ) {
return this.postTemplate;
} else {
return $("#post-template");
}
}
// how do we map usernames into urls // how do we map usernames into urls
this.userUrl = function(username) { this.userUrl = function(username) {
//if( $.hasOwnProperty("mobile") ) { //if( $.hasOwnProperty("mobile") ) {

15
js/tmobile.js

@ -5,6 +5,7 @@
var twisterInitialized = false; var twisterInitialized = false;
var handlersInstalled = false; var handlersInstalled = false;
function initializeTwister( redirectNetwork, redirectLogin, cbFunc, cbArg ) { function initializeTwister( redirectNetwork, redirectLogin, cbFunc, cbArg ) {
if( !handlersInstalled ) { if( !handlersInstalled ) {
interfaceNetworkHandlers(); interfaceNetworkHandlers();
@ -18,7 +19,6 @@ function initializeTwister( redirectNetwork, redirectLogin, cbFunc, cbArg ) {
}); });
// home screen timeline refresh button // home screen timeline refresh button
$('.timeline-refresh').on('click', function (e) { $('.timeline-refresh').on('click', function (e) {
$.MAL.setPostTemplate( $("#post-template-home") );
requestTimelineUpdate("latest",postsPerRefresh,followingUsers); requestTimelineUpdate("latest",postsPerRefresh,followingUsers);
$.mobile.silentScroll(0); $.mobile.silentScroll(0);
}); });
@ -31,6 +31,10 @@ function initializeTwister( redirectNetwork, redirectLogin, cbFunc, cbArg ) {
; ;
handlersInstalled = true; handlersInstalled = true;
twister.tmpl.post = extractTemplate('#template-post');
twister.tmpl.postFull = extractTemplate('#template-post-full');
twister.tmpl.postFull.find('.post-stats').hide();
} }
if( twisterInitialized ) { if( twisterInitialized ) {
@ -103,7 +107,6 @@ var router=new $.mobile.Router(
cleanupStorage(); cleanupStorage();
getFullname( defaultScreenName, $("#home .rtitle")); getFullname( defaultScreenName, $("#home .rtitle"));
$(".mentions-count").attr("href","#mentions?user="+defaultScreenName ); $(".mentions-count").attr("href","#mentions?user="+defaultScreenName );
$.MAL.setPostTemplate( $("#post-template-home") );
requestTimelineUpdate("latestFirstTime",postsPerRefresh,followingUsers); requestTimelineUpdate("latestFirstTime",postsPerRefresh,followingUsers);
} }
}); });
@ -127,7 +130,6 @@ var router=new $.mobile.Router(
} }
$.mobile.loading('show'); $.mobile.loading('show');
$.MAL.setPostTemplate( $("#post-template-home") );
updateProfileData( $("#profile"), user); updateProfileData( $("#profile"), user);
}); });
}, },
@ -171,8 +173,7 @@ var router=new $.mobile.Router(
initializeTwister( true, true, function() { initializeTwister( true, true, function() {
var $ulPost = $("#post ul.posts"); var $ulPost = $("#post ul.posts");
$ulPost.text(""); $ulPost.text("");
$.MAL.setPostTemplate( $("#post-template-post") ); var originalLi = postToElem(JSON.parse(params.userpost), 'original', false, twister.tmpl.postFull);
var originalLi = postToElem(JSON.parse(params.userpost), 'original');
$ulPost.append(originalLi); $ulPost.append(originalLi);
$ulPost.find(".post-interactions").trigger('create'); $ulPost.find(".post-interactions").trigger('create');
$ulPost.listview('refresh'); $ulPost.listview('refresh');
@ -201,7 +202,6 @@ var router=new $.mobile.Router(
var $replyOriginal = $(".reply-original-post") var $replyOriginal = $(".reply-original-post")
$replyOriginal.html(""); $replyOriginal.html("");
if( params && params.hasOwnProperty("userpost") ) { if( params && params.hasOwnProperty("userpost") ) {
$.MAL.setPostTemplate( $("#post-template-home") );
var originalLi = postToElem(JSON.parse(params.userpost), 'original'); var originalLi = postToElem(JSON.parse(params.userpost), 'original');
$replyOriginal.append(originalLi); $replyOriginal.append(originalLi);
$replyOriginal.listview('refresh'); $replyOriginal.listview('refresh');
@ -215,7 +215,6 @@ var router=new $.mobile.Router(
initializeTwister( true, true, function() { initializeTwister( true, true, function() {
var $rtOriginal = $(".rt-original-post") var $rtOriginal = $(".rt-original-post")
$rtOriginal.html(""); $rtOriginal.html("");
$.MAL.setPostTemplate( $("#post-template-home") );
var originalLi = postToElem(JSON.parse(params.userpost), 'original'); var originalLi = postToElem(JSON.parse(params.userpost), 'original');
$rtOriginal.append(originalLi); $rtOriginal.append(originalLi);
$rtOriginal.listview('refresh'); $rtOriginal.listview('refresh');
@ -521,7 +520,6 @@ function reachedScrollBottom() {
var curPage = $.mobile.activePage.attr("id"); var curPage = $.mobile.activePage.attr("id");
if( curPage == "home" ) { if( curPage == "home" ) {
if( timelineLoaded ) { if( timelineLoaded ) {
$.MAL.setPostTemplate( $("#post-template-home") );
requestTimelineUpdate("older", postsPerRefresh, followingUsers); requestTimelineUpdate("older", postsPerRefresh, followingUsers);
} }
} }
@ -544,7 +542,6 @@ function encode_utf8(s) {
var tmobileQueryReq; var tmobileQueryReq;
function setupHashtagOrMention(board, query, resource) { function setupHashtagOrMention(board, query, resource) {
$.MAL.setPostTemplate( $("#post-template-home") );
$.mobile.loading('show'); $.mobile.loading('show');
board.empty(); board.empty();

7
js/twister_formatpost.js

@ -30,7 +30,7 @@ $(function () {
// format "userpost" to html element // format "userpost" to html element
// kind = "original"/"ancestor"/"descendant" // kind = "original"/"ancestor"/"descendant"
function postToElem(post, kind, promoted) { function postToElem(post, kind, promoted, templatePost) {
/* /*
"userpost" : "userpost" :
{ {
@ -99,8 +99,11 @@ function postToElem(post, kind, promoted) {
msg = msg.slice(0,$.Options.MaxPostDisplayChars.val) + "\u2026"; msg = msg.slice(0,$.Options.MaxPostDisplayChars.val) + "\u2026";
} }
if (!templatePost)
templatePost = twister.tmpl.post;
// Now create the html elements // Now create the html elements
var elem = $.MAL.getPostTemplate().clone(true).appendTo(twister.html.detached); var elem = templatePost.clone(true).appendTo(twister.html.detached);
elem.removeAttr('id') elem.removeAttr('id')
.addClass(kind) .addClass(kind)
.attr('data-time', time) .attr('data-time', time)

12
tmobile.html

@ -738,7 +738,8 @@
</li> </li>
</div> </div>
<li id="post-template-home" class="post-li module post" data-time=""> <div id="template-post">
<li class="post-li module post" data-time="">
<img class="avatar" src="img/grayed_avatar_placeholder_24.png" alt="user-photo"/> <img class="avatar" src="img/grayed_avatar_placeholder_24.png" alt="user-photo"/>
<div class="post-data" data-userpost="" data-content_to_rt="" data-content_to_sigrt="" <div class="post-data" data-userpost="" data-content_to_rt="" data-content_to_sigrt=""
data-screen-name="" data-id="" data-text="" data-text-mentions=""> data-screen-name="" data-id="" data-text="" data-text-mentions="">
@ -750,7 +751,8 @@
<p class="post-text no-ellipsis"></p> <p class="post-text no-ellipsis"></p>
<div class="post-context" style="display: none;"></div> <div class="post-context" style="display: none;"></div>
</div> </div>
</li> <!-- post-template --> </li>
</div>
<div id="post-preview-template"> <div id="post-preview-template">
<div id="post-preview"> <div id="post-preview">
@ -765,7 +767,8 @@
<a class="shorten-uri">shorten URL</a> <a class="shorten-uri">shorten URL</a>
</div> </div>
<li id="post-template-post" class="module post" data-time=""> <div id="template-post-full">
<li class="module post" data-time="">
<img class="avatar" src="img/grayed_avatar_placeholder_24.png" alt="user-photo"/> <img class="avatar" src="img/grayed_avatar_placeholder_24.png" alt="user-photo"/>
<div class="post-data" data-userpost="" data-content_to_rt="" data-content_to_sigrt="" <div class="post-data" data-userpost="" data-content_to_rt="" data-content_to_sigrt=""
data-screen-name="" data-id="" data-text="" data-text-mentions=""> data-screen-name="" data-id="" data-text="" data-text-mentions="">
@ -795,7 +798,8 @@
</div> </div>
</div> </div>
</div> <!-- post-data --> </div> <!-- post-data -->
</li> <!-- post-template --> </li>
</div>
<div id="template-post-rt-reference"> <div id="template-post-rt-reference">
<div class="post-rt-reference"> <div class="post-rt-reference">

Loading…
Cancel
Save