【问题标题】:How to open a file with epiceditor?如何用epiceditor打开文件?
【发布时间】:2013-08-08 04:45:17
【问题描述】:

我有以下文件结构

在 content.php 中我有以下 JS 代码

        var file = "http://2sense.net/blog/posts/my-second-post.md"
        var opts = {
          basePath: "http://2sense.net/blog/posts/",
          container: 'epiceditor',
          textarea: null,
          basePath: 'epiceditor',
          clientSideStorage: true,
          localStorageName: 'epiceditor',
          useNativeFullscreen: true,
          parser: marked,
          file: {
            name: 'epiceditor',
            defaultContent: '',
            autoSave: 100
          },
          theme: {
            base: '/themes/base/epiceditor.css',
            preview: '/themes/preview/preview-dark.css',
            editor: '/themes/editor/epic-dark.css'
          },
          button: {
            preview: true,
            fullscreen: true
          },
          focusOnLoad: false,
          shortcut: {
            modifier: 18,
            fullscreen: 70,
            preview: 80
          },
          string: {
            togglePreview: 'Toggle Preview Mode',
            toggleEdit: 'Toggle Edit Mode',
            toggleFullscreen: 'Enter Fullscreen'
          }
        }
        window.editor = new EpicEditor(opts);
        editor.load(function () {
          console.log("Editor loaded.")
        });

        $("#openfile").on("click", function() {
            console.log("openfile");
            editor.open(file);
            editor.enterFullscreen();
        })

当我尝试使用“editor.open(file);”打开文件时不会发生任何事情。而且我已经验证了当我按下按钮时该事件被正确触发。 你知道如何解决这个问题吗,或者你有一个真实的例子吗……epiceditor 网站上的 API 文档并没有说太多。

干杯

【问题讨论】:

    标签: javascript epiceditor


    【解决方案1】:

    客户端 JS 无法打开桌面文件(或者,不容易或跨浏览器)。这将是与 File API 一起使用的一个不错的功能,但尚未实现。 EpicEditor 将“文件”存储在 localStorage 中。当您执行editor.open('foo') 时,您基本上是在执行:JSON.parse(localStorage['epiceditor'])['foo'].content。这已经被问过几次了,所以我做了一张票,以便在文档中更清楚地说明。

    https://github.com/OscarGodson/EpicEditor/issues/276

    这有帮助吗?

    附:总是欢迎您提出对您有意义的文档的拉取请求:)

    【讨论】:

    • 谢谢奥斯卡!任何其他“已知”的解决方案可以实现这一目标?
    • 使用你的后端语言像editor.import($filename, $content)那样写给它,或者像$.get('/path/to/file.md', function (data) { editor.importFile('file', data) })那样使用ajax来写
    猜你喜欢
    • 1970-01-01
    • 2010-10-05
    • 1970-01-01
    • 1970-01-01
    • 2010-10-28
    • 1970-01-01
    • 2013-09-22
    • 2019-12-28
    • 2016-03-27
    相关资源
    最近更新 更多