Skip to content Skip to sidebar Skip to footer

Pagedown Markdown Script Inserts Image Url Once

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

Solution 1:

I managed to make it work

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(); 

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 = newMarkdown.Converter();
 var help = function () { window.open('http://stackoverflow.com/editing-help'); }
 var editor = newMarkdown.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('');

            };

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

editor.run();

})();

</script>

Post a Comment for "Pagedown Markdown Script Inserts Image Url Once"