@@ -385,7 +385,8 @@ if (!("classList" in document.createElement("_"))) {
385385
386386( function ( root , factory ) {
387387 'use strict' ;
388- if ( typeof module === 'object' ) {
388+ var isElectron = typeof module === 'object' && process && process . versions && process . versions . electron ;
389+ if ( ! isElectron && typeof module === 'object' ) {
389390 module . exports = factory ;
390391 } else if ( typeof define === 'function' && define . amd ) {
391392 define ( function ( ) {
@@ -2788,6 +2789,8 @@ MediumEditor.extensions = {};
27882789 // Detecting drop on the contenteditables
27892790 this . attachToEachElement ( 'drop' , this . handleDrop ) ;
27902791 break ;
2792+ // TODO: We need to have a custom 'paste' event separate from 'editablePaste'
2793+ // Need to think about the way to introduce this without breaking folks
27912794 case 'editablePaste' :
27922795 // Detecting paste on the contenteditables
27932796 this . attachToEachElement ( 'paste' , this . handlePaste ) ;
@@ -2984,7 +2987,7 @@ MediumEditor.extensions = {};
29842987 } ,
29852988
29862989 handlePaste : function ( event ) {
2987- this . triggerCustomEvent ( 'editablePaste' , { currentTarget : event . currentTarget , target : event . target } , event . currentTarget ) ;
2990+ this . triggerCustomEvent ( 'editablePaste' , event , event . currentTarget ) ;
29882991 } ,
29892992
29902993 handleKeydown : function ( event ) {
@@ -5171,11 +5174,20 @@ MediumEditor.extensions = {};
51715174 MediumEditor . Extension . prototype . init . apply ( this , arguments ) ;
51725175
51735176 if ( this . forcePlainText || this . cleanPastedHTML ) {
5174- this . subscribe ( 'editablePaste' , this . handlePaste . bind ( this ) ) ;
51755177 this . subscribe ( 'editableKeydown' , this . handleKeydown . bind ( this ) ) ;
5178+ // We need access to the full event data in paste
5179+ // so we can't use the editablePaste event here
5180+ this . getEditorElements ( ) . forEach ( function ( element ) {
5181+ this . on ( element , 'paste' , this . handlePaste . bind ( this ) ) ;
5182+ } , this ) ;
5183+ this . subscribe ( 'addElement' , this . handleAddElement . bind ( this ) ) ;
51765184 }
51775185 } ,
51785186
5187+ handleAddElement : function ( event , editable ) {
5188+ this . on ( editable , 'paste' , this . handlePaste . bind ( this ) ) ;
5189+ } ,
5190+
51795191 destroy : function ( ) {
51805192 // Make sure pastebin is destroyed in case it's still around for some reason
51815193 if ( this . forcePlainText || this . cleanPastedHTML ) {
@@ -5573,20 +5585,32 @@ MediumEditor.extensions = {};
55735585 } ,
55745586
55755587 initPlaceholders : function ( ) {
5576- this . getEditorElements ( ) . forEach ( function ( el ) {
5577- if ( ! el . getAttribute ( 'data-placeholder' ) ) {
5578- el . setAttribute ( 'data-placeholder' , this . text ) ;
5579- }
5580- this . updatePlaceholder ( el ) ;
5581- } , this ) ;
5588+ this . getEditorElements ( ) . forEach ( this . initElement , this ) ;
5589+ } ,
5590+
5591+ handleAddElement : function ( event , editable ) {
5592+ this . initElement ( editable ) ;
5593+ } ,
5594+
5595+ initElement : function ( el ) {
5596+ if ( ! el . getAttribute ( 'data-placeholder' ) ) {
5597+ el . setAttribute ( 'data-placeholder' , this . text ) ;
5598+ }
5599+ this . updatePlaceholder ( el ) ;
55825600 } ,
55835601
55845602 destroy : function ( ) {
5585- this . getEditorElements ( ) . forEach ( function ( el ) {
5586- if ( el . getAttribute ( 'data-placeholder' ) === this . text ) {
5587- el . removeAttribute ( 'data-placeholder' ) ;
5588- }
5589- } , this ) ;
5603+ this . getEditorElements ( ) . forEach ( this . cleanupElement , this ) ;
5604+ } ,
5605+
5606+ handleRemoveElement : function ( event , editable ) {
5607+ this . cleanupElement ( editable ) ;
5608+ } ,
5609+
5610+ cleanupElement : function ( el ) {
5611+ if ( el . getAttribute ( 'data-placeholder' ) === this . text ) {
5612+ el . removeAttribute ( 'data-placeholder' ) ;
5613+ }
55905614 } ,
55915615
55925616 showPlaceholder : function ( el ) {
@@ -5615,7 +5639,7 @@ MediumEditor.extensions = {};
56155639
56165640 updatePlaceholder : function ( el , dontShow ) {
56175641 // If the element has content, hide the placeholder
5618- if ( el . querySelector ( 'img, blockquote, ul, ol' ) || ( el . textContent . replace ( / ^ \s + | \s + $ / g, '' ) !== '' ) ) {
5642+ if ( el . querySelector ( 'img, blockquote, ul, ol, table ' ) || ( el . textContent . replace ( / ^ \s + | \s + $ / g, '' ) !== '' ) ) {
56195643 return this . hidePlaceholder ( el ) ;
56205644 }
56215645
@@ -5635,6 +5659,10 @@ MediumEditor.extensions = {};
56355659
56365660 // When the editor loses focus, check if the placeholder should be visible
56375661 this . subscribe ( 'blur' , this . handleBlur . bind ( this ) ) ;
5662+
5663+ // Need to know when elements are added/removed from the editor
5664+ this . subscribe ( 'addElement' , this . handleAddElement . bind ( this ) ) ;
5665+ this . subscribe ( 'removeElement' , this . handleRemoveElement . bind ( this ) ) ;
56385666 } ,
56395667
56405668 handleInput : function ( event , element ) {
@@ -7587,6 +7615,9 @@ MediumEditor.extensions = {};
75877615
75887616 // Add new elements to our internal elements array
75897617 this . elements . push ( element ) ;
7618+
7619+ // Trigger event so extensions can know when an element has been added
7620+ this . trigger ( 'addElement' , { target : element , currentTarget : element } , element ) ;
75907621 } , this ) ;
75917622 } ,
75927623
@@ -7609,6 +7640,8 @@ MediumEditor.extensions = {};
76097640 if ( element . getAttribute ( 'medium-editor-textarea-id' ) ) {
76107641 cleanupTextareaElement ( element ) ;
76117642 }
7643+ // Trigger event so extensions can clean-up elements that are being removed
7644+ this . trigger ( 'removeElement' , { target : element , currentTarget : element } , element ) ;
76127645 return false ;
76137646 }
76147647 return true ;
@@ -7664,7 +7697,7 @@ MediumEditor.parseVersionString = function (release) {
76647697
76657698MediumEditor . version = MediumEditor . parseVersionString . call ( this , ( {
76667699 // grunt-bump looks for this:
7667- 'version' : '5.20.2 '
7700+ 'version' : '5.21.0 '
76687701} ) . version ) ;
76697702
76707703 return MediumEditor ;
0 commit comments