首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >配置为使用localStorage作为终结点,而不是本地服务器

配置为使用localStorage作为终结点,而不是本地服务器
EN

Stack Overflow用户
提问于 2014-11-18 05:56:26
回答 1查看 418关注 0票数 0

我使用的是一个generates annotations within an ePub的javascript库。我希望使用HTML5 localStorage来存储注释数据。

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

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

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

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

我编辑后的当前版本(不起作用)如下:

代码语言:javascript
运行
复制
    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();
        }



}
EN

回答 1

Stack Overflow用户

发布于 2015-04-10 00:06:28

为了结束这个循环,解决方案:

这个文件不是一个真正的ePub,它是一个用ePub.js摄取ePub然后以定制的方式显示它的“外壳”……

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26982738

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档