|
|
(4 intermediate revisions by the same user not shown) |
Line 33: |
Line 33: |
|
| |
|
| ==== Table of content ==== | | ==== Table of content ==== |
| <blockquote>function TableOfContents () {</blockquote><blockquote>this.getSections = function() {</blockquote><blockquote>/*</blockquote><blockquote>- return an array of section objects</blockquote><blockquote>- in case there there is no table of content, return an empty array</blockquote><blockquote>*/</blockquote><blockquote>}</blockquote><blockquote><br> | | <syntaxhighlight lang="javascript" line='line'> |
| </blockquote><blockquote>this.scrollToSection = function(index: number) {</blockquote><blockquote>/*</blockquote><blockquote>- scroll to a section with index in array returned by this.getSections</blockquote><blockquote>- perform change to the page so that the section become available for reading, such as expanding the collapsed section</blockquote><blockquote>*/</blockquote><blockquote>}</blockquote><blockquote><br>
| | function TableOfContents () { |
| </blockquote><blockquote>// OPTIONAL</blockquote><blockquote>this.visibleSectionIndexes = function() {</blockquote><blockquote>/*</blockquote><blockquote>- return an array of visible section's indexes</blockquote><blockquote>- in case there there is no table of content, return an empty array</blockquote><blockquote>*/</blockquote><blockquote>}</blockquote><blockquote><br>
| | this.getSections = function() { |
| </blockquote><blockquote>// OPTIONAL</blockquote><blockquote>this.startVisibleSectionCallBack = function () {</blockquote><blockquote>/*</blockquote><blockquote>- start page visible section call back</blockquote><blockquote>- using this call back, the reader app could know which section is currently visible to the user and highlighting the location in table of content</blockquote><blockquote>- implementation to be discussed. It might not be a good idea to modify window.onscroll directly</blockquote><blockquote>*/</blockquote><blockquote>var handleScroll = function() {</blockquote><blockquote>var visible = tableOfContents.visibleSectionIndexes();</blockquote><blockquote>if (visible.length > 0) {</blockquote><blockquote>window.location = 'pagescroll:scrollEnded?start=' + visible[0] + '&length=' + visible.length;</blockquote><blockquote>}</blockquote><blockquote>}</blockquote><blockquote>window.onscroll = handleScroll;</blockquote><blockquote>handleScroll();</blockquote><blockquote>}</blockquote><blockquote><br>
| | /* |
| </blockquote><blockquote>// OPTIONAL</blockquote><blockquote>this.stopVisibleSectionCallBack = function () {</blockquote><blockquote>/*</blockquote><blockquote>- stop page visible section call back</blockquote><blockquote>*/</blockquote><blockquote>window.onscroll = undefined;</blockquote><blockquote>}</blockquote><blockquote>}</blockquote><blockquote><br>
| | - return an array of section objects |
| </blockquote><blockquote>function Section(title: string, level: number) {}</blockquote>
| | - in case there there is no table of content, return an empty array |
| | */ |
| | } |
| | |
| | this.scrollToSection = function(index: number) { |
| | /* |
| | - scroll to a section with index in array returned by this.getSections |
| | - perform change to the page so that the section become available for reading, such as expanding the collapsed section |
| | */ |
| | } |
| | |
| | // OPTIONAL |
| | this.visibleSectionIndexes = function() { |
| | /* |
| | - return an array of visible section's indexes |
| | - in case there there is no table of content, return an empty array |
| | */ |
| | } |
| | |
| | // OPTIONAL |
| | this.startVisibleSectionCallBack = function () { |
| | /* |
| | - start page visible section call back |
| | - using this call back, the reader app could know which section is currently visible to the user and highlighting the location in table of content |
| | - implementation to be discussed. It might not be a good idea to modify window.onscroll directly |
| | */ |
| | var handleScroll = function() { |
| | var visible = tableOfContents.visibleSectionIndexes(); |
| | if (visible.length > 0) { |
| | window.location = 'pagescroll:scrollEnded?start=' + visible[0] + '&length=' + visible.length; |
| | } |
| | } |
| | window.onscroll = handleScroll; |
| | handleScroll(); |
| | } |
| | |
| | // OPTIONAL |
| | this.stopVisibleSectionCallBack = function () { |
| | /* |
| | - stop page visible section call back |
| | */ |
| | window.onscroll = undefined; |
| | } |
| | |
| | } |
| | |
| | function Section(title: string, level: number) {} |
| | </syntaxhighlight> |