define(function(require, exports, module) { 'use strict'; /** * Dependencies */ var debug = require('debug')('view:viewfinder'); var bind = require('lib/bind'); var CameraUtils = require('lib/camera-utils'); var View = require('view'); /** * Locals */ var isZoomEnabled = false; var scaleSizeTo = { fill: CameraUtils.scaleSizeToFillViewport, fit: CameraUtils.scaleSizeToFitViewport }; var clamp = function(value, minimum, maximum) { return Math.min(Math.max(value, minimum), maximum); }; module.exports = View.extend({ name: 'viewfinder', className: 'js-viewfinder', fadeTime: 360, initialize: function() { this.render(); this.getSize(); }, render: function() { this.el.innerHTML = this.template(); this.els.frame = this.find('.js-frame'); this.els.video = this.find('.js-video'); this.els.videoContainer = this.find('.js-video-container'); // Clean up delete this.template; debug('rendered'); return this.bindEvents(); }, bindEvents: function() { bind(this.el, 'click', this.onClick); bind(this.el, 'animationend', this.onShutterEnd); return this; }, /** * Stores the container size. * * We're using window dimensions * here to avoid causing costly * reflows. * * @public */ getSize: function() { this.width = window.innerWidth; this.height = window.innerHeight; return { width: this.width, height: this.height }; }, onClick: function(e) { this.emit('click', e); }, enableZoom: function(minimumZoom, maximumZoom) { if (minimumZoom) { this._minimumZoom = minimumZoom; } if (maximumZoom) { this._maximumZoom = maximumZoom; } isZoomEnabled = true; }, disableZoom: function() { this._minimumZoom = 1.0; this._maximumZoom = 1.0; this.setZoom(1.0); isZoomEnabled = false; }, _minimumZoom: 1.0, setMinimumZoom: function(minimumZoom) { this._minimumZoom = minimumZoom; }, _maximumZoom: 1.0, setMaximumZoom: function(maximumZoom) { this._maximumZoom = maximumZoom; }, _zoom: 1.0, /** * Update the internal state of the view so that any future * pinch-to-zoom gestures can correctly adjust the current zoom * level in the event that the zoom level is changed outside of * the pinch-to-zoom gesture (e.g.: ZoomBar). This gets called * when the `Camera` emits a `zoomchanged` event. */ setZoom: function(zoom) { if (!isZoomEnabled) { return; } this._zoom = clamp(zoom, this._minimumZoom, this._maximumZoom); }, _useZoomPreviewAdjustment: false, enableZoomPreviewAdjustment: function() { this._useZoomPreviewAdjustment = true; }, disableZoomPreviewAdjustment: function() { this._useZoomPreviewAdjustment = false; }, /** * Adjust the scale of the