Guest User

Untitled

a guest
Oct 19th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. function TableOfContents () {
  2. this.getSections = function() {
  3. /*
  4. - return an array of section objects
  5. - in case there there is no table of content, return an empty array
  6. */
  7. }
  8.  
  9. this.scrollToSection = function(index: number) {
  10. /*
  11. - scroll to a section with index in array returned by this.getSections
  12. - perform change to the page so that the section become available for reading, such as expanding the collapsed section
  13. */
  14. }
  15.  
  16. // OPTIONAL
  17. this.visibleSectionIndexes = function() {
  18. /*
  19. - return an array of visible section's indexes
  20. - in case there there is no table of content, return an empty array
  21. */
  22. }
  23.  
  24. // OPTIONAL
  25. this.startVisibleSectionCallBack = function () {
  26. /*
  27. - start page visible section call back
  28. - 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
  29. - implementation to be discussed. It might not be a good idea to modify window.onscroll directly
  30. */
  31. var handleScroll = function() {
  32. var visible = tableOfContents.visibleSectionIndexes();
  33. if (visible.length > 0) {
  34. window.location = 'pagescroll:scrollEnded?start=' + visible[0] + '&length=' + visible.length;
  35. }
  36. }
  37. window.onscroll = handleScroll;
  38. handleScroll();
  39. }
  40.  
  41. // OPTIONAL
  42. this.stopVisibleSectionCallBack = function () {
  43. /*
  44. - stop page visible section call back
  45. */
  46. window.onscroll = undefined;
  47. }
  48.  
  49. }
  50.  
  51. function Section(title: string, level: number) {}
Add Comment
Please, Sign In to add comment