-
Notifications
You must be signed in to change notification settings - Fork 2
/
media.js
86 lines (82 loc) · 2.28 KB
/
media.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
/**
* Implements hook_field_formatter_view().
*/
function media_field_formatter_view(entity_type, entity, field, instance, langcode, items, display) {
try {
//console.log(entity_type);
//console.log(entity);
//console.log(field);
//console.log(instance);
//console.log(langcode);
//console.log(items);
//console.log(display);
// Iterate over each item, and place a widget onto the render array.
var content = {};
for (var delta in items) {
if (!items.hasOwnProperty(delta)) { continue; }
var item = items[delta];
switch (display.type) {
case 'file_rendered':
content[delta] = { item: item };
content[delta].theme = 'media_file_rendered';
break;
default:
console.log('media_field_formatter_view() - unsupported display type: ' + display.type);
break;
}
}
return content;
}
catch (error) { console.log('media_field_formatter_view - ' + error); }
}
/**
*
*/
function theme_media_file_rendered(variables) {
try {
var item = variables.item;
switch (item.filemime) {
case 'image/jpeg':
return theme('image', {
path: drupalgap_image_path(item.uri)
});
break;
case 'application/pdf':
return bl(
item.filename,
drupalgap_image_path(item.uri),
{
InAppBrowser: true,
attributes: {
'data-icon': 'action'
}
}
);
break;
default:
// check of mimetipe 'video/*'
if ((/video\//).test(item.filemime)){
return theme('video', {
path: drupalgap_image_path(item.uri),
attributes: {
controls: '',
class: 'media-video'
}
});
} else if ((/audio\//).test(item.filemime)) {
return theme('audio', {
path: drupalgap_image_path(item.uri),
attributes: {
controls: '',
class: 'media-audio'
}
});
} else {
console.log('theme_media_file_rendered() - unsupported filemime: ' + item.filemime);
}
break;
}
return '';
}
catch (error) { console.log('variables - ' + error); }
}