Skip to content

Initialize Reader

Aferdita Muriqi edited this page May 25, 2020 · 5 revisions

R2D2BC

Initialize Reader

<head>
    <!-- R2 Reader CSS -->
    <link rel="stylesheet" href="reader.css" />

    <script> var exports = {}; </script>
    <script src="reader.js"></script>
</head>
<body>
 	<script>
        
        D2Reader.load({
            url: new URL("http.....")
        }).then(instance => {
            console.log("D2Reader loaded ", instance);
        }).catch(error => {
            console.error("error.message ", error.message);
        });
  
    </script>
</body>

... with Initial Reading Position

<script>

    var lastReadingPosition = '{"href":"/OEBPS/Text/cover.xhtml","locations":{"progression":0.2},"created":"2019-05-21T12:53:08.145Z","type":"application/xhtml+xml","title":"Cover"}';

    D2Reader.load({
        url: new URL("http....."),
        lastReadingPosition: lastReadingPosition
    }).then(instance => {
        console.log("D2Reader loaded ", instance);
    }).catch(error => {
        console.error("error.message ", error.message);
    });

</script>

... with Initial Bookmarks

<script>

    var bookmarks = '[{"href":"/OEBPS/Text/cover.xhtml","locations":{"progression":0.2},"created":"2019-05-21T12:53:08.145Z","type":"application/xhtml+xml","title":"Cover"}]';

    var initialAnnotations = {"bookmarks":bookmarks};

    D2Reader.load({
        url: new URL("http....."),
        initialAnnotations: initialAnnotations
    }).then(instance => {
        console.log("D2Reader loaded ", instance);
    }).catch(error => {
        console.error("error.message ", error.message);
    });

</script>

... with Initial Highlights

<script>

    var bookmarks = '[{"href":"/OEBPS/Text/cover.xhtml","locations":{"progression":0.2},"created":"2019-05-21T12:53:08.145Z","type":"application/xhtml+xml","title":"Cover"}]';

    var highlights = '[{"href":"/OEBPS/Text/cover.xhtml","locations":{"progression":0.2},"created":"2019-05-21T12:53:08.145Z","type":"application/xhtml+xml","title":"Cover"}]';

    var initialAnnotations = {"bookmarks":bookmarks, "highlights": highlights};

    D2Reader.load({
        url: new URL("http....."),
        initialAnnotations: initialAnnotations
    }).then(instance => {
        console.log("D2Reader loaded ", instance);
    }).catch(error => {
        console.error("error.message ", error.message);
    });

</script>

... with initial User Settings

<script>

    var userSettings = {
        // appearance: "readium-sepia-on", //readium-default-on, readium-night-on, readium-sepia-on
        // fontFamily: "serif", //Original, serif, sans-serif
        // textAlignment: "justify", //"auto", "justify", "start"
        // columnCount: "auto", // "auto", "1", "2"
        // verticalScroll: false,
        // fontSize: 100.0,
        // wordSpacing: 0.0,
        // letterSpacing: 0.0,
        // pageMargins: 2.0,
        // lineHeight: 1.0
    }


    D2Reader.load({
        url: new URL("http....."),
        userSettings: userSettings
    }).then(instance => {
        console.log("D2Reader loaded ", instance);
    }).catch(error => {
        console.error("error.message ", error.message);
    });

</script>

... with session vs local storage

<script>

    D2Reader.load({
        url: new URL("http....."),
        useLocalStorage: true // true = local storage, false = session storage (default)
    }).then(instance => {
        console.log("D2Reader loaded ", instance);
    }).catch(error => {
        console.error("error.message ", error.message);
    });

</script>