11/*!
2- * medium-editor-insert-plugin v2.2.0 - jQuery insert plugin for MediumEditor
2+ * medium-editor-insert-plugin v2.2.1 - jQuery insert plugin for MediumEditor
33 *
44 * https://github.com/orthes/medium-editor-insert-plugin
55 *
@@ -315,15 +315,10 @@ this["MediumInsert"]["Templates"]["src/js/templates/images-toolbar.hbs"] = Handl
315315 */
316316
317317 Core . prototype . editorUpdatePlaceholder = function ( el ) {
318- var $clone = $ ( el ) . clone ( ) ,
319- cloneHtml ;
318+ var contents = $ ( el ) . children ( )
319+ . not ( '.medium-insert-buttons' ) . contents ( ) ;
320320
321- $clone . find ( '.medium-insert-buttons' ) . remove ( ) ;
322- cloneHtml = $clone . html ( )
323- . replace ( / ^ \s + | \s + $ / g, '' )
324- . replace ( / ^ < p ( c l a s s = " m e d i u m - i n s e r t - a c t i v e " ) ? > < b r > < \/ p > $ / , '' ) ;
325-
326- if ( ! ( el . querySelector ( 'img, blockquote' ) ) && cloneHtml === '' ) {
321+ if ( contents . length === 1 && contents [ 0 ] . nodeName . toLowerCase ( ) === 'br' ) {
327322 this . showPlaceholder ( el ) ;
328323 this . base . _hideInsertButtons ( $ ( el ) ) ;
329324 } else {
@@ -1484,6 +1479,7 @@ this["MediumInsert"]["Templates"]["src/js/templates/images-toolbar.hbs"] = Handl
14841479 function Images ( el , options ) {
14851480 this . el = el ;
14861481 this . $el = $ ( el ) ;
1482+ this . $currentImage = null ;
14871483 this . templates = window . MediumInsert . Templates ;
14881484 this . core = this . $el . data ( 'plugin_' + pluginName ) ;
14891485
@@ -1735,14 +1731,10 @@ this["MediumInsert"]["Templates"]["src/js/templates/images-toolbar.hbs"] = Handl
17351731 */
17361732
17371733 Images . prototype . uploadDone = function ( e , data ) {
1738- var $el = $ . proxy ( this , 'showImage' , data . result . files [ 0 ] . url , data ) ( ) ;
1734+ $ . proxy ( this , 'showImage' , data . result . files [ 0 ] . url , data ) ( ) ;
17391735
17401736 this . core . clean ( ) ;
17411737 this . sorting ( ) ;
1742-
1743- if ( this . options . uploadCompleted ) {
1744- this . options . uploadCompleted ( $el , data ) ;
1745- }
17461738 } ;
17471739
17481740 /**
@@ -1767,8 +1759,13 @@ this["MediumInsert"]["Templates"]["src/js/templates/images-toolbar.hbs"] = Handl
17671759 domImage = this . getDOMImage ( ) ;
17681760 domImage . onload = function ( ) {
17691761 data . context . find ( 'img' ) . attr ( 'src' , domImage . src ) ;
1762+
1763+ if ( this . options . uploadCompleted ) {
1764+ this . options . uploadCompleted ( data . context , data ) ;
1765+ }
1766+
17701767 that . core . triggerInput ( ) ;
1771- } ;
1768+ } . bind ( this ) ;
17721769 domImage . src = img ;
17731770 } else {
17741771 data . context = $ ( this . templates [ 'src/js/templates/images-image.hbs' ] ( {
@@ -1798,6 +1795,8 @@ this["MediumInsert"]["Templates"]["src/js/templates/images-toolbar.hbs"] = Handl
17981795
17991796 if ( this . options . preview ) {
18001797 data . submit ( ) ;
1798+ } else if ( this . options . uploadCompleted ) {
1799+ this . options . uploadCompleted ( data . context , data ) ;
18011800 }
18021801 }
18031802
@@ -1822,6 +1821,8 @@ this["MediumInsert"]["Templates"]["src/js/templates/images-toolbar.hbs"] = Handl
18221821 var $image = $ ( e . target ) ,
18231822 that = this ;
18241823
1824+ this . $currentImage = $image ;
1825+
18251826 // Hide keyboard on mobile devices
18261827 this . $el . blur ( ) ;
18271828
@@ -1864,6 +1865,7 @@ this["MediumInsert"]["Templates"]["src/js/templates/images-toolbar.hbs"] = Handl
18641865 } else if ( $el . is ( 'figcaption' ) === false ) {
18651866 this . core . removeCaptions ( ) ;
18661867 }
1868+ this . $currentImage = null ;
18671869 } ;
18681870
18691871 /**
@@ -1990,6 +1992,7 @@ this["MediumInsert"]["Templates"]["src/js/templates/images-toolbar.hbs"] = Handl
19901992 */
19911993
19921994 Images . prototype . toolbarAction = function ( e ) {
1995+ if ( this . $currentImage === null ) return ;
19931996 var $button = $ ( e . target ) . is ( 'button' ) ? $ ( e . target ) : $ ( e . target ) . closest ( 'button' ) ,
19941997 $li = $button . closest ( 'li' ) ,
19951998 $ul = $li . closest ( 'ul' ) ,
@@ -2031,6 +2034,7 @@ this["MediumInsert"]["Templates"]["src/js/templates/images-toolbar.hbs"] = Handl
20312034 */
20322035
20332036 Images . prototype . toolbar2Action = function ( e ) {
2037+ if ( this . $currentImage === null ) return ;
20342038 var $button = $ ( e . target ) . is ( 'button' ) ? $ ( e . target ) : $ ( e . target ) . closest ( 'button' ) ,
20352039 callback = this . options . actions [ $button . data ( 'action' ) ] . clicked ;
20362040
0 commit comments