first commit
This commit is contained in:
commit
8e0c8a1497
8 changed files with 380 additions and 0 deletions
4
README.md
Normal file
4
README.md
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
bungloo-plugins
|
||||||
|
===============
|
||||||
|
|
||||||
|
A set of plugins for Tent client Bungloo
|
43
it.to.work/hide-replies.css
Normal file
43
it.to.work/hide-replies.css
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
/* !HIDE REPLIES */
|
||||||
|
.hide_replies {
|
||||||
|
width: 18px;
|
||||||
|
height: 12px;
|
||||||
|
float: right;
|
||||||
|
margin-left: 3px;
|
||||||
|
visibility: hidden;
|
||||||
|
font-size: 2em;
|
||||||
|
line-height: 0.8em;
|
||||||
|
color: #535353;
|
||||||
|
}
|
||||||
|
li:hover aside .hide_replies {
|
||||||
|
visibility: visible;
|
||||||
|
}
|
||||||
|
li:hover aside .hide_replies:before {
|
||||||
|
content: "\293C";
|
||||||
|
}
|
||||||
|
li.has-hidden-replies:hover aside .hide_replies:before {
|
||||||
|
content: "\293D";
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
.has-hidden-replies {
|
||||||
|
border-left: 5px solid fuchsia;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
li[class*='in-reply-to-'] {
|
||||||
|
-webkit-transition: all 0.5s ease;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
.hidden-reply {
|
||||||
|
/* border-left: 5px solid red; */
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
.is-reply {
|
||||||
|
border-left: 5px solid red;
|
||||||
|
}
|
||||||
|
.has-reply {
|
||||||
|
border-left: 5px solid fuchsia;
|
||||||
|
}
|
||||||
|
*/
|
101
it.to.work/hide-replies.js
Normal file
101
it.to.work/hide-replies.js
Normal file
|
@ -0,0 +1,101 @@
|
||||||
|
define(['module', 'jquery', 'plugins/it.to.work/scrollingElement'], function(myself, $, scrollingElement) {
|
||||||
|
|
||||||
|
return new function() {
|
||||||
|
|
||||||
|
//include css file
|
||||||
|
$('<link/>', {
|
||||||
|
rel: 'stylesheet',
|
||||||
|
type: 'text/css',
|
||||||
|
href: myself.uri.replace(/.js$/, '.css')
|
||||||
|
}).appendTo('head');
|
||||||
|
|
||||||
|
$(document).ready(function() {
|
||||||
|
if (bungloo.timeline) {
|
||||||
|
bungloo.timeline.body.addEventListener('DOMNodeInserted', hideReplies, false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
function hideReplies(e) {
|
||||||
|
var element = e.target;
|
||||||
|
if (element.nodeName != 'LI')
|
||||||
|
return;
|
||||||
|
var parent = element.parentNode;
|
||||||
|
if (parent != bungloo.timeline.body) return;
|
||||||
|
|
||||||
|
// mark the post as reply
|
||||||
|
var mentions = element.status.mentions;
|
||||||
|
for (var i=0; i<mentions.length; i++) {
|
||||||
|
if (mentions[i].hasOwnProperty('post')) {
|
||||||
|
//add a class with the parent post
|
||||||
|
var parentPostId = mentions[i].post;
|
||||||
|
$(element).addClass('in-reply-to-'+parentPostId);
|
||||||
|
|
||||||
|
var parentPost = $('#post-'+parentPostId+'-timeline');
|
||||||
|
addHideRepliesButton(parentPost[0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// check if there are replies for this post
|
||||||
|
var replies = $('.in-reply-to-'+element.status.id);
|
||||||
|
if (replies.length > 0) {
|
||||||
|
addHideRepliesButton(element);
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
var addHideRepliesButton = function(element) {
|
||||||
|
//add the hide button
|
||||||
|
//var buttons_container = $(element).find('.reply_to').parent()[0];
|
||||||
|
var buttons_container = element.getElementsByTagName('aside')[0];
|
||||||
|
if ($(buttons_container).find('.hide_replies').length == 0) {
|
||||||
|
var a = document.createElement('a');
|
||||||
|
var hideRepliesButton = a.cloneNode();
|
||||||
|
hideRepliesButton.className = 'hide_replies';
|
||||||
|
//hideRepliesButton.innerText = '⇞';
|
||||||
|
hideRepliesButton.href = '#';
|
||||||
|
hideRepliesButton.onclick = function() {
|
||||||
|
var classaction = 'add';
|
||||||
|
if ($(element).hasClass('has-hidden-replies')) {
|
||||||
|
classaction = 'remove';
|
||||||
|
}
|
||||||
|
$(element).toggleClass('has-hidden-replies');
|
||||||
|
|
||||||
|
var st_pre = scrollingElement.scrollTop();
|
||||||
|
var ot_pre = $(element).offset().top;
|
||||||
|
|
||||||
|
processPost([element], classaction);
|
||||||
|
|
||||||
|
var ot_post = $(element).offset().top;
|
||||||
|
var st_post = st_pre - ot_pre + ot_post;
|
||||||
|
|
||||||
|
scrollingElement.scrollTop(st_post);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
buttons_container.appendChild(hideRepliesButton);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
var processPost = function(parentPost, classaction) {
|
||||||
|
for (var i=0; i<parentPost.length; i++) {
|
||||||
|
var parentPostId = parentPost[i].status.id;
|
||||||
|
//$(parentPost[i]).toggleClass('has-hidden-replies');
|
||||||
|
var replies = $('.in-reply-to-'+parentPostId);
|
||||||
|
if (classaction == 'add')
|
||||||
|
replies.addClass('hidden-reply');
|
||||||
|
else {
|
||||||
|
replies.removeClass('hidden-reply');
|
||||||
|
$(parentPost[i]).removeClass('has-hidden-replies');
|
||||||
|
}
|
||||||
|
//process replies
|
||||||
|
for (var j=0; j<replies.length; j++) {
|
||||||
|
processPost([replies[j]], classaction);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
});
|
5
it.to.work/marked-posts.css
Normal file
5
it.to.work/marked-posts.css
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
/* mark posts with dbl-click */
|
||||||
|
.marked {
|
||||||
|
border-left: 5px solid green;
|
||||||
|
padding-left: 3px;
|
||||||
|
}
|
32
it.to.work/marked-posts.js
Normal file
32
it.to.work/marked-posts.js
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
// mark posts with dbl-click
|
||||||
|
// $('ol').delegate('a', 'click dblclick', function(e) {
|
||||||
|
// e.stopPropagation();
|
||||||
|
// }).delegate('li', 'dblclick', function(e) {
|
||||||
|
// $(this).toggleClass('marked');
|
||||||
|
// });
|
||||||
|
|
||||||
|
/*
|
||||||
|
//Mark posts with a double click
|
||||||
|
$('ol').on('dblclick', 'li:not(a)', function(e) {
|
||||||
|
//Deselect this post as the intention was to mark it
|
||||||
|
$(this).removeClass('selected');
|
||||||
|
$(this).toggleClass('marked'); //Mark this post only
|
||||||
|
});
|
||||||
|
*/
|
||||||
|
|
||||||
|
//(Un)Mark posts with a double click
|
||||||
|
define(['module', 'jquery'], function(myself, $) {
|
||||||
|
return new function() {
|
||||||
|
|
||||||
|
//include css file
|
||||||
|
$('<link/>', {
|
||||||
|
rel: 'stylesheet',
|
||||||
|
type: 'text/css',
|
||||||
|
href: myself.uri.replace(/.js$/, '.css')
|
||||||
|
}).appendTo('head');
|
||||||
|
|
||||||
|
$('ol').on('dblclick', 'li:not(a)', function(e) {
|
||||||
|
$(this).toggleClass('marked'); //Mark this post only
|
||||||
|
});
|
||||||
|
};
|
||||||
|
});
|
10
it.to.work/scrollingElement.js
Normal file
10
it.to.work/scrollingElement.js
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
define(['jquery'], function($) {
|
||||||
|
var scrollingElement = $(document);
|
||||||
|
setTimeout(function() {
|
||||||
|
if ($('#content').css('overflow') == 'scroll')
|
||||||
|
scrollingElement = $('#content');
|
||||||
|
}, 1000);
|
||||||
|
|
||||||
|
return scrollingElement;
|
||||||
|
});
|
||||||
|
|
35
it.to.work/unread-posts.css
Normal file
35
it.to.work/unread-posts.css
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
/* !SCROLL LOCK */
|
||||||
|
#unread-badge {
|
||||||
|
color: white;
|
||||||
|
background: red;
|
||||||
|
border: 2px solid white;
|
||||||
|
border-radius: 1em;
|
||||||
|
box-shadow: 0 0 1em black;
|
||||||
|
padding: 0 0.3em;
|
||||||
|
position: absolute;
|
||||||
|
top: 65px;
|
||||||
|
right: 10px;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
||||||
|
#unread-badge:empty {
|
||||||
|
/*display: none;*/
|
||||||
|
}
|
||||||
|
|
||||||
|
.last-read-post {
|
||||||
|
border-top: 15px solid #00317a !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
#content ol > li.last-read-post:first-child {
|
||||||
|
border-top: 0 !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
#content ol > li[id^="post-"].last-read-post {
|
||||||
|
background: -webkit-linear-gradient(top, #ccf, #f0f0f0);
|
||||||
|
}
|
||||||
|
|
||||||
|
#content ol > li[id^="post-"].last-read-post:first-child {
|
||||||
|
background: -webkit-linear-gradient(top, #fff, #f0f0f0);
|
||||||
|
}
|
||||||
|
*/
|
150
it.to.work/unread-posts.js
Normal file
150
it.to.work/unread-posts.js
Normal file
|
@ -0,0 +1,150 @@
|
||||||
|
define(['module', 'jquery', 'plugins/it.to.work/scrollingElement'], function(myself, $, scrollingElement) {
|
||||||
|
|
||||||
|
return new function() {
|
||||||
|
|
||||||
|
var lastReadPost;
|
||||||
|
var unreadCount = 0;
|
||||||
|
var liWidth;
|
||||||
|
|
||||||
|
$(document).ready(function() {
|
||||||
|
//include css file
|
||||||
|
$('<link/>', {
|
||||||
|
rel: 'stylesheet',
|
||||||
|
type: 'text/css',
|
||||||
|
href: myself.uri.replace(/.js$/, '.css')
|
||||||
|
}).appendTo('head');
|
||||||
|
|
||||||
|
if (bungloo.timeline) {
|
||||||
|
|
||||||
|
setTimeout(function() {
|
||||||
|
addUnreadBadge();
|
||||||
|
|
||||||
|
bungloo.timeline.body.addEventListener( 'DOMNodeInserted', lockScroll, false );
|
||||||
|
|
||||||
|
setInterval(function() {
|
||||||
|
updateUnread();
|
||||||
|
}, 1000);
|
||||||
|
|
||||||
|
}, 15000);
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
function addUnreadBadge() {
|
||||||
|
var div = document.createElement('div');
|
||||||
|
div.id = 'unread-badge';
|
||||||
|
div.innerHTML = '1';
|
||||||
|
div.onclick = function() {
|
||||||
|
var firstUnreadTop = lastReadPost.previousElementSibling.offsetTop;
|
||||||
|
var newPosition = firstUnreadTop;
|
||||||
|
|
||||||
|
//scrollingElement.animate({ scrollTop: newPosition });
|
||||||
|
scrollingElement.scrollTop(newPosition);
|
||||||
|
|
||||||
|
updateUnread();
|
||||||
|
};
|
||||||
|
div.style.display = 'none';
|
||||||
|
|
||||||
|
$('.sidebar-timeline > a').after(div);
|
||||||
|
};
|
||||||
|
|
||||||
|
function updateUnread() {
|
||||||
|
var currentTopPost = document.elementFromPoint(70, 1);
|
||||||
|
// stops if you are not in the timeline
|
||||||
|
if ($(currentTopPost).closest('.timeline > ol').length <= 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var ctpop = $(currentTopPost).offset().top;
|
||||||
|
var dst = scrollingElement.scrollTop();
|
||||||
|
if (ctpop < dst)
|
||||||
|
currentTopPost = $(currentTopPost).next();
|
||||||
|
|
||||||
|
if (typeof lastReadPost === 'undefined' || lastReadPost.offsetHeight == 0)
|
||||||
|
lastReadPost = $('.timeline > ol > li:first')[0];
|
||||||
|
|
||||||
|
// var start = new Date().getTime();
|
||||||
|
// var postsList = $('ol.timeline > li');
|
||||||
|
var postsList = $('.timeline > ol > li').filter(':visible');
|
||||||
|
var lastReadPostIndex = postsList.index(lastReadPost);
|
||||||
|
var currentTopPostIndex = postsList.index(currentTopPost);
|
||||||
|
// var end = new Date().getTime();
|
||||||
|
// var time = end - start;
|
||||||
|
|
||||||
|
unreadCount = Math.min(lastReadPostIndex, currentTopPostIndex);
|
||||||
|
updateUnreadBadge(unreadCount);
|
||||||
|
|
||||||
|
$('.timeline > ol > li.last-read-post').removeClass('last-read-post');
|
||||||
|
if (currentTopPostIndex < lastReadPostIndex)
|
||||||
|
lastReadPost = currentTopPost;
|
||||||
|
$(lastReadPost).addClass('last-read-post');
|
||||||
|
|
||||||
|
liWidth = $(currentTopPost).width();
|
||||||
|
};
|
||||||
|
|
||||||
|
function updateUnreadBadge(newCount) {
|
||||||
|
var badge = $('#unread-badge');
|
||||||
|
|
||||||
|
if (typeof newCount === 'undefined') {
|
||||||
|
oldCount = parseInt(badge[0].innerText);
|
||||||
|
newCount = ++oldCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
badge[0].innerHTML = newCount;
|
||||||
|
|
||||||
|
if (newCount <= 0) {
|
||||||
|
badge.hide();
|
||||||
|
} else
|
||||||
|
badge.show();
|
||||||
|
};
|
||||||
|
|
||||||
|
$.fn.isBefore= function(sel){
|
||||||
|
return this.nextAll(sel).length !== 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
function lockScroll(e) {
|
||||||
|
var elem = e.target;
|
||||||
|
if (elem.nodeName != 'LI')
|
||||||
|
return;
|
||||||
|
var parent = elem.parentNode;
|
||||||
|
if (parent != bungloo.timeline.body) return;
|
||||||
|
|
||||||
|
var rescroll = function(element) {
|
||||||
|
// try to grab the height of the elem
|
||||||
|
var elementHeight = element.offsetHeight;
|
||||||
|
if (elementHeight <= 0) {
|
||||||
|
// if height is zero, then we're dealing with a hidden element
|
||||||
|
//var copied_elem = $(element).clone().css({
|
||||||
|
var copied_elem = $(element).clone().attr('id', false).css({
|
||||||
|
// visibility:'hidden',
|
||||||
|
display:'block',
|
||||||
|
width: liWidth,
|
||||||
|
position:'absolute'
|
||||||
|
});
|
||||||
|
|
||||||
|
var ol = $(document.createElement('ol'));
|
||||||
|
ol.addClass('timeline');
|
||||||
|
ol.append(copied_elem);
|
||||||
|
$('#content').append(ol);
|
||||||
|
|
||||||
|
elementHeight = copied_elem.outerHeight();
|
||||||
|
ol.remove();
|
||||||
|
|
||||||
|
bungloo.timeline.saveScrollTop += elementHeight;
|
||||||
|
} else {
|
||||||
|
var oldPosition = scrollingElement.scrollTop();
|
||||||
|
var newPosition = oldPosition + elementHeight;
|
||||||
|
scrollingElement.scrollTop(newPosition);
|
||||||
|
}
|
||||||
|
|
||||||
|
updateUnreadBadge();
|
||||||
|
};
|
||||||
|
|
||||||
|
if ( $(elem).isBefore(lastReadPost) ) //is a new posts
|
||||||
|
rescroll(elem);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
});
|
Loading…
Add table
Add a link
Reference in a new issue