Skip to content

Commit

Permalink
Closes #1029 – Unwanted styling copy/paste mode
Browse files Browse the repository at this point in the history
  • Loading branch information
lumberman committed Feb 24, 2020
1 parent c7defde commit 841fb40
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
4 changes: 2 additions & 2 deletions includes/display-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ function dslc_display_composer() {

<!-- Module Options Actions -->
<div class="dslca-module-edit-actions">
<a href="#" class="dslca-module-edit-save"><?php esc_attr_e( 'Confirm', 'live-composer-page-builder' ); ?></a>
<a href="#" class="dslca-module-edit-cancel"><?php esc_attr_e( 'Cancel', 'live-composer-page-builder' ); ?></a>
<a href="#" class="dslca-module-edit-save" data-event="module-confirm"><?php esc_attr_e( 'Confirm', 'live-composer-page-builder' ); ?></a>
<a href="#" class="dslca-module-edit-cancel" data-event="module-cancel"><?php esc_attr_e( 'Cancel', 'live-composer-page-builder' ); ?></a>
</div><!-- .dslca-module-edit-actions -->

<!-- Row Options Filters -->
Expand Down
16 changes: 14 additions & 2 deletions js/src/editor/backend/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@ export const eventsInit = () =>{
const modalWysiwygConfirm = new CustomEvent('modalWysiwygConfirm', { detail: event.target });
document.dispatchEvent( modalWysiwygConfirm );
}

if ( event.target.matches( '[data-event="module-confirm"]' ) ) {
// Create "Module Confirm" event
const moduleConfirm = new CustomEvent('moduleConfirm', { detail: event.target });
document.dispatchEvent( moduleConfirm );
}

if ( event.target.matches( '[data-event="module-cancel"]' ) ) {
// Create "Module Cancel" event
const moduleCancel = new CustomEvent('moduleCancel', { detail: event.target });
document.dispatchEvent( moduleCancel );
}
}, false);

// Preview iframe events.
Expand Down Expand Up @@ -60,13 +72,13 @@ export const eventsInit = () =>{
}

if ( event.target.matches( '[data-event="module-style-copy"]' ) ) {
// Create a new "Copy Modyle Style" event
// Create a new "Copy Module Style" event
const copyStyles = new CustomEvent('copyModuleStyles', { detail: event.target });
document.dispatchEvent( copyStyles );
}

if ( event.target.matches( '[data-event="module-style-paste"]' ) ) {
// Create a new "Paste Modyle Style" event
// Create a new "Paste Module Style" event
const pasteStyles = new CustomEvent('pasteModuleStyles', { detail: event.target });
document.dispatchEvent( pasteStyles );
}
Expand Down
20 changes: 20 additions & 0 deletions js/src/editor/backend/uigeneral.js
Original file line number Diff line number Diff line change
Expand Up @@ -655,8 +655,12 @@ export const keypressEvents = () => {

// CMD button press event.
dslc_cmd_press( keydown_event );

// Events to run when any button preset.
dslc_keydown( keydown_event );
});

// Key UP events.
jQuery( [document, LiveComposer.Builder.PreviewAreaWindow.document ] ).unbind('keyup').bind('keyup', function (keyup_event) {
dslc_cmd_unpress( keyup_event );
});
Expand Down Expand Up @@ -742,11 +746,26 @@ function dslc_save_page(e) {
}
}


/**
* If any key is pressed.
*/
function dslc_keydown( e ) {
console.log( "dslc_keydown:" );
if ( LiveComposer.Builder.UI.cmdMode ) {
if ( ! e.metaKey && ! e.ctrlKey ) {
LiveComposer.Builder.UI.cmdMode = false;
LiveComposer.Builder.PreviewAreaWindow.document.querySelector('body').classList.remove( 'key-press-cmd' );
}
}
}

/**
* If Command key is pressed.
*/
function dslc_cmd_press( e ) {
if ( e.metaKey || e.ctrlKey ) {
LiveComposer.Builder.UI.cmdMode = true;
LiveComposer.Builder.PreviewAreaWindow.document.querySelector('body').classList.add( 'key-press-cmd' );
}
}
Expand All @@ -756,6 +775,7 @@ function dslc_cmd_press( e ) {
*/
function dslc_cmd_unpress( e ) {
if ( e.key === "Meta" ) {
LiveComposer.Builder.UI.cmdMode = false;
LiveComposer.Builder.PreviewAreaWindow.document.querySelector('body').classList.remove( 'key-press-cmd' );
}
}
Expand Down

0 comments on commit 841fb40

Please sign in to comment.