Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Batch import image files #57

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 28 additions & 21 deletions image.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,17 @@ var H5P = H5P || {};
this.placeholder = true;
}
else {
this.source = H5P.getPath(params.file.path, id);
this.width = params.file.width;
this.height = params.file.height;
}

this.alt = (!params.decorative && params.alt !== undefined) ? params.alt : '';

if (params.title !== undefined) {
this.title = params.title;
this.imageSet = []
for(let i = 0;i<params.file.length;i++){
const image = {
source: H5P.getPath(params.file[i].path, id),
width: params.file[i].width,
height: params.file[i].height,
alt: (!params.decorative[i] && params.alt[i] !== undefined) ? params.alt[i] : '',
title: params.title[i] ? '' : params.title[i]
}
this.imageSet.append(image);
}
}
};

Expand All @@ -39,7 +41,7 @@ var H5P = H5P || {};
*/
H5P.Image.prototype.attach = function ($wrapper) {
var self = this;
var source = this.source;
var imageSet = this.imageSet;

if (self.$img === undefined) {
if(self.placeholder) {
Expand All @@ -55,18 +57,23 @@ var H5P = H5P || {};
}
});
} else {
self.$img = $('<img>', {
width: '100%',
height: '100%',
src: source,
alt: this.alt,
title: this.title === undefined ? '' : this.title,
on: {
load: function () {
self.trigger('loaded');
}
self.$img = $('<div>', {
class: 'h5p-placeholder',
});
for(let i = 0;i<imageSet.length;i++){
self.$img.append($('<img>', {
width: '100%',
height: '100%',
src: imageSet[i].source,
alt: imageSet[i].alt,
title: imageSet[i].title,
on: {
load: function () {
self.trigger('loaded');
}
}
}));
}
});
}
}

Expand Down