Skip to content

Commit 9bdf1e8

Browse files
committed
Merge branch 'gutenberg'
2 parents e0bc438 + 0b2df90 commit 9bdf1e8

File tree

4 files changed

+54
-11
lines changed

4 files changed

+54
-11
lines changed

class-fw-extension-page-builder.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,11 @@ private function add_actions() {
7474
add_action( 'fw_extensions_init', array( $this, '_admin_action_fw_extensions_init' ) );
7575
add_action( 'fw_post_options_update', array( $this, '_action_fw_post_options_update' ), 11, 3 );
7676
add_action( 'fw_admin_enqueue_scripts:post', array( $this, '_action_enqueue_shortcodes_admin_scripts' ) );
77+
7778
/** @since 1.6.15 */
78-
add_action( 'rest_api_init', array( $this, '_rest_api_init' ) );
79+
if ( ! is_admin() ) {
80+
add_action( 'rest_api_init', array( $this, '_rest_api_init' ) );
81+
}
7982
}
8083

8184
/**

includes/page-builder/class-fw-option-type-page-builder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ protected function _enqueue_static( $id, $option, $data ) {
122122
'fw_option_type_' . str_replace('-', '_', $this->get_type()) . '_editor_integration_data',
123123
array(
124124
'l10n' => array(
125-
'showButton' => __('Visual Page Builder', 'fw'),
125+
'showButton' => __('Unyson Builder', 'fw'),
126126
'hideButton' => __('Default Editor', 'fw'),
127127
'eye' => __('Hide / Show', 'fw'),
128128
'responsive' => __( 'Display Controls', 'fw' )

includes/page-builder/static/css/editor_integration.css

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
margin-bottom: 0;
33
}
44

5+
.block-editor .fw-use-builder {
6+
margin: 0 15px;
7+
}
8+
59
.fw-disable-editor {
610
pointer-events: none;
711
z-index: 0;
@@ -12,5 +16,5 @@
1216
}
1317

1418
.page-builder-hide-button {
15-
margin: 20px 0 5px !important;
19+
margin: 5px 0 5px !important;
1620
}

includes/page-builder/static/js/editor_integration.js

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
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
@@ -44,19 +49,29 @@
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();
@@ -65,12 +80,27 @@
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()
@@ -235,6 +265,10 @@
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 );
@@ -262,6 +296,7 @@
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();
@@ -317,6 +352,7 @@
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

Comments
 (0)