Skip to content

Commit 6c5f654

Browse files
committed
release: v0.5.1
1 parent d06947e commit 6c5f654

File tree

4 files changed

+395
-359
lines changed

4 files changed

+395
-359
lines changed

dist/eagle.cjs.js

+144-126
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* eagle.js v0.5.0
2+
* eagle.js v0.5.1
33
*
44
* @license
55
* Copyright 2017-2019, Zulko
@@ -12,6 +12,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
1212
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
1313

1414
var throttle = _interopDefault(require('lodash.throttle'));
15+
var _Object$assign = _interopDefault(require('babel-runtime/core-js/object/assign'));
1516
var Vue = _interopDefault(require('vue'));
1617

1718
var Slideshow = {
@@ -260,7 +261,7 @@ var Slideshow = {
260261
var _this2 = this;
261262

262263
Options.plugins.forEach(function (plugin) {
263-
plugin[0].destroy(_this2);
264+
plugin[0].destroy(_this2, plugin[1]);
264265
});
265266
}
266267
},
@@ -591,159 +592,176 @@ var Timer = { render: function render() {
591592
}
592593
};
593594

594-
var height = void 0,
595-
width = void 0,
596-
center = void 0,
597-
boundary = void 0;
598-
599-
var scale = 2;
600-
601-
function updateCoords() {
602-
height = document.documentElement.clientHeight;
603-
width = document.documentElement.clientWidth;
604-
center.x = width / 2;
605-
center.y = height / 2;
606-
boundary.x = center.x / scale;
607-
boundary.y = center.y / scale;
608-
}
595+
var hasZoom = false;
596+
597+
var updateCoords = function updateCoords(slideshow, config) {
598+
return function () {
599+
slideshow._height = document.documentElement.clientHeight;
600+
slideshow._width = document.documentElement.clientWidth;
601+
slideshow._center.x = slideshow._width / 2;
602+
slideshow._center.y = slideshow._height / 2;
603+
slideshow._boundary.x = slideshow._center.x / config.scale;
604+
slideshow._boundary.y = slideshow._center.y / config.scale;
605+
};
606+
};
609607

610-
function magnify(event) {
611-
if (!event.altKey) return;
612-
if (document.body.style.transform) {
613-
document.body.style.transform = '';
614-
document.body.style.overflow = 'auto';
615-
} else {
616-
document.body.style.height = height + 'px';
617-
document.body.style.overflow = 'hidden';
618-
document.body.style.transition = '0.5s';
619-
var translateX = center.x - event.clientX;
620-
var translateY = center.y - event.clientY;
621-
translateX = translateX < boundary.x ? translateX > -boundary.x ? translateX : -boundary.x : boundary.x;
622-
translateY = translateY < boundary.y ? translateY > -boundary.y ? translateY : -boundary.y : boundary.y;
623-
document.body.style.transform = 'scale(' + scale + ') translate(' + translateX + 'px, ' + translateY + 'px)';
624-
}
625-
}
608+
var magnify = function magnify(slideshow, config) {
609+
return function (event) {
610+
if (!event.altKey) return;
611+
if (document.body.style.transform) {
612+
document.body.style.transform = '';
613+
document.body.style.overflow = 'auto';
614+
} else {
615+
document.body.style.height = slideshow._height + 'px';
616+
document.body.style.overflow = 'hidden';
617+
document.body.style.transition = '0.5s';
618+
var translateX = slideshow._center.x - event.clientX;
619+
var translateY = slideshow._center.y - event.clientY;
620+
translateX = translateX < slideshow._boundary.x ? translateX > -slideshow._boundary.x ? translateX : -slideshow._boundary.x : slideshow._boundary.x;
621+
translateY = translateY < slideshow._boundary.y ? translateY > -slideshow._boundary.y ? translateY : -slideshow._boundary.y : slideshow._boundary.y;
622+
document.body.style.transform = 'scale(' + config.scale + ') translate(' + translateX + 'px, ' + translateY + 'px)';
623+
}
624+
};
625+
};
626626

