-
Notifications
You must be signed in to change notification settings - Fork 0
/
ffmpeg_wrapper.js
115 lines (98 loc) · 4.2 KB
/
ffmpeg_wrapper.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
/**
* @param string $prefix is the prefix of the elements
* @param string $source is the source for the output type
*/
function ffmpeg_wrapper_update_options(prefix, source) {
// get the path to the output settings set in ffmpeg_wrapper module
var path = Drupal.settings.ffmpeg_wrapper.ffmpeg_wrapper_output_url;
// get the output type
var output = $('#'+prefix+source).val();
// only look for the value if there is one selected
if (output != 0) {
// now get the values for this codec
$.getJSON(path+output, function(json) {
// now we need to itterate through each of the keys returned and
// limit the choices to the incoming values.
var data = eval (json);
// first break the configuration into the types of config data we have
for (var type in data) {
// catch the flag for default settings and don't do
// any form updating for this value
if (data[type] != 'default') {
// now get each of the items in the config
// types here are 'audio' and 'video'
for (var key in data[type] ) {
// build the element from the prefix value: ffmpeg & the kind of item it is & the key
var element = '#'+prefix+'ffmpeg-'+type+'-'+key;
// make sure element exists
if ($(element)) {
// remove existing html from this select box
$(element).html('');
var html = '';
// break each of the options out for each select box
for (var option in data[type][key]) {
// create the description for this element
var description = data[type][key][option].valueOf();
// now we check to see if the option coming in contains
// the default value for this configuration so we know to use it as default
// make a new variable to properly type cast the value
var test = ''+data[type][key][option]+'';
// search this string for the "default" text and save it for
// use after the select is rebuilt
if (test.match(Drupal.settings.ffmpeg_wrapper.default_string) ) {
var selected = option;
}
// now build the html for the select options
html += ffmpeg_wrapper_select_builder(option, description);
}
// build the new select element
$(element).html(html);
// now update the selected value
if (selected) {
$(element).val(selected);
selected = null;
}
}
}
// now turn on the advanced options so they are picked up
$('#'+prefix+'ffmpeg-'+type+'-advanced').attr('checked', true);
}
else {
// is the configuration data being passed back was the default data?
// turn off the advanced configuration so that nothing nasty
// happens without user action
$('#'+prefix+'ffmpeg-audio-advanced').attr('checked', false);
$('#'+prefix+'ffmpeg-video-advanced').attr('checked', false);
}
}
});
}
}
/**
* this builds the html for the output of the selects
* simple function but makes code easier
* @param string $value is the key value
* @param string $description is the text value
*/
function ffmpeg_wrapper_select_builder(value, description) {
if (selected) { var selected = 'selected'; }
else { var selected = ''; }
return '<option value="'+value+'">'+description+'</option>';
}
/**
* This shows and hides the frame size other option in the
* video options dropdown
*/
if (Drupal.jsEnabled) {
$(document).ready(function () {
// get the video size element
$('#edit-ffmpeg-video-size').bind('change', function () {
if ($(this).val() == 'other'){
$('#edit-ffmpeg-video-size-other').show('slow');
}
else {
$('#edit-ffmpeg-video-size-other').hide('slow');
}
});
});
}