1111//= require libs/summernote
1212//= require libs/summernote-ko-KR
1313//= require libs/summernote-ext-video
14- //= require libs/summernote-ext-fontstyle
1514//= require libs/summernote-ext-codeblock
1615//= require libs/spin
1716//= require libs/jquery.spin
@@ -72,24 +71,57 @@ if (typeof jQuery !== 'undefined') {
7271 }
7372 } ) ;
7473
75- var onImagaUpload = function ( files , editor , $editable ) {
74+ $ . onImageUpload = function ( $editor ) {
7675
77- var $form = $ ( '.note-image-dialog .note-modal-form' ) ;
76+ return function ( files ) {
7877
79- $ ( '<iframe src="about:blank" style="display: none;" name="imageUploadHandlerFrame"></iframe>' ) . appendTo ( 'body' ) ;
78+ var createImage = function ( sUrl , filename ) {
79+ return $ . Deferred ( function ( deferred ) {
80+ var $img = $ ( '<img>' ) ;
8081
81- $ . imageUploaded = function ( image ) {
82- editor . insertImage ( $editable , image ) ;
83- } ;
82+ $img . one ( 'load' , function ( ) {
83+ $img . off ( 'error abort' ) ;
84+ deferred . resolve ( $img ) ;
85+ } ) . one ( 'error abort' , function ( ) {
86+ $img . off ( 'load' ) . detach ( ) ;
87+ deferred . reject ( $img ) ;
88+ } ) . css ( {
89+ display : 'none'
90+ } ) . appendTo ( document . body ) . attr ( {
91+ 'src' : sUrl ,
92+ 'data-filename' : filename
93+ } ) ;
94+ } ) . promise ( ) ;
95+ } ;
96+
97+ var $form = $ ( '.note-image-dialog .note-modal-form' ) ;
98+
99+ $ ( '<iframe src="about:blank" style="display: none;" name="imageUploadHandlerFrame"></iframe>' ) . appendTo ( 'body' ) ;
100+
101+ $ . imageUploaded = function ( sUrl , filename ) {
102+
103+ createImage ( sUrl , filename ) . then ( function ( $image ) {
104+ var width = $image . width ( ) >= $editor . width ( ) ? '100%' : $image . width ( ) ;
84105
85- $form . attr ( {
106+ $image . css ( {
107+ display : '' ,
108+ width : width
109+ } ) ;
110+
111+ $editor . summernote ( 'insertNode' , $image . get ( 0 ) ) ;
112+ } ) ;
113+ } ;
114+
115+ $form . attr ( {
86116 enctype : 'multipart/form-data' ,
87117 target : 'imageUploadHandlerFrame' ,
88118 action : contextPath + '/file/image' ,
89119 method : 'post'
90- } ) ;
120+ } ) ;
91121
92- $form [ 0 ] . submit ( ) ;
122+ $form [ 0 ] . submit ( ) ;
123+
124+ } ;
93125 } ;
94126
95127 $ . extend ( $ . summernote . options , {
@@ -107,8 +139,7 @@ if (typeof jQuery !== 'undefined') {
107139 [ 'para' , [ 'ul' , 'ol' , 'table' ] ] ,
108140 [ 'insert' , [ 'codeblock' , 'link' , 'picture' , 'video' , 'hr' ] ] ,
109141 [ 'view' , [ 'fullscreen' , 'codeview' , 'help' ] ]
110- ] ,
111- onImageUpload : onImagaUpload
142+ ]
112143 } ) ;
113144
114145 } ) ( jQuery ) ;
0 commit comments