mditor icon indicating copy to clipboard operation
mditor copied to clipboard

更改图片工具条行为

Open wugy11 opened this issue 8 years ago • 7 comments

按照说明,更改图片工具条行为API:let btn = mditor.Toolbar.getItem('image');但页面报错:Uncaught TypeError: Cannot read property 'getItem' of undefined,求指教!

wugy11 avatar Apr 14 '17 00:04 wugy11

@devotion987

//toolbar 是小写的
let btn = mditor.toolbar.getItem('image');

Houfeng avatar Apr 14 '17 06:04 Houfeng

@Houfeng 小写也不行

wugy11 avatar Apr 14 '17 07:04 wugy11

@devotion987 是否写在了 ready 中?

//获取或设置编辑器的值
mditor.on('ready', function(){
  //toolbar 是小写的
  let btn = mditor.toolbar.getItem('image');
  console.log(btn);
});

Houfeng avatar Apr 14 '17 08:04 Houfeng

我是这么写的,按照你的方式没错了,感谢! $(document).ready(function () {

// window.mditor =
mditor = Mditor.fromTextarea(document.getElementById('md-editor'));

//更改按钮行为
//示例,更改「图片」按钮配置,其它按钮是同样的方法
let btn = mditor.toolbar.getItem('image');
//替换按钮动作
//btn.handler = function(){
//自定义处理逻辑
//this 指向当前 mditor 实例
}; 

});

wugy11 avatar Apr 14 '17 08:04 wugy11

@Houfeng 你好大神,想请教下点击“图片”工具条从本地选择图片然后上传到服务器,在上述代码 btn.handler == function() {} 代码块中该如何实现?谢谢!

wugy11 avatar Apr 14 '17 13:04 wugy11

@devotion987 你先去 google 一下,了解一些对应的浏览器 api,实现的过程中,有具体的问题,我会很乐意回答。

Houfeng avatar Apr 17 '17 01:04 Houfeng

@Houfeng 最近在使用tale搭建博客,编辑器使用的是mditor,觉得图片上传功能使用不太方便,想到两种实现方式,第一种是上面说的,第二种是当使用截图工具截取图片时,ctrl+v直接复制将图片上传到本地或者七牛服务器,然后返回图片链接地址。由于本人主要做后端开发,对前端了解不太多,还请指点一二,功能完成也可以分享出来,不胜感激,另外,有QQ或Q群可以加下,方便交流!

wugy11 avatar Apr 18 '17 00:04 wugy11