CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

| Download
Project: KOB1
Views: 16973
1
// Custom reveal.js integration
2
(function(){
3
var revealElement = document.querySelector( '.reveal' );
4
if( revealElement ) {
5
6
revealElement.addEventListener( 'mousedown', function( event ) {
7
var defaultModifier = /Linux/.test( window.navigator.platform ) ? 'ctrl' : 'alt';
8
9
var modifier = ( Reveal.getConfig().zoomKey ? Reveal.getConfig().zoomKey : defaultModifier ) + 'Key';
10
var zoomLevel = ( Reveal.getConfig().zoomLevel ? Reveal.getConfig().zoomLevel : 2 );
11
12
if( event[ modifier ] && !Reveal.isOverview() ) {
13
event.preventDefault();
14
15
zoom.to({
16
x: event.clientX,
17
y: event.clientY,
18
scale: zoomLevel,
19
pan: false
20
});
21
}
22
} );
23
24
}
25
})();
26
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
36
// The current zoom level (scale)
37
var level = 1;
38
39
// The current mouse position, used for panning
40
var mouseX = 0,
41
mouseY = 0;
42
43
// Timeout before pan is activated
44
var panEngageTimeout = -1,
45
panUpdateInterval = -1;
46
47
// Check for transform support so that we can fallback otherwise
48
var supportsTransforms = 'WebkitTransform' in document.body.style ||
49
'MozTransform' in document.body.style ||
50
'msTransform' in document.body.style ||
51
'OTransform' in document.body.style ||
52
'transform' in document.body.style;
53
54
if( supportsTransforms ) {
55
// The easing that will be applied when we zoom in/out
56
document.body.style.transition = 'transform 0.8s ease';
57
document.body.style.OTransition = '-o-transform 0.8s ease';
58
document.body.style.msTransition = '-ms-transform 0.8s ease';
59
document.body.style.MozTransition = '-moz-transform 0.8s ease';
60
document.body.style.WebkitTransition = '-webkit-transform 0.8s ease';
61
}
62
63
// Zoom out if the user hits escape
64
document.addEventListener( 'keyup', function( event ) {
65
if( level !== 1 && event.keyCode === 27 ) {
66
zoom.out();
67
}
68
} );
69
70
// Monitor mouse movement for panning
71
document.addEventListener( 'mousemove', function( event ) {
72
if( level !== 1 ) {
73
mouseX = event.clientX;
74
mouseY = event.clientY;
75
}
76
} );
77
78
/**
79
* Applies the CSS required to zoom in, prefers the use of CSS3
80
* transforms but falls back on zoom for IE.
81
*
82
* @param {Object} rect
83
* @param {Number} scale
84
*/
85
function magnify( rect, scale ) {
86
87
var scrollOffset = getScrollOffset();
88
89
// Ensure a width/height is set
90
rect.width = rect.width || 1;
91
rect.height = rect.height || 1;
92
93
// Center the rect within the zoomed viewport
94
rect.x -= ( window.innerWidth - ( rect.width * scale ) ) / 2;
95
rect.y -= ( window.innerHeight - ( rect.height * scale ) ) / 2;
96
97
if( supportsTransforms ) {
98
// Reset
99
if( scale === 1 ) {
100
document.body.style.transform = '';
101
document.body.style.OTransform = '';
102
document.body.style.msTransform = '';
103
document.body.style.MozTransform = '';
104
document.body.style.WebkitTransform = '';
105
}
106
// Scale
107
else {
108
var origin = scrollOffset.x +'px '+ scrollOffset.y +'px',
109
transform = 'translate('+ -rect.x +'px,'+ -rect.y +'px) scale('+ scale +')';
110
111
document.body.style.transformOrigin = origin;
112
document.body.style.OTransformOrigin = origin;
113
document.body.style.msTransformOrigin = origin;
114
document.body.style.MozTransformOrigin = origin;
115
document.body.style.WebkitTransformOrigin = origin;
116
117
document.body.style.transform = transform;
118
document.body.style.OTransform = transform;
119
document.body.style.msTransform = transform;
120
document.body.style.MozTransform = transform;
121
document.body.style.WebkitTransform = transform;
122
}
123
}
124
else {
125
// Reset
126
if( scale === 1 ) {
127
document.body.style.position = '';
128
document.body.style.left = '';
129
document.body.style.top = '';
130
document.body.style.width = '';
131
document.body.style.height = '';
132
document.body.style.zoom = '';
133
}
134
// Scale
135
else {
136
document.body.style.position = 'relative';
137
document.body.style.left = ( - ( scrollOffset.x + rect.x ) / scale ) + 'px';
138
document.body.style.top = ( - ( scrollOffset.y + rect.y ) / scale ) + 'px';
139
document.body.style.width = ( scale * 100 ) + '%';
140
document.body.style.height = ( scale * 100 ) + '%';
141
document.body.style.zoom = scale;
142
}
143
}
144
145
level = scale;
146
147
if( document.documentElement.classList ) {
148
if( level !== 1 ) {
149
document.documentElement.classList.add( 'zoomed' );
150
}
151
else {
152
document.documentElement.classList.remove( 'zoomed' );
153
}
154
}
155
}
156
157
/**
158
* Pan the document when the mosue cursor approaches the edges
159
* of the window.
160
*/
161
function pan() {
162
var range = 0.12,
163
rangeX = window.innerWidth * range,
164
rangeY = window.innerHeight * range,
165
scrollOffset = getScrollOffset();
166
167
// Up
168
if( mouseY < rangeY ) {
169
window.scroll( scrollOffset.x, scrollOffset.y - ( 1 - ( mouseY / rangeY ) ) * ( 14 / level ) );
170
}
171
// Down
172
else if( mouseY > window.innerHeight - rangeY ) {
173
window.scroll( scrollOffset.x, scrollOffset.y + ( 1 - ( window.innerHeight - mouseY ) / rangeY ) * ( 14 / level ) );
174
}
175
176
// Left
177
if( mouseX < rangeX ) {
178
window.scroll( scrollOffset.x - ( 1 - ( mouseX / rangeX ) ) * ( 14 / level ), scrollOffset.y );
179
}
180
// Right
181
else if( mouseX > window.innerWidth - rangeX ) {
182
window.scroll( scrollOffset.x + ( 1 - ( window.innerWidth - mouseX ) / rangeX ) * ( 14 / level ), scrollOffset.y );
183
}
184
}
185
186
function getScrollOffset() {
187
return {
188
x: window.scrollX !== undefined ? window.scrollX : window.pageXOffset,
189
y: window.scrollY !== undefined ? window.scrollY : window.pageYOffset
190
}
191
}
192
193
return {
194
/**
195
* Zooms in on either a rectangle or HTML element.
196
*
197
* @param {Object} options
198
* - element: HTML element to zoom in on
199
* OR
200
* - x/y: coordinates in non-transformed space to zoom in on
201
* - width/height: the portion of the screen to zoom in on
202
* - scale: can be used instead of width/height to explicitly set scale
203
*/
204
to: function( options ) {
205
206
// Due to an implementation limitation we can't zoom in
207
// to another element without zooming out first
208
if( level !== 1 ) {
209
zoom.out();
210
}
211
else {
212
options.x = options.x || 0;
213
options.y = options.y || 0;
214
215
// If an element is set, that takes precedence
216
if( !!options.element ) {
217
// Space around the zoomed in element to leave on screen
218
var padding = 20;
219
var bounds = options.element.getBoundingClientRect();
220
221
options.x = bounds.left - padding;
222
options.y = bounds.top - padding;
223
options.width = bounds.width + ( padding * 2 );
224
options.height = bounds.height + ( padding * 2 );
225
}
226
227
// If width/height values are set, calculate scale from those values
228
if( options.width !== undefined && options.height !== undefined ) {
229
options.scale = Math.max( Math.min( window.innerWidth / options.width, window.innerHeight / options.height ), 1 );
230
}
231
232
if( options.scale > 1 ) {
233
options.x *= options.scale;
234
options.y *= options.scale;
235
236
magnify( options, options.scale );
237
238
if( options.pan !== false ) {
239
240
// Wait with engaging panning as it may conflict with the
241
// zoom transition
242
panEngageTimeout = setTimeout( function() {
243
panUpdateInterval = setInterval( pan, 1000 / 60 );
244
}, 800 );
245
246
}
247
}
248
}
249
},
250
251
/**
252
* Resets the document zoom state to its default.
253
*/
254
out: function() {
255
clearTimeout( panEngageTimeout );
256
clearInterval( panUpdateInterval );
257
258
magnify( { x: 0, y: 0 }, 1 );
259
260
level = 1;
261
},
262
263
// Alias
264
magnify: function( options ) { this.to( options ) },
265
reset: function() { this.out() },
266
267
zoomLevel: function() {
268
return level;
269
}
270
}
271
272
})();
273
274