Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

更改图片工具条行为 #30

Open
wugy11 opened this issue Apr 14, 2017 · 7 comments
Open

更改图片工具条行为 #30

wugy11 opened this issue Apr 14, 2017 · 7 comments

Comments

@wugy11
Copy link

wugy11 commented Apr 14, 2017

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

@Houfeng
Copy link
Owner

Houfeng commented Apr 14, 2017

@devotion987

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

@wugy11
Copy link
Author

wugy11 commented Apr 14, 2017

@Houfeng 小写也不行

@Houfeng
Copy link
Owner

Houfeng commented Apr 14, 2017

@devotion987
是否写在了 ready 中?

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

@wugy11
Copy link
Author

wugy11 commented Apr 14, 2017

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

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

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

});

@wugy11
Copy link
Author

wugy11 commented Apr 14, 2017

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

@Houfeng
Copy link
Owner

Houfeng commented Apr 17, 2017

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

@wugy11
Copy link
Author

wugy11 commented Apr 18, 2017

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants