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 @@ @@ -185,7 +185,6 @@
<!-- END postboard-top -->
<ol id="posts" class="postboard-posts">
<!-- use "post-template" here -->
</ol>
<div class="postboard-loading" style="display: none;">
@ -349,7 +348,8 @@ @@ -349,7 +348,8 @@
<a class="shorten-uri">shorten URL</a>
</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=""
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>
@ -391,7 +391,8 @@ @@ -391,7 +391,8 @@
</div> <!-- expanded-content -->
<div class="new-replies-available"><button></button></div>
</div> <!-- post-data -->
</li> <!-- post-template -->
</li>
</div>
<div id="template-post-rt-reference">
<div class="post-rt-reference">

48
js/interface_common.js

@ -2775,25 +2775,8 @@ function initInterfaceCommon() { @@ -2775,25 +2775,8 @@ function initInterfaceCommon() {
$('.module.mini-profile .open-followers').on('mouseup', {route: '#followers'}, routeOnClick);
$('.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-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')
.on('click', function (e) {composeNewPost(e, $(this));})
.clickoutside(unfocusPostAreaNew)
@ -2809,10 +2792,6 @@ function initInterfaceCommon() { @@ -2809,10 +2792,6 @@ function initInterfaceCommon() {
$('.modal-propagate').on('click', retweetSubmit);
$('.modal-fav-public').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')
$('.undo-unicode').on('click', undoLastUnicode).css('display', 'none');
else
@ -2897,6 +2876,33 @@ function initInterfaceCommon() { @@ -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) {

2
js/interface_home.js

@ -51,7 +51,7 @@ var InterfaceFunctions = function() { @@ -51,7 +51,7 @@ var InterfaceFunctions = function() {
if (!defaultScreenName) {
$('.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').prop('disabled', true);
getElem('.post-area-new > textarea', true).prop('disabled', true);
$miniProfile.find(".mini-profile-name").text("guest");
$miniProfile.find(".posts-count").text("0");
$miniProfile.find(".following-count").text("0");

14
js/mobile_abstract.js

@ -140,20 +140,6 @@ var MAL = function() @@ -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
this.userUrl = function(username) {
//if( $.hasOwnProperty("mobile") ) {

15
js/tmobile.js

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

7
js/twister_formatpost.js

@ -30,7 +30,7 @@ $(function () { @@ -30,7 +30,7 @@ $(function () {
// format "userpost" to html element
// kind = "original"/"ancestor"/"descendant"
function postToElem(post, kind, promoted) {
function postToElem(post, kind, promoted, templatePost) {
/*
"userpost" :
{
@ -99,8 +99,11 @@ function postToElem(post, kind, promoted) { @@ -99,8 +99,11 @@ function postToElem(post, kind, promoted) {
msg = msg.slice(0,$.Options.MaxPostDisplayChars.val) + "\u2026";
}
if (!templatePost)
templatePost = twister.tmpl.post;
// 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')
.addClass(kind)
.attr('data-time', time)

12
tmobile.html

@ -738,7 +738,8 @@ @@ -738,7 +738,8 @@
</li>
</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"/>
<div class="post-data" data-userpost="" data-content_to_rt="" data-content_to_sigrt=""
data-screen-name="" data-id="" data-text="" data-text-mentions="">
@ -750,7 +751,8 @@ @@ -750,7 +751,8 @@
<p class="post-text no-ellipsis"></p>
<div class="post-context" style="display: none;"></div>
</div>
</li> <!-- post-template -->
</li>
</div>
<div id="post-preview-template">
<div id="post-preview">
@ -765,7 +767,8 @@ @@ -765,7 +767,8 @@
<a class="shorten-uri">shorten URL</a>
</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"/>
<div class="post-data" data-userpost="" data-content_to_rt="" data-content_to_sigrt=""
data-screen-name="" data-id="" data-text="" data-text-mentions="">
@ -795,7 +798,8 @@ @@ -795,7 +798,8 @@
</div>
</div>
</div> <!-- post-data -->
</li> <!-- post-template -->
</li>
</div>
<div id="template-post-rt-reference">
<div class="post-rt-reference">

Loading…
Cancel
Save