mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-07-21 10:38:26 +00:00
feature(view) add audio
This commit is contained in:
parent
ae5e7ea2ab
commit
a0a579b84d
2 changed files with 56 additions and 4 deletions
4
html/audio.html
Normal file
4
html/audio.html
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
<div id="js-audio">
|
||||
<audio src="{{ src }}" controls autoplay></audio>
|
||||
<p class="reduce-text"><strong>{{ name }}</strong></p>
|
||||
</div>
|
||||
|
|
@ -61,7 +61,7 @@ var CloudCmd, Util, DOM, CloudFunc, $;
|
|||
* function shows FancyBox
|
||||
*/
|
||||
function show(data, callback, newConfig) {
|
||||
var path, element, func, name, isImage,
|
||||
var path, element, func, name,
|
||||
config = {};
|
||||
|
||||
if (!Loading) {
|
||||
|
|
@ -83,11 +83,16 @@ var CloudCmd, Util, DOM, CloudFunc, $;
|
|||
} else {
|
||||
Images.showLoad();
|
||||
path = CloudFunc.FS + Info.path;
|
||||
isImage = $.fancybox.isImage(path);
|
||||
|
||||
if (isImage) {
|
||||
if (isImage(path))
|
||||
$.fancybox.open({ href : path }, Config);
|
||||
} else
|
||||
else if (isMusic(path))
|
||||
getMusicElement(path, function(element) {
|
||||
$.fancybox.open(element, {
|
||||
beforeShow: musicBeforeShow
|
||||
});
|
||||
});
|
||||
else
|
||||
Info.getData(function(data) {
|
||||
var element = document.createTextNode(data);
|
||||
/* add margin only for view text documents */
|
||||
|
|
@ -103,6 +108,49 @@ var CloudCmd, Util, DOM, CloudFunc, $;
|
|||
$.fancybox.close();
|
||||
}
|
||||
|
||||
function isImage(name) {
|
||||
var isMatch = $.fancybox.isImage(name);
|
||||
|
||||
return isMatch;
|
||||
}
|
||||
|
||||
function isMusic(name) {
|
||||
var isMatch,
|
||||
isStr = Util.isString(name),
|
||||
exts = '.mp3|.mp4',
|
||||
extsReg = new RegExp(exts);
|
||||
|
||||
if (isStr)
|
||||
isMatch = name.match(extsReg);
|
||||
|
||||
return isMatch;
|
||||
}
|
||||
|
||||
function getMusicElement(src, callback) {
|
||||
DOM.ajax({
|
||||
url : '/html/audio.html',
|
||||
success : function(template) {
|
||||
var rendered = Util.render(template, {
|
||||
src: src,
|
||||
name: Info.name
|
||||
}),
|
||||
|
||||
element = $(rendered);
|
||||
Util.exec(callback, element);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function musicBeforeShow() {
|
||||
var audioDiv = $('#js-audio'),
|
||||
audio = audioDiv.find('audio'),
|
||||
width = audio.width() +'px';
|
||||
|
||||
audioDiv.width(width);
|
||||
|
||||
Images.hideLoad();
|
||||
}
|
||||
|
||||
/**
|
||||
* function loads css and js of FancyBox
|
||||
* @callback - executes, when everything loaded
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue