From ce09b3bcde52ea6024ab23d625ad6c1d9c801913 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Mon, 28 Oct 2013 11:10:26 +0000 Subject: [PATCH] scroll to current reference --- static/js/textPanel.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/static/js/textPanel.js b/static/js/textPanel.js index 1c28966d..f79bb998 100644 --- a/static/js/textPanel.js +++ b/static/js/textPanel.js @@ -71,6 +71,9 @@ pandora.ui.textPanel = function() { float: 'right', margin: '4px 2px 4px 2px' }) + .bindEvent({ + click: scrollToSelectedEmbed + }) .appendTo($toolbar), $previousButton = Ox.Button({ @@ -183,6 +186,12 @@ pandora.ui.textPanel = function() { return urls; } + function scrollToSelectedEmbed() { + var scrollTop = Math.max(pandora.$ui.text[0].scrollTop + $('#embed' + selected).offset().top - 50, 0), + position = 100 * scrollTop / pandora.$ui.text[0].scrollHeight; + pandora.$ui.text.scrollTo(position); + } + that.selectEmbed = function(index) { if (index != selected) { selected = index; @@ -190,6 +199,7 @@ pandora.ui.textPanel = function() { $('.OxSpecialLink').removeClass('OxActive'); selected > -1 && $('#embed' + selected).addClass('OxActive'); pandora.$ui.textEmbed.update(selectedURL); + scrollToSelectedEmbed(); } }; @@ -332,6 +342,8 @@ pandora.ui.textHTML = function(text) { that[0].scrollTop = that[0].scrollHeight/100 * position; } + that.scrollTo = scrollTo; + that.update = function() { $text.options({ width: getWidth()