配置为使用localStorage作为端点而不是本地服务器

时间:2014-11-17 21:56:26

标签: javascript annotations epub

我正在使用generates annotations within an ePub的JavaScript库。我希望使用HTML5 localStorage来存储注释数据。

有没有办法让端点网址与localStorage相关联?

在调用库的钩子中有一个用于' server'的变量,它当前设置为本地服务器的端口5000端口。

我希望用一些指向localStorage的指针替换它,但我不确定会涉及哪个端点。似乎添加信息的唯一方法是方法" localStorage.setItem",它又需要变量名作为参数,因此它不适合作为端点。

在我定制它之前,纯粹的钩子在this github repo

我编辑后的当前版本(不运行)如下:

    EPUBJS.Hooks.register("beforeChapterDisplay").annotate = function(callback, chapter){

        var chap = chapter.bodyEl,
            server = localStorage;
            files = [
                        EPUBJS.filePath + "annotator-full.js"
                     ];

        console.log(files);//show the pathways defined above

        EPUBJS.core.load(files, chapter.doc.head);
        $(chapter.doc.body).annotator().annotator('setupPlugins', {}, {

            Filter:false,
            Store: {
                annotationData: {
                  'uri': chapter.path
                },
                loadFromSearch: {
                    'limit': 100,
                    'uri': chapter.path
                }
            }

        });

        Util.mousePosition = function(e, offsetEl) {
          var offset;
          offset = $(offsetEl).position();
          return {
            top: e.pageY,
            left: e.pageX
          };
        };

            devAnnotator = new Annotator(chapter.doc.body)
            // .addPlugin('Auth', {
            //            tokenUrl: 'http://annotateit.org/api/token',//'http://localhost:5001/api/token'
            //          })
            // .addPlugin('Unsupported')
            // .addPlugin('AnnotateItPermissions')
            // .addPlugin('Store', {
            //   prefix: 'http://annotateit.org/api',//'http://localhost:5000',
            //   loadFromSearch: {
            //     uri: chapter.currentChapter.href
            //   },
            //   annotationData: {
            //     uri: chapter.currentChapter.href
            //   }
            // });

      //         devAnnotator.plugins.Auth.withToken(function (tok) {
      //           console.log(tok);
      //         })

        // EPUBJS.core.addCss("../libs/annotator/css/annotator.css", false, chapter.doc.head);

        if(callback) callback();

        function annotate(){
            // EPUBJS.core.addCss("css/annotator.css", false, chapter.doc.head);

            var s = document.createElement("script");
            s.type = 'text/javascript';

            console.log(jQuery);
            var a = "jQuery.migrateTrace = false;";
            a += "console.log(document.getElementById('c001p0002').getBoundingClientRect());";

            a += "var content = $('body').annotator().annotator('setupPlugins', {}, {Filter:false});";

            //-- Use Local Server:

            a += "var content = $('body').annotator(),";
            a += "  server = '" + server + "';";
            a += "  path = '" + chapter.path + "';";

            a += " content.annotator('addPlugin', 'Store', {";
            // The endpoint of the store on your server.
            a += "  prefix: server,";

            // Attach the uri of the current page to all annotations to allow search.
            a += "  annotationData: {";
            a += "  'uri': path";
            a += "  }";

              // This will perform a search action rather than read when the plugin
              // loads. Will request the last 20 annotations for the current url.
              // eg. /store/endpoint/search?limit=20&uri=http://this/document/only
            a += ","
            a += "  loadFromSearch: {";
            a += "  'limit': 20,";
            a += "  'uri': path";
            a += "  }";
            a += "});";

            s.innerHTML = a;

            chapter.doc.body.appendChild(s);

            if(callback) callback();
        }



}

1 个答案:

答案 0 :(得分:1)

关闭此解决方案:

该文件不是真正的ePub,它是用ePub.js摄取ePub然后以自定义方式显示它的“shell”...