Difference between revisions of "Javascript API"

Jump to navigation Jump to search
185 bytes removed ,  14:31, 18 October 2017
 
(2 intermediate revisions by the same user not shown)
Line 33: Line 33:


==== Table of content ====
==== Table of content ====
<nowiki><source></nowiki>
<syntaxhighlight lang="javascript" line='line'>
 
function TableOfContents () {
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.getSections = function() {
    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
        - 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
    // 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
        */
    }


    this.visibleSectionIndexes = function() {
    // OPTIONAL
 
    this.startVisibleSectionCallBack = function () {
        /*
        /*
 
        - start page visible section call back
        - return an array of visible section's indexes
        - 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
        - in case there there is no table of content, return an empty array
        */
 
        var handleScroll = function() {
        */
            var visible = tableOfContents.visibleSectionIndexes();
 
            if (visible.length > 0) {
    }
                window.location = 'pagescroll:scrollEnded?start=' + visible[0] + '&length=' + visible.length;
 
            }
 
        }
 
        window.onscroll = handleScroll;
    // OPTIONAL
        handleScroll();
 
    }
    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;
 
    }


    // OPTIONAL
    this.stopVisibleSectionCallBack = function () {
        /*
        - stop page visible section call back
        */
        window.onscroll = undefined;
    }
   
}
}


function Section(title: string, level: number) {}
function Section(title: string, level: number) {}
 
</syntaxhighlight>
<nowiki></source></nowiki>
12

edits

Navigation menu