惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
H
Hacker News: Front Page
P
Palo Alto Networks Blog
T
ThreatConnect
Apple Machine Learning Research
Apple Machine Learning Research
博客园_首页
T
True Tiger Recordings
P
Privacy & Cybersecurity Law Blog
B
Blog
IT之家
IT之家
Last Week in AI
Last Week in AI
F
Full Disclosure
Hacker News: Ask HN
Hacker News: Ask HN
C
Comments on: Blog
Microsoft Azure Blog
Microsoft Azure Blog
C
Cybersecurity and Infrastructure Security Agency CISA
Microsoft Security Blog
Microsoft Security Blog
博客园 - 【当耐特】
N
News and Events Feed by Topic
NISL@THU
NISL@THU
腾讯CDC
雷峰网
雷峰网
Security Latest
Security Latest
李成银的技术随笔
M
Microsoft Research Blog - Microsoft Research
L
LangChain Blog
L
Lohrmann on Cybersecurity
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
C
Check Point Blog
Y
Y Combinator Blog
Recent Announcements
Recent Announcements
博客园 - Franky
N
News | PayPal Newsroom
V
V2EX
A
About on SuperTechFans
The Register - Security
The Register - Security
月光博客
月光博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google Online Security Blog
Google Online Security Blog
MyScale Blog
MyScale Blog
Cisco Talos Blog
Cisco Talos Blog
Vercel News
Vercel News
WordPress大学
WordPress大学
C
Cyber Attacks, Cyber Crime and Cyber Security
The Hacker News
The Hacker News
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
爱范儿
爱范儿
A
Arctic Wolf
L
LINUX DO - 最新话题
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

博客园 - 蓝蓝的天2016

学习materialize VS2013 启用avalon 智能提示 Intelligence 推荐一款开源的C#TCP通讯框架 js/jquery 获取本地文件的文件路劲 获取input框中type=‘file’ 中的文件路径(转载) HTML5的 input:file上传类型控制(转载) Jquery append()总结(一) 转载 Visual Studio各版本工程文件之间的转换 [转载] 创建数据库表(转载) 用IIS防止mdb数据库被下载(转载) 放映PPT幻灯片演示文稿如何让演讲者备注不投影到屏幕上(转载) 操作App.config的类(转载) C# MemoryCache 类[转载] 转载css3 图片圆形显示 如何CSS将正方形图片显示为圆形图片布局 微信 学习网址 winform 路径 CodeSimth - .Net Framework Data Provider 可能没有安装。解决方法[转载 ] 加载js代码 tinymce 上传图片空间(转) 页面跳转
tinymce4.x 上传本地图片 (转载)
蓝蓝的天2016 · 2016-11-01 · via 博客园 - 蓝蓝的天2016

转载自:http://www.cnblogs.com/fhen/p/5809514.html

tinymce4.x 上传本地图片 

tinymce是一款挺不错的html文本编辑器。但是添加图片是直接添加链接,不能直接选择本地图片。

下面我写了一个插件用于直接上传本地图片。

在tinymce的plugins目录下新建一个uploadimage目录,用于存放我新写的上传本地图片的插件。

下面看看plugin.js文件的具体内容。

复制代码

/**
 * tinymce plugin
 * Created by jerry on 16/8/5.
 */
tinymce.PluginManager.add('uploadimage', function (editor) {

    function selectLocalImages() {
        var dom = editor.dom;
        var input_f = $('<input type="file" name="thumbnail" accept="image/jpg,image/jpeg,image/png,image/gif" multiple="multiple">');
        input_f.on('change', function () {
            var form = $("<form/>",
                {
                    action: editor.settings.upload_image_url, //设置上传图片的路由,配置在初始化时
                    style: 'display:none',
                    method: 'post',
                    enctype: 'multipart/form-data'
                }
            );
            form.append(input_f);
            //ajax提交表单
            form.ajaxSubmit({
                beforeSubmit: function () {
                    return true;
                },
                success: function (data) {
                    if (data && data.file_path) {
                        editor.focus();
                        data.file_path.forEach(function (src) {
                            editor.selection.setContent(dom.createHTML('img', {src: src}));
                        })
                    }
                }
            });
        });

        input_f.click();
    }

    editor.addCommand("mceUploadImageEditor", selectLocalImages);

    editor.addButton('uploadimage', {
        icon: 'image',
        tooltip: '上传图片',
        onclick: selectLocalImages
    });

    editor.addMenuItem('uploadimage', {
        icon: 'image',
        text: '上传图片',
        context: 'tools',
        onclick: selectLocalImages
    });
});

复制代码

下面是组件初始化js代码:

复制代码

tinymce.init({
            selector: "textarea[data-provide='tinymce']",
            upload_image_url: '/upload/cloud', //配置的上传图片的路由
            height: 400,
            plugins: [
                'advlist autolink autosave lists link image charmap print preview anchor',
                'searchreplace visualblocks code fullscreen textcolor colorpicker textpattern code uploadimage',
                'contextmenu paste'
            ],
            toolbar1: "undo redo | bold italic underline strikethrough | alignleft aligncenter alignright alignjustify | fontselect fontsizeselect ",
            toolbar2: "forecolor backcolor | bullist numlist | outdent indent | removeformat | link unlink uploadimage | preview fullscreen ",
            menubar: false,
            //statusbar : false,
            content_css: [
                '/style/tinymce.css'
            ]
            //参考网站 https://www.tinymce.com/
        });

复制代码

现在运行编辑器菜单如下:

点击图片小图标就可以从本地选择图片上传了。

posted on 2016-11-01 17:07  蓝蓝的天2016  阅读(834)  评论()    收藏  举报