Pagedown markdown脚本一次插入图片网址 [英] Pagedown markdown script inserts image url once

查看:113
本文介绍了Pagedown markdown脚本一次插入图片网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个经过修改的pagedown markdown标记脚本,用于将图像url插入到编辑器中,但是它只能在第一次使用.

I have a modified pagedown markdown markup script for inserting image url to the editor but it works only the first time.

我已经用注释解释了我的代码

I have explained my code with comments

 </script>
 <script type="text/javascript">
(function () {
 var converter = new Markdown.Converter();
 var help = function () { window.open('http://mywebsite.com/editing-help'); }
 var editor = new Markdown.Editor(converter);
 editor.hooks.set('insertImageDialog', function(callback) {
 setTimeout(function () 
{
        //i use bootstrap dialog to enter the url
        $('#fileModal').modal('show');  

        /*i have a button for clearing the textbox when i open 
        it the second time since when i open it the second 
        time the modal still contains what i had placed previously*/
        $("#clear").on("click", function(e) {
        e.preventDefault();
          $("#imgt").val(''); 
          $("#file").val('');
        });


        //the button that when clicked inserts the image url
        $("#insert_image_post").on("click", function(e) {
        e.preventDefault(); 

        //the image file being inserted
        if($("#imgt").val().length > 0)
        {
            var $url    =   $('input[type=text]');
            var image   =   $("#imgt").val();
            callback(image);
            $("#fileModal").modal('hide');

        }

    });


 }, 0);
return true; // tell the editor that we'll take care of getting the image url
 });

editor.run();

})();
</script>

有没有使用pagedown markdown javascript的人...可以帮助我了解我要去哪里的想法吗?

Any one with pagedown markdown javascript... ideas to help me understand where i am going wrong?

推荐答案

我设法使其正常工作

在我的情况下,就像markdown编辑器无法顺利运行.on("click", function(e)...一样.即

Its like markdown editor does not smoothly run the .on("click", function(e)... in my case. i.e.

$("#insert_image_post").on("click", function(e) {
e.preventDefault(); 

所以我在浏览了他们的Markdown.Editor.js文件后即使用了他们的文件.

So i used theirs after going through their Markdown.Editor.js file i.e.

var thebtn = document.getElementById("insert_image_post");
thebtn.onclick = function () {

下面的完整调整后的代码

The full adjusted code below

<script>
(function () {
 var converter = new Markdown.Converter();
 var help = function () { window.open('http://stackoverflow.com/editing-help'); }
 var editor = new Markdown.Editor(converter);

 editor.hooks.set("insertImageDialog", function (callback) {

        $('#fileModal').modal('show');

            var thebtn = document.getElementById("insert_image_post");
            thebtn.onclick = function () {
                var images  =   $(".img-url").val();
                callback(images)
                 $('#fileModal').modal('hide');
            };

            var theclear = document.getElementById("clear");
            theclear.onclick = function () {

                  $("#imgt").val(''); 
                  $("#file").val('');

            };

    return true; // tell the editor that we'll take care of getting the image url
});

editor.run();

})();

</script>

这篇关于Pagedown markdown脚本一次插入图片网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