简体   繁体   English

将PageDown编辑器嵌入到网页中时,如何阻止它进行实时转换?

[英]When embedding PageDown editor in my webpage, how I can I stop it from doing conversion in real time?

I noticed from the docs that PageDown offers a refreshPreview method. 我从文档中注意到PageDown提供了refreshPreview方法。 I'd like to turn off real-time editing and use this method to only do the conversion when the user presses a preview button. 我想关闭实时编辑,并仅在用户按下预览按钮时使用此方法进行转换。

I tried having the onPreviewRefresh hook return false, but it still updates on every change event. 我尝试使onPreviewRefresh挂钩返回false,但是它仍会在每个更改事件上更新。

Here is my code: 这是我的代码:

$(document).ready(function() {
  var converter = Markdown.getSanitizingConverter();
  Markdown.Extra.init(converter, {table_class: "table table-striped"});
  var editor = new Markdown.Editor(converter);

  editor.hooks.chain("onPreviewRefresh", function () {
    console.debug("the preview has been updated");
  });

  editor.run();

  (function() {
    $('#wmd-preview').hide();

    $('button.preview').click(function() {
      editor.refreshPreview();
      $('#wmd-editor').hide();
      $('#wmd-preview').show();
    });

    $('button.edit').click(function() {
      $('#wmd-preview').hide();
      $('#wmd-editor').show();
    });
  })();
});

Update: 更新:

Commenting out the following line ( line 909 here ) will actually accomplish what I want: 注释掉以下行( 此处为909行 )实际上将完成我想要的操作:

//timeout = setTimeout(makePreviewHtml, delay);

However, I'd be worried about unintended side effects, so I'd prefer a more surgical approach -- preferably one that doesn't require modifying the editor source code. 但是,我会担心意外的副作用,所以我更喜欢一种外科手术方法-最好是不需要修改编辑器源代码的方法。

There is one function called refreshPreview() which, according to the docs, 根据文档,有一个函数称为refreshPreview()

forces the preview to be updated. 强制更新预览。 This method is only available after run() was called. 该方法仅在调用run()之后可用。

So you can probably call that function in the click handler to the button that you will create to control refreshes, for example : 因此,您可能可以在点击处理程序中将该函数调用到将要创建的用于控制刷新的按钮, 例如

var converter1 = Markdown.getSanitizingConverter();
var editor1 = new Markdown.Editor(converter1);
editor1.run();
editor1.refreshPreview(); //<- something like this

Now as for preventing a refresh on each keydown and keypress events (that's how PageDown does it I guess), I think you have at least two options : 现在,关于防止刷新每个keydownkeypress事件(我猜这就是PageDown的方式),我认为您至少有两个选择

  • Write your custom javascript/jquery code that overrides keydown / keypress events for the input text area 编写您的自定义javascript / jquery代码,该代码将覆盖输入文本区域的keydown / keypress事件
  • Edit file Markdown.Editor.js (around lines 593-627 in my version) so as to comment out the lines where event handlers are set up for keypress and keydown events. 编辑文件Markdown.Editor.js (大约在我的版本线593-627),以注释掉其中的事件处理程序都设置了按键的keydown事件的线。 In particular, I think it's the following line that triggers refreshes from key events: 特别是,我认为是以下几行触发了关键事件的刷新:

     util.addEvent(panels.input, "keydown", handleModeChange); 

Hope this helps. 希望这可以帮助。

The update I added to my question actually led me to an answer. 我添加到问题中的更新实际上使我找到了答案。

Apparently, the startType var here in the PreviewManager function was provided expressly for this purpose. 显然,为此明确提供了PreviewManager函数中startType var。 Changing it from delayed to manual has the desired effect (hopefully without unforeseen side-effects). 将其从delayed更改为manual具有预期的效果(希望不会产生不可预见的副作用)。

I'd feel more reassured if the setting had been offered as a Markdown.Editor configuration option. 如果将设置作为Markdown.Editor配置选项提供,我会更加放心。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 单击时如何实时更新组件? - How can I update my component in real time when clicking? 如何在网页上启用/禁用(实时)javascript插件? - How can I enable/disable(in real time) javascript plugins on a webpage? 如何使用mysql数据库中的nodejs和socket.io在网页上实时更新? - How can I get real time update on a webpage using nodejs and socket.io from a mysql database? 如何在pagedown编辑器中提供自己的插入链接对话框? - How do I provide my own insert link dialog in pagedown editor? 如何更改Google Pagedown Editor以使用字体真棒图标? - How can I change the Google Pagedown Editor to use font awesome icons? 如何修复用Javascript制作的实时时钟(我在网页中看不到)? - How do I fix a real-time-clock made in Javascript(I can't see it in the webpage)? 如何打包Github的Atom编辑器以嵌入网页? - How do I package up Github's Atom editor for embedding on a webpage? 打印网页时如何隐藏输入内容? - How can I hide my inputs when printing my webpage? 如何在网页上显示其他时区的当前时间? - How can I show the current time from a different timezone on my webpage? 如何在我的网页上每分钟从所选时区更新时间? - How can I update the time from chosen timezone every minute on my webpage?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM