If possible, support audio content types
Adding support for HTML5 audio playback if the browser supports both the audio HTML5 element and the content type.
This commit is contained in:
@@ -338,6 +338,10 @@ class OperationView extends Backbone.View
|
|||||||
# if server is nice, and sends content-type back, we can use it
|
# if server is nice, and sends content-type back, we can use it
|
||||||
contentType = if headers && headers["Content-Type"] then headers["Content-Type"].split(";")[0].trim() else null
|
contentType = if headers && headers["Content-Type"] then headers["Content-Type"].split(";")[0].trim() else null
|
||||||
|
|
||||||
|
supportsAudioPlayback = (contentType) ->
|
||||||
|
audioElement = document.createElement('audio')
|
||||||
|
return !!(audioElement.canPlayType && audioElement.canPlayType(contentType).replace(/no/, ''))
|
||||||
|
|
||||||
if !content
|
if !content
|
||||||
code = $('<code />').text("no content")
|
code = $('<code />').text("no content")
|
||||||
pre = $('<pre class="json" />').append(code)
|
pre = $('<pre class="json" />').append(code)
|
||||||
@@ -352,6 +356,8 @@ class OperationView extends Backbone.View
|
|||||||
pre = $('<pre class="xml" />').append(code)
|
pre = $('<pre class="xml" />').append(code)
|
||||||
else if /^image\//.test(contentType)
|
else if /^image\//.test(contentType)
|
||||||
pre = $('<img>').attr('src',url)
|
pre = $('<img>').attr('src',url)
|
||||||
|
else if /^audio\//.test(contentType) and supportsAudioPlayback(contentType)
|
||||||
|
pre = $('<audio controls>').append($('<source>').attr('src', url).attr('type', contentType))
|
||||||
else
|
else
|
||||||
# don't know what to render!
|
# don't know what to render!
|
||||||
code = $('<code />').text(content)
|
code = $('<code />').text(content)
|
||||||
|
|||||||
Reference in New Issue
Block a user