From 0ef598195c7730adafec9974a82e5248946bb046 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Fri, 8 Nov 2013 18:57:24 +0000 Subject: [PATCH] text names --- pandora/text/models.py | 3 +++ static/js/URL.js | 15 ++++++++++----- static/js/pandora.js | 3 ++- static/js/textPanel.js | 2 +- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/pandora/text/models.py b/pandora/text/models.py index 2d758ae77..52a40047f 100644 --- a/pandora/text/models.py +++ b/pandora/text/models.py @@ -188,6 +188,9 @@ class Text(models.Model): if self.type == 'pdf': response['uploaded'] = True if self.file and not self.uploading else False response['embeds'] = self.embeds + response['names'] = [] + else: + response['names'] = re.compile('<[^<>]*?data-name="(.+?)"').findall(self.text) return response def path(self, name=''): diff --git a/static/js/URL.js b/static/js/URL.js index 6edcedba5..0dd103b6c 100644 --- a/static/js/URL.js +++ b/static/js/URL.js @@ -65,10 +65,12 @@ pandora.URL = (function() { : [] ); } else if (pandora.user.ui.section == 'texts') { - var position = pandora.user.ui.texts[state.item] - ? pandora.user.ui.texts[state.item].position - : 0; - if (position) { + var textState = pandora.user.ui.texts[state.item], + position = textState.position || 0; + + if (textState.name) { + state.span = textState.name; + } else { state.span = [position]; } } @@ -217,7 +219,10 @@ pandora.URL = (function() { } else if (state.type == 'texts') { if (state.span) { - set['texts.' + pandora.UI.encode(state.item) + '.position'] = state.span[0]; + set['texts.' + pandora.UI.encode(state.item)] = { + position: Ox.isArray(state.span) ? state.span[0] : 0, + name: Ox.isArray(state.span) ? '' : state.span + }; } } diff --git a/static/js/pandora.js b/static/js/pandora.js index 82b015207..dd38ceed5 100644 --- a/static/js/pandora.js +++ b/static/js/pandora.js @@ -355,7 +355,8 @@ appPanel view: 'list' }; pandora.site.textSettings = { - position: 0 + position: 0, + name: '' }; Ox.extend(pandora.user, { diff --git a/static/js/textPanel.js b/static/js/textPanel.js index f4bc56761..359698b4a 100644 --- a/static/js/textPanel.js +++ b/static/js/textPanel.js @@ -190,7 +190,7 @@ pandora.ui.textPanel = function() { } function scrollToSelectedEmbed() { - var scrollTop = Math.max(pandora.$ui.text[0].scrollTop + $('#embed' + selected).offset().top - 50, 0), + var scrollTop = Math.max(pandora.$ui.text[0].scrollTop + $('#embed' + selected).offset().top - 48, 0), position = 100 * scrollTop / pandora.$ui.text[0].scrollHeight; pandora.$ui.text.scrollTo(position); }