add current position to html text urls and scroll to position on load

This commit is contained in:
j 2013-09-08 21:01:45 +00:00
parent ac1cae44cc
commit 8d4c790446

View file

@ -214,6 +214,18 @@ pandora.ui.textHTML = function(text) {
that = Ox.Element() that = Ox.Element()
.css({ .css({
'overflow-y': 'auto' 'overflow-y': 'auto'
})
.bind({
scroll: function(event) {
var position = Math.round(100 * that[0].scrollTop / that[0].scrollHeight)
position = position - position % 10;
if (position != pandora.user.ui.texts[pandora.user.ui.text].position) {
pandora.UI.set(
'texts.' + pandora.UI.encode(pandora.user.ui.text) + '.position',
position ? [position] : 0
);
}
}
}), }),
$content = Ox.Element().css({ $content = Ox.Element().css({
margin: '16px', margin: '16px',
@ -301,6 +313,8 @@ pandora.ui.textHTML = function(text) {
}) })
.appendTo($content); .appendTo($content);
scrollTo(pandora.user.ui.texts[pandora.user.ui.text].position || 0);
function getHeight() { function getHeight() {
// 24 menu + 24 toolbar + 16 statusbar + 32 title + 32 margins // 24 menu + 24 toolbar + 16 statusbar + 32 title + 32 margins
// + 1px to ge trid of scrollbar // + 1px to ge trid of scrollbar
@ -314,6 +328,10 @@ pandora.ui.textHTML = function(text) {
- 32 - 16; - 32 - 16;
} }
function scrollTo(position) {
that[0].scrollTop = that[0].scrollHeight/100 * position;
}
that.update = function() { that.update = function() {
$text.options({ $text.options({
maxHeight: getHeight(), maxHeight: getHeight(),
@ -321,6 +339,7 @@ pandora.ui.textHTML = function(text) {
}).css({ }).css({
width: getWidth() + 'px' width: getWidth() + 'px'
}); });
scrollTo(pandora.user.ui.texts[pandora.user.ui.text].position || 0);
return that; return that;
}; };