From 3bc32f6085591e222c8799dd3b19f8184c43681e Mon Sep 17 00:00:00 2001 From: yflory Date: Fri, 3 Apr 2020 12:32:25 +0200 Subject: [PATCH] Start at the correct index when previewing multiple mediatags --- www/common/diffMarked.js | 25 +++++++++++++++++++------ www/common/drive-ui.js | 27 +++++++++++++++++++++------ www/common/inner/common-mediatag.js | 29 +++++++++++++++++++++-------- 3 files changed, 61 insertions(+), 20 deletions(-) diff --git a/www/common/diffMarked.js b/www/common/diffMarked.js index d4fad71ea..852fa2599 100644 --- a/www/common/diffMarked.js +++ b/www/common/diffMarked.js @@ -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); }); } }); diff --git a/www/common/drive-ui.js b/www/common/drive-ui.js index adac4e353..4523c99f5 100644 --- a/www/common/drive-ui.js +++ b/www/common/drive-ui.js @@ -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), diff --git a/www/common/inner/common-mediatag.js b/www/common/inner/common-mediatag.js index 22e4d9cfc..a97f05618 100644 --- a/www/common/inner/common-mediatag.js +++ b/www/common/inner/common-mediatag.js @@ -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); } });