-
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
6 changed files
with
260 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
71 changes: 71 additions & 0 deletions
71
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,71 @@ | ||
(function (global, doc, ibexa) { | ||
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 noticeContainers = doc.querySelectorAll('.ibexa-field-edit__focus-mode-notice-container') | ||
const getEditorUiInstance = (editorContainer) => { | ||
const editorSourceElement = editorContainer.querySelector('.ibexa-data-source__richtext'); | ||
const editorInstance = editorSourceElement.ckeditorInstance; | ||
|
||
return editorInstance.ui; | ||
}; | ||
const changeFocusModeState = (enable) => { | ||
if (!activeFieldEdit) { | ||
return; | ||
} | ||
|
||
const dispatchEventName = enable | ||
? 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--in-focus-mode', enable); | ||
editorInstance.set('focusModeEnabled', enable); | ||
|
||
doc.body.dispatchEvent( | ||
new CustomEvent(dispatchEventName, { | ||
detail: { | ||
activeFieldEdit | ||
}, | ||
}), | ||
); | ||
|
||
if (!enable) { | ||
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) | ||
}); | ||
|
||
noticeContainers.forEach((noticeContainer) => { | ||
const alerts = noticeContainer.querySelectorAll('.ibexa-alert'); | ||
|
||
alerts.forEach((alert) => { | ||
alert.addEventListener('closed.bs.alert', () => { | ||
const container = noticeContainer.closest('.ibexa-field-edit'); | ||
const editorUiInstance = getEditorUiInstance(container); | ||
|
||
editorUiInstance.fire('ibexa-rt-update-ui'); | ||
}); | ||
}) | ||
}); | ||
|
||
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, window.ibexa); |
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
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