From 481423bac9915a431020b5e5e7672300d4adb3b0 Mon Sep 17 00:00:00 2001 From: Chip Black Date: Fri, 5 Aug 2011 17:57:00 -0500 Subject: [PATCH 1/1] Add inline support for media formats --- www/images/play.png | Bin 0 -> 143 bytes www/index.html | 1 + www/js/blerg.js | 19 ++++++++++++++ www/js/blergmedia.js | 58 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 78 insertions(+) create mode 100644 www/images/play.png create mode 100644 www/js/blergmedia.js diff --git a/www/images/play.png b/www/images/play.png new file mode 100644 index 0000000000000000000000000000000000000000..90ba32d2171a971f48d2312741fb1e167fb68c97 GIT binary patch literal 143 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!60wlNoGJgf67>k44ofy`glX(f`czU`xhG?8` zop_Lo!GOa_``i6%)3-l9mho!kqr|4XX}R%B*XKwC9-o=5@+i)WQCR5xLXi(jhOFAG q9_$4ScNqV$R + diff --git a/www/js/blerg.js b/www/js/blerg.js index 83a8a88..83483fa 100644 --- a/www/js/blerg.js +++ b/www/js/blerg.js @@ -404,6 +404,25 @@ function mangleRecord(record, template) { l = l.replace(/(\s|^)(https?:\/\/[a-zA-Z0-9.-]*[a-zA-Z0-9](\/([^\s"]*[^.!,;?()\s])?)?)/g, '$1$2'); // Turn markdown links into links + var re; + + // Craft a regex that finds URLs that end in the extensions specified by BlergMedia.audioExtensions. + re = new RegExp('(\\s|^)\\[([^\\]]+)\\]\\((https?:\\/\\/[a-zA-Z0-9.-]*[a-zA-Z0-9]\\/[^)"]*?\\.(' + BlergMedia.audioExtensions.join('|') + '))\\)', 'g'); + l = l.replace(re, '$1$2 '); + + // Ditto, but use the extended markdown link syntax to specify the format + re = new RegExp('(\\s|^)\\[([^\\]]+)\\]\\((https?:\\/\\/[a-zA-Z0-9.-]*[a-zA-Z0-9](\\/[^)"]*?)?)\\s+audio:(' + BlergMedia.audioExtensions.join('|') + ')\\)', 'g'); + l = l.replace(re, '$1$2 '); + + // Craft a regex that finds URLs that end in the extensions specified by BlergMedia.videoExtensions. + re = new RegExp('(\\s|^)\\[([^\\]]+)\\]\\((https?:\\/\\/[a-zA-Z0-9.-]*[a-zA-Z0-9]\\/[^)"]*?\\.(' + BlergMedia.videoExtensions.join('|') + '))\\)', 'g'); + l = l.replace(re, '$1$2 '); + + // Ditto, but use the extended markdown link syntax to specify the format + re = new RegExp('(\\s|^)\\[([^\\]]+)\\]\\((https?:\\/\\/[a-zA-Z0-9.-]*[a-zA-Z0-9](\\/[^)"]*?)?)\\s+video:(' + BlergMedia.videoExtensions.join('|') + ')\\)', 'g'); + l = l.replace(re, '$1$2 '); + + // Regular markdown links l = l.replace(/(\s|^)\[([^\]]+)\]\((https?:\/\/[a-zA-Z0-9.-]*[a-zA-Z0-9](\/[^)"]*?)?)\)/g, '$1$2'); // Turn *foo* into italics and **foo** into bold diff --git a/www/js/blergmedia.js b/www/js/blergmedia.js new file mode 100644 index 0000000..0528a9b --- /dev/null +++ b/www/js/blergmedia.js @@ -0,0 +1,58 @@ +var BlergMedia = { + audioExtensions: [], + videoExtensions: [] +}; + +function media_init() { + var e = document.createElement('audio'); + if (!!e.canPlayType) { + BlergMedia.has_audio = true; + if (e.canPlayType('audio/mpeg; codecs="mp3"')) { + BlergMedia.has_mp3 = true; + BlergMedia.audioExtensions.push('mp3'); + } + if (e.canPlayType('audio/ogg; codecs="vorbis"')) { + BlergMedia.has_vorbis = true; + BlergMedia.audioExtensions.push('ogg', 'oga'); + } + if (e.canPlayType('audio/wav')) { + BlergMedia.has_wav = true; + BlergMedia.audioExtensions.push('wav'); + } + } + + var e = document.createElement('video'); + if (!!e.canPlayType) { + BlergMedia.has_video = true; + if (e.canPlayType('video/mp4; codecs="avc"')) { + BlergMedia.has_h264 = true; + BlergMedia.videoExtensions.push('mp4'); + } + if (e.canPlayType('video/ogg; codecs="theora, vorbis"')) { + BlergMedia.has_theora = true; + BlergMedia.videoExtensions.push('ogv'); + } + if (e.canPlayType('video/webm; codecs="vp8, vorbis"')) { + BlergMedia.has_webm = true; + BlergMedia.videoExtensions.push('webm'); + } + } +} + +function play_audio() { + var e = event.target.parentElement; + var url = event.target.parentElement.href; + var audio_element = new Element('audio', {src: url, controls: 1, autoplay: 1}); + e.replace(audio_element); +} + +function play_video() { + var e = event.target.parentElement; + var url = event.target.parentElement.href; + var p = new Element('p'); + var video_element = new Element('video', {src: url, controls: 1, autoplay: 1}); + p.insert(video_element); + e.replace(p); +} + +window.addEventListener('load', media_init, false); -- 2.34.1