Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- initZoom: function() {
- var isImage, isVideo;
- var itemObjectContainer, itemObject;
- var fromWidth, fromHeight, toWidth, toHeight;
- if($('imageStage')) {
- isImage = true;
- itemObjectContainer = $('imageStage');
- itemObject = itemObjectContainer.down('img');
- // Define source and target dimensions
- fromWidth = 445;
- fromHeight = 364;
- toWidth = 661;
- toHeight = 524;
- } else {
- isVideo = true;
- itemObjectContainer = $('videoPlayer');
- itemObject = $('flashVideoPlayer');
- // Define source and target dimensions
- fromWidth = 445;
- fromHeight = 364;
- toWidth = 661;
- toHeight = 524;
- }
- var contentLeft = itemObjectContainer.up('div.contentLeft');
- var aElm = $('itemStage').down('a');
- var zoomedInfoBox = $('zoomedInfoBox');
- var zoomedOverlay = $('zoomedOverlay');
- // Assign the image's dimensions as CSS properties for easier use
- var itemObjectOriginalDimensions = itemObjectContainer.getDimensions();
- // Assign a fixed height to the itemStage in order
- // to compensate the actual image that will be absolutized
- // when zoomed and therefore leave a gap in the layout
- itemObjectContainer.setStyle({height: itemObjectOriginalDimensions.height + 'px'});
- var zoomIn = function() {
- if(!itemObjectContainer.hasClassName('zoomed')) {
- new Effect.ScaleAndMove(itemObject, (toWidth / fromWidth) * 100, (toHeight / fromHeight) * 100, {
- beforeStart: function() {
- if($('imageStage')) {
- // Necessary to make z-index work in Gecko browsers
- // (element has "overflow: hidden" by default)
- contentLeft.setStyle({overflow: 'visible'});
- // Absolutize image position
- itemObject.absolutize();
- }
- itemObjectContainer.addClassName('zoomed');
- // There is a bug in MacOS/Flash that puts scrollbars
- // over Flash movies, so we will hide the problematic scrollbar
- if(navigator.platform.indexOf('Mac') != -1) {
- $$('#moreItems .scrollbox')[0].setStyle({overflow: 'hidden'});
- }
- // Position and show transparent overlay
- var contentLeftOffset = contentLeft.cumulativeOffset();
- zoomedOverlay.setStyle({
- left: contentLeftOffset.left + 'px',
- top: contentLeftOffset.top + 'px',
- width: toWidth + 'px',
- height: contentLeft.getHeight() + 'px'
- });
- zoomedOverlay.removeClassName('hide');
- },
- duration: 1.0,
- scaleMode: {
- originalWidth: itemObjectOriginalDimensions.width,
- originalHeight: itemObjectOriginalDimensions.height
- },
- moveX: false,
- moveToY: contentLeft.cumulativeOffset().top,
- afterFinish: function() {
- // Position the info box below the zoomed item
- zoomedInfoBox.setStyle({
- left: itemObject.cumulativeOffset().left + 'px',
- top: (parseInt(itemObject.getStyle('top')) + itemObject.getHeight()) + 'px',
- width: toWidth + 'px'
- });
- // Add "Close" button functionality
- zoomedInfoBox.down('a.redButton').observe('click', function(e) {
- zoomOut();
- // Stop actual link click
- e.stop();
- });
- // Show the box
- zoomedInfoBox.removeClassName('hide');
- }
- });
- }
- };
- var zoomOut = function() {
- if(itemObjectContainer.hasClassName('zoomed')) {
- new Effect.ScaleAndMove(itemObject, (fromWidth / toWidth) * 100, (fromHeight / toHeight) * 100, {
- beforeStart: function() {
- zoomedInfoBox.addClassName('hide');
- },
- // Zooming out should be a little bit faster than zooming in
- duration: 0.6,
- scaleMode: {
- // Calculate the current dimensions through the original ones
- // by a simple calculation
- originalWidth: (toWidth / fromWidth) * itemObjectOriginalDimensions.width,
- originalHeight: (toHeight / fromHeight) * itemObjectOriginalDimensions.height
- },
- moveX: false,
- moveToY: itemObjectContainer.cumulativeOffset().top,
- afterFinish: function() {
- // Hide transparent overlay
- zoomedOverlay.addClassName('hide');
- // Unhide scrollbar
- if(navigator.platform.indexOf('Mac') != -1) {
- $$('#moreItems .scrollbox')[0].setStyle({overflow: 'auto'});
- }
- itemObjectContainer.removeClassName('zoomed');
- if($('imageStage')) {
- // Un-absolutize image position (this is not the same as
- // relativize()!)
- itemObject.setStyle({
- position: 'static',
- left: 0,
- top: 0
- });
- // Reset CSS overflow property
- contentLeft.setStyle({overflow: 'hidden'});
- }
- }
- });
- }
- };
- aElm.observe('click', function(e) {
- if(!itemObjectContainer.hasClassName('zoomed')) {
- zoomIn();
- } else {
- zoomOut();
- }
- // Stop actual link click
- e.stop();
- });
- // Track mouse clicks to trigger zoomOut()
- // (we use "mouseup" for that in order to avoid conflicting
- // with any existing click event listeners that won't bubble the click)
- document.observe('mouseup', function(e) {
- var eventElement = e.element();
- if(!eventElement.matchAny('#zoomedInfoBox', '#zoomedInfoBox *', '#flashideoPlayer')) {
- zoomOut();
- }
- });
- // Ignore the above listener for all clicks in the info box
- // or the video player (yes, it is possible on i.e. MacOS to catch
- // events that happen on flash movies)
- //zoomedInfoBox.observe('mouseup', function(e) { e.stop(); });
- //if(isVideo) itemObject.observe('mouseup', function(e) { e.stop(); });
- },
Add Comment
Please, Sign In to add comment