2016-09-18 14 views
2

我有一個修改的pagedown markdown腳本插入圖像的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> 

任何一個與PageDown鍵降價的JavaScript ...想法,以幫助我理解我要去的地方錯誤的代碼?

回答

0

我設法使它工作

它就像降價編輯器不流暢運行在我的情況下.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>