wepub

Check-in [3f780220b4]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Tap to adjust font size.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | master | trunk
Files: files | file ages | folders
SHA3-256:3f780220b41cd150de1776d2692d4971959269c998ba475d9c8c2309cd04b3c7
User & Date: ajv-899-334-8894@vsta.org 2017-04-06 04:01:42
Context
2017-06-24
04:32
Add UI for font size up/down, smooth scroll, save font size for book. check-in: 5d74a2880e user: ajv-899-334-8894@vsta.org tags: master, trunk
2017-04-06
04:01
Tap to adjust font size. check-in: 3f780220b4 user: ajv-899-334-8894@vsta.org tags: master, trunk
2016-11-24
17:12
Flatten extended code points. TBD if we should lean on UTF8. check-in: 959a164154 user: ajv-899-334-8894@vsta.org tags: master, trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to get.py.

   152    152               head = "%s chapter %d" % (nm, chapnum)
   153    153               buf = self.build_header(head)
   154    154               buf += '<script src="/js/reader.js"></script>\n'
   155    155               if chapnum > 0:
   156    156                   buf += '<a href="%d">Previous Chapter</a>\n' % \
   157    157                    (chapnum-1,)
   158    158               buf += '<div id="textview"\n'
   159         -            buf += '  style="color: white; background: black; width: 100%;">\n'
          159  +            buf += '  style="color: white; background: black;'
          160  +            buf += '  width: 100%; font-size: 14px;">\n'
   160    161               buf += chore.utils.uncharenc(chap.read())
   161    162               buf += '</div>\n'
   162    163               if chapnum < len(book.chapters)-1:
   163    164                   buf += '<a href="%d">Next Chapter</a>\n' % \
   164    165                    (chapnum+1,)
   165    166               doc.close()
   166    167               buf += '<script>reading("%s", "%s", "%s");</script>\n' % \

Changes to js/reader.js.

    10     10   var docname = null;
    11     11   
    12     12   // Section number
    13     13   var secnum = null;
    14     14   
    15     15   // Web element with text content which scrolls
    16     16   var pane = null;
           17  +
           18  +// Current font size
           19  +var curSize = 14;
    17     20   
    18     21   // Wrappers for XMLHttpRequest
    19     22   function xhr_get(url, fn) {
    20     23       var req = new XMLHttpRequest();
    21     24       req.open("GET", url);
    22     25       req.onreadystatechange = function() {
    23     26           // Ignore progress/errors
................................................................................
    87     90           st.pos = parseFloat(d.scrollTop) / parseFloat(d.scrollHeight);
    88     91   
    89     92           // Send it over
    90     93           xhr_put_json("/state.json?doc=" + encodeURIComponent(docname),
    91     94               JSON.stringify(st), null);
    92     95       }
    93     96   }
           97  +
           98  +// They tapped the screen.
           99  +//
          100  +// First pass, upper half shrinks text, lower grows.
          101  +function tapped(ev) {
          102  +    // When we changed font size, our scroll position has to be refreshed
          103  +    //  to be the same portion of the new scrollable size.
          104  +    var d = document.scrollingElement;
          105  +    var pos = parseFloat(d.scrollTop) / parseFloat(d.scrollHeight);
          106  +
          107  +    // Shrink for upper tap, grow for lower
          108  +    var coord = ev.screenY;
          109  +    if (coord < window.innerHeight/2) {
          110  +        if (curSize > 4) {
          111  +            curSize -= 2;
          112  +        }
          113  +    } else {
          114  +        curSize += 2;
          115  +    }
          116  +    pane.style.fontSize = curSize.toString() + "px";
          117  +
          118  +    // Now reposition based on new scrollHeight
          119  +    d.scrollTop = d.scrollHeight * pos;
          120  +}
    94    121   
    95    122   // On page load, configure to track this user for this scrollable
    96    123   //  text content of this document.  If there's a saved position,
    97    124   //  scroll to it.
    98    125   function reading(arg_who, arg_doc, arg_pane) {
    99    126       // Save for future
   100    127       who = arg_who;
   101    128       docname = arg_doc;
   102    129       pane = document.getElementById(arg_pane);
   103    130   
          131  +    // Tap handler
          132  +    pane.onclick = tapped;
          133  +
   104    134       // Calculate section number
   105    135       var url = document.URL;
   106    136       var slidx = url.lastIndexOf('/');
   107    137       if (slidx > 0) {
   108    138           secnum = parseInt(url.slice(slidx+1));
   109    139       }
   110    140