mirror of
https://github.com/ONLYOFFICE/sdkjs.git
synced 2026-04-07 14:09:12 +08:00
Load first slide images on first open
This commit is contained in:
committed by
Sergey Luzyanin
parent
331b348a08
commit
6e52ead2cc
@ -396,13 +396,10 @@
|
||||
// loading
|
||||
this.Api = null;
|
||||
this.ThemeLoader = null;
|
||||
this.images_loading = null;
|
||||
|
||||
this.bIsLoadDocumentFirst = false;
|
||||
this.bIsAsyncLoadDocumentImages = false;
|
||||
|
||||
this.nNoByOrderCounter = 0;
|
||||
|
||||
this.isBlockchainSupport = false;
|
||||
var oThis = this;
|
||||
|
||||
@ -462,130 +459,96 @@
|
||||
else
|
||||
image.src = url;
|
||||
};
|
||||
|
||||
this.LoadDocumentImages = function(images, isCheckExists)
|
||||
{
|
||||
if (isCheckExists)
|
||||
{
|
||||
for (let i = images.length - 1; i >= 0; i--)
|
||||
{
|
||||
let id = AscCommon.getFullImageSrc2(images[i]);
|
||||
if (this.map_image_index[id] && (this.map_image_index[id].Status === ImageLoadStatus.Complete))
|
||||
{
|
||||
images.splice(i, 1);
|
||||
}
|
||||
}
|
||||
|
||||
if (0 === images.length)
|
||||
return;
|
||||
}
|
||||
this.LoadDocumentImages = function (images, isCheckExists, syncImages) {
|
||||
if (isCheckExists) {
|
||||
for (let i = images.length - 1; i >= 0; i--) {
|
||||
let id = AscCommon.getFullImageSrc2(images[i]);
|
||||
if (this.map_image_index[id] && (this.map_image_index[id].Status === ImageLoadStatus.Complete)) {
|
||||
images.splice(i, 1);
|
||||
}
|
||||
}
|
||||
|
||||
// сначала заполним массив
|
||||
if (0 === images.length)
|
||||
return;
|
||||
}
|
||||
|
||||
this.images_loading = [];
|
||||
for (let id in images)
|
||||
{
|
||||
this.images_loading[this.images_loading.length] = AscCommon.getFullImageSrc2(images[id]);
|
||||
}
|
||||
if (this.ThemeLoader == null)
|
||||
this.Api.asyncImagesDocumentStartLoaded(this.images_loading);
|
||||
else
|
||||
this.ThemeLoader.asyncImagesStartLoaded(this.images_loading);
|
||||
// сначала заполним массив
|
||||
|
||||
if (!this.bIsAsyncLoadDocumentImages)
|
||||
{
|
||||
this.nNoByOrderCounter = 0;
|
||||
this._LoadImages();
|
||||
}
|
||||
else
|
||||
{
|
||||
let len = this.images_loading.length;
|
||||
for (let i = 0; i < len; i++)
|
||||
this.LoadImageAsync(i);
|
||||
const oRequiredSyncImages = {};
|
||||
const arrImagesLoading = [];
|
||||
for (let id in images) {
|
||||
const sFullImageSrc = AscCommon.getFullImageSrc2(images[id]);
|
||||
arrImagesLoading.push(sFullImageSrc);
|
||||
if (syncImages && syncImages[images[id]]) {
|
||||
oRequiredSyncImages[sFullImageSrc] = true;
|
||||
}
|
||||
}
|
||||
if (syncImages) {
|
||||
for (let id in syncImages) {
|
||||
const sFullImageSrc = AscCommon.getFullImageSrc2(id);
|
||||
if (!oRequiredSyncImages[sFullImageSrc]) {
|
||||
arrImagesLoading.push(sFullImageSrc);
|
||||
oRequiredSyncImages[sFullImageSrc] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (this.ThemeLoader == null)
|
||||
this.Api.asyncImagesDocumentStartLoaded(arrImagesLoading);
|
||||
else
|
||||
this.ThemeLoader.asyncImagesStartLoaded(arrImagesLoading);
|
||||
|
||||
this.images_loading.splice(0, len);
|
||||
if (!this.bIsAsyncLoadDocumentImages) {
|
||||
this._LoadImages(arrImagesLoading);
|
||||
} else {
|
||||
this._LoadImagesAsync(arrImagesLoading, oRequiredSyncImages);
|
||||
}
|
||||
};
|
||||
|
||||
if (this.ThemeLoader == null)
|
||||
this.Api.asyncImagesDocumentEndLoaded();
|
||||
else
|
||||
this.ThemeLoader.asyncImagesEndLoaded();
|
||||
}
|
||||
};
|
||||
this._LoadImages = function (arrImages) {
|
||||
let fOnEachImageLoadCallback;
|
||||
if (oThis.bIsLoadDocumentFirst === true) {
|
||||
fOnEachImageLoadCallback = function () {
|
||||
oThis.Api.OpenDocumentProgress.CurrentImage++;
|
||||
oThis.Api.SendOpenProgress();
|
||||
};
|
||||
}
|
||||
this.LoadImagesWithCallback(arrImages, function () {
|
||||
if (oThis.ThemeLoader == null)
|
||||
oThis.Api.asyncImagesDocumentEndLoaded();
|
||||
else
|
||||
oThis.ThemeLoader.asyncImagesEndLoaded();
|
||||
}, [], false, fOnEachImageLoadCallback);
|
||||
};
|
||||
|
||||
this._LoadImages = function()
|
||||
{
|
||||
for (let i = 0; i < this.images_loading.length; i++)
|
||||
{
|
||||
let id = this.images_loading[i];
|
||||
if (this.map_image_index[id] && (this.map_image_index[id].Status === ImageLoadStatus.Complete))
|
||||
{
|
||||
this.images_loading.splice(i, 1);
|
||||
}
|
||||
}
|
||||
let count_images = this.images_loading.length;
|
||||
this._LoadImagesAsync = function (arrImages, oRequiredSyncImages) {
|
||||
const arrAsyncImages = [];
|
||||
const arrSyncImages = [];
|
||||
for (let i = 0; i < arrImages.length; i += 1) {
|
||||
if (oRequiredSyncImages[arrImages[i]]) {
|
||||
arrSyncImages.push(arrImages[i]);
|
||||
} else {
|
||||
arrAsyncImages.push(arrImages[i]);
|
||||
}
|
||||
}
|
||||
let fOnEachImageLoadCallback;
|
||||
if (oThis.bIsLoadDocumentFirst === true) {
|
||||
fOnEachImageLoadCallback = function () {
|
||||
oThis.Api.OpenDocumentProgress.CurrentImage++;
|
||||
oThis.Api.SendOpenProgress();
|
||||
};
|
||||
}
|
||||
this.LoadImagesWithCallback(arrSyncImages, function () {
|
||||
for (let i = 0; i < arrAsyncImages.length; i += 1) {
|
||||
oThis.LoadImageAsync(arrAsyncImages[i]);
|
||||
}
|
||||
|
||||
if (0 === count_images)
|
||||
{
|
||||
this.nNoByOrderCounter = 0;
|
||||
|
||||
if (this.ThemeLoader == null)
|
||||
this.Api.asyncImagesDocumentEndLoaded();
|
||||
else
|
||||
this.ThemeLoader.asyncImagesEndLoaded();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
for (let i = 0; i < count_images; i++)
|
||||
{
|
||||
var _id = this.images_loading[i];
|
||||
var oImage = new CImage(_id);
|
||||
oImage.Status = ImageLoadStatus.Loading;
|
||||
oImage.Image = new Image();
|
||||
oThis.map_image_index[oImage.src] = oImage;
|
||||
oImage.Image.parentImage = oImage;
|
||||
oImage.Image.onload = function ()
|
||||
{
|
||||
this.parentImage.Status = ImageLoadStatus.Complete;
|
||||
oThis.nNoByOrderCounter++;
|
||||
|
||||
if (oThis.bIsLoadDocumentFirst === true)
|
||||
{
|
||||
oThis.Api.OpenDocumentProgress.CurrentImage++;
|
||||
oThis.Api.SendOpenProgress();
|
||||
}
|
||||
|
||||
if (oThis.nNoByOrderCounter === oThis.images_loading.length)
|
||||
{
|
||||
oThis.images_loading = [];
|
||||
oThis._LoadImages();
|
||||
}
|
||||
};
|
||||
oImage.Image.onerror = function ()
|
||||
{
|
||||
this.parentImage.Status = ImageLoadStatus.Complete;
|
||||
this.parentImage.Image = null;
|
||||
oThis.nNoByOrderCounter++;
|
||||
|
||||
if (oThis.bIsLoadDocumentFirst === true)
|
||||
{
|
||||
oThis.Api.OpenDocumentProgress.CurrentImage++;
|
||||
oThis.Api.SendOpenProgress();
|
||||
}
|
||||
|
||||
if (oThis.nNoByOrderCounter === oThis.images_loading.length)
|
||||
{
|
||||
oThis.images_loading = [];
|
||||
oThis._LoadImages();
|
||||
}
|
||||
};
|
||||
AscCommon.backoffOnErrorImg(oImage.Image, function(img) {
|
||||
oThis.loadImageByUrl(img, img.src);
|
||||
});
|
||||
//oImage.Image.crossOrigin = 'anonymous';
|
||||
oThis.loadImageByUrl(oImage.Image, oImage.src);
|
||||
}
|
||||
};
|
||||
if (oThis.ThemeLoader == null)
|
||||
oThis.Api.asyncImagesDocumentEndLoaded();
|
||||
else
|
||||
oThis.ThemeLoader.asyncImagesEndLoaded();
|
||||
}, [], false, fOnEachImageLoadCallback);
|
||||
};
|
||||
|
||||
this.LoadImage = function(src, type)
|
||||
{
|
||||
@ -621,9 +584,9 @@
|
||||
return null;
|
||||
};
|
||||
|
||||
this.LoadImageAsync = function(i)
|
||||
this.LoadImageAsync = function(imgSrc)
|
||||
{
|
||||
var oImage = new CImage(this.images_loading[i]);
|
||||
var oImage = new CImage(imgSrc);
|
||||
|
||||
oImage.Status = ImageLoadStatus.Loading;
|
||||
oImage.Image = new Image();
|
||||
@ -645,13 +608,15 @@
|
||||
oThis.loadImageByUrl(oImage.Image, oImage.src);
|
||||
};
|
||||
|
||||
this.LoadImagesWithCallback = function(arr, loadImageCallBack, loadImageCallBackArgs, isDisableCrypto)
|
||||
this.LoadImagesWithCallback = function(arr, loadImageCallBack, loadImageCallBackArgs, isDisableCrypto, onEachImageLoadCallback)
|
||||
{
|
||||
let arrAsync = [];
|
||||
for (let i = 0; i < arr.length; i++)
|
||||
{
|
||||
if (this.map_image_index[arr[i]] === undefined)
|
||||
arrAsync.push(arr[i]);
|
||||
if (this.map_image_index[arr[i]] && (this.map_image_index[arr[i]].Status === ImageLoadStatus.Complete))
|
||||
continue;
|
||||
|
||||
arrAsync.push(arr[i]);
|
||||
}
|
||||
|
||||
if (arrAsync.length == 0)
|
||||
@ -675,7 +640,7 @@
|
||||
{
|
||||
this.parentImage.Status = ImageLoadStatus.Complete;
|
||||
asyncImageCounter--;
|
||||
|
||||
onEachImageLoadCallback && onEachImageLoadCallback();
|
||||
if (asyncImageCounter === 0)
|
||||
callback();
|
||||
};
|
||||
@ -684,7 +649,7 @@
|
||||
this.parentImage.Image = null;
|
||||
this.parentImage.Status = ImageLoadStatus.Complete;
|
||||
asyncImageCounter--;
|
||||
|
||||
onEachImageLoadCallback && onEachImageLoadCallback();
|
||||
if (asyncImageCounter === 0)
|
||||
callback();
|
||||
};
|
||||
|
||||
@ -685,6 +685,18 @@ function CPresentation(DrawingDocument) {
|
||||
}
|
||||
|
||||
AscFormat.InitClass(CPresentation, AscFormat.CBaseFormatObject, AscDFH.historyitem_type_Presentation);
|
||||
CPresentation.prototype.getFirstSlideImagesMap = function () {
|
||||
const oRequiredSyncImagesMap = {};
|
||||
const oFirstSlide = this.Slides[0];
|
||||
if (oFirstSlide) {
|
||||
const aImages = oFirstSlide.getAllRasterImagesOnSlide();
|
||||
for (let i = 0; i < aImages.length; i++) {
|
||||
const sImg = aImages[i];
|
||||
oRequiredSyncImagesMap[sImg] = true;
|
||||
}
|
||||
}
|
||||
return oRequiredSyncImagesMap;
|
||||
};
|
||||
CPresentation.prototype.sendEvent = function()
|
||||
{
|
||||
if (!this.Api)
|
||||
|
||||
@ -1103,6 +1103,20 @@ AscFormat.InitClass(Slide, AscFormat.CBaseFormatObject, AscDFH.historyitem_type_
|
||||
});
|
||||
};
|
||||
|
||||
Slide.prototype.getAllRasterImagesOnSlide = function (aImages) {
|
||||
aImages = aImages || [];
|
||||
this.getAllRasterImages(aImages);
|
||||
const oLayout = this.Layout;
|
||||
if (oLayout) {
|
||||
oLayout.getAllRasterImages(aImages);
|
||||
const oMaster = oLayout.Master;
|
||||
if (oMaster) {
|
||||
oMaster.getAllRasterImages(aImages);
|
||||
}
|
||||
}
|
||||
return aImages;
|
||||
};
|
||||
|
||||
|
||||
Slide.prototype.getAllRasterImagesForDraw = function(images) {
|
||||
let aImages = images;
|
||||
|
||||
16
slide/api.js
16
slide/api.js
@ -6055,8 +6055,8 @@ background-repeat: no-repeat;\
|
||||
this.EndActionLoadImages = 2;
|
||||
this.sync_StartAction(c_oAscAsyncActionType.Information, c_oAscAsyncAction.LoadImage);
|
||||
}
|
||||
|
||||
this.ImageLoader.LoadDocumentImages(this.saveImageMap);
|
||||
const oRequiredSyncImagesMap = this.isApplyChangesOnOpen ? this.getFirstSlideImagesMap() : null;
|
||||
this.ImageLoader.LoadDocumentImages(this.saveImageMap, false, oRequiredSyncImagesMap);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -6083,8 +6083,16 @@ background-repeat: no-repeat;\
|
||||
this.sync_StartAction(c_oAscAsyncActionType.BlockInteraction, c_oAscAsyncAction.LoadDocumentImages);
|
||||
}
|
||||
|
||||
const oRequiredSyncImagesMap = AscCommon.CollaborativeEditing.m_aChanges.length ? null : this.getFirstSlideImagesMap();
|
||||
this.ImageLoader.bIsLoadDocumentFirst = true;
|
||||
this.ImageLoader.LoadDocumentImages(_loader_object.ImageMap);
|
||||
this.ImageLoader.LoadDocumentImages(_loader_object.ImageMap, false, oRequiredSyncImagesMap);
|
||||
};
|
||||
asc_docs_api.prototype.getFirstSlideImagesMap = function () {
|
||||
const oLogicDocument = this.getLogicDocument();
|
||||
if (oLogicDocument) {
|
||||
return oLogicDocument.getFirstSlideImagesMap();
|
||||
}
|
||||
return null;
|
||||
};
|
||||
asc_docs_api.prototype.asyncImagesDocumentEndLoaded = function()
|
||||
{
|
||||
@ -6172,6 +6180,7 @@ background-repeat: no-repeat;\
|
||||
this.isApplyChangesOnOpenEnabled = false;
|
||||
this.bNoSendComments = true;
|
||||
var OtherChanges = AscCommon.CollaborativeEditing.m_aChanges.length > 0;
|
||||
this.isApplyChangesOnOpen = true;
|
||||
this._applyPreOpenLocks();
|
||||
let perfStart = performance.now();
|
||||
AscCommon.CollaborativeEditing.Apply_Changes();
|
||||
@ -6181,7 +6190,6 @@ background-repeat: no-repeat;\
|
||||
}
|
||||
AscCommon.CollaborativeEditing.Release_Locks();
|
||||
this.bNoSendComments = false;
|
||||
this.isApplyChangesOnOpen = true;
|
||||
if(OtherChanges && this.isSaveFonts_Images){
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user