-
Notifications
You must be signed in to change notification settings - Fork 0
/
jmpress.allplugins.js
311 lines (299 loc) · 9.72 KB
/
jmpress.allplugins.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
/*!
* plugin for jmpress.js v0.4.5
*
* Copyright 2014 Kyle Robinson Young @shama & Tobias Koppers @sokra
* Licensed MIT
* http://www.opensource.org/licenses/mit-license.php
*//*
* jmpress.toggle plugin
* For binding a key to toggle de/initialization of jmpress.js.
*/
(function( $, document, window, undefined ) {
'use strict';
$.jmpress("register", "toggle", function( key, config, initial ) {
var jmpress = this;
$(document).bind("keydown", function( event ) {
if ( event.keyCode === key ) {
if ($(jmpress).jmpress("initialized")) {
$(jmpress).jmpress("deinit");
} else {
$(jmpress).jmpress(config);
}
}
});
if ( initial ) {
$(jmpress).jmpress(config);
}
});
}(jQuery, document, window));
/*
* jmpress.secondary plugin
* Apply a secondary animation when step is selected.
*/
(function( $, document, window, undefined ) {
'use strict';
$.jmpress("initStep", function( step, eventData ) {
for(var name in eventData.data) {
if(name.indexOf("secondary") === 0) {
eventData.stepData[name] = eventData.data[name];
}
}
});
function exchangeIf(childStepData, condition, step) {
if(childStepData.secondary &&
childStepData.secondary.split(" ").indexOf(condition) !== -1) {
for(var name in childStepData) {
if(name.length > 9 && name.indexOf("secondary") === 0) {
var tmp = childStepData[name];
var normal = name.substr(9);
normal = normal.substr(0, 1).toLowerCase() + normal.substr(1);
childStepData[name] = childStepData[normal];
childStepData[normal] = tmp;
}
}
$(this).jmpress("reapply", $(step));
}
}
$.jmpress("beforeActive", function( step, eventData ) {
exchangeIf.call(eventData.jmpress, $(step).data("stepData"), "self", step);
var parent = $(step).parent();
$(parent)
.children(eventData.settings.stepSelector)
.each(function(idx, child) {
var childStepData = $(child).data("stepData");
exchangeIf.call(eventData.jmpress, childStepData, "siblings", child);
});
function grandchildrenFunc(idx, child) {
var childStepData = $(child).data("stepData");
exchangeIf.call(eventData.jmpress, childStepData, "grandchildren", child);
}
for(var i = 1; i < eventData.parents.length; i++) {
$(eventData.parents[i])
.children(eventData.settings.stepSelector)
.each();
}
});
$.jmpress("setInactive", function( step, eventData ) {
exchangeIf.call(eventData.jmpress, $(step).data("stepData"), "self", step);
var parent = $(step).parent();
$(parent)
.children(eventData.settings.stepSelector)
.each(function(idx, child) {
var childStepData = $(child).data("stepData");
exchangeIf.call(eventData.jmpress, childStepData, "siblings", child);
});
function grandchildrenFunc(idx, child) {
var childStepData = $(child).data("stepData");
exchangeIf.call(eventData.jmpress, childStepData, "grandchildren", child);
}
for(var i = 1; i < eventData.parents.length; i++) {
$(eventData.parents[i])
.children(eventData.settings.stepSelector)
.each(grandchildrenFunc);
}
});
}(jQuery, document, window));
/*
* jmpress.duration plugin
* For auto advancing steps after a given duration and optionally displaying a
* progress bar.
*/
(function( $, document, window, undefined ) {
'use strict';
$.jmpress("defaults").duration = {
defaultValue: -1
,defaultAction: "next"
,barSelector: undefined
,barProperty: "width"
,barPropertyStart: "0"
,barPropertyEnd: "100%"
};
$.jmpress("initStep", function( step, eventData ) {
eventData.stepData.duration = eventData.data.duration && parseInt(eventData.data.duration, 10);
eventData.stepData.durationAction = eventData.data.durationAction;
});
$.jmpress("setInactive", function( step, eventData ) {
var settings = eventData.settings,
durationSettings = settings.duration,
current = eventData.current;
var dur = eventData.stepData.duration || durationSettings.defaultValue;
if( current.durationTimeout ) {
if( durationSettings.barSelector ) {
var css = {
transitionProperty: durationSettings.barProperty
,transitionDuration: '0'
,transitionDelay: '0'
,transitionTimingFunction: 'linear'
};
css[durationSettings.barProperty] = durationSettings.barPropertyStart;
var bars = $(durationSettings.barSelector);
$.jmpress("css", bars, css);
bars.each(function(idx, element) {
var next = $(element).next();
var parent = $(element).parent();
$(element).detach();
if(next.length) {
next.insertBefore(element);
} else {
parent.append(element);
}
});
}
clearTimeout(current.durationTimeout);
delete current.durationTimeout;
}
});
$.jmpress("setActive", function( step, eventData ) {
var settings = eventData.settings,
durationSettings = settings.duration,
current = eventData.current;
var dur = eventData.stepData.duration || durationSettings.defaultValue;
if( dur && dur > 0 ) {
if( durationSettings.barSelector ) {
var css = {
transitionProperty: durationSettings.barProperty
,transitionDuration: (dur-settings.transitionDuration*2/3-100)+"ms"
,transitionDelay: (settings.transitionDuration*2/3)+'ms'
,transitionTimingFunction: 'linear'
};
css[durationSettings.barProperty] = durationSettings.barPropertyEnd;
$.jmpress("css", $(durationSettings.barSelector), css);
}
var jmpress = this;
if(current.durationTimeout) {
clearTimeout(current.durationTimeout);
current.durationTimeout = undefined;
}
current.durationTimeout = setTimeout(function() {
var action = eventData.stepData.durationAction || durationSettings.defaultAction;
$(jmpress).jmpress(action);
}, dur);
}
});
}(jQuery, document, window));
/*
* jmpress.presentation-mode plugin
* Display a window for the presenter with notes and a control and view of the
* presentation
*/
(function( $, document, window, undefined ) {
'use strict';
var $jmpress = $.jmpress;
var PREFIX = "jmpress-presentation-";
/* FUNCTIONS */
function randomString() {
return "" + Math.round(Math.random() * 100000, 0);
}
/* DEFAULTS */
$jmpress("defaults").presentationMode = {
use: true,
url: "presentation-screen.html",
notesUrl: false,
transferredValues: ["userZoom", "userTranslateX", "userTranslateY"]
};
$jmpress("defaults").keyboard.keys[80] = "presentationPopup"; // p key
/* HOOKS */
$jmpress("afterInit", function( nil, eventData) {
var current = eventData.current;
current.selectMessageListeners = [];
if(eventData.settings.presentationMode.use) {
window.addEventListener("message", function(event) {
// We do not test orgin, because we want to accept messages
// from all orgins
try {
if(typeof event.data !== "string" || event.data.indexOf(PREFIX) !== 0) {
return;
}
var json = JSON.parse(event.data.slice(PREFIX.length));
switch(json.type) {
case "select":
$.each(eventData.settings.presentationMode.transferredValues, function(idx, name) {
eventData.current[name] = json[name];
});
if(/[a-z0-9\-]+/i.test(json.targetId) && typeof json.substep in {number:1,undefined:1}) {
$(eventData.jmpress).jmpress("select", {step: "#"+json.targetId, substep: json.substep}, json.reason);
} else {
$.error("For security reasons the targetId must match /[a-z0-9\\-]+/i and substep must be a number.");
}
break;
case "listen":
current.selectMessageListeners.push(event.source);
break;
case "ok":
clearTimeout(current.presentationPopupTimeout);
break;
case "read":
try {
event.source.postMessage(PREFIX + JSON.stringify({type: "url", url: window.location.href, notesUrl: eventData.settings.presentationMode.notesUrl}), "*");
} catch(e) {
$.error("Cannot post message to source: " + e);
}
break;
default:
throw "Unknown message type: " + json.type;
}
} catch(e) {
$.error("Received message is malformed: " + e);
}
});
try {
if(window.parent && window.parent !== window) {
window.parent.postMessage(PREFIX + JSON.stringify({
"type": "afterInit"
}), "*");
}
} catch(e) {
$.error("Cannot post message to parent: " + e);
}
}
});
$jmpress("afterDeinit", function( nil, eventData) {
if(eventData.settings.presentationMode.use) {
try {
if(window.parent && window.parent !== window) {
window.parent.postMessage(PREFIX + JSON.stringify({
"type": "afterDeinit"
}), "*");
}
} catch(e) {
$.error("Cannot post message to parent: " + e);
}
}
});
$jmpress("setActive", function( step, eventData) {
var stepId = $(eventData.delegatedFrom).attr("id"),
substep = eventData.substep,
reason = eventData.reason;
$.each(eventData.current.selectMessageListeners, function(idx, listener) {
try {
var msg = {
"type": "select",
"targetId": stepId,
"substep": substep,
"reason": reason
};
$.each(eventData.settings.presentationMode.transferredValues, function(idx, name) {
msg[name] = eventData.current[name];
});
listener.postMessage(PREFIX + JSON.stringify(msg), "*");
} catch(e) {
$.error("Cannot post message to listener: " + e);
}
});
});
$jmpress("register", "presentationPopup", function() {
function trySend() {
jmpress.jmpress("current").presentationPopupTimeout = setTimeout(trySend, 100);
try {
popup.postMessage(PREFIX + JSON.stringify({type: "url", url: window.location.href, notesUrl: jmpress.jmpress("settings").presentationMode.notesUrl}), "*");
} catch(e) {
}
}
var jmpress = $(this),
popup;
if(jmpress.jmpress("settings").presentationMode.use) {
popup = window.open($(this).jmpress("settings").presentationMode.url);
jmpress.jmpress("current").presentationPopupTimeout = setTimeout(trySend, 100);
}
});
}(jQuery, document, window));