Created
October 18, 2017 14:21
-
-
Save automactic/b2ed501505676f4e6a21a95cae328f20 to your computer and use it in GitHub Desktop.
js in zim
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function TableOfContents () { | |
this.getSections = function() { | |
/* | |
- return an array of section objects | |
- 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) {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment