From e8cb91e45e5a4feef9893f9f2cd82016b527229f Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Mon, 11 Nov 2013 09:19:34 +0000 Subject: [PATCH] scale scroll to be from 0 to 100, data-name can contain spaces --- static/js/textPanel.js | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/static/js/textPanel.js b/static/js/textPanel.js index 9a8ab1b1..7b106795 100644 --- a/static/js/textPanel.js +++ b/static/js/textPanel.js @@ -189,7 +189,8 @@ pandora.ui.textPanel = function() { function scrollToSelectedEmbed() { 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); } @@ -230,10 +231,11 @@ pandora.ui.textHTML = function(text) { }) .bind({ 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; - if (!scrolling && pandora.user.ui.texts[pandora.user.ui.text] - && position != pandora.user.ui.texts[pandora.user.ui.text].position) { + if (!scrolling && settings && (settings.name || (position != settings.position))) { pandora.UI.set('texts.' + pandora.UI.encode(pandora.user.ui.text), { position: position ? position : 0 }); @@ -243,7 +245,7 @@ pandora.ui.textHTML = function(text) { }) .bindEvent({ pandora_showsidebar: function(data) { - that.resize(); + that.update(); }, }) .bindEvent('pandora_texts.' + text.id.toLowerCase(), function(data) { @@ -336,6 +338,8 @@ pandora.ui.textHTML = function(text) { }) .appendTo($content); + scrollToPosition(); + function getHeight() { // 24 menu + 24 toolbar + 16 statusbar + 32 title + 32 margins // + 1px to ge trid of scrollbar @@ -361,9 +365,11 @@ pandora.ui.textHTML = function(text) { element, scrollTop; if (settings.name) { - element = that.find('*[data-name=' + settings.name + ']'); - scrollTop = Math.max(that[0].scrollTop + element.offset().top - 48, 0); - position = 100 * scrollTop / that[0].scrollHeight; + element = that.find('*[data-name="' + settings.name + '"]'); + if (element.length) { + scrollTop = Math.max(that[0].scrollTop + element.offset().top - 48, 0); + position = 100 * scrollTop / that[0].scrollHeight; + } } scrollTo(position); }