PageSourceSearch

https://shumskaya-school.ru/nassets/1ee1e72c/js/audio-comments.js?v=1777898469

js shumskaya-school.ru collected 2026-09-28 09:03:45 UTC 10,541 bytes, 319 lines download raw bytes

1function $t(category, key, fallback = '') {
2  if (typeof Yii != 'undefined') {
3    return Yii.t(category, key);
4  }
5  return fallback ? fallback : key;
6}
7
8window.audioComments = {
9	recordAudio: '',
10	recordStatus: '',
11	mediaStream: '',
12
13	isMimeTypeSupported(mimeType) {
14
15		return true;
16
17		if (typeof MediaRecorder.isTypeSupported !== 'function') {
18			return true;
19		}
20		if ( mimeType == 'audio/webm' && window.testDisableWebm ) {
21			return false;
22		}
23
24		return MediaRecorder.isTypeSupported(mimeType);
25	},
26
27	record: function (x) {
28		var self = $(x);
29
30		if (!self.parent().children('div.audio-upload').length) {
31			$('<div class="audio-upload"></div>').appendTo(self.parent());
32		}
33
34		var inputUpload = self.parent().children('div.audio-upload');
35		var audioStatus = self.children('span.audio-status');
36		var microphone = self.children('i.fa-microphone');
37
38		if (
39			!window.audioComments.recordStatus
40			|| window.audioComments.recordStatus == 'stop'
41		) {
42			window.audioComments.recordStatus = 'allow';
43
44			var buttons = $(
45				[
46					'<div class="audio-tip">',
47					'<div class="tooltip-inner">',
48					'<div class="audio-record"><span class="glyphicon glyphicon-record" aria-hidden="true"></span> ' + $t('common', 'запись') + '</div>',
49					'<div class="audio-cancel"><span class="glyphicon glyphicon-trash" aria-hidden="true"></span> ' + $t('common', 'отменить') + '</div>',
50					'<div class="audio-save"><span class="glyphicon glyphicon-stop" aria-hidden="true"></span> ' + $t('common', 'стоп') + '</div> ',
51					'</div></div>'
52				].join(' ')).appendTo(self.next()).hide();
53
54			audioStatus.show().html($t('common', 'разрешите доступ к микрофону...'));
55		}
56
57		if (window.audioComments.recordStatus == 'allow') {
58			window.audioComments.recordStatus = 'check';
59
60			var recorderType = StereoAudioRecorder;
61			var mimeType = "audio/wav";
62
63
64			if ( this.isMimeTypeSupported("audio/webm") ) {
65				recorderType = MediaStreamRecorder;
66				mimeType = "audio/webm";
67			}
68
69			var isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
70            var isIOS = /iPad|iPhone|iPod/.test(navigator.userAgent)
71                || (navigator.platform === 'iPad' || (navigator.platform === 'MacIntel' && 'ontouchend' in document));
72
73			if (isSafari || (window.isWebview && isIOS)) {
74				recorderType = StereoAudioRecorder;
75				mimeType = "audio/wav";
76			}
77
78			window.navigator.mediaDevices.getUserMedia({audio: true})
79				.then(function(localMediaStream) {
80
81					window.audioComments.recordAudio = RecordRTC(localMediaStream, {
82						type: 'audio',
83						mimeType: mimeType,
84						recorderType: recorderType,
85						disableLogs: false
86					});
87
88					window.audioComments.mediaStream = localMediaStream;
89					audioStatus.hide();
90					buttons.show();
91					window.audioComments.recordStatus = 'start';
92				})
93				.catch(function(err) {
94					/* handle the error */
95                    console.error(err);
96					audioStatus.show().html($t('common', 'доступ к микрофону запрещен!'));
97				});
98
99			/*
100			window.navigator.mediaDevices.getUserMedia({audio: true}, function (localMediaStream) {
101				window.audioComments.recordAudio = RecordRTC(localMediaStream, {
102					type: 'audio',
103					mimeType: mimeType,
104					recorderType: recorderType,
105					disableLogs: false
106				});
107
108				window.audioComments.mediaStream = localMediaStream;
109				audioStatus.hide();
110				buttons.show();
111				window.audioComments.recordStatus = 'start';
112
113			}, function (e) {
114				audioStatus.show().html('доступ к микрофону запрещен!');
115			});
116			*/
117		}
118
119		$('.audio-cancel', buttons).click(function () {
120			if (window.audioComments.recordStatus == 'allow') {
121				return;
122			}
123			microphone.css('color', '#999');
124			if (window.audioComments.mediaStream) {
125				window.audioComments.mediaStream.getAudioTracks()[0].stop();
126			}
127			audioStatus.html('');
128			buttons.remove();
129			window.audioComments.recordStatus = 'stop';
130		});
131
132		$('.audio-record', buttons).click(function() {
133			if (window.audioComments.recordStatus == 'start') {
134				window.audioComments.startRecord(audioStatus, microphone);
135			}
136
137		});
138
139		//	var extension = this.isMimeTypeSupported("audio/webm") ? "webm" : "wav";
140		var extension = isSafari ? "wav": "webm" ;
141
142		$('.audio-save', buttons).click(function () {
143
144			if (window.audioComments.recordStatus == 'recording') {
145				buttons.remove();
146				window.audioComments.recordStatus = 'stop';
147
148				window.audioComments.recordAudio.stopRecording(function () {
149
150					microphone.css('color', '#999');
151					audioStatus.html($t('common', 'сохранение...'));
152
153					window.audioComments.mediaStream.getAudioTracks()[0].stop();
154
155
156					var now = new Date();
157					var fileName = now.getFullYear() + '' + now.getMonth() + '' + now.getDate() + '' + now.getHours() + '' + now.getMinutes() + '' + now.getSeconds();
158					fileName += '_';
159					fileName += Math.round(Math.random() * 9999) + '.' + extension;
160
161					var formData = new FormData();
162					var audioBlob = window.audioComments.recordAudio.getBlob();
163					formData.append('Filedata', audioBlob);
164					formData.append('BlobfileName', fileName);
165
166					var uploadFormToUrl = function (url, formData) {
167						$.ajax({
168							url: url,
169							type: 'POST',
170							data: formData,
171							processData: false,
172							contentType: false,
173							success: function (data) {
174								if (data == 'Error') {
175									alert($t('common', 'Невозможно сохранить файл!'));
176								} else {
177
178									var info = $('<span class="audio-info">'
179										+ '<span class="close-info" style="float:right;">x</span>'
180										+ '<div>'
181										+ '<audio controls=""><source src="' + data.download_url + '" type="audio/mpeg"></audio>'
182										+ '<br>' + fileName
183										+ '</div>'
184										+ '</span>'
185									);
186									$('.close-info', info).click(function () {
187										info.remove();
188									});
189                                    var audioAnswer = microphone.closest('.audio-answer');
190                                    console.log('audioAnswer', audioAnswer);
191                                    var input;
192
193                                    if (audioAnswer.length) {
194                                        input = $('<input type="hidden" class="audio-value" name="' + audioAnswer.data('name') + '">');
195                                        var input2 = $('[name="' + audioAnswer.data('hashInput') + '"]');
196                                        if (input2) {
197                                            input2.val(data.hash);
198                                            console.log(input2);
199                                        }
200                                        var forRemove = inputUpload
201                                            .parents('.addfield.addfield-type-string_with_audio, .addfield.addfield-type-audio')
202                                            .find('.js__old-audio-info');
203                                        if (forRemove) {forRemove.remove();}
204                                        info.addClass('js__old-audio-info');
205                                    } else {
206                                        input = $('<input type="hidden" class="audio-value" name="GetCourseComment[audioFiles][]">');
207                                    }
208									input.val(data.hash);
209									input.appendTo(info);
210									info.appendTo(inputUpload);
211									audioStatus.html('');
212									self.parent().children('.comment-form-wrapper .new-comment .btn-send').show();
213									self.next().next().children('.save-button').removeClass('disabled');
214								}
215							},
216							error: function (error) {
217								buttons.show();
218								audioStatus.html($t('common', 'ошибка сохранения') +': ' + error.statusText);
219							}
220						});
221					};
222
223					if (window.fileserviceUploadHost) {
224						formData.append('fullAnswer', true);
225						var secureDirectUploadUri = '/fileservice/widget/secure-direct-upload';
226						try {
227							var session = localStorage.getItem('session');
228							var requestParams = {"fs_ref": window.location.href};
229
230							if (session !== undefined && session != null){
231								var objSession = jQuery.parseJSON(session);
232
233								if (objSession.hasOwnProperty('user_id') && objSession.user_id != null) {
234									requestParams.fs_u = objSession.user_id;
235								} else {
236									requestParams.fs_u = -1;
237								}
238							}
239
240							secureDirectUploadUri += '?' + jQuery.param(requestParams);
241						} catch (err) {
242						}
243
244						$.ajax({
245							url: '/fileservice/widget/create-secret-link',
246							method: 'GET',
247							data: {
248								host: window.fileserviceUploadHost,
249								uri: secureDirectUploadUri,
250								expires: 600
251							},
252							success: function (data) {
253								if (data.link) {
254									uploadFormToUrl(data.link, formData);
255								} else {
256									buttons.show();
257									audioStatus.html($t('common', 'ошибка сохранения'));
258								}
259							},
260							error: function (error) {
261								buttons.show();
262								audioStatus.html($t('common', 'ошибка сохранения') +': ' + error.statusText);
263								try{sendCreateLinkError(http, message, exc);}catch (e) {}
264							},
265							async: false
266						});
267					} else {
268						uploadFormToUrl(
269							'/fileservice/widget/upload?deprecated=9'
270								+ '&secure=' + window.isEnabledSecureUpload
271								+ '&host=' + window.fileserviceUploadHost,
272							formData
273						);
274					}
275
276				});
277			}
278
279		});
280	},
281
282	startRecord: function(audioStatus, microphone) {
283		window.audioComments.recordAudio.startRecording();
284
285		window.audioComments.recordStatus = 'recording';
286
287		audioStatus.show().html($t('common', 'идет запись...'));
288		microphone.css('color', 'red !important');
289		$('.audio-record').css('color', 'red');
290	},
291
292	init: function() {
293        $('.audio-comment, .audio-answer').on('click', function() {
294            return window.audioComments.record(this);
295        });
296	}
297};
298
299$(function() {
300	window.audioComments.init();
301
302	$( document ).ready(function() {
303		try {
304			window.AudioContext = window.AudioContext || window.webkitAudioContext;
305			window.navigator.getUserMedia = window.navigator.getUserMedia || window.navigator.webkitGetUserMedia || window.navigator.mediaDevices.getUserMedia;
306			window.URL = window.URL || window.webkitURL;
307
308
309
310			if (window.AudioContext && window.navigator.getUserMedia && window.URL) {
311				$('.audio-comment, .audio-answer').show();
312			}
313
314		} catch (e) {
315			$('.audio-comment, .audio-answer').hide();
316		}
317	});
318
319});

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.