mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-07-30 04:23:11 +03:00
Updated codeblock editor to work with fade animation
- Added fadeIn to animation JS service. - Updated overlay to use anim service and to recieve a callback for after-anim actions. - Updated code editor popup to refresh Codemirror instance layout after animation has completed. Fixes #1672
This commit is contained in:
@ -5,6 +5,22 @@
|
||||
*/
|
||||
const animateStylesCleanupMap = new WeakMap();
|
||||
|
||||
/**
|
||||
* Fade in the given element.
|
||||
* @param {Element} element
|
||||
* @param {Number} animTime
|
||||
* @param {Function|null} onComplete
|
||||
*/
|
||||
export function fadeIn(element, animTime = 400, onComplete = null) {
|
||||
cleanupExistingElementAnimation(element);
|
||||
element.style.display = 'block';
|
||||
animateStyles(element, {
|
||||
opacity: ['0', '1']
|
||||
}, animTime, () => {
|
||||
if (onComplete) onComplete();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Fade out the given element.
|
||||
* @param {Element} element
|
||||
|
@ -258,10 +258,18 @@ function setMode(cmInstance, modeSuggestion, content) {
|
||||
function setContent(cmInstance, codeContent) {
|
||||
cmInstance.setValue(codeContent);
|
||||
setTimeout(() => {
|
||||
cmInstance.refresh();
|
||||
updateLayout(cmInstance);
|
||||
}, 10);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the layout (codemirror refresh) of a cm instance.
|
||||
* @param cmInstance
|
||||
*/
|
||||
function updateLayout(cmInstance) {
|
||||
cmInstance.refresh();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a CodeMirror instance to use for the markdown editor.
|
||||
* @param {HTMLElement} elem
|
||||
@ -301,6 +309,7 @@ export default {
|
||||
popupEditor: popupEditor,
|
||||
setMode: setMode,
|
||||
setContent: setContent,
|
||||
updateLayout: updateLayout,
|
||||
markdownEditor: markdownEditor,
|
||||
getMetaKey: getMetaKey,
|
||||
};
|
||||
|
Reference in New Issue
Block a user