-
Notifications
You must be signed in to change notification settings - Fork 0
/
prg.dialogs.js
176 lines (159 loc) · 6.7 KB
/
prg.dialogs.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/*! Copyright 2014 Rainer Rillke <[email protected]>
* Quintuple-licensed under
* - GPLv2 and, at your option any later version of that license,
* - LGPL 2.1 and, at your option any later version of that license,
* - Creative Commons Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0),
* - GNU Free Documentation License (GNU FDL aka. GFDL) 1.2
* and, at your option any later version of that license.
* - MIT (http://opensource.org/licenses/MIT)
* For detailed information confer to LICENSE in the repository's root directory.
*
* @author Rainer Rillke
*/
/**
* Pronunciation recording gadget.
* Framework for recording audio in a browser.
*
* Funded by the Wikimedia Foundation as part of an Individual Investment Grant.
* This means the Wikimedia Foundation supported creation materially
* but did not directly endorse creation of this software.
* More information about
* [Individual Investment Grants](https://meta.wikimedia.org/wiki/Grants:IEG).
*
* @class prg.RecorderUI
* Basic recorder User Interface
*
* @requires OO.ui
* @requires jQuery
*/
/*global mediaWiki:false, OO:false, jQuery:false*/
( function( $, global ) {
// Make sure the namespace exists
if ( !global.prg ) {
throw new Error( "Namespace required by Pronunciation Recording Gadget (prg.RecorderUI)!" );
}
// Setup
var windows = {},
windowManager = new OO.ui.WindowManager();
// Templates
var $prgContent = $( '<div>' )
.addClass( 'prg-content' ),
$prgWelcomeHeading = $( '<h1>' )
.text( "New to pronunciation recording gadget?" ),
$prgWelcomeText = $( '<p>' )
.text( "This tool facilates recording uploading and embedding pronunciation recordings with just a few clicks." ),
$prgAdviceIntro = $( '<p>' )
.text( "It's easy but please read the following advice before starting." ),
$prgAdviceMicroHead = $( '<h2>' )
.text( "The microphone:" ),
$prgAdviceMicroText = $( '<p>' )
.addClass( 'prg-indeted' )
.text( "With a good microphone you can achieve significantally better results. If you only own a cheap one, try the following: Mount it at a distance of about 10\u00A0cm and slighly below your mouth so you avoid clipping while speaking 'p' or 's' tones." ),
$prgAdvicePronunciationHead = $( '<h2>' )
.text( "Pronunciation:" ),
$prgAdvicePronunciatioText = $( '<p>' )
.addClass( 'prg-indeted' )
.text( "If possible, choose a calm environment, stand up while speaking, speak the word in one or more clearly intonated sentences before recording." ),
$prgMicrophoneCheckPermissionText = $( '<p>' )
.text( "All right? Let's proceed to the next and check whether your microphone is correctly installed." );
prg.RecorderUI = function ( config ) {
prg.RecorderUI.super.call( this, config );
};
OO.inheritClass( prg.RecorderUI, OO.ui.ProcessDialog );
prg.RecorderUI.static.title = "Pronunciation recording gadget (" + prg.version + ")";
prg.RecorderUI.static.actions = [
{ action: 'continue', label: "Proceed", flags: 'primary' },
{ action: 'cancel', label: "Cancel", flags: ['safe', 'destructive'] }
];
prg.RecorderUI.prototype.initialize = function () {
var dialog = this;
prg.RecorderUI.super.prototype.initialize.apply( dialog, arguments );
dialog.content = new OO.ui.PanelLayout( { $: dialog.$, padded: true, expanded: false } );
dialog.content.$element.append( '<div class="prg-dialog-content">If you see this text, Pronunciation Recording has an error that should be reported to its software developer.</div>' );
dialog.$body.append( dialog.content.$element );
};
prg.RecorderUI.prototype.getReadyProcess = function ( data ) {
var process,
dialog = this;
process = prg.RecorderUI.super.prototype.getReadyProcess.call( this, data );
dialog.getActions().get( { actions: ['cancel'] } )[0].on( 'click', function() {
dialog.close( { action: 'cancel' } );
if ( dialog.accessGranted ) {
var error = [new OO.ui.Error( 'User aborted.' )];
dialog.accessGranted.reject( [] );
dialog.hideErrors();
}
} );
return process;
};
prg.RecorderUI.prototype.getSetupProcess = function ( data ) {
this.content.$element.empty().append( data.message );
return prg.RecorderUI.super.prototype.getSetupProcess.call( this, data );
};
prg.RecorderUI.prototype.getActionProcess = function ( action ) {
var dialog = this;
if ( action === 'cancel' ) {
dialog.close( { action: action } );
return prg.RecorderUI.super.prototype.getActionProcess.call( this, action );
} else {
return prg.RecorderUI.super.prototype.getActionProcess
.call( this, action )
.next( function () {
this.getActions().get( { actions: ['continue'] } )[0].setDisabled( true );
var Recorder = prg.getCompatibleRecorder(),
recorder = new Recorder(),
accessGranted = $.Deferred();
dialog.accessGranted = accessGranted;
$prgContent
.empty()
.append( 'Please grant pronunciation recording gadget access to your microphone and only select microphones, i.e. not "stereo mix".' );
recorder.requestMicrophoneAccess().done( function () {
$prgContent
.empty()
.append( 'Superb: Pronunciation Recorder has now access to your microphone. Now, let\'s check the input level.' );
accessGranted.resolve();
} ).fail( function () {
var error = [new OO.ui.Error( 'Without access to your microphone, pronunciation recordings cannot be created.' )];
// dialog.showErrors( error );
accessGranted.reject( error );
} );
return accessGranted;
}, this )
.next( 1000 )
.next( function () {
dialog.close( { action: action } );
} );
}
};
prg.RecorderUI.prototype.getBodyHeight = function () {
return this.content.$element.outerHeight( true );
};
windows['RecorderUI'] = new prg.RecorderUI( { size: 'large' } );
windowManager.addWindows( windows );
var openDlg = function() {
var nextButton = new OO.ui.ActionWidget( {
label: 'Okay, let\'s start!',
icon: 'next',
framed: true
} ).on( 'click', function () {
windows['RecorderUI'].executeAction( 'continue' );
} );
windowManager.openWindow( 'RecorderUI', {
title: 'Pronunciation recording',
message: $prgContent
.empty()
.append( $prgWelcomeHeading, $prgWelcomeText )
.append( $prgAdviceIntro, $prgAdviceMicroHead, $prgAdviceMicroText )
.append( $prgAdvicePronunciationHead, $prgAdvicePronunciatioText )
.append( $prgMicrophoneCheckPermissionText )
.append( nextButton.$element ),
verbose: true
} ).done(function() {
console.log('window open');
} );
console.log( nextButton.$element )
};
var $el = $( '#bodyContent' ).length ? $( '#bodyContent' ) : $( 'body' );
windowManager.$element.appendTo( $el );
$('<button>').text( 'Open Dlg' ).click(openDlg).appendTo( $el );
}( jQuery, window ) );