627627
var zoom = {
628628
isPlugin: true,
629629
init: function init(slideshow, config) {
630-
if (!slideshow.embedded) return;
631-
632-
scale = config.scale || scale;
633-
height = document.documentElement.clientHeight;
634-
width = document.documentElement.clientWidth;
635-
center = {
636-
x: width / 2,
637-
y: height / 2
630+
if (slideshow.embedded || slideshow.inserted || hasZoom) return;
631+
632+
config = _Object$assign({
633+
scale: 2
634+
}, config);
635+
636+
hasZoom = true;
637+
slideshow._zoom = true;
638+
639+
slideshow._height = document.documentElement.clientHeight;
640+
slideshow._width = document.documentElement.clientWidth;
641+
slideshow._center = {
642+
x: slideshow._width / 2,
643+
y: slideshow._height / 2
638644
};
639-
boundary = {
640-
x: center.x / scale,
641-
y: center.y / scale
645+
slideshow._boundary = {
646+
x: slideshow._center.x / config.scale,
647+
y: slideshow._center.y / config.scale
642648
};
643649

644-
window.addEventListener('resize', updateCoords);
645-
window.addEventListener('mousedown', magnify);
650+
window.addEventListener('resize', updateCoords(slideshow, config));
651+
window.addEventListener('mousedown', magnify(slideshow, config));
646652
},
647-
destroy: function destroy() {
648-
window.removeEventListener('resize', updateCoords);
649-
window.removeEventListener('mousedown', magnify);
653+
destroy: function destroy(slideshow, config) {
654+
if (slideshow._zoom) {
655+
window.removeEventListener('resize', updateCoords(slideshow, config));
656+
window.removeEventListener('mousedown', magnify(slideshow, config));
657+
}
650658
}
659+
};
651660

661+
var hasPresenter = false;
662+
663+
var keydown = function keydown(slideshow, config) {
664+
return function (evt) {
665+
if (slideshow.keyboardNavigation && (slideshow.currentSlide.keyboardNavigation || evt.ctrlKey || evt.metaKey)) {
666+
if (evt.key === 'ArrowLeft' || evt.key === 'PageUp') {
667+
postMessage(slideshow, '{"method": "previousStep"}');
668+
} else if (evt.key === 'ArrowRight' || evt.key === 'PageDown') {
669+
postMessage(slideshow, '{"method": "nextStep"}');
670+
} else if (evt.key === config.presenterModeKey && !slideshow.parentWindow) {
671+
togglePresenterMode(slideshow);
672+
evt.preventDefault();
673+
}
674+
}
675+
};
652676
};
653677

654-
var slideshow = void 0,
655-
childWindow = void 0,
656-
parentWindow = void 0;
657-
658-
var presenterModeKey = 'p';
659-
660-
function keydown(evt) {
661-
if (slideshow.keyboardNavigation && (slideshow.currentSlide.keyboardNavigation || evt.ctrlKey || evt.metaKey)) {
662-
if (evt.key === 'ArrowLeft' || evt.key === 'PageUp') {
663-
postMessage('{"method": "previousStep"}');
664-
} else if (evt.key === 'ArrowRight' || evt.key === 'PageDown') {
665-
postMessage('{"method": "nextStep"}');
666-
} else if (evt.key === presenterModeKey && !this.parentWindow) {
667-
togglePresenterMode();
668-
evt.preventDefault();
678+
var click = function click(slideshow) {
679+
return function (evt) {
680+
if (slideshow.mouseNavigation && slideshow.currentSlide.mouseNavigation && !evt.altKey) {
681+
var clientX = evt.clientX != null ? evt.clientX : evt.touches[0].clientX;
682+
if (clientX < 0.25 * document.documentElement.clientWidth) {
683+
postMessage(slideshow, '{"method": "previousStep"}');
684+
} else if (clientX > 0.75 * document.documentElement.clientWidth) {
685+
postMessage(slideshow, '{"method": "nextStep"}');
686+
}
669687
}
670-
}
671-
}
688+
};
689+
};
672690

673-
function click(evt) {
674-
if (slideshow.mouseNavigation && slideshow.currentSlide.mouseNavigation && !evt.altKey) {
675-
var clientX = evt.clientX != null ? evt.clientX : evt.touches[0].clientX;
676-
if (clientX < 0.25 * document.documentElement.clientWidth) {
677-
postMessage('{"method": "previousStep"}');
678-
} else if (clientX > 0.75 * document.documentElement.clientWidth) {
679-
postMessage('{"method": "nextStep"}');
691+
var message = function message(slideshow) {
692+
return function (evt) {
693+
if (evt.origin !== window.location.origin) {
694+
return void 0;
680695
}
681-
}
682-
}
696+
try {
697+
var data = JSON.parse(evt.data);
698+
switch (data.method) {
699+
case 'nextStep':
700+
case 'previousStep':
701+
slideshow[data.method]();
702+
break;
703+
case 'getCurrentSlide':
704+
postMessage(slideshow, '{\n "method": "setCurrentSlide", \n "slideIndex": ' + slideshow.currentSlideIndex + ',\n "step": ' + slideshow.step + '\n }');
705+
break;
706+
case 'setCurrentSlide':
707+
slideshow.currentSlideIndex = data.slideIndex;
708+
slideshow.$nextTick(function () {
709+
slideshow.step = data.step;
710+
});
711+
break;
712+
default:
713+
}
714+
} catch (e) {
715+
console.log('Presenter mode runs into an error: ' + e);
716+
}
717+
};
718+
};
683719

684-
function postMessage(message) {
685-
if (childWindow) {
686-
childWindow.postMessage(message, window.location.origin);
720+
function postMessage(slideshow, message) {
721+
if (slideshow.childWindow) {
722+
slideshow.childWindow.postMessage(message, window.location.origin);
687723
}
688-
if (parentWindow) {
689-
parentWindow.postMessage(message, window.location.origin);
724+
if (slideshow.parentWindow) {
725+
slideshow.parentWindow.postMessage(message, window.location.origin);
690726
}
691727
}
692728

693-
function togglePresenterMode() {
694-
if (childWindow) {
695-
childWindow.close();
696-
childWindow = null;
729+
function togglePresenterMode(slideshow) {
730+
if (slideshow.childWindow) {
731+
slideshow.childWindow.close();
732+
slideshow.childWindow = null;
697733
} else {
698-
childWindow = window.open(window.location.href, 'eagle-presenter');
699-
window.addEventListener('message', message);
700-
}
701-
}
702-
703-
function message(evt) {
704-
if (evt.origin !== window.location.origin) {
705-
return void 0;
734+
slideshow.childWindow = window.open(window.location.href, 'eagle-presenter');
735+
window.addEventListener('message', message(slideshow));
706736
}
707-
try {
708-
var data = JSON.parse(evt.data);
709-
switch (data.method) {
710-
case 'nextStep':
711-
case 'previousStep':
712-
slideshow[data.method]();
713-
break;
714-
case 'getCurrentSlide':
715-
postMessage('{\n "method": "setCurrentSlide", \n "slideIndex": ' + slideshow.currentSlideIndex + ',\n "step": ' + slideshow.step + '\n }');
716-
break;
717-
case 'setCurrentSlide':
718-
slideshow.currentSlideIndex = data.slideIndex;
719-
slideshow.$nextTick(function () {
720-
slideshow.step = data.step;
721-
});
722-
break;
723-
default:
724-
}
725-
} catch (e) {}
726737
}
727738

728739
var presenter = {
729740
isPlugin: true,
730-
init: function init(s, config) {
731-
presenterModeKey = config.presenterModeKey || presenterModeKey;
732-
slideshow = s;
733-
if (!slideshow.inserted) {
734-
if (window.opener && window.opener.location.href === window.location.href) {
735-
parentWindow = window.opener;
736-
postMessage('{"method": "getCurrentSlide"}');
737-
window.addEventListener('message', message);
738-
}
739-
window.addEventListener('keydown', keydown);
740-
window.addEventListener('click', click);
741+
init: function init(slideshow, config) {
742+
if (slideshow.embedded || slideshow.inserted || hasPresenter) return;
743+
744+
config = _Object$assign({
745+
presenterModeKey: 'p'
746+
}, config);
747+
748+
hasPresenter = true;
749+
slideshow._presenter = true;
750+
751+
if (window.opener && window.opener.location.href === window.location.href) {
752+
slideshow.parentWindow = window.opener;
753+
postMessage(slideshow, '{"method": "getCurrentSlide"}');
754+
window.addEventListener('message', message(slideshow));
741755
}
756+
window.addEventListener('keydown', keydown(slideshow, config));
757+
window.addEventListener('click', click(slideshow));
742758
},
743-
destroy: function destroy() {
744-
window.removeEventListener('message', message);
745-
window.removeEventListener('keydown', keydown);
746-
window.addEventListener('click', click);
759+
destroy: function destroy(slideshow, config) {
760+
if (slideshow._presenter) {
761+
window.removeEventListener('message', message(slideshow));
762+
window.removeEventListener('keydown', keydown(slideshow, config));
763+
window.addEventListener('click', click(slideshow));
764+
}
747765
}
748766
};
749767

0 commit comments

Comments
 (0)