FluidbookLinks.prototype = {
init: function () {
+
+ var $this = this;
+
$(document).on('click', '[data-wescosales-ref]', function () {
});
+
+ // ToDo: consider re-using existing popinOverlay div?
+ $('body').append('<div id="zoomPopupOverlay"></div><div id="zoomPopupWrapper"><a href="#" class="zoomPopupClose"></a></div>');
+
+ $(document).on('click', '.zoomPopup', function(e) {
+ e.preventDefault();
+ $this.zoomLink(this);
+ return false;
+ });
+
+ $(document).on('click touchend', '#zoomPopupOverlay, .zoomPopupClose', function(e) {
+ console.log('closing zoomPopup...');
+ $this.zoomLinkReset();
+ });
+
},
initLinks: function (pageNr) {
if (pageNr == undefined) {
}
},
+ zoomLink: function(link) {
+
+ var $this = this;
+
+ if($('body').hasClass('zoomPopup')) return false; // Ignore clicks on other zoom links if popup is already open
+
+ // If the interface is zoomed in, we must zoom out first
+ if ($('body').hasClass('zoomed')) {
+ console.log('zooming out before opening zoom box');
+ //currentScale = this.fluidbook.desktop.desktopScale; // Get current scale so the size of the popup can be calculated correctly
+
+ // Wait for clickZoom out to finish before trying again to open zoom link
+ $(document).one('fluidbookZoomOutEnded', function() {
+ $this.zoomLink(link);
+ });
+
+ // Zoom out
+ this.fluidbook.resetZoom();
+
+ return false;
+ }
+
+ //this.zoomLinkReset();
+
+ var z = $('#zoomPopupWrapper'),
+ zoomMargin = 50,
+ availableWidth = $(window).width() - (2 * zoomMargin),
+ availableHeight = $(window).height() - (2 * zoomMargin),
+ $link = $(link),
+ box = $link[0].getBoundingClientRect(),
+ parent = $link.parent('.link'),
+ maxZoom = parseInt($link.data('maxzoom')) || 2,
+ zoomImage = $link.data('zoomimage'),
+ x,
+ y,
+ zoomWidth,
+ zoomHeight,
+ zoomScale;
+
+ // Calculate best scale factor to fit and also to honour the maxZoom level
+ zoomScale = Math.min((availableWidth / box.width), (availableHeight / box.height), maxZoom);
+
+ zoomWidth = box.width * zoomScale;
+ zoomHeight = box.height * zoomScale;
+
+ // Calculate translate co-ordinates
+ x = availableWidth/2 - parent.offset().left - zoomWidth/2 + zoomMargin;
+ y = availableHeight/2 - parent.offset().top - zoomHeight/2 + zoomMargin;
+
+ // console.log(parent);
+ // console.info(box);
+ // console.info(availableWidth, availableHeight);
+
+ z.css({
+ transform: 'none',
+ width: box.width,
+ height: box.height,
+ left: box.left,
+ top: box.top
+ //backgroundImage: 'url('+ zoomImage +')'
+ });
+
+ z.show();
+
+ setTimeout(function(){
+ z.css({
+ transform: 'translateX('+ x +'px) translateY('+ y +'px)',
+ width: zoomWidth,
+ height: zoomHeight
+ });
+ }, 50);
+
+ z.data('scale', zoomScale);
+
+ $('body').addClass('zoomPopup');
+
+ },
+
+ zoomLinkReset: function() {
+
+ if (!$('body').hasClass('zoomPopup')) return false; // Already open
+
+ var z = $('#zoomPopupWrapper'),
+ scale = z.data('scale');
+
+ z.css({
+ transform: 'translate(0,0)',
+ width: z.width() / scale,
+ height: z.height() / scale
+ });
+
+ // Hide popup after transition completes
+ // ToDo: use CSS transition end event to do this without needing a timeout value (or use Web Animation API)
+ // ToDo: see https://davidwalsh.name/css-animation-callback
+ setTimeout(function() {
+ $('#zoomPopupWrapper').hide();
+ $('body').removeClass('zoomPopup');
+ }, 500);
+
+ //z.attr('style', '');
+
+ return false;
+ }
+
}
\ No newline at end of file