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

add some events(full,exit,render) #604

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions src/js/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ export const EVENT_ZOOM = 'zoom';
export const EVENT_ZOOMED = 'zoomed';
export const EVENT_PLAY = 'play';
export const EVENT_STOP = 'stop';
export const EVENT_FULL = 'full';
export const EVENT_EXIT = 'exit';

// Data keys
export const DATA_ACTION = `${NAMESPACE}Action`;
Expand Down
24 changes: 24 additions & 0 deletions src/js/methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import {
CLASS_TRANSITION,
EVENT_CLICK,
EVENT_ERROR,
EVENT_EXIT,
EVENT_FULL,
EVENT_HIDE,
EVENT_LOAD,
EVENT_MOVE,
Expand Down Expand Up @@ -945,6 +947,7 @@ export default {
// Enter modal mode (only available in inline mode)
full() {
const {
element,
options,
viewer,
image,
Expand All @@ -955,6 +958,16 @@ export default {
return this;
}

if (isFunction(options.full)) {
addListener(element, EVENT_FULL, options.full, {
once: true,
});
}

if (dispatchEvent(element, EVENT_FULL) === false) {
return this;
}

this.fulled = true;
this.open();
addClass(this.button, CLASS_FULLSCREEN_EXIT);
Expand Down Expand Up @@ -1003,6 +1016,7 @@ export default {
// Exit modal mode (only available in inline mode)
exit() {
const {
element,
options,
viewer,
image,
Expand All @@ -1013,6 +1027,16 @@ export default {
return this;
}

if (isFunction(options.exit)) {
addListener(element, EVENT_EXIT, options.exit, {
once: true,
});
}

if (dispatchEvent(element, EVENT_EXIT) === false) {
return this;
}

this.fulled = false;
this.close();
removeClass(this.button, CLASS_FULLSCREEN_EXIT);
Expand Down
14 changes: 11 additions & 3 deletions src/js/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
getImageNaturalSizes,
getTransforms,
hasClass,
isFunction,
isNumber,
removeClass,
removeListener,
Expand Down Expand Up @@ -275,13 +276,20 @@ export default {
marginTop: imageData.y,
}, getTransforms(imageData)));

if (done) {
if (done || isFunction(this.options.rendered)) {
const callback = () => {
done();
if (isFunction(this.options.rendered)) {
this.options.rendered();
}
};

if ((this.viewing || this.moving || this.rotating || this.scaling || this.zooming)
&& this.options.transition
&& hasClass(image, CLASS_TRANSITION)) {
const onTransitionEnd = () => {
this.imageRendering = false;
done();
callback();
};

this.imageRendering = {
Expand All @@ -294,7 +302,7 @@ export default {
once: true,
});
} else {
done();
callback();
}
}
},
Expand Down