How do I insert text at the focus into a markitup editor with javascript?
I've implemented markitup to handle users entering markdown text. I want to replace the default image insert command with a nice jquery routine that lets the user browse for an image. I'm able to edit the set.js
file to call my javascript routine that brings up the file browser:
{name: 'Picture', key: 'P', call: 'insertImage'},
My insertImag开发者_运维知识库e
function looks like this:
function insertImage()
{
// launch Image Browser
}
When the user selects an image in the image browser, another javascript function is called:
function addImage(imageurl,alttext)
{
var imagetext = "!["+alttext+"]("+imageurl+")";
// how do I insert imageurl into markitup??
}
I need help implementing addImage
.
You just need to do this:
function addImage(imageurl,alttext)
{
var imagetext = "!["+alttext+"]("+imageurl+")";
$.markItUp({ replaceWith: imagetext });
}
精彩评论