Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. /*!
  2. * reveal.js Zoom plugin
  3. */
  4. const Plugin = {
  5. id: 'zoom',
  6. init: function( reveal ) {
  7. reveal.getRevealElement().addEventListener( 'mousedown', function( event ) {
  8. var defaultModifier = /Linux/.test( window.navigator.platform ) ? 'ctrl' : 'alt';
  9. var modifier = ( reveal.getConfig().zoomKey ? reveal.getConfig().zoomKey : defaultModifier ) + 'Key';
  10. var zoomLevel = ( reveal.getConfig().zoomLevel ? reveal.getConfig().zoomLevel : 2 );
  11. if( event[ modifier ] && !reveal.isOverview() ) {
  12. event.preventDefault();
  13. zoom.to({
  14. x: event.clientX,
  15. y: event.clientY,
  16. scale: zoomLevel,
  17. pan: false
  18. });
  19. }
  20. } );
  21. },
  22. destroy: () => {
  23. zoom.reset();
  24. }
  25. };
  26. export default () => Plugin;
  27. /*!
  28. * zoom.js 0.3 (modified for use with reveal.js)
  29. * http://lab.hakim.se/zoom-js
  30. * MIT licensed
  31. *
  32. * Copyright (C) 2011-2014 Hakim El Hattab, http://hakim.se
  33. */
  34. var zoom = (function(){
  35. // The current zoom level (scale)
  36. var level = 1;
  37. // The current mouse position, used for panning
  38. var mouseX = 0,
  39. mouseY = 0;
  40. // Timeout before pan is activated
  41. var panEngageTimeout = -1,
  42. panUpdateInterval = -1;
  43. // Check for transform support so that we can fallback otherwise
  44. var supportsTransforms = 'transform' in document.body.style;
  45. if( supportsTransforms ) {
  46. // The easing that will be applied when we zoom in/out
  47. document.body.style.transition = 'transform 0.8s ease';
  48. }
  49. // Zoom out if the user hits escape
  50. document.addEventListener( 'keyup', function( event ) {
  51. if( level !== 1 && event.keyCode === 27 ) {
  52. zoom.out();
  53. }
  54. } );
  55. // Monitor mouse movement for panning
  56. document.addEventListener( 'mousemove', function( event ) {
  57. if( level !== 1 ) {
  58. mouseX = event.clientX;
  59. mouseY = event.clientY;
  60. }
  61. } );
  62. /**
  63. * Applies the CSS required to zoom in, prefers the use of CSS3
  64. * transforms but falls back on zoom for IE.
  65. *
  66. * @param {Object} rect
  67. * @param {Number} scale
  68. */
  69. function magnify( rect, scale ) {
  70. var scrollOffset = getScrollOffset();
  71. // Ensure a width/height is set
  72. rect.width = rect.width || 1;
  73. rect.height = rect.height || 1;
  74. // Center the rect within the zoomed viewport
  75. rect.x -= ( window.innerWidth - ( rect.width * scale ) ) / 2;
  76. rect.y -= ( window.innerHeight - ( rect.height * scale ) ) / 2;
  77. if( supportsTransforms ) {
  78. // Reset
  79. if( scale === 1 ) {
  80. document.body.style.transform = '';
  81. }
  82. // Scale
  83. else {
  84. var origin = scrollOffset.x +'px '+ scrollOffset.y +'px',
  85. transform = 'translate('+ -rect.x +'px,'+ -rect.y +'px) scale('+ scale +')';
  86. document.body.style.transformOrigin = origin;
  87. document.body.style.transform = transform;
  88. }
  89. }
  90. else {
  91. // Reset
  92. if( scale === 1 ) {
  93. document.body.style.position = '';
  94. document.body.style.left = '';
  95. document.body.style.top = '';
  96. document.body.style.width = '';
  97. document.body.style.height = '';
  98. document.body.style.zoom = '';
  99. }
  100. // Scale
  101. else {
  102. document.body.style.position = 'relative';
  103. document.body.style.left = ( - ( scrollOffset.x + rect.x ) / scale ) + 'px';
  104. document.body.style.top = ( - ( scrollOffset.y + rect.y ) / scale ) + 'px';
  105. document.body.style.width = ( scale * 100 ) + '%';
  106. document.body.style.height = ( scale * 100 ) + '%';
  107. document.body.style.zoom = scale;
  108. }
  109. }
  110. level = scale;
  111. if( document.documentElement.classList ) {
  112. if( level !== 1 ) {
  113. document.documentElement.classList.add( 'zoomed' );
  114. }
  115. else {
  116. document.documentElement.classList.remove( 'zoomed' );
  117. }
  118. }
  119. }
  120. /**
  121. * Pan the document when the mosue cursor approaches the edges
  122. * of the window.
  123. */
  124. function pan() {
  125. var range = 0.12,
  126. rangeX = window.innerWidth * range,
  127. rangeY = window.innerHeight * range,
  128. scrollOffset = getScrollOffset();
  129. // Up
  130. if( mouseY < rangeY ) {
  131. window.scroll( scrollOffset.x, scrollOffset.y - ( 1 - ( mouseY / rangeY ) ) * ( 14 / level ) );
  132. }
  133. // Down
  134. else if( mouseY > window.innerHeight - rangeY ) {
  135. window.scroll( scrollOffset.x, scrollOffset.y + ( 1 - ( window.innerHeight - mouseY ) / rangeY ) * ( 14 / level ) );
  136. }
  137. // Left
  138. if( mouseX < rangeX ) {
  139. window.scroll( scrollOffset.x - ( 1 - ( mouseX / rangeX ) ) * ( 14 / level ), scrollOffset.y );
  140. }
  141. // Right
  142. else if( mouseX > window.innerWidth - rangeX ) {
  143. window.scroll( scrollOffset.x + ( 1 - ( window.innerWidth - mouseX ) / rangeX ) * ( 14 / level ), scrollOffset.y );
  144. }
  145. }
  146. function getScrollOffset() {
  147. return {
  148. x: window.scrollX !== undefined ? window.scrollX : window.pageXOffset,
  149. y: window.scrollY !== undefined ? window.scrollY : window.pageYOffset
  150. }
  151. }
  152. return {
  153. /**
  154. * Zooms in on either a rectangle or HTML element.
  155. *
  156. * @param {Object} options
  157. * - element: HTML element to zoom in on
  158. * OR
  159. * - x/y: coordinates in non-transformed space to zoom in on
  160. * - width/height: the portion of the screen to zoom in on
  161. * - scale: can be used instead of width/height to explicitly set scale
  162. */
  163. to: function( options ) {
  164. // Due to an implementation limitation we can't zoom in
  165. // to another element without zooming out first
  166. if( level !== 1 ) {
  167. zoom.out();
  168. }
  169. else {
  170. options.x = options.x || 0;
  171. options.y = options.y || 0;
  172. // If an element is set, that takes precedence
  173. if( !!options.element ) {
  174. // Space around the zoomed in element to leave on screen
  175. var padding = 20;
  176. var bounds = options.element.getBoundingClientRect();
  177. options.x = bounds.left - padding;
  178. options.y = bounds.top - padding;
  179. options.width = bounds.width + ( padding * 2 );
  180. options.height = bounds.height + ( padding * 2 );
  181. }
  182. // If width/height values are set, calculate scale from those values
  183. if( options.width !== undefined && options.height !== undefined ) {
  184. options.scale = Math.max( Math.min( window.innerWidth / options.width, window.innerHeight / options.height ), 1 );
  185. }
  186. if( options.scale > 1 ) {
  187. options.x *= options.scale;
  188. options.y *= options.scale;
  189. magnify( options, options.scale );
  190. if( options.pan !== false ) {
  191. // Wait with engaging panning as it may conflict with the
  192. // zoom transition
  193. panEngageTimeout = setTimeout( function() {
  194. panUpdateInterval = setInterval( pan, 1000 / 60 );
  195. }, 800 );
  196. }
  197. }
  198. }
  199. },
  200. /**
  201. * Resets the document zoom state to its default.
  202. */
  203. out: function() {
  204. clearTimeout( panEngageTimeout );
  205. clearInterval( panUpdateInterval );
  206. magnify( { x: 0, y: 0 }, 1 );
  207. level = 1;
  208. },
  209. // Alias
  210. magnify: function( options ) { this.to( options ) },
  211. reset: function() { this.out() },
  212. zoomLevel: function() {
  213. return level;
  214. }
  215. }
  216. })();