Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic support for different media types #248

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions static/css/pad.css
Original file line number Diff line number Diff line change
Expand Up @@ -1160,3 +1160,10 @@ width:33px !important;
#qrcode{
margin-left:10px;
}

#innerdocbody img, #innerdocbody video, #innerdocbody audio {
padding: 2px;
margin-bottom: 4px;
box-shadow: 0 0 4px #aaa;
background: #fff;
}
59 changes: 56 additions & 3 deletions static/js/domline.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,65 @@ domline.createDomLine = function(nonEmpty, doesWrap, optBrowser, optDocument)
{
if (href)
{
if(!~href.indexOf("http")) // if the url doesn't include http or https etc prefix it.

// if the url doesn't include http or https prefix it
if(!~href.indexOf("http"))
{
href = "http://"+href;
}
extraOpenTags = extraOpenTags + '<a href="' + href.replace(/\"/g, '&quot;') + '">';
extraCloseTags = '</a>' + extraCloseTags;

// check extension and decide, whether it's media (image,audio,video) or a simple link
var href_ext = href.slice(-4);

// images
if (href_ext==".jpg" || href_ext==".png" || href_ext==".gif" || href_ext==".svg") {
extraOpenTags = extraOpenTags + '<img src="' + href.replace(/\"/g, '&quot;') + '"><br>';
}

// music
if (href_ext==".mp3" || href_ext==".wav" || href_ext==".oga") {
extraOpenTags = extraOpenTags + '<audio controls preload="metadata" src="' + href.replace(/\"/g, '&quot;') + '"></audio><br>';
}

// video
if (href_ext==".mp4" || href_ext==".ogv" || href_ext==".ogg" || href.slice(-5)==".webm" || href_ext==".mov") {
extraOpenTags = extraOpenTags + '<video controls preload="metadata" src="' + href.replace(/\"/g, '&quot;') + '"></video><br>';
}

// Imgur
if (href.match(/[http|https]\:\/\/imgur\.com\/([A-Za-z0-9]{5})/) != null) {
var imgur_id = href.match(/[http|https]\:\/\/imgur\.com\/([A-Za-z0-9]{5})/)[1];
extraOpenTags = extraOpenTags + '<img src="http://i.imgur.com/' + imgur_id + '.png"><br>';
}

// Twitpic
if (href.match(/[http|https]\:\/\/twitpic\.com\/([A-Za-z0-9]+)/) != null) {
var twitpic_id = href.match(/[http|https]\:\/\/twitpic\.com\/([A-Za-z0-9]+)/)[1];
extraOpenTags = extraOpenTags + '<img src="https://twitpic.com/show/full/' + twitpic_id + '"><br>';
}

/* not working in Firefox
// YouTube
if (href.match(/[http|https]\:\/\/www\.youtube\.com\/watch\?v=([A-z0-9-_]{11})/) != null) {
var youtube_id = href.match(/[http|https]\:\/\/www\.youtube\.com\/watch\?v=([A-z0-9-_]{11})/)[1];
txt = 'https://www.youtube.com/watch?v=' + youtube_id;
extraOpenTags = extraOpenTags + '<div style="height:385px"><iframe width=640 height=385 src="https://www.youtube.com/embed/' + youtube_id + '"></iframe></div><br>';
}
// Vimeo
if (href.match(/[http|https]\:\/\/vimeo\.com\/(\d{8})/) != null) {
var vimeo_id = href.match(/[http|https]\:\/\/vimeo\.com\/(\d{8})/)[1];
txt = 'https://vimeo.com/' + vimeo_id;
extraOpenTags = extraOpenTags + '<div style="height:338px"><iframe width=640 height=338 src="https://player.vimeo.com/video/' + vimeo_id + '?title=0&byline=0&portrait=0"></iframe></div><br>';
}
*/

// If nothing applies, consider it as a normal url
if (extraOpenTags.length == 0) {
extraOpenTags = extraOpenTags + '<a href="' + href.replace(/\"/g, '&quot;') + '">';
extraCloseTags = '</a>' + extraCloseTags;
}


}
if (simpleTags)
{
Expand Down