mirror of
https://github.com/lrsjng/h5ai.git
synced 2025-03-23 13:59:59 +01:00
Add video preview.
This commit is contained in:
parent
1e15c9fb9c
commit
b7081b32de
14
src/_h5ai/client/css/inc/preview-vid.less
Normal file
14
src/_h5ai/client/css/inc/preview-vid.less
Normal file
@ -0,0 +1,14 @@
|
||||
|
||||
#pv-vid-video {
|
||||
position: absolute;
|
||||
|
||||
max-width: 100%;
|
||||
max-height: 100%;
|
||||
|
||||
box-shadow: 0 0 8px 2px rgba(0, 0, 0, 0.3);
|
||||
}
|
||||
|
||||
#pv-vid-video:-webkit-full-screen {
|
||||
top: auto !important;
|
||||
left: auto !important;
|
||||
}
|
125
src/_h5ai/client/js/inc/ext/preview-vid.js
Normal file
125
src/_h5ai/client/js/inc/ext/preview-vid.js
Normal file
@ -0,0 +1,125 @@
|
||||
|
||||
modulejs.define('ext/preview-vid', ['_', '$', 'core/settings', 'core/event', 'ext/preview'], function (_, $, allsettings, event, preview) {
|
||||
|
||||
var settings = _.extend({
|
||||
enabled: false,
|
||||
types: []
|
||||
}, allsettings['preview-vid']),
|
||||
|
||||
preloadVid = function (src, callback) {
|
||||
|
||||
var $video = $('<video/>')
|
||||
.one('loadedmetadata', function () {
|
||||
|
||||
callback($video);
|
||||
// setTimeout(function () { callback($video); }, 1000); // for testing
|
||||
})
|
||||
.attr('autoplay', 'autoplay')
|
||||
.attr('controls', 'controls')
|
||||
.attr('preload', 'auto')
|
||||
.attr('src', src);
|
||||
},
|
||||
|
||||
onEnter = function (items, idx) {
|
||||
|
||||
var currentItems = items,
|
||||
currentIdx = idx,
|
||||
currentItem = items[idx],
|
||||
|
||||
onAdjustSize = function () {
|
||||
|
||||
var $content = $('#pv-content'),
|
||||
$vid = $('#pv-vid-video');
|
||||
|
||||
if ($vid.length) {
|
||||
|
||||
$vid.css({
|
||||
'left': '' + (($content.width()-$vid.width())*0.5) + 'px',
|
||||
'top': '' + (($content.height()-$vid.height())*0.5) + 'px',
|
||||
'max-width': $content.width(),
|
||||
'height': $content.height()
|
||||
});
|
||||
|
||||
preview.setLabels([
|
||||
currentItem.label,
|
||||
'' + $vid[0].videoWidth + 'x' + $vid[0].videoHeight,
|
||||
'' + (100 * $vid.width() / $vid[0].videoWidth).toFixed(0) + '%'
|
||||
]);
|
||||
}
|
||||
},
|
||||
|
||||
onIdxChange = function (rel) {
|
||||
|
||||
currentIdx = (currentIdx + rel + currentItems.length) % currentItems.length;
|
||||
currentItem = currentItems[currentIdx];
|
||||
|
||||
var spinnerTimeout = setTimeout(function () { preview.showSpinner(true); }, 200);
|
||||
|
||||
if ($('#pv-vid-video').length) {
|
||||
$('#pv-vid-video')[0].pause();
|
||||
}
|
||||
preloadVid(currentItem.absHref, function ($preloaded_vid) {
|
||||
|
||||
clearTimeout(spinnerTimeout);
|
||||
preview.showSpinner(false);
|
||||
|
||||
$('#pv-content').fadeOut(100, function () {
|
||||
$('#pv-content').empty().append($preloaded_vid.attr('id', 'pv-vid-video')).fadeIn(200);
|
||||
|
||||
// small timeout, so $preloaded_vid is visible and therefore $preloaded_vid.width is available
|
||||
setTimeout(function () {
|
||||
onAdjustSize();
|
||||
|
||||
preview.setIndex(currentIdx + 1, currentItems.length);
|
||||
preview.setRawLink(currentItem.absHref);
|
||||
}, 10);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
onIdxChange(0);
|
||||
preview.setOnIndexChange(onIdxChange);
|
||||
preview.setOnAdjustSize(onAdjustSize);
|
||||
preview.enter();
|
||||
},
|
||||
|
||||
initItem = function (item) {
|
||||
|
||||
if (item.$view && _.indexOf(settings.types, item.type) >= 0) {
|
||||
item.$view.find('a').on('click', function (event) {
|
||||
|
||||
event.preventDefault();
|
||||
|
||||
var matchedEntries = _.compact(_.map($('#items .item'), function (item) {
|
||||
|
||||
item = $(item).data('item');
|
||||
return _.indexOf(settings.types, item.type) >= 0 ? item : null;
|
||||
}));
|
||||
|
||||
onEnter(matchedEntries, _.indexOf(matchedEntries, item));
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
onLocationChanged = function (item) {
|
||||
|
||||
_.each(item.content, initItem);
|
||||
},
|
||||
|
||||
onLocationRefreshed = function (item, added, removed) {
|
||||
|
||||
_.each(added, initItem);
|
||||
},
|
||||
|
||||
init = function () {
|
||||
|
||||
if (!settings.enabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
event.sub('location.changed', onLocationChanged);
|
||||
event.sub('location.refreshed', onLocationRefreshed);
|
||||
};
|
||||
|
||||
init();
|
||||
});
|
@ -249,6 +249,16 @@ Options
|
||||
}
|
||||
},
|
||||
|
||||
/*
|
||||
Show a video preview on click.
|
||||
|
||||
- types: array of types
|
||||
*/
|
||||
"preview-vid": {
|
||||
"enabled": true,
|
||||
"types": ["vid"]
|
||||
},
|
||||
|
||||
/*
|
||||
Show QRCodes on hovering files.
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user