Guest User

Untitled

a guest
May 24th, 2018
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.70 KB | None | 0 0
  1. initZoom: function() {
  2. var isImage, isVideo;
  3. var itemObjectContainer, itemObject;
  4. var fromWidth, fromHeight, toWidth, toHeight;
  5.  
  6. if($('imageStage')) {
  7. isImage = true;
  8. itemObjectContainer = $('imageStage');
  9. itemObject = itemObjectContainer.down('img');
  10.  
  11. // Define source and target dimensions
  12. fromWidth = 445;
  13. fromHeight = 364;
  14. toWidth = 661;
  15. toHeight = 524;
  16. } else {
  17. isVideo = true;
  18. itemObjectContainer = $('videoPlayer');
  19. itemObject = $('flashVideoPlayer');
  20.  
  21. // Define source and target dimensions
  22. fromWidth = 445;
  23. fromHeight = 364;
  24. toWidth = 661;
  25. toHeight = 524;
  26. }
  27.  
  28. var contentLeft = itemObjectContainer.up('div.contentLeft');
  29. var aElm = $('itemStage').down('a');
  30.  
  31. var zoomedInfoBox = $('zoomedInfoBox');
  32. var zoomedOverlay = $('zoomedOverlay');
  33.  
  34. // Assign the image's dimensions as CSS properties for easier use
  35. var itemObjectOriginalDimensions = itemObjectContainer.getDimensions();
  36.  
  37. // Assign a fixed height to the itemStage in order
  38. // to compensate the actual image that will be absolutized
  39. // when zoomed and therefore leave a gap in the layout
  40. itemObjectContainer.setStyle({height: itemObjectOriginalDimensions.height + 'px'});
  41.  
  42. var zoomIn = function() {
  43. if(!itemObjectContainer.hasClassName('zoomed')) {
  44. new Effect.ScaleAndMove(itemObject, (toWidth / fromWidth) * 100, (toHeight / fromHeight) * 100, {
  45. beforeStart: function() {
  46. if($('imageStage')) {
  47. // Necessary to make z-index work in Gecko browsers
  48. // (element has "overflow: hidden" by default)
  49. contentLeft.setStyle({overflow: 'visible'});
  50.  
  51. // Absolutize image position
  52. itemObject.absolutize();
  53. }
  54.  
  55. itemObjectContainer.addClassName('zoomed');
  56.  
  57. // There is a bug in MacOS/Flash that puts scrollbars
  58. // over Flash movies, so we will hide the problematic scrollbar
  59. if(navigator.platform.indexOf('Mac') != -1) {
  60. $$('#moreItems .scrollbox')[0].setStyle({overflow: 'hidden'});
  61. }
  62.  
  63. // Position and show transparent overlay
  64. var contentLeftOffset = contentLeft.cumulativeOffset();
  65. zoomedOverlay.setStyle({
  66. left: contentLeftOffset.left + 'px',
  67. top: contentLeftOffset.top + 'px',
  68. width: toWidth + 'px',
  69. height: contentLeft.getHeight() + 'px'
  70. });
  71. zoomedOverlay.removeClassName('hide');
  72. },
  73. duration: 1.0,
  74. scaleMode: {
  75. originalWidth: itemObjectOriginalDimensions.width,
  76. originalHeight: itemObjectOriginalDimensions.height
  77. },
  78. moveX: false,
  79. moveToY: contentLeft.cumulativeOffset().top,
  80. afterFinish: function() {
  81. // Position the info box below the zoomed item
  82. zoomedInfoBox.setStyle({
  83. left: itemObject.cumulativeOffset().left + 'px',
  84. top: (parseInt(itemObject.getStyle('top')) + itemObject.getHeight()) + 'px',
  85. width: toWidth + 'px'
  86. });
  87.  
  88. // Add "Close" button functionality
  89. zoomedInfoBox.down('a.redButton').observe('click', function(e) {
  90. zoomOut();
  91. // Stop actual link click
  92. e.stop();
  93. });
  94.  
  95. // Show the box
  96. zoomedInfoBox.removeClassName('hide');
  97. }
  98. });
  99. }
  100. };
  101.  
  102. var zoomOut = function() {
  103. if(itemObjectContainer.hasClassName('zoomed')) {
  104. new Effect.ScaleAndMove(itemObject, (fromWidth / toWidth) * 100, (fromHeight / toHeight) * 100, {
  105. beforeStart: function() {
  106. zoomedInfoBox.addClassName('hide');
  107. },
  108. // Zooming out should be a little bit faster than zooming in
  109. duration: 0.6,
  110. scaleMode: {
  111. // Calculate the current dimensions through the original ones
  112. // by a simple calculation
  113. originalWidth: (toWidth / fromWidth) * itemObjectOriginalDimensions.width,
  114. originalHeight: (toHeight / fromHeight) * itemObjectOriginalDimensions.height
  115. },
  116. moveX: false,
  117. moveToY: itemObjectContainer.cumulativeOffset().top,
  118. afterFinish: function() {
  119. // Hide transparent overlay
  120. zoomedOverlay.addClassName('hide');
  121.  
  122. // Unhide scrollbar
  123. if(navigator.platform.indexOf('Mac') != -1) {
  124. $$('#moreItems .scrollbox')[0].setStyle({overflow: 'auto'});
  125. }
  126.  
  127. itemObjectContainer.removeClassName('zoomed');
  128.  
  129. if($('imageStage')) {
  130. // Un-absolutize image position (this is not the same as
  131. // relativize()!)
  132. itemObject.setStyle({
  133. position: 'static',
  134. left: 0,
  135. top: 0
  136. });
  137.  
  138. // Reset CSS overflow property
  139. contentLeft.setStyle({overflow: 'hidden'});
  140. }
  141. }
  142. });
  143. }
  144. };
  145.  
  146. aElm.observe('click', function(e) {
  147. if(!itemObjectContainer.hasClassName('zoomed')) {
  148. zoomIn();
  149. } else {
  150. zoomOut();
  151. }
  152.  
  153. // Stop actual link click
  154. e.stop();
  155. });
  156.  
  157. // Track mouse clicks to trigger zoomOut()
  158. // (we use "mouseup" for that in order to avoid conflicting
  159. // with any existing click event listeners that won't bubble the click)
  160. document.observe('mouseup', function(e) {
  161. var eventElement = e.element();
  162.  
  163. if(!eventElement.matchAny('#zoomedInfoBox', '#zoomedInfoBox *', '#flashideoPlayer')) {
  164. zoomOut();
  165. }
  166. });
  167. // Ignore the above listener for all clicks in the info box
  168. // or the video player (yes, it is possible on i.e. MacOS to catch
  169. // events that happen on flash movies)
  170. //zoomedInfoBox.observe('mouseup', function(e) { e.stop(); });
  171. //if(isVideo) itemObject.observe('mouseup', function(e) { e.stop(); });
  172. },
Add Comment
Please, Sign In to add comment