-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
293 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
61 changes: 61 additions & 0 deletions
61
src/bundle/Resources/public/js/scripts/admin.focus.mode.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
(function (global, doc) { | ||
let activeFieldEdit = null; | ||
const ENABLE_FOCUS_MODE_EVENT_NAME = 'ibexa-focus-mode:on'; | ||
const DISABLE_FOCUS_MODE_EVENT_NAME = 'ibexa-focus-mode:off'; | ||
const focusModeEnableBtns = doc.querySelectorAll('.ibexa-field-edit__focus-mode-control-btn--enable'); | ||
const focusModeDisbaleBtns = doc.querySelectorAll('.ibexa-field-edit__focus-mode-control-btn--disable'); | ||
const changeFocusModeState = (active) => { | ||
if (!activeFieldEdit) { | ||
return; | ||
} | ||
|
||
const dispatchEventName = active ? ENABLE_FOCUS_MODE_EVENT_NAME : DISABLE_FOCUS_MODE_EVENT_NAME; | ||
const editorSourceElement = activeFieldEdit.querySelector('.ibexa-data-source__richtext'); | ||
const editorInstance = editorSourceElement.ckeditorInstance; | ||
|
||
activeFieldEdit.classList.toggle('ibexa-field-edit--focus-mode-active', active); | ||
editorInstance.set('focusModeActive', active); | ||
|
||
doc.body.dispatchEvent( | ||
new CustomEvent(dispatchEventName, { | ||
detail: { | ||
activeFieldEdit, | ||
}, | ||
}), | ||
); | ||
|
||
if (!active) { | ||
activeFieldEdit = null; | ||
} | ||
}; | ||
const watchDisableFocusModeByKeyboard = (event) => { | ||
if (event.key === 'Escape' || event.keyCode === 27) { | ||
changeFocusModeState(false); | ||
} | ||
}; | ||
|
||
focusModeEnableBtns.forEach((btn) => { | ||
btn.addEventListener( | ||
'click', | ||
({ currentTarget }) => { | ||
activeFieldEdit = currentTarget.closest('.ibexa-field-edit'); | ||
changeFocusModeState(true); | ||
}, | ||
false, | ||
); | ||
}); | ||
focusModeDisbaleBtns.forEach((btn) => { | ||
btn.addEventListener('click', () => changeFocusModeState(false), false); | ||
}); | ||
|
||
doc.body.addEventListener( | ||
ENABLE_FOCUS_MODE_EVENT_NAME, | ||
() => doc.body.addEventListener('keydown', watchDisableFocusModeByKeyboard), | ||
false, | ||
); | ||
doc.body.addEventListener( | ||
DISABLE_FOCUS_MODE_EVENT_NAME, | ||
() => doc.body.removeEventListener('keydown', watchDisableFocusModeByKeyboard), | ||
false, | ||
); | ||
})(window, window.document); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.