forked from CIT/Vmeda.Online
		
	
						commit
						1d5fbb3bd7
					
				@ -82,7 +82,6 @@ export class CoreEditorRichTextEditorComponent implements OnInit, AfterContentIn
 | 
			
		||||
 | 
			
		||||
    protected element: HTMLDivElement;
 | 
			
		||||
    protected editorElement?: HTMLDivElement;
 | 
			
		||||
    protected kbHeight = 0; // Last known keyboard height.
 | 
			
		||||
    protected minHeight = 200; // Minimum height of the editor.
 | 
			
		||||
 | 
			
		||||
    protected valueChangeSubscription?: Subscription;
 | 
			
		||||
@ -257,7 +256,7 @@ export class CoreEditorRichTextEditorComponent implements OnInit, AfterContentIn
 | 
			
		||||
            );
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
        this.resizeFunction = this.maximizeEditorSize.bind(this);
 | 
			
		||||
        this.resizeFunction = this.windowResized.bind(this);
 | 
			
		||||
        window.addEventListener('resize', this.resizeFunction!);
 | 
			
		||||
 | 
			
		||||
        // Start observing the target node for configured mutations
 | 
			
		||||
@ -266,8 +265,9 @@ export class CoreEditorRichTextEditorComponent implements OnInit, AfterContentIn
 | 
			
		||||
        this.selectionChangeFunction = this.updateToolbarStyles.bind(this);
 | 
			
		||||
        document.addEventListener('selectionchange', this.selectionChangeFunction!);
 | 
			
		||||
 | 
			
		||||
        this.keyboardObserver = CoreEvents.on(CoreEvents.KEYBOARD_CHANGE, (kbHeight: number) => {
 | 
			
		||||
            this.kbHeight = kbHeight;
 | 
			
		||||
        this.keyboardObserver = CoreEvents.on(CoreEvents.KEYBOARD_CHANGE, () => {
 | 
			
		||||
            // Opening or closing the keyboard also calls the resize function, but sometimes the resize is called too soon.
 | 
			
		||||
            // Check the height again, now the window height should have been updated.
 | 
			
		||||
            this.maximizeEditorSize();
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
@ -284,46 +284,18 @@ export class CoreEditorRichTextEditorComponent implements OnInit, AfterContentIn
 | 
			
		||||
     *
 | 
			
		||||
     * @return Resolved with calculated editor size.
 | 
			
		||||
     */
 | 
			
		||||
    protected maximizeEditorSize(): Promise<number> {
 | 
			
		||||
        // this.content.resize();
 | 
			
		||||
 | 
			
		||||
        const deferred = CoreUtils.promiseDefer<number>();
 | 
			
		||||
 | 
			
		||||
        setTimeout(async () => {
 | 
			
		||||
            let contentVisibleHeight = await CoreDomUtils.getContentHeight(this.content);
 | 
			
		||||
            if (!CoreApp.isAndroid()) {
 | 
			
		||||
                // In Android we ignore the keyboard height because it is not part of the web view.
 | 
			
		||||
                contentVisibleHeight -= this.kbHeight;
 | 
			
		||||
            }
 | 
			
		||||
    protected async maximizeEditorSize(): Promise<number> {
 | 
			
		||||
        const contentVisibleHeight = await CoreDomUtils.getContentHeight(this.content);
 | 
			
		||||
 | 
			
		||||
        if (contentVisibleHeight <= 0) {
 | 
			
		||||
                deferred.resolve(0);
 | 
			
		||||
 | 
			
		||||
                return;
 | 
			
		||||
            return 0;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
            setTimeout(async () => {
 | 
			
		||||
        await CoreUtils.wait(100);
 | 
			
		||||
 | 
			
		||||
        // Editor is ready, adjust Height if needed.
 | 
			
		||||
                let height: number;
 | 
			
		||||
 | 
			
		||||
                if (CoreApp.isAndroid()) {
 | 
			
		||||
                    // In Android we ignore the keyboard height because it is not part of the web view.
 | 
			
		||||
        const contentHeight = await CoreDomUtils.getContentHeight(this.content);
 | 
			
		||||
                    height = contentHeight - this.getSurroundingHeight(this.element);
 | 
			
		||||
                } else if (CoreApp.isIOS() && this.kbHeight > 0 && CoreApp.getPlatformMajorVersion() < 12) {
 | 
			
		||||
                    // Keyboard open in iOS 11 or previous. The window height changes when the keyboard is open.
 | 
			
		||||
                    height = window.innerHeight - this.getSurroundingHeight(this.element);
 | 
			
		||||
 | 
			
		||||
                    if (this.element.getBoundingClientRect().top < 40) {
 | 
			
		||||
                        // In iOS sometimes the editor is placed below the status bar. Move the scroll a bit so it doesn't happen.
 | 
			
		||||
                        window.scrollTo(window.scrollX, window.scrollY - 40);
 | 
			
		||||
                    }
 | 
			
		||||
 | 
			
		||||
                } else {
 | 
			
		||||
                    // Header is fixed, use the content to calculate the editor height.
 | 
			
		||||
                    const contentHeight = await CoreDomUtils.getContentHeight(this.content);
 | 
			
		||||
                    height = contentHeight - this.kbHeight - this.getSurroundingHeight(this.element);
 | 
			
		||||
                }
 | 
			
		||||
        const height = contentHeight - this.getSurroundingHeight(this.element);
 | 
			
		||||
 | 
			
		||||
        if (height > this.minHeight) {
 | 
			
		||||
            this.element.style.height = CoreDomUtils.formatPixelsSize(height - 1);
 | 
			
		||||
@ -331,11 +303,7 @@ export class CoreEditorRichTextEditorComponent implements OnInit, AfterContentIn
 | 
			
		||||
            this.element.style.height = '';
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
                deferred.resolve(height);
 | 
			
		||||
            }, 100);
 | 
			
		||||
        }, 100);
 | 
			
		||||
 | 
			
		||||
        return deferred.promise;
 | 
			
		||||
        return height;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
@ -901,6 +869,8 @@ export class CoreEditorRichTextEditorComponent implements OnInit, AfterContentIn
 | 
			
		||||
            this.toolbarArrows = true;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        await CoreUtils.nextTick();
 | 
			
		||||
 | 
			
		||||
        await this.toolbarSlides.update();
 | 
			
		||||
 | 
			
		||||
        await this.updateToolbarArrows();
 | 
			
		||||
@ -1105,6 +1075,16 @@ export class CoreEditorRichTextEditorComponent implements OnInit, AfterContentIn
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Window resized.
 | 
			
		||||
     */
 | 
			
		||||
    protected async windowResized(): Promise<void> {
 | 
			
		||||
        await CoreDomUtils.waitForResizeDone();
 | 
			
		||||
 | 
			
		||||
        this.maximizeEditorSize();
 | 
			
		||||
        this.updateToolbarButtons();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * User entered the page that contains the component.
 | 
			
		||||
     */
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user