This repository has been archived by the owner on Nov 3, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
confirm.js
116 lines (95 loc) · 2.58 KB
/
confirm.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
define(function(require, exports, module) {
'use strict';
/**
* Dependencies
*/
var addPanAndZoomHandlers = require('lib/panzoom');
var MediaFrame = require('MediaFrame');
var View = require('vendor/view');
var bind = require('lib/bind');
var orientation = require('lib/orientation');
/**
* Exports
*/
module.exports = View.extend({
name: 'confirm',
initialize: function() {
this.on('destroy', this.onDestroy);
},
render: function() {
var l10n = navigator.mozL10n;
this.show();
this.el.innerHTML = this.template({
retake: l10n.get('retake-button'),
select: l10n.get('select-button')
});
// Get elements
this.els.mediaFrame = this.find('.js-media-frame');
this.els.retake = this.find('.js-retake');
this.els.select = this.find('.js-select');
// Events
bind(this.els.retake, 'click', this.onButtonClick);
bind(this.els.select, 'click', this.onButtonClick);
this.setupMediaFrame();
return this;
},
setupMediaFrame: function() {
this.mediaFrame = new MediaFrame(this.els.mediaFrame);
addPanAndZoomHandlers(this.mediaFrame);
window.addEventListener('resize', this.onResize);
return this;
},
hide: function() {
this.el.classList.add('hidden');
orientation.lock();
},
show: function() {
this.el.classList.remove('hidden');
orientation.unlock();
},
showImage: function(image) {
this.mediaFrame.displayImage(
image.blob,
image.width,
image.height,
image.preview,
image.rotation,
image.mirrored);
return this;
},
showVideo: function(video) {
this.mediaFrame.displayVideo(
video.blob,
video.poster.blob,
video.width,
video.height,
video.rotation);
return this;
},
template: function(data) {
/*jshint maxlen:false*/
return '<div class="confirm-media-frame js-media-frame"></div>' +
'<footer id="confirm-controls" class="confirm-controls">' +
'<button class="retake-button js-retake" name="retake">' +
data.retake + '</button>' +
'<button class="select-button test-confirm-select js-select" name="select">' +
data.select + '</button>' +
'</footer>';
},
onButtonClick: function(event) {
var el = event.currentTarget;
var name = el.getAttribute('name');
this.emit('click:' + name);
},
onResize: function() {
this.mediaFrame.resize();
if (this.mediaFrame.displayingVideo) {
this.mediaFrame.video.setPlayerSize();
}
},
onDestroy: function() {
window.removeEventListener('resize', this.onResize);
this.mediaFrame.clear();
}
});
});