mediabox.ts 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /**
  2. * This file is part of Threema Web.
  3. *
  4. * Threema Web is free software: you can redistribute it and/or modify it
  5. * under the terms of the GNU Affero General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or (at
  7. * your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
  12. * General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Affero General Public License
  15. * along with Threema Web. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. import {MediaboxService} from '../services/mediabox';
  18. export default [
  19. '$rootScope',
  20. '$filter',
  21. 'MediaboxService',
  22. function($rootScope: ng.IRootScopeService,
  23. $filter: ng.IFilterService,
  24. mediaboxService: MediaboxService) {
  25. return {
  26. restrict: 'E',
  27. scope: {},
  28. bindToController: {},
  29. controllerAs: 'ctrl',
  30. controller: [function() {
  31. this.imageDataUrl = null;
  32. this.close = () => {
  33. this.imageDataUrl = null;
  34. };
  35. const filter = $filter('bufferToUrl') as (buffer: ArrayBuffer, mimeType: string) => string;
  36. mediaboxService.evtMediaChanged.attach((dataAvailable: boolean) => {
  37. $rootScope.$apply(() => {
  38. this.imageDataUrl = filter(mediaboxService.data, 'image/jpeg');
  39. });
  40. });
  41. }],
  42. // tslint:disable:max-line-length
  43. template: `
  44. <div class="box" ng-if="ctrl.imageDataUrl !== null">
  45. <md-icon class="close material-icons md-24" ng-click="ctrl.close()" aria-label="Close" translate-attr="{'aria-label': 'common.CLOSE'}">close</md-icon>
  46. <div class="inner">
  47. <img ng-src="{{ ctrl.imageDataUrl }}">
  48. <div class="caption">
  49. Image Caption
  50. </div>
  51. </div>
  52. </div>
  53. `,
  54. };
  55. },
  56. ];