$link = $(link),
links = [],
zoomMargin = 50,
+ zoomZonesGap = 30, // Space between grouped zoom links
availableWidth = $(window).width() - (2 * zoomMargin),
availableHeight = $(window).height() - (2 * zoomMargin);
}
}
- links.forEach(function(zoomLink) {
- // console.log('Found link with ID: ' + zoomLink.attr('id'));
+ // Sort links so topmost (lowest Y value) link is first. This allows it to be first/top when placed.
+ links.sort(function(a, b) {
+ return a.data('y') - b.data('y');
+ });
+
+
+ // Calculate positions and scaling for all zoomLink blocks
+ // First, get max height of all zoomLink blocks
+ var zoomGroupHeight = links.reduce(function(sum, zoomLink) {
+ return sum + (zoomLink.data('height') * zoomLink.data('maxzoom'));
+ }, 0);
+
+ // Find widest element in collection
+ var zoomGroupMaxWidth = links.reduce(function(maxWidth, zoomLink) {
+ var width = (zoomLink.data('width') * zoomLink.data('maxzoom'));
+ return (width > maxWidth) ? width : maxWidth;
+ }, 0);
+
+
+ // Todo: figure out which will offer best fit: stacked or side-by-side blocks
+
+ // Count gaps between blocks (always 1 less gap than total blocks)
+ // For now we're assuming blocks are stacked, not side-by-side...
+ zoomGroupHeight += (links.length - 1) * zoomZonesGap;
+
+ var zoomGroupScale = Math.min(availableHeight / zoomGroupHeight, availableWidth / zoomGroupMaxWidth, 1);
+
+ zoomGroupHeight = zoomGroupHeight * zoomGroupScale;
+
+
+ // Y position of first block (so both blocks are vertically centred)
+ var zoomGroupY = Math.round((availableHeight - zoomGroupHeight) / 2);
+
+ links.forEach(function(zoomLink, index) {
+ // console.log(index, 'Found link with ID: ' + zoomLink.attr('id'));
var zoomID = zoomLink.attr('id');
baseWidth = parseInt(zoomLink.data('width')), // Width of the original link from the editor
baseHeight = parseInt(zoomLink.data('height')), // Height of the original link from the editor
maxZoom = parseInt(zoomLink.data('maxzoom')) || 2, // The default value for this should match that of the compiler in zoomLink::generateImage()
- x,
- y,
+ zoomX,
+ zoomY,
zoomWidth,
zoomHeight,
zoomScale;
// link editor width (baseWidth) and comparing it to the actual link width.
//maxZoom = maxZoom / (box.width / baseWidth); // Adjusted maxZoom level...
+ // Apply any necessary group scaling to the individual element
+ baseHeight = baseHeight * zoomGroupScale;
+ baseWidth = baseWidth * zoomGroupScale;
+
// Calculate best scale factor to fit and also to honour the maxZoom level
zoomScale = Math.min((availableWidth / baseWidth), (availableHeight / baseHeight), maxZoom);
// Calculate translate co-ordinates so image is centred correctly
// Values are rounded so we don't end up with image being positioned between pixels, which causes blurring
- x = Math.round((availableWidth / 2) - parent.offset().left - (zoomWidth / 2) + zoomMargin);
- y = Math.round((availableHeight / 2) - parent.offset().top - (zoomHeight / 2) + zoomMargin);
+ zoomX = Math.round((availableWidth / 2) - parent.offset().left - (zoomWidth / 2) + zoomMargin);
+ // zoomY = Math.round((availableHeight / 2) - parent.offset().top - (zoomHeight / 2) + zoomMargin);
+
+ // If this is the first / only block, use calculated zoomGroupY position
+ if (index == 0) {
+ zoomY = zoomGroupY - parent.offset().top + zoomMargin;
+
+ // Otherwise, calculateY position based on first element position
+ } else {
+ zoomY = Math.round(zoomGroupY + links[0].data('height') * links[0].data('maxzoom') * zoomGroupScale + zoomZonesGap + zoomMargin - parent.offset().top);
+ }
// Keep starting scale with zoom element so it can be used when zooming back out
z.data('starting-scale', box.width / zoomWidth);
setTimeout(function () {
z.css({
boxShadow: '0 0 100px rgba(0,0,0,0.3)',
- transform: 'translateX(' + x + 'px) translateY(' + y + 'px) scale(1)'
+ transform: 'translateX(' + zoomX + 'px) translateY(' + zoomY + 'px) scale(1)'
});
}, 50);