@@ -151,13 +151,15 @@ this["MediumInsert"]["Templates"]["src/js/templates/images-toolbar.hbs"] = Handl
151151 this . _name = pluginName ;
152152
153153 // Extend editor's functions
154- if ( options && options . editor ) {
155- options . editor . _serialize = options . editor . serialize ;
156- options . editor . _deactivate = options . editor . deactivate ;
157- options . editor . _activate = options . editor . activate ;
158- options . editor . serialize = this . editorSerialize ;
159- options . editor . deactivate = this . editorDeactivate ;
160- options . editor . activate = this . editorActivate ;
154+ if ( this . options && this . options . editor ) {
155+ this . options . editor . _serialize = this . options . editor . serialize ;
156+ this . options . editor . _deactivate = this . options . editor . deactivate ;
157+ this . options . editor . _activate = this . options . editor . activate ;
158+ this . options . editor . _hideInsertButtons = this . hideButtons ;
159+ this . options . editor . serialize = this . editorSerialize ;
160+ this . options . editor . deactivate = this . editorDeactivate ;
161+ this . options . editor . activate = this . editorActivate ;
162+ this . options . editor . activatePlaceholder = this . editorActivatePlaceholder ;
161163 }
162164
163165 this . init ( ) ;
@@ -192,8 +194,8 @@ this["MediumInsert"]["Templates"]["src/js/templates/images-toolbar.hbs"] = Handl
192194 . on ( 'dragover drop' , function ( e ) {
193195 e . preventDefault ( ) ;
194196 } )
195- . on ( 'blur' , $ . proxy ( this , 'addEditorPlaceholder ' ) )
196- . on ( 'keyup click' , $ . proxy ( this , 'showButtons ' ) )
197+ . on ( 'blur' , $ . proxy ( this , 'activatePlaceholder ' ) )
198+ . on ( 'keyup click' , $ . proxy ( this , 'toggleButtons ' ) )
197199 . on ( 'selectstart mousedown' , '.medium-insert, .medium-insert-buttons' , $ . proxy ( this , 'disableSelection' ) )
198200 . on ( 'keydown' , $ . proxy ( this , 'fixSelectAll' ) )
199201 . on ( 'click' , '.medium-insert-buttons-show' , $ . proxy ( this , 'toggleAddons' ) )
@@ -250,6 +252,38 @@ this["MediumInsert"]["Templates"]["src/js/templates/images-toolbar.hbs"] = Handl
250252 } ) ;
251253 } ;
252254
255+ /**
256+ * Extend editor's activatePlaceholder function to activate placeholder dispite of the plugin buttons
257+ *
258+ * @return {void }
259+ */
260+
261+ Core . prototype . editorActivatePlaceholder = function ( el ) {
262+ var $clone = $ ( el ) . clone ( ) ,
263+ cloneHtml ;
264+
265+ $clone . find ( '.medium-insert-buttons' ) . remove ( ) ;
266+ cloneHtml = $clone . html ( ) . replace ( / ^ \s + | \s + $ / g, '' ) . 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 > $ / , '' ) ;
267+
268+ if ( ! ( el . querySelector ( 'img' ) ) &&
269+ ! ( el . querySelector ( 'blockquote' ) ) &&
270+ cloneHtml === '' ) {
271+
272+ el . classList . add ( 'medium-editor-placeholder' ) ;
273+ this . _hideInsertButtons ( $ ( el ) ) ;
274+ }
275+ } ;
276+
277+ /**
278+ * Activate placeholder
279+ *
280+ * @return {void }
281+ */
282+
283+ Core . prototype . activatePlaceholder = function ( ) {
284+ this . options . editor . activatePlaceholder ( this . $el . get ( 0 ) ) ;
285+ } ;
286+
253287 /**
254288 * Deselects selected text
255289 *
@@ -322,24 +356,6 @@ this["MediumInsert"]["Templates"]["src/js/templates/images-toolbar.hbs"] = Handl
322356 }
323357 } ;
324358
325- /**
326- * Adds .medium-editor-placeholder class to the editor, when its content is empty
327- *
328- * @return {void }
329- */
330-
331- Core . prototype . addEditorPlaceholder = function ( ) {
332- var $clone = this . $el . clone ( ) ,
333- cloneHtml ;
334-
335- $clone . find ( '.medium-insert' ) . remove ( ) ;
336- cloneHtml = $clone . html ( ) . replace ( / ^ \s + | \s + $ / g, '' ) ;
337-
338- if ( cloneHtml === '' || cloneHtml === '<p><br></p>' ) {
339- this . $el . addClass ( 'medium-editor-placeholder' ) ;
340- }
341- } ;
342-
343359 /**
344360 * Initialize addons
345361 *
@@ -434,7 +450,7 @@ this["MediumInsert"]["Templates"]["src/js/templates/images-toolbar.hbs"] = Handl
434450 * @return {void }
435451 */
436452
437- Core . prototype . showButtons = function ( e ) {
453+ Core . prototype . toggleButtons = function ( e ) {
438454 var $el = $ ( e . target ) ,
439455 selection = window . getSelection ( ) ,
440456 range = selection . getRangeAt ( 0 ) ,
@@ -475,12 +491,15 @@ this["MediumInsert"]["Templates"]["src/js/templates/images-toolbar.hbs"] = Handl
475491 /**
476492 * Hides buttons
477493 *
494+ * @param {jQuery } $el - Editor element
478495 * @returns {void }
479496 */
480497
481- Core . prototype . hideButtons = function ( ) {
482- this . $el . find ( '.medium-insert-buttons' ) . hide ( ) ;
483- this . $el . find ( '.medium-insert-buttons-addons' ) . hide ( ) ;
498+ Core . prototype . hideButtons = function ( $el ) {
499+ $el = $el || this . $el ;
500+
501+ $el . find ( '.medium-insert-buttons' ) . hide ( ) ;
502+ $el . find ( '.medium-insert-buttons-addons' ) . hide ( ) ;
484503 } ;
485504
486505 /**
0 commit comments