Add scrollback from Equinox theme

This commit is contained in:
ViViDboarder 2016-12-08 10:07:01 -08:00
parent eba41eecf8
commit 086a7813d3
2 changed files with 105 additions and 4 deletions

View File

@ -718,6 +718,27 @@ div[mtype*=myself] {
/* @end */ /* @end */
/* @group Hidden scrollback history bar */
#scrolling_history {
z-index: 400;
position: fixed;
bottom: 0;
left: 0;
right: 0;
height: auto;
box-shadow: 0 1px 5px #777;
border-top: 1px solid #404040;
text-shadow: 1px 1px rgba(10, 10, 10, 0.7);
background: rgba(31, 51, 81, 0.95);
display: none;
overflow: hidden;
}
#scrolling_history .senderContainer {
background: rgba(31, 51, 81, .95);
}
/* @end */
/* /*
vim: set foldmethod=marker: vim: set foldmethod=marker:
vim: set foldmarker=@group,@end: vim: set foldmarker=@group,@end:

View File

@ -1,18 +1,98 @@
/* Defined in: "Textual.app -> Contents -> Resources -> JavaScript -> API -> core.js" */ /* Defined in: "Textual.app -> Contents -> Resources -> JavaScript -> API -> core.js" */
/* Room state from Equinox */
var rs = { // room state
nick: {
count: 1,
delete: false,
id: undefined,
nick: undefined
}
};
/* Taken from Equinox to determine if a message is visible */
function isMessageInViewport(elem) {
'use strict';
if (!elem.getBoundingClientRect) {
return true;
}
// Have to use Math.floor() because sometimes the getBoundingClientRect().bottom is a fraction of a pixel (!!!)
return (Math.floor(elem.getBoundingClientRect().bottom) <= Math.floor(document.documentElement.clientHeight));
}
Textual.viewBodyDidLoad = function() Textual.viewBodyDidLoad = function()
{ {
Textual.fadeOutLoadingScreen(1.00, 0.95); Textual.fadeOutLoadingScreen(1.00, 0.95);
} }
/* Taken from Equinox to create history div */
Textual.viewInitiated = function () {
'use strict';
/* When the view is loaded, create a hidden history div which we display if there is scrollback */
var body = document.getElementById('body_home'), div = document.createElement('div');
div.id = 'scrolling_history';
document.getElementsByTagName('body')[0].appendChild(div);
rs.history = div;
/* setup the scrolling event to display the hidden history if the bottom element isn't in the viewport
also hide the topic bar when scrolling */
window.onscroll = function () {
var line, lines;
var topic = document.getElementById('topic_bar');
lines = body.getElementsByClassName('line');
if (lines.length < 2) {
return;
}
line = lines[lines.length - 1];
if (isMessageInViewport(line) === false) {
// scrollback
rs.history.style.display = 'inline';
if (topic) { topic.style.visibility = 'hidden'; }
} else {
// at the bottom
rs.history.style.display = 'none';
if (topic) { topic.style.visibility = 'visible'; }
}
};
};
Textual.newMessagePostedToView = function(line) Textual.newMessagePostedToView = function(line)
{ {
var element = document.getElementById("line-" + line); 'use strict';
var message = document.getElementById("line-" + line);
ConversationTracking.updateNicknameWithNewMessage(element); ConversationTracking.updateNicknameWithNewMessage(message);
/* Added from Equinox for scroll window */
var clone;
// if it's a private message, colorize the nick and then track the state and fade away the nicks if needed
if (message.getAttribute('ltype') === 'privmsg' || message.getAttribute('ltype') === 'action') {
// Track the previous message's id
rs.nick.id = message.getAttribute('id');
// Copy the message into the hidden history
clone = message.cloneNode(true);
clone.removeAttribute('id');
rs.history.appendChild(clone);
// Remove old messages, if the history is longer than three messages
if (rs.history.childElementCount > 2) {
rs.history.removeChild(rs.history.childNodes[0]);
// Hide the first nick in the hidden history, if it's the same as the second
if ((rs.nick.count > 1) && (message.getAttribute('ltype') !== 'action')) {
rs.history.getElementsByClassName('sender')[0].style.visibility = 'hidden';
}
}
}
} }
Textual.nicknameSingleClicked = function(e) Textual.nicknameSingleClicked = function(e)
{ {
ConversationTracking.nicknameSingleClickEventCallback(e); ConversationTracking.nicknameSingleClickEventCallback(e);
} }