From a7d70c15ead4e4c650f12192e954dcb6469407be Mon Sep 17 00:00:00 2001 From: j Date: Tue, 13 Mar 2018 18:40:37 +0530 Subject: [PATCH] parse document position --- static/js/URL.js | 2 +- static/js/textPanel.js | 13 +++++++++++-- static/js/utils.js | 14 +++++++++++--- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/static/js/URL.js b/static/js/URL.js index 47a18527..c6d274b1 100644 --- a/static/js/URL.js +++ b/static/js/URL.js @@ -254,7 +254,7 @@ pandora.URL = (function() { set[!state.item ? 'collectionView' : 'documentView'] = state.view; } if (state.span) { - if (Ox.isNumber(state.pan)) { + if (Ox.isNumber(state.span)) { set['documents.' + state.item] = {position: state.span}; } else { set['documents.' + state.item] = {name: state.span}; diff --git a/static/js/textPanel.js b/static/js/textPanel.js index d04e5541..a7aa4129 100644 --- a/static/js/textPanel.js +++ b/static/js/textPanel.js @@ -393,8 +393,17 @@ pandora.ui.textHTML = function(text) { if (settings.name) { 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; + scrollTop = that[0].scrollTop + element.offset().top; + if (pandora.user.ui.page == 'document') { + scrollTop -= 48; + } else { + scrollTop -= 80; + if (pandora.user.ui.showBrowser) { + scrollTop -= (112 + Ox.UI.SCROLLBAR_SIZE); + } + } + + position = 100 * Math.max(scrollTop, 0) / that[0].scrollHeight; } } scrollTo(position); diff --git a/static/js/utils.js b/static/js/utils.js index 22ddb586..b923954c 100644 --- a/static/js/utils.js +++ b/static/js/utils.js @@ -1994,9 +1994,11 @@ pandora.getSpan = function(state, val, callback) { if (Ox.contains(['epub', 'pdf', 'txt'], extension)) { state.span = Ox.limit(parseInt(val), 1, dimensions); } else if (Ox.contains(['html'], extension)) { - //fixme: allow numbers or check names? - //state.span = Ox.limit(parseInt(val), 0, 100); - state.span = val + if (pandora.isNumericalSpan(val)) { + state.span = Ox.limit(parseInt(val), 0, 100); + } else { + state.span = val; + } } else if (Ox.contains(['gif', 'jpg', 'png'], extension)) { values = val.split(','); if (values.length == 4) { @@ -2443,6 +2445,12 @@ pandora.isLicensed = function() { return !pandora.site.license || pandora.site.license > +new Date(); }; +pandora.isNumericalSpan = function(str) { + return str.split(',').every(function(str) { + return /^[0-9-\.:]+$/.test(str); + }); +} + pandora.isPrintURL = function(url) { url = url || document.location.href; var hash = Ox.parseURL(url).hash;