scale scroll to be from 0 to 100, data-name can contain spaces

This commit is contained in:
j 2013-11-11 09:19:34 +00:00
parent ef3083ab2c
commit e8cb91e45e

View file

@ -189,7 +189,8 @@ pandora.ui.textPanel = function() {
function scrollToSelectedEmbed() { function scrollToSelectedEmbed() {
var scrollTop = Math.max(pandora.$ui.text[0].scrollTop + $('#embed' + selected).offset().top - 48, 0), var scrollTop = Math.max(pandora.$ui.text[0].scrollTop + $('#embed' + selected).offset().top - 48, 0),
position = 100 * scrollTop / pandora.$ui.text[0].scrollHeight; position = 100 * scrollTop / Math.max(1,
pandora.$ui.text[0].scrollHeight - pandora.$ui.text.height());
pandora.$ui.text.scrollTo(position); pandora.$ui.text.scrollTo(position);
} }
@ -230,10 +231,11 @@ pandora.ui.textHTML = function(text) {
}) })
.bind({ .bind({
scroll: function(event) { scroll: function(event) {
var position = Math.round(100 * that[0].scrollTop / that[0].scrollHeight) var position = Math.round(100 * that[0]. scrollTop / Math.max(1,
that[0].scrollHeight - that.height())),
settings = pandora.user.ui.texts[pandora.user.ui.text];
position = position - position % 10; position = position - position % 10;
if (!scrolling && pandora.user.ui.texts[pandora.user.ui.text] if (!scrolling && settings && (settings.name || (position != settings.position))) {
&& position != pandora.user.ui.texts[pandora.user.ui.text].position) {
pandora.UI.set('texts.' + pandora.UI.encode(pandora.user.ui.text), { pandora.UI.set('texts.' + pandora.UI.encode(pandora.user.ui.text), {
position: position ? position : 0 position: position ? position : 0
}); });
@ -243,7 +245,7 @@ pandora.ui.textHTML = function(text) {
}) })
.bindEvent({ .bindEvent({
pandora_showsidebar: function(data) { pandora_showsidebar: function(data) {
that.resize(); that.update();
}, },
}) })
.bindEvent('pandora_texts.' + text.id.toLowerCase(), function(data) { .bindEvent('pandora_texts.' + text.id.toLowerCase(), function(data) {
@ -336,6 +338,8 @@ pandora.ui.textHTML = function(text) {
}) })
.appendTo($content); .appendTo($content);
scrollToPosition();
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
@ -361,9 +365,11 @@ pandora.ui.textHTML = function(text) {
element, element,
scrollTop; scrollTop;
if (settings.name) { if (settings.name) {
element = that.find('*[data-name=' + settings.name + ']'); element = that.find('*[data-name="' + settings.name + '"]');
scrollTop = Math.max(that[0].scrollTop + element.offset().top - 48, 0); if (element.length) {
position = 100 * scrollTop / that[0].scrollHeight; scrollTop = Math.max(that[0].scrollTop + element.offset().top - 48, 0);
position = 100 * scrollTop / that[0].scrollHeight;
}
} }
scrollTo(position); scrollTo(position);
} }