This repository was archived by the owner on Sep 11, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +35
-2
lines changed
Expand file tree Collapse file tree 2 files changed +35
-2
lines changed Original file line number Diff line number Diff line change 359359
360360 Images . prototype . showImage = function ( img , data ) {
361361 var $place = this . $el . find ( '.medium-insert-active' ) ,
362- domImage ;
362+ domImage ,
363+ that ;
363364
364365 // Hide editor's placeholder
365366 $place . click ( ) ;
366367
367368 // If preview is allowed and preview image already exists,
368369 // replace it with uploaded image
370+ that = this ;
369371 if ( this . options . preview && data . context ) {
370372 domImage = this . getDOMImage ( ) ;
371373 domImage . onload = function ( ) {
372374 data . context . find ( 'img' ) . attr ( 'src' , domImage . src ) ;
375+ that . $el . trigger ( 'input' ) ;
373376 } ;
374377 domImage . src = img ;
375378 } else {
Original file line number Diff line number Diff line change @@ -171,6 +171,36 @@ asyncTest('triggering input event on showImage', function () {
171171 } ) ;
172172} ) ;
173173
174+ asyncTest ( 'triggering input event twice on showImage for preview' , function ( assert ) {
175+ var that = this ,
176+ inputTriggerCount = 0 ,
177+ stubbedImage ,
178+ context ;
179+
180+ stubbedImage = sinon . stub ( ) ;
181+ sinon . stub ( this . addon , 'getDOMImage' ) . returns ( stubbedImage ) ;
182+ context = this . $el . prepend ( '<div class="medium-insert-images medium-insert-active">' +
183+ '<figure><img src="data:" alt=""></figure>' +
184+ '</div>' ) ;
185+
186+ assert . expect ( 2 ) ;
187+ this . $el . on ( 'input' , function ( ) {
188+ if ( inputTriggerCount === 0 )
189+ start ( ) ;
190+ if ( inputTriggerCount === 2 ) {
191+ that . $el . off ( 'input' ) ;
192+ } else {
193+ inputTriggerCount ++ ;
194+ }
195+ ok ( 1 , 'input triggered' ) ;
196+ } ) ;
197+
198+ this . addon . showImage ( 'http://image.co' , {
199+ context : context
200+ } ) ;
201+ stubbedImage . onload ( ) ;
202+ } ) ;
203+
174204test ( 'selecting image' , function ( ) {
175205 this . $el . find ( 'p' )
176206 . addClass ( 'medium-insert-images' )
@@ -451,4 +481,4 @@ test('editor\'s serialize removes also contenteditable attr', function () {
451481
452482 equal(editor.serialize()['element-0'].value, html, 'contenteditable attr were removed');
453483});
454- */
484+ */
You can’t perform that action at this time.
0 commit comments