diff --git a/src/js/constants.js b/src/js/constants.js index 0d7b679f..1a1d1194 100644 --- a/src/js/constants.js +++ b/src/js/constants.js @@ -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`; diff --git a/src/js/methods.js b/src/js/methods.js index b86a26d2..011434db 100644 --- a/src/js/methods.js +++ b/src/js/methods.js @@ -11,6 +11,8 @@ import { CLASS_TRANSITION, EVENT_CLICK, EVENT_ERROR, + EVENT_EXIT, + EVENT_FULL, EVENT_HIDE, EVENT_LOAD, EVENT_MOVE, @@ -945,6 +947,7 @@ export default { // Enter modal mode (only available in inline mode) full() { const { + element, options, viewer, image, @@ -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); @@ -1003,6 +1016,7 @@ export default { // Exit modal mode (only available in inline mode) exit() { const { + element, options, viewer, image, @@ -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); diff --git a/src/js/render.js b/src/js/render.js index 3e350ba4..db752207 100644 --- a/src/js/render.js +++ b/src/js/render.js @@ -15,6 +15,7 @@ import { getImageNaturalSizes, getTransforms, hasClass, + isFunction, isNumber, removeClass, removeListener, @@ -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 = { @@ -294,7 +302,7 @@ export default { once: true, }); } else { - done(); + callback(); } } },