diff --git a/opds_catalog/FB2_22_xhtml.xsl b/opds_catalog/FB2_22_xhtml.xsl index 6c8aa5123c1b046b1fa9e0a8077c3aa809643454..5e0213cb4e1e8f06b7262512c6f6d1c9e04c5914 100644 --- a/opds_catalog/FB2_22_xhtml.xsl +++ b/opds_catalog/FB2_22_xhtml.xsl @@ -114,7 +114,7 @@ <div><xsl:apply-templates/></div> </xsl:template> - <xsl:template match="fb:section"> + <xsl:template match="fb:section" name="section"> <a name="TOC_{position()}"></a> <xsl:if test="@id"> <xsl:element name="a"> @@ -171,12 +171,17 @@ </h5> </xsl:template> <!-- p --> - <xsl:template match="fb:p"> - <div id="{position()}" align="justify"><xsl:if test="@id"> - <xsl:element name="a"> - <xsl:attribute name="name"><xsl:value-of select="@id"/></xsl:attribute> - </xsl:element> - </xsl:if>    <xsl:apply-templates/></div> + <xsl:template match="fb:p"> + <xsl:variable name="count"> + <xsl:number/> + </xsl:variable> + <div id="{1+count(ancestor::fb:section/preceding-sibling::fb:section)}.{$count}" align="justify"> + <xsl:if test="@id"> + <xsl:element name="a"> + <xsl:attribute name="name"><xsl:value-of select="@id"/></xsl:attribute> + </xsl:element> + </xsl:if>    <xsl:apply-templates/> + </div> </xsl:template> <!-- strong --> <xsl:template match="fb:strong"> diff --git a/sopds_web_backend/templates/BookReader.html b/sopds_web_backend/templates/BookReader.html index bbfcbf9d8186e9de43d1b86b04cdfa325f42d319..f8c7032513ad457cce2b5aa60b894e19fdc1c992 100644 --- a/sopds_web_backend/templates/BookReader.html +++ b/sopds_web_backend/templates/BookReader.html @@ -27,15 +27,20 @@ } var SetPos = function(){ - var CurrentPos = window.scrollY; - $.ajax( { - url: '{% url 'web:setpos' book_id %}?pos='+CurrentPos, - type: 'GET', - cache: false, - success: function() { - window.setTimeout(SetPos, 10000); - } - }); + var Reader = $('#ReaderBlock'); + xPos = window.scrollY; + Reader.find('div').each(function(idx,el){ + var elem = $(el); + if ((elem.offset().top+elem.height()) > xPos) { + var CurrentPos = $(el).attr('id'); + $.ajax( { + url: '{% url 'web:setpos' book_id %}?pos='+CurrentPos, + type: 'GET', + cache: false + }); + return false; + }; + }) } var GetPos = function(){ @@ -43,13 +48,18 @@ url: '{% url 'web:getpos' book_id %}', type: 'GET', cache: false, - success: function(data) { - window.scrollTo(0,data); + success: function(lineID) { + var Reader = $('#ReaderBlock'); + Reader.find('div').each(function(idx,el){ + if ($(el).attr('id') == lineID) { + window.scrollTo(0,$(el).offset().top); + }; + }) } }); } - var LoadBook = function(){ + LoadBook = function(){ if (localStorage.getItem(BookID)){ $("#ReaderBlock").html(LZString.decompress(localStorage.getItem(BookID))); GetPos();