UEditor 기반 단독 이미지 업로드 구현

1496 단어
// UEditor 
(function($){
    $.uploadimages = function(uploadId){
        var rand = Math.ceil(Math.random() * 1000) * Math.floor(Math.random() * 100);
        var editorId = 'upload_images_' +rand + '_ueditor';
        $("<div style='display:none;'></div>")
        .append("<script id='"+editorId+"' type='text/plain'></script>")
        .appendTo('body');

        var _editor = this.getEditor(editorId);
        _editor.ready(function(){
            _editor.setDisabled('insertimage');
            _editor.hide();
            _editor.addListener('beforeinsertimage',function(t,args){
                var url = args[0].src;
                //alert(t + '['+ uploadId+']:' + url);
                if(typeof(uploadId) == 'string'){
                    $('#' + uploadId).val(url);
                }else if(typeof(uploadId) == 'object'){
                    $(uploadId).val(url);
                }
                
            });
        });
    };

    $.uploadimages.prototype = {
        getEditor:function(editorId){
            this.editor = UE.getEditor(editorId);
            return this.editor;
        },
        show:function(){
            var _editor = this.editor;
            var img = _editor.getDialog('insertimage');
            img.render();
            img.open();
        }
    };
})(jQuery);

좋은 웹페이지 즐겨찾기