@@ -218,6 +218,8 @@ global.MonsieurBizRichEditorManager = class {
218218 initInterface ( ) {
219219 this . initUiElementsInterface ( ) ;
220220 this . initUiPanelsInterface ( ) ;
221+ this . initUiToolsInterface ( ) ;
222+
221223 document . dispatchEvent ( new CustomEvent ( 'mbiz:rich-editor:init-interface-complete' , {
222224 'detail' : { 'editorManager' : this }
223225 } ) ) ;
@@ -226,6 +228,30 @@ global.MonsieurBizRichEditorManager = class {
226228 action . classList . remove ( 'disabled' ) ;
227229 } . bind ( this ) ) ;
228230 } . bind ( this ) ) ;
231+
232+ document . addEventListener ( 'mbiz:rich-editor:uielements:copied' , function ( e ) {
233+ this . container . querySelectorAll ( '.js-uie-tools-paste-all' ) . forEach ( function ( action ) {
234+ action . removeAttribute ( 'disabled' ) ;
235+ } . bind ( this ) ) ;
236+ } . bind ( this ) ) ;
237+ }
238+
239+ initUiToolsInterface ( ) {
240+ const copyAllButton = this . container . querySelector ( '.js-uie-tools-copy-all' ) ;
241+ const pasteAllButton = this . container . querySelector ( '.js-uie-tools-paste-all' ) ;
242+ const trashAllButton = this . container . querySelector ( '.js-uie-tools-trash-all' ) ;
243+
244+ copyAllButton && copyAllButton . addEventListener ( 'click' , e => {
245+ this . saveUiElementsToClipboard ( e . currentTarget ) ;
246+ } ) ;
247+
248+ pasteAllButton && pasteAllButton . addEventListener ( 'click' , e => {
249+ this . pasteUiElementsFromClipboard ( ) ;
250+ } ) ;
251+
252+ trashAllButton && trashAllButton . addEventListener ( 'click' , e => {
253+ this . resetUiElements ( ) ;
254+ } ) ;
229255 }
230256
231257 initUiPanelsInterface ( ) {
@@ -300,7 +326,7 @@ global.MonsieurBizRichEditorManager = class {
300326 ) ;
301327 } ) ;
302328 // Disabled?
303- if ( ! this . isClipboardEmpty ( ) ) {
329+ if ( ! this . isClipboardEmpty ( 'monsieurBizRichEditorElementClipboard' ) ) {
304330 actions . querySelector ( '.js-uie-paste' ) . classList . remove ( 'disabled' ) ;
305331 }
306332
@@ -617,19 +643,65 @@ global.MonsieurBizRichEditorManager = class {
617643 req . send ( data ) ;
618644 }
619645
620- isClipboardEmpty ( ) {
621- const clipboard = window . localStorage . getItem ( 'monsieurBizRichEditorClipboard' ) ;
646+ isClipboardEmpty ( clipboardKey ) {
647+ const clipboard = window . localStorage . getItem ( clipboardKey ) ;
622648 return null === clipboard || '' === clipboard ;
623649 }
624650
651+ resetUiElements ( ) {
652+ if ( this . uiElements . length === 0 ) {
653+ return ;
654+ }
655+
656+ this . loadUiConfirmationModal ( ( ) => { this . initUiElements ( [ ] , ( ) => { this . write ( ) ; } ) } )
657+ }
658+
659+ loadUiConfirmationModal ( callback ) {
660+ const modal = document . querySelector ( '#monsieurbiz-rich-editor-confirmation-modal' ) ;
661+ const confirmButton = modal . querySelector ( '#monsieurbiz-rich-editor-confirmation-button' ) ;
662+
663+ const clonedConfirmButtom = confirmButton . cloneNode ( true ) ;
664+ confirmButton . parentNode . replaceChild ( clonedConfirmButtom , confirmButton ) ;
665+ clonedConfirmButtom . addEventListener ( 'click' , ( ) => {
666+ callback ( ) ;
667+ } )
668+
669+ $ ( modal ) . modal ( 'show' ) ;
670+ }
671+
672+ saveUiElementsToClipboard ( button ) {
673+ window . localStorage . setItem ( 'monsieurBizRichEditorElementsClipboard' , JSON . stringify ( this . uiElements ) ) ;
674+
675+ const originalText = button . dataset . tooltip ;
676+ button . dataset . tooltip = button . dataset . alternateText ;
677+ window . setTimeout ( function ( ) {
678+ button . dataset . tooltip = originalText ;
679+ } , 1000 ) ;
680+
681+ document . dispatchEvent ( new CustomEvent ( 'mbiz:rich-editor:uielements:copied' , { } ) ) ;
682+ }
683+
684+ pasteUiElementsFromClipboard ( ) {
685+ const clipboard = window . localStorage . getItem ( 'monsieurBizRichEditorElementsClipboard' ) ;
686+ if ( clipboard !== null ) {
687+ const pastedUiElement = JSON . parse ( clipboard ) ;
688+
689+ if ( this . uiElements . length > 0 ) {
690+ this . loadUiConfirmationModal ( ( ) => { this . initUiElements ( pastedUiElement , ( ) => { this . write ( ) ; } ) } )
691+ } else {
692+ this . initUiElements ( pastedUiElement , ( ) => { this . write ( ) ; } ) ;
693+ }
694+ }
695+ }
696+
625697 saveUiElementToClipboard ( uiElement , callback ) {
626- window . localStorage . setItem ( 'monsieurBizRichEditorClipboard ' , JSON . stringify ( uiElement ) ) ;
698+ window . localStorage . setItem ( 'monsieurBizRichEditorElementClipboard ' , JSON . stringify ( uiElement ) ) ;
627699 callback ( ) ;
628700 document . dispatchEvent ( new CustomEvent ( 'mbiz:rich-editor:uielement:copied' , { } ) ) ;
629701 }
630702
631703 pasteUiElementFromClipboard ( futurePosition ) {
632- const clipboard = window . localStorage . getItem ( 'monsieurBizRichEditorClipboard ' ) ;
704+ const clipboard = window . localStorage . getItem ( 'monsieurBizRichEditorElementClipboard ' ) ;
633705 if ( null !== clipboard ) {
634706 const pastedUiElement = JSON . parse ( clipboard ) ;
635707 const manager = this ;
0 commit comments