Start at the correct index when previewing multiple mediatags

pull/1/head
yflory 5 years ago
parent b4c61ee753
commit 3bc32f6085

@ -375,19 +375,32 @@ define([
$mt.off('dblclick');
if ($mt.find('img').length) {
$mt.on('dblclick', function () {
var mts = [{
src: $mt.attr('src'),
key: $mt.attr('data-crypto-key')
}];
var mts = [];
$content.find('media-tag').each(function (i, el) {
var $el = $(el);
if ($el.attr('src') === $mt.attr('src')) { return; }
mts.push({
src: $el.attr('src'),
key: $el.attr('data-crypto-key')
});
});
common.getMediaTagPreview(mts);
// Find initial position
var idx = -1;
mts.some(function (obj, i) {
if (obj.src === $mt.attr('src')) {
idx = i;
return true;
}
});
if (idx === -1) {
mts.unshift({
src: $mt.attr('src'),
key: $mt.attr('data-crypto-key')
});
idx = 0;
}
common.getMediaTagPreview(mts, idx);
});
}
});

@ -1048,22 +1048,37 @@ define([
};
var previewMediaTag = function (data) {
var mts = [{
href: data.href,
password: data.password
}];
var mts = [];
$content.find('.cp-app-drive-element.cp-border-color-file').each(function (i, el) {
var path = $(el).data('path');
var id = manager.find(path);
if (!id) { return; }
var _data = manager.getFileData(id);
if (!_data || _data.channel < 48 || _data.channel === data.channel) { return; }
if (!_data || _data.channel < 48) { return; }
mts.push({
channel: _data.channel,
href: _data.href,
password: _data.password
});
});
common.getMediaTagPreview(mts);
// Find initial position
var idx = -1;
mts.some(function (obj, i) {
if (obj.channel === data.channel) {
idx = i;
return true;
}
});
if (idx === -1) {
mts.unshift({
href: data.href,
password: data.password
});
idx = 0;
}
common.getMediaTagPreview(mts, idx);
};
// `app`: true (force open wiht the app), false (force open in preview),

@ -208,10 +208,10 @@ define([
return data;
};
MT.getMediaTagPreview = function (common, tags) {
MT.getMediaTagPreview = function (common, tags, start) {
if (!Array.isArray(tags) || !tags.length) { return; }
var i = 0;
var i = start;
var metadataMgr = common.getMetadataMgr();
var priv = metadataMgr.getPrivateData();
@ -418,19 +418,32 @@ define([
window.saveAs(media._blob.content, media.name);
}
else if ($(this).hasClass("cp-app-code-context-open")) {
var mts = [{
src: $mt.attr('src'),
key: $mt.attr('data-crypto-key')
}];
var mts = [];
$container.find('media-tag').each(function (i, el) {
var $el = $(el);
if ($el.attr('src') === $mt.attr('src')) { return; }
mts.push({
src: $el.attr('src'),
key: $el.attr('data-crypto-key')
});
});
common.getMediaTagPreview(mts);
// Find initial position
var idx = -1;
mts.some(function (obj, i) {
if (obj.src === $mt.attr('src')) {
idx = i;
return true;
}
});
if (idx === -1) {
mts.unshift({
src: $mt.attr('src'),
key: $mt.attr('data-crypto-key')
});
idx = 0;
}
common.getMediaTagPreview(mts, idx);
}
});

Loading…
Cancel
Save