MOBILE-2995 qr: Add QR button in RTE

main
Dani Palou 2019-10-11 16:02:28 +02:00
parent 394dd6e24d
commit c3f39abafa
2 changed files with 26 additions and 0 deletions

View File

@ -71,6 +71,11 @@
<core-icon name="fa-eraser"></core-icon>
</button>
</ion-slide>
<ion-slide *ngIf="canScanQR">
<button [disabled]="!rteEnabled" (click)="scanQR($event)" (mousedown)="stopBubble($event)">
<core-icon name="fa-qrcode"></core-icon>
</button>
</ion-slide>
<ion-slide>
<button [attr.aria-pressed]="!rteEnabled" (click)="toggleEditor($event)" (mousedown)="mouseDownAction($event)" [title]=" 'core.editor.toggle' | translate">
<core-icon name="fa-code"></core-icon>

View File

@ -95,6 +95,8 @@ export class CoreEditorRichTextEditorComponent implements AfterContentInit, OnDe
ol: 'false',
};
infoMessage: string;
canScanQR: boolean;
protected isCurrentView = true;
protected toolbarButtonWidth = 40;
protected toolbarArrowWidth = 28;
@ -119,6 +121,7 @@ export class CoreEditorRichTextEditorComponent implements AfterContentInit, OnDe
this.contentChanged = new EventEmitter<string>();
this.element = elementRef.nativeElement as HTMLDivElement;
this.pageInstance = 'app_' + Date.now(); // Generate a "unique" ID based on timestamp.
this.canScanQR = this.utils.canScanQR();
}
/**
@ -865,6 +868,24 @@ export class CoreEditorRichTextEditorComponent implements AfterContentInit, OnDe
}, timeout);
}
/**
* Scan a QR code and put its text in the editor.
*
* @param $event Event data
*/
scanQR($event: any): void {
this.stopBubble($event);
// Scan for a QR code.
this.utils.scanQR().then((text) => {
if (text) {
document.execCommand('insertText', false, text);
}
this.content.resize(); // Resize content, otherwise the content height becomes 1 for some reason.
});
}
/**
* User entered the page that contains the component.
*/