From 8e0c8a14970d07c5527bcd705089aebba22cbf70 Mon Sep 17 00:00:00 2001 From: Paolo Date: Thu, 25 Apr 2013 12:22:42 +0200 Subject: [PATCH] first commit --- README.md | 4 + it.to.work/hide-replies.css | 43 ++++++++++ it.to.work/hide-replies.js | 101 ++++++++++++++++++++++ it.to.work/marked-posts.css | 5 ++ it.to.work/marked-posts.js | 32 +++++++ it.to.work/scrollingElement.js | 10 +++ it.to.work/unread-posts.css | 35 ++++++++ it.to.work/unread-posts.js | 150 +++++++++++++++++++++++++++++++++ 8 files changed, 380 insertions(+) create mode 100644 README.md create mode 100644 it.to.work/hide-replies.css create mode 100644 it.to.work/hide-replies.js create mode 100644 it.to.work/marked-posts.css create mode 100644 it.to.work/marked-posts.js create mode 100644 it.to.work/scrollingElement.js create mode 100644 it.to.work/unread-posts.css create mode 100644 it.to.work/unread-posts.js diff --git a/README.md b/README.md new file mode 100644 index 0000000..3c34ea1 --- /dev/null +++ b/README.md @@ -0,0 +1,4 @@ +bungloo-plugins +=============== + +A set of plugins for Tent client Bungloo \ No newline at end of file diff --git a/it.to.work/hide-replies.css b/it.to.work/hide-replies.css new file mode 100644 index 0000000..06de916 --- /dev/null +++ b/it.to.work/hide-replies.css @@ -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; +} +*/ \ No newline at end of file diff --git a/it.to.work/hide-replies.js b/it.to.work/hide-replies.js new file mode 100644 index 0000000..1a8555b --- /dev/null +++ b/it.to.work/hide-replies.js @@ -0,0 +1,101 @@ +define(['module', 'jquery', 'plugins/it.to.work/scrollingElement'], function(myself, $, scrollingElement) { + + return new function() { + +//include css file +$('', { + 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 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', { + 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 + }); + }; +}); \ No newline at end of file diff --git a/it.to.work/scrollingElement.js b/it.to.work/scrollingElement.js new file mode 100644 index 0000000..3091efa --- /dev/null +++ b/it.to.work/scrollingElement.js @@ -0,0 +1,10 @@ +define(['jquery'], function($) { + var scrollingElement = $(document); + setTimeout(function() { + if ($('#content').css('overflow') == 'scroll') + scrollingElement = $('#content'); + }, 1000); + + return scrollingElement; +}); + diff --git a/it.to.work/unread-posts.css b/it.to.work/unread-posts.css new file mode 100644 index 0000000..e5c7da4 --- /dev/null +++ b/it.to.work/unread-posts.css @@ -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); +} +*/ diff --git a/it.to.work/unread-posts.js b/it.to.work/unread-posts.js new file mode 100644 index 0000000..423dc44 --- /dev/null +++ b/it.to.work/unread-posts.js @@ -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 + $('', { + 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); +}; + + + + }; + +});