Summernote文件上传

时间:2017-02-26 22:31:22

标签: javascript jquery jquery-plugins summernote

我使用summernote作为html编辑器。我想将文件上传到我的服务器并在我的系统中返回已保存文件的guid。我写了第二部分,问题是如何用模态添加模块。

(function (factory) {
    /* global define */
    if (typeof define === 'function' && define.amd) {
        // AMD. Register as an anonymous module.
        define(['jquery'], factory);
    } else if (typeof module === 'object' && module.exports) {
        // Node/CommonJS
        module.exports = factory(require('jquery'));
    } else {
        // Browser globals
        factory(window.jQuery);
    }
}(function ($) {

    // Extends plugins for adding hello.
    //  - plugin is external module for customizing.
    $.extend($.summernote.plugins, {
        /**
         * @param {Object} context - context object has status of editor.
         */
        'hello': function (context) {
            var self = this;
            console.log("hello");
            // ui has renders to build ui elements.
            //  - you can create a button with `ui.button`
            var ui = $.summernote.ui;

            // add hello button
            context.memo('button.hello', function () {
                // create button
                var button = ui.button({
                    contents: '<i class="fa fa-file"/> ',
                    tooltip: 'File',
                    click: function () {
                        //self.$panel.show();
                        //self.$panel.hide(500);
                        // invoke insertText method with 'hello' on editor module.
                        //$("#myModal3").modal();


                    }
                });

                // create jQuery object from button instance.
                var $hello = button.render();
                return $hello;
            });

            // This events will be attached when editor is initialized.
            this.events = {
                // This will be called after modules are initialized.
                'summernote.init': function (we, e) {
                    console.log('summernote initialized', we, e);
                },
                // This will be called when user releases a key on editable.
                'summernote.keyup': function (we, e) {
                    //console.log('summernote keyup', we, e);
                }
            };

            // This method will be called when editor is initialized by $('..').summernote();
            // You can create elements for plugin
            this.initialize = function () {
                this.$panel = $('<div class="hello-panel"/>').css({
                    position: 'absolute',
                    width: 100,
                    height: 100,
                    left: '50%',
                    top: '50%',
                    background: 'red'
                }).hide();

                this.$panel.appendTo('body');
            };

            // This methods will be called when editor is destroyed by $('..').summernote('destroy');
            // You should remove elements on `initialize`.
            this.destroy = function () {
                this.$panel.remove();
                this.$panel = null;
            };
        }
    });
})

下面的模块正在工作,但在这个模块中,我想打开模态,在模态选择文件中,当我点击模态的保存按钮时,我将发送post方法并获取guid并制作此URL。

如何为此模块使用模态。

提前致谢

0 个答案:

没有答案