11( function ( $ , fwe , data ) {
2+
23 var gui = {
4+ gutenbergContainer : $ ( '#editor.block-editor__container' ) ,
5+ isGutenberg : function ( ) {
6+ return this . gutenbergContainer . length > 0 ;
7+ } ,
38 elements : {
4- $useBuilderBtn : $ ( '<a href="#" class="button button-primary">' + data . l10n . showButton + '</a>' ) ,
9+ $useBuilderBtn : $ ( '<a href="#" class="button button-primary fw-use-builder ">' + data . l10n . showButton + '</a>' ) ,
510 $useWpEditorBtn : $ ( '<a href="#" class="button button-primary page-builder-hide-button">' + data . l10n . hideButton + '</a>' ) ,
611 $option : $ ( '#' + data . optionId ) ,
712 $builderBox : null , // initialized later
4449 }
4550 } ,
4651 showBuilder : function ( ) {
47-
4852 this . elements . $useWpEditorBtn . show ( ) ;
4953 this . elements . $wpPostBodyContent . addClass ( 'page-builder-visible' ) ;
5054 this . elements . $wpPostDivRich . addClass ( 'fw-disable-editor' ) ;
5155 this . elements . $builderBox . show ( ) . removeClass ( 'closed' ) ;
5256
57+ if ( this . isGutenberg ( ) ) {
58+
59+ if ( ! wp . data . select ( 'core/editor' ) . getEditedPostAttribute ( 'title' ) ) {
60+ wp . data . dispatch ( 'core/editor' ) . editPost ( { title : 'Post #' + $ ( '#post_ID' ) . val ( ) } ) ;
61+ }
62+
63+ this . gutenbergContainer . find ( '.edit-post-header-toolbar' ) . children ( ) . hide ( ) ;
64+ this . elements . $useWpEditorBtn . show ( ) ;
65+ this . elements . $useBuilderBtn . hide ( ) ;
66+ this . gutenbergContainer . find ( '.editor-block-list__layout' ) . hide ( ) ;
67+ }
68+
5369 // set the hidden to store that the builder is active
5470 this . elements . $builderActiveHidden . val ( 'true' ) ;
5571
5672 this . events . trigger ( 'show' ) ;
5773 } ,
5874 hideBuilder : function ( ) {
59-
6075 this . elements . $wpPostBodyContent . removeClass ( 'page-builder-visible' ) ;
6176 this . elements . $useWpEditorBtn . hide ( ) ;
6277 this . elements . $builderBox . hide ( ) ;
6580 // set the hidden to store that the builder is inactive
6681 this . elements . $builderActiveHidden . val ( 'false' ) ;
6782 //tinyMCE.get( gui.editorId ).execCommand("mceRepaint");
83+
84+ if ( this . isGutenberg ( ) ) {
85+ this . gutenbergContainer . find ( '.edit-post-header-toolbar' ) . children ( ) . show ( ) ;
86+ this . elements . $useWpEditorBtn . hide ( ) ;
87+ this . elements . $useBuilderBtn . show ( ) ;
88+ this . gutenbergContainer . find ( '.editor-block-list__layout' ) . show ( ) ;
89+ }
90+
6891 this . events . trigger ( 'hide' ) ;
6992 } ,
7093 initButtons : function ( ) {
71- // insert the show button
72- $ ( '#wp-content-media-buttons' ) . prepend ( this . elements . $useBuilderBtn ) ;
73- this . elements . $wpPostDivRich . before ( this . elements . $useWpEditorBtn ) ;
94+
95+ if ( this . isGutenberg ( ) ) {
96+ this . gutenbergContainer . find ( '.edit-post-header-toolbar' ) . children ( ) . hide ( ) ;
97+ this . gutenbergContainer . find ( '.edit-post-header-toolbar' ) . append ( this . elements . $useBuilderBtn ) ;
98+ this . gutenbergContainer . find ( '.edit-post-header-toolbar' ) . append ( this . elements . $useWpEditorBtn ) ;
99+ } else {
100+ // insert the show button
101+ $ ( '#wp-content-media-buttons' ) . prepend ( this . elements . $useBuilderBtn ) ;
102+ this . elements . $wpPostDivRich . before ( this . elements . $useWpEditorBtn ) ;
103+ }
74104
75105 if ( this . elements . $option . attr ( 'data-builder-active' ) ) {
76106 this . showBuilder ( )
235265 this . elements . $builderInput = this . elements . $option . find ( 'input[type="hidden"]:first' ) ;
236266 var self = this ;
237267
268+ if ( this . isGutenberg ( ) ) {
269+ this . elements . $wpPostBodyContent = this . gutenbergContainer ;
270+ }
271+
238272 // fixes on firs show or hide
239273 this . events . once ( 'show' , _ . bind ( function ( ) {
240274 this . fixOnFirstShowOrHide ( true ) ;
262296 * and I think it's faster if they are executed one by one (not in parallel)
263297 */
264298 $ ( document . body ) . on ( 'fw:option-type:builder:init.fw_ext_page_builder_integration' , function ( e , data ) {
299+
265300 if ( 'page-builder' === data . builder . get ( 'type' ) ) {
266301
267302 self . insertHidden ( ) ;
317352 fwEvents . on ( 'fw:ext:page-builder:editor-integration:hide' , function hide ( ) {
318353 $ ( 'body' ) . removeClass ( className ) ;
319354 } ) ;
355+
320356} ) ( jQuery , fwEvents , fw_option_type_page_builder_editor_integration_data ) ;
321357
322358/**
@@ -336,7 +372,7 @@ jQuery( function ( $ ) {
336372 * Use mouseup instead of click to be executed before
337373 * https://github.com/WordPress/WordPress/blob/4.5/wp-admin/js/post.js#L295
338374 */
339- $ ( '#post-preview' ) . on ( 'mouseup' + eventsNamespace + ' touchend' + eventsNamespace , function ( ) {
375+ $ ( '#post-preview, .editor-post-preview ' ) . on ( 'mouseup' + eventsNamespace + ' touchend' + eventsNamespace , function ( ) {
340376 if ( ! isBuilderActive ( ) ) {
341377 return ;
342378 }
@@ -363,4 +399,4 @@ jQuery( function ( $ ) {
363399
364400 originalContentValue = '' ; // free memory
365401 } ) ;
366- } ) ;
402+ } ) ;
0 commit comments