4 imageExtensions: ['jpg', 'jpeg', 'gif', 'png']
7 BlergMedia.media_init = function() {
8 var e = document.createElement('audio');
10 BlergMedia.has_audio = true;
11 if (e.canPlayType('audio/mpeg; codecs="mp3"')) {
12 BlergMedia.has_mp3 = true;
13 BlergMedia.audioExtensions.push('mp3');
15 if (e.canPlayType('audio/ogg; codecs="vorbis"')) {
16 BlergMedia.has_vorbis = true;
17 BlergMedia.audioExtensions.push('ogg', 'oga');
19 if (e.canPlayType('audio/wav')) {
20 BlergMedia.has_wav = true;
21 BlergMedia.audioExtensions.push('wav');
23 BlergMedia.audioTypeRegex = new RegExp("audio:(" + BlergMedia.audioExtensions.join('|') + ")$");
24 BlergMedia.audioExtensionRegex = new RegExp("\\.(" + BlergMedia.audioExtensions.join('|') + ")$");
27 var e = document.createElement('video');
28 if (!!e.canPlayType) {
29 BlergMedia.has_video = true;
30 if (e.canPlayType('video/mp4; codecs="avc"')) {
31 BlergMedia.has_h264 = true;
32 BlergMedia.videoExtensions.push('mp4');
34 if (e.canPlayType('video/ogg; codecs="theora, vorbis"')) {
35 BlergMedia.has_theora = true;
36 BlergMedia.videoExtensions.push('ogv');
38 if (e.canPlayType('video/webm; codecs="vp8, vorbis"')) {
39 BlergMedia.has_webm = true;
40 BlergMedia.videoExtensions.push('webm');
42 BlergMedia.videoTypeRegex = new RegExp("video:(" + BlergMedia.videoExtensions.join('|') + ")$");
43 BlergMedia.videoExtensionRegex = new RegExp("\\.(" + BlergMedia.videoExtensions.join('|') + ")$");
46 BlergMedia.imageTypeRegex = new RegExp("image:(" + BlergMedia.imageExtensions.join('|') + ")$");
47 BlergMedia.imageExtensionRegex = new RegExp("\\.(" + BlergMedia.imageExtensions.join('|') + ")$");
50 BlergMedia.play_audio = function(ev) {
51 var e = ev.target.parentElement;
52 var url = ev.target.parentElement.href;
53 var audio_element = document.createElement('audio');
54 audio_element.src = url;
55 audio_element.controls = 1;
56 audio_element.autoplay = 1;
57 e.parentElement.replaceChild(audio_element, e);
60 BlergMedia.play_video = function(ev) {
61 var e = ev.target.parentElement;
62 var url = ev.target.parentElement.href;
63 var p = document.createElement('p');
64 var video_element = document.createElement('video');
65 video_element.src = url;
66 video_element.controls = 1;
67 video_element.autoplay = 1;
68 p.appendChild(video_element);
69 e.parentElement.replaceChild(video_element, e);
72 BlergMedia.show_image = function(ev) {
74 var medialink = img.parentElement;
75 var url = medialink.href;
76 var anchor = medialink.previousElementSibling;
77 var title = anchor.firstChild.data;
79 img.title = img.alt = title;
80 // Get rid of whitespace between anchor and medialink
81 medialink.parentElement.removeChild(medialink.previousSibling);
82 anchor.parentElement.removeChild(anchor);
85 BlergMedia.process = function(data) {
86 if (BlergMedia.imageExtensionRegex.test(data.url) ||
87 (data.extra && BlergMedia.imageExtensionRegex.test(data.extra))) {
88 data.widget = '<a href="' + data.url + '" onclick="BlergMedia.show_image(event); return false"><img src="/images/play.png"></a>';
89 } else if (BlergMedia.audioExtensionRegex.test(data.url) ||
90 (data.extra && BlergMedia.audioTypeRegex.test(data.extra))) {
91 data.widget = '<a href="' + data.url + '" onclick="BlergMedia.play_audio(event); return false"><img src="/images/play.png"></a>';
92 } else if (BlergMedia.videoExtensionRegex.test(data.url) ||
93 (data.extra && BlergMedia.videoTypeRegex.test(data.extra))) {
94 data.widget = '<a href="' + data.url + '" onclick="BlergMedia.play_video(event); return false"><img src="/images/play.png"></a>';