Сценарий уценки Pagedown вставляет URL-адрес изображения один раз

У меня есть модифицированный скрипт разметки pagedown markdown для вставки URL-адреса изображения в редактор, но он работает только в первый раз.

Я объяснил свой код с комментариями

 </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>

Любой, у кого есть javascript уценки страницы вниз ... идеи, которые помогут мне понять, где я ошибаюсь?


person Omari Victor Omosa    schedule 18.09.2016    source источник


Ответы (1)


мне удалось заставить его работать

В моем случае это похоже на то, что редактор уценки не работает плавно с .on("click", function(e).... то есть

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

Поэтому я использовал их после просмотра их файла Markdown.Editor.js, т.е.

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

Полный скорректированный код ниже

<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>
person Omari Victor Omosa    schedule 19.09.2016