mixpanel-browser 2.41.0 → 2.45.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,1309 +0,0 @@
1
- /* eslint camelcase: "off" */
2
-
3
- import { CAMPAIGN_IDS_KEY } from './mixpanel-persistence';
4
- import { evaluateSelector } from './property-filters';
5
- import { _ } from './utils';
6
-
7
- // Internal class for notification display
8
-
9
- var MixpanelNotification = function(notif_data, mixpanel_instance) {
10
- _.bind_instance_methods(this);
11
-
12
- this.mixpanel = mixpanel_instance;
13
- this.persistence = this.mixpanel['persistence'];
14
- this.resource_protocol = this.mixpanel.get_config('inapp_protocol');
15
- this.cdn_host = this.mixpanel.get_config('cdn');
16
-
17
- this.campaign_id = _.escapeHTML(notif_data['id']);
18
- this.message_id = _.escapeHTML(notif_data['message_id']);
19
-
20
- this.body = (_.escapeHTML(notif_data['body']) || '').replace(/\n/g, '<br/>');
21
- this.cta = _.escapeHTML(notif_data['cta']) || 'Close';
22
- this.notif_type = _.escapeHTML(notif_data['type']) || 'takeover';
23
- this.style = _.escapeHTML(notif_data['style']) || 'light';
24
- this.title = _.escapeHTML(notif_data['title']) || '';
25
- this.video_width = MixpanelNotification.VIDEO_WIDTH;
26
- this.video_height = MixpanelNotification.VIDEO_HEIGHT;
27
-
28
- this.display_triggers = notif_data['display_triggers'] || [];
29
-
30
- // These fields are url-sanitized in the backend already.
31
- this.dest_url = notif_data['cta_url'] || null;
32
- this.image_url = notif_data['image_url'] || null;
33
- this.thumb_image_url = notif_data['thumb_image_url'] || null;
34
- this.video_url = notif_data['video_url'] || null;
35
-
36
- if (this.thumb_image_url && this.thumb_image_url.indexOf('//') === 0) {
37
- this.thumb_image_url = this.thumb_image_url.replace('//', this.resource_protocol);
38
- }
39
-
40
- this.clickthrough = true;
41
- if (!this.dest_url) {
42
- this.dest_url = '#dismiss';
43
- this.clickthrough = false;
44
- }
45
-
46
- this.mini = this.notif_type === 'mini';
47
- if (!this.mini) {
48
- this.notif_type = 'takeover';
49
- }
50
- this.notif_width = !this.mini ? MixpanelNotification.NOTIF_WIDTH : MixpanelNotification.NOTIF_WIDTH_MINI;
51
-
52
- this._set_client_config();
53
- this.imgs_to_preload = this._init_image_html();
54
- this._init_video();
55
- };
56
-
57
- MixpanelNotification.ANIM_TIME = 200;
58
- MixpanelNotification.MARKUP_PREFIX = 'mixpanel-notification';
59
- MixpanelNotification.BG_OPACITY = 0.6;
60
- MixpanelNotification.NOTIF_TOP = 25;
61
- MixpanelNotification.NOTIF_START_TOP = 200;
62
- MixpanelNotification.NOTIF_WIDTH = 388;
63
- MixpanelNotification.NOTIF_WIDTH_MINI = 420;
64
- MixpanelNotification.NOTIF_HEIGHT_MINI = 85;
65
- MixpanelNotification.THUMB_BORDER_SIZE = 5;
66
- MixpanelNotification.THUMB_IMG_SIZE = 60;
67
- MixpanelNotification.THUMB_OFFSET = Math.round(MixpanelNotification.THUMB_IMG_SIZE / 2);
68
- MixpanelNotification.VIDEO_WIDTH = 595;
69
- MixpanelNotification.VIDEO_HEIGHT = 334;
70
-
71
- MixpanelNotification.prototype.show = function() {
72
- var self = this;
73
- this._set_client_config();
74
-
75
- // don't display until HTML body exists
76
- if (!this.body_el) {
77
- setTimeout(function() { self.show(); }, 300);
78
- return;
79
- }
80
-
81
- this._init_styles();
82
- this._init_notification_el();
83
-
84
- // wait for any images to load before showing notification
85
- this._preload_images(this._attach_and_animate);
86
- };
87
-
88
- MixpanelNotification.prototype.dismiss = _.safewrap(function() {
89
- if (!this.marked_as_shown) {
90
- // unexpected condition: user interacted with notif even though we didn't consider it
91
- // visible (see _mark_as_shown()); send tracking signals to mark delivery
92
- this._mark_delivery({'invisible': true});
93
- }
94
-
95
- var exiting_el = this.showing_video ? this._get_el('video') : this._get_notification_display_el();
96
- if (this.use_transitions) {
97
- this._remove_class('bg', 'visible');
98
- this._add_class(exiting_el, 'exiting');
99
- setTimeout(this._remove_notification_el, MixpanelNotification.ANIM_TIME);
100
- } else {
101
- var notif_attr, notif_start, notif_goal;
102
- if (this.mini) {
103
- notif_attr = 'right';
104
- notif_start = 20;
105
- notif_goal = -100;
106
- } else {
107
- notif_attr = 'top';
108
- notif_start = MixpanelNotification.NOTIF_TOP;
109
- notif_goal = MixpanelNotification.NOTIF_START_TOP + MixpanelNotification.NOTIF_TOP;
110
- }
111
- this._animate_els([
112
- {
113
- el: this._get_el('bg'),
114
- attr: 'opacity',
115
- start: MixpanelNotification.BG_OPACITY,
116
- goal: 0.0
117
- },
118
- {
119
- el: exiting_el,
120
- attr: 'opacity',
121
- start: 1.0,
122
- goal: 0.0
123
- },
124
- {
125
- el: exiting_el,
126
- attr: notif_attr,
127
- start: notif_start,
128
- goal: notif_goal
129
- }
130
- ], MixpanelNotification.ANIM_TIME, this._remove_notification_el);
131
- }
132
- });
133
-
134
- MixpanelNotification.prototype._add_class = _.safewrap(function(el, class_name) {
135
- class_name = MixpanelNotification.MARKUP_PREFIX + '-' + class_name;
136
- if (typeof el === 'string') {
137
- el = this._get_el(el);
138
- }
139
- if (!el.className) {
140
- el.className = class_name;
141
- } else if (!~(' ' + el.className + ' ').indexOf(' ' + class_name + ' ')) {
142
- el.className += ' ' + class_name;
143
- }
144
- });
145
- MixpanelNotification.prototype._remove_class = _.safewrap(function(el, class_name) {
146
- class_name = MixpanelNotification.MARKUP_PREFIX + '-' + class_name;
147
- if (typeof el === 'string') {
148
- el = this._get_el(el);
149
- }
150
- if (el.className) {
151
- el.className = (' ' + el.className + ' ')
152
- .replace(' ' + class_name + ' ', '')
153
- .replace(/^[\s\xA0]+/, '')
154
- .replace(/[\s\xA0]+$/, '');
155
- }
156
- });
157
-
158
- MixpanelNotification.prototype._animate_els = _.safewrap(function(anims, mss, done_cb, start_time) {
159
- var self = this,
160
- in_progress = false,
161
- ai, anim,
162
- cur_time = 1 * new Date(), time_diff;
163
-
164
- start_time = start_time || cur_time;
165
- time_diff = cur_time - start_time;
166
-
167
- for (ai = 0; ai < anims.length; ai++) {
168
- anim = anims[ai];
169
- if (typeof anim.val === 'undefined') {
170
- anim.val = anim.start;
171
- }
172
- if (anim.val !== anim.goal) {
173
- in_progress = true;
174
- var anim_diff = anim.goal - anim.start,
175
- anim_dir = anim.goal >= anim.start ? 1 : -1;
176
- anim.val = anim.start + anim_diff * time_diff / mss;
177
- if (anim.attr !== 'opacity') {
178
- anim.val = Math.round(anim.val);
179
- }
180
- if ((anim_dir > 0 && anim.val >= anim.goal) || (anim_dir < 0 && anim.val <= anim.goal)) {
181
- anim.val = anim.goal;
182
- }
183
- }
184
- }
185
- if (!in_progress) {
186
- if (done_cb) {
187
- done_cb();
188
- }
189
- return;
190
- }
191
-
192
- for (ai = 0; ai < anims.length; ai++) {
193
- anim = anims[ai];
194
- if (anim.el) {
195
- var suffix = anim.attr === 'opacity' ? '' : 'px';
196
- anim.el.style[anim.attr] = String(anim.val) + suffix;
197
- }
198
- }
199
- setTimeout(function() { self._animate_els(anims, mss, done_cb, start_time); }, 10);
200
- });
201
-
202
- MixpanelNotification.prototype._attach_and_animate = _.safewrap(function() {
203
- var self = this;
204
-
205
- // no possibility to double-display
206
- if (this.shown || this._get_shown_campaigns()[this.campaign_id]) {
207
- return;
208
- }
209
- this.shown = true;
210
-
211
- this.body_el.appendChild(this.notification_el);
212
- setTimeout(function() {
213
- var notif_el = self._get_notification_display_el();
214
- if (self.use_transitions) {
215
- if (!self.mini) {
216
- self._add_class('bg', 'visible');
217
- }
218
- self._add_class(notif_el, 'visible');
219
- self._mark_as_shown();
220
- } else {
221
- var notif_attr, notif_start, notif_goal;
222
- if (self.mini) {
223
- notif_attr = 'right';
224
- notif_start = -100;
225
- notif_goal = 20;
226
- } else {
227
- notif_attr = 'top';
228
- notif_start = MixpanelNotification.NOTIF_START_TOP + MixpanelNotification.NOTIF_TOP;
229
- notif_goal = MixpanelNotification.NOTIF_TOP;
230
- }
231
- self._animate_els([
232
- {
233
- el: self._get_el('bg'),
234
- attr: 'opacity',
235
- start: 0.0,
236
- goal: MixpanelNotification.BG_OPACITY
237
- },
238
- {
239
- el: notif_el,
240
- attr: 'opacity',
241
- start: 0.0,
242
- goal: 1.0
243
- },
244
- {
245
- el: notif_el,
246
- attr: notif_attr,
247
- start: notif_start,
248
- goal: notif_goal
249
- }
250
- ], MixpanelNotification.ANIM_TIME, self._mark_as_shown);
251
- }
252
- }, 100);
253
- _.register_event(self._get_el('cancel'), 'click', function(e) {
254
- e.preventDefault();
255
- self.dismiss();
256
- });
257
- var click_el = self._get_el('button') ||
258
- self._get_el('mini-content');
259
- _.register_event(click_el, 'click', function(e) {
260
- e.preventDefault();
261
- if (self.show_video) {
262
- self._track_event('$campaign_open', {'$resource_type': 'video'});
263
- self._switch_to_video();
264
- } else {
265
- self.dismiss();
266
- if (self.clickthrough) {
267
- var tracking_cb = null;
268
- if (self.mixpanel.get_config('inapp_link_new_window')) {
269
- window.open(self.dest_url);
270
- } else {
271
- tracking_cb = function() {
272
- window.location.href = self.dest_url;
273
- };
274
- }
275
- self._track_event('$campaign_open', {'$resource_type': 'link'}, tracking_cb);
276
- }
277
- }
278
- });
279
- });
280
-
281
- MixpanelNotification.prototype._get_el = function(id) {
282
- return document.getElementById(MixpanelNotification.MARKUP_PREFIX + '-' + id);
283
- };
284
-
285
- MixpanelNotification.prototype._get_notification_display_el = function() {
286
- return this._get_el(this.notif_type);
287
- };
288
-
289
- MixpanelNotification.prototype._get_shown_campaigns = function() {
290
- return this.persistence['props'][CAMPAIGN_IDS_KEY] || (this.persistence['props'][CAMPAIGN_IDS_KEY] = {});
291
- };
292
-
293
- MixpanelNotification.prototype._matches_event_data = _.safewrap(function(event_data) {
294
- var event_name = event_data['event'] || '';
295
- for (var i = 0; i < this.display_triggers.length; i++) {
296
- var display_trigger = this.display_triggers[i];
297
- var match_event = display_trigger['event'] || '';
298
- if (match_event === '$any_event' || event_name === display_trigger['event']) {
299
- if (display_trigger['selector'] && !_.isEmptyObject(display_trigger['selector'])) {
300
- if (evaluateSelector(display_trigger['selector'], event_data['properties'])) {
301
- return true;
302
- }
303
- } else {
304
- return true;
305
- }
306
- }
307
- }
308
- return false;
309
- });
310
-
311
-
312
- MixpanelNotification.prototype._browser_lte = function(browser, version) {
313
- return this.browser_versions[browser] && this.browser_versions[browser] <= version;
314
- };
315
-
316
- MixpanelNotification.prototype._init_image_html = function() {
317
- var imgs_to_preload = [];
318
-
319
- if (!this.mini) {
320
- if (this.image_url) {
321
- imgs_to_preload.push(this.image_url);
322
- this.img_html = '<img id="img" src="' + this.image_url + '"/>';
323
- } else {
324
- this.img_html = '';
325
- }
326
- if (this.thumb_image_url) {
327
- imgs_to_preload.push(this.thumb_image_url);
328
- this.thumb_img_html =
329
- '<div id="thumbborder-wrapper"><div id="thumbborder"></div></div>' +
330
- '<img id="thumbnail"' +
331
- ' src="' + this.thumb_image_url + '"' +
332
- ' width="' + MixpanelNotification.THUMB_IMG_SIZE + '"' +
333
- ' height="' + MixpanelNotification.THUMB_IMG_SIZE + '"' +
334
- '/>' +
335
- '<div id="thumbspacer"></div>';
336
- } else {
337
- this.thumb_img_html = '';
338
- }
339
- } else {
340
- this.thumb_image_url = this.thumb_image_url || (this.cdn_host + '/site_media/images/icons/notifications/mini-news-dark.png');
341
- imgs_to_preload.push(this.thumb_image_url);
342
- }
343
-
344
- return imgs_to_preload;
345
- };
346
-
347
- MixpanelNotification.prototype._init_notification_el = function() {
348
- var notification_html = '';
349
- var video_src = '';
350
- var video_html = '';
351
- var cancel_html = '<div id="cancel">' +
352
- '<div id="cancel-icon"></div>' +
353
- '</div>';
354
-
355
- this.notification_el = document.createElement('div');
356
- this.notification_el.id = MixpanelNotification.MARKUP_PREFIX + '-wrapper';
357
- if (!this.mini) {
358
- // TAKEOVER notification
359
- var close_html = (this.clickthrough || this.show_video) ? '' : '<div id="button-close"></div>',
360
- play_html = this.show_video ? '<div id="button-play"></div>' : '';
361
- if (this._browser_lte('ie', 7)) {
362
- close_html = '';
363
- play_html = '';
364
- }
365
- notification_html =
366
- '<div id="takeover">' +
367
- this.thumb_img_html +
368
- '<div id="mainbox">' +
369
- cancel_html +
370
- '<div id="content">' +
371
- this.img_html +
372
- '<div id="title">' + this.title + '</div>' +
373
- '<div id="body">' + this.body + '</div>' +
374
- '<div id="tagline">' +
375
- '<a href="http://mixpanel.com?from=inapp" target="_blank">POWERED BY MIXPANEL</a>' +
376
- '</div>' +
377
- '</div>' +
378
- '<div id="button">' +
379
- close_html +
380
- '<a id="button-link" href="' + this.dest_url + '">' + this.cta + '</a>' +
381
- play_html +
382
- '</div>' +
383
- '</div>' +
384
- '</div>';
385
- } else {
386
- // MINI notification
387
- notification_html =
388
- '<div id="mini">' +
389
- '<div id="mainbox">' +
390
- cancel_html +
391
- '<div id="mini-content">' +
392
- '<div id="mini-icon">' +
393
- '<div id="mini-icon-img"></div>' +
394
- '</div>' +
395
- '<div id="body">' +
396
- '<div id="body-text"><div>' + this.body + '</div></div>' +
397
- '</div>' +
398
- '</div>' +
399
- '</div>' +
400
- '<div id="mini-border"></div>' +
401
- '</div>';
402
- }
403
- if (this.youtube_video) {
404
- video_src = this.resource_protocol + 'www.youtube.com/embed/' + this.youtube_video +
405
- '?wmode=transparent&showinfo=0&modestbranding=0&rel=0&autoplay=1&loop=0&vq=hd1080';
406
- if (this.yt_custom) {
407
- video_src += '&enablejsapi=1&html5=1&controls=0';
408
- video_html =
409
- '<div id="video-controls">' +
410
- '<div id="video-progress" class="video-progress-el">' +
411
- '<div id="video-progress-total" class="video-progress-el"></div>' +
412
- '<div id="video-elapsed" class="video-progress-el"></div>' +
413
- '</div>' +
414
- '<div id="video-time" class="video-progress-el"></div>' +
415
- '</div>';
416
- }
417
- } else if (this.vimeo_video) {
418
- video_src = this.resource_protocol + 'player.vimeo.com/video/' + this.vimeo_video + '?autoplay=1&title=0&byline=0&portrait=0';
419
- }
420
- if (this.show_video) {
421
- this.video_iframe =
422
- '<iframe id="' + MixpanelNotification.MARKUP_PREFIX + '-video-frame" ' +
423
- 'width="' + this.video_width + '" height="' + this.video_height + '" ' +
424
- ' src="' + video_src + '"' +
425
- ' frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen="1" scrolling="no"' +
426
- '></iframe>';
427
- video_html =
428
- '<div id="video-' + (this.flip_animate ? '' : 'no') + 'flip">' +
429
- '<div id="video">' +
430
- '<div id="video-holder"></div>' +
431
- video_html +
432
- '</div>' +
433
- '</div>';
434
- }
435
- var main_html = video_html + notification_html;
436
- if (this.flip_animate) {
437
- main_html =
438
- (this.mini ? notification_html : '') +
439
- '<div id="flipcontainer"><div id="flipper">' +
440
- (this.mini ? video_html : main_html) +
441
- '</div></div>';
442
- }
443
-
444
- this.notification_el.innerHTML =
445
- ('<div id="overlay" class="' + this.notif_type + '">' +
446
- '<div id="campaignid-' + this.campaign_id + '">' +
447
- '<div id="bgwrapper">' +
448
- '<div id="bg"></div>' +
449
- main_html +
450
- '</div>' +
451
- '</div>' +
452
- '</div>')
453
- .replace(/class="/g, 'class="' + MixpanelNotification.MARKUP_PREFIX + '-')
454
- .replace(/id="/g, 'id="' + MixpanelNotification.MARKUP_PREFIX + '-');
455
- };
456
-
457
- MixpanelNotification.prototype._init_styles = function() {
458
- if (this.style === 'dark') {
459
- this.style_vals = {
460
- bg: '#1d1f25',
461
- bg_actions: '#282b32',
462
- bg_hover: '#3a4147',
463
- bg_light: '#4a5157',
464
- border_gray: '#32353c',
465
- cancel_opacity: '0.4',
466
- mini_hover: '#2a3137',
467
- text_title: '#fff',
468
- text_main: '#9498a3',
469
- text_tagline: '#464851',
470
- text_hover: '#ddd'
471
- };
472
- } else {
473
- this.style_vals = {
474
- bg: '#fff',
475
- bg_actions: '#e7eaee',
476
- bg_hover: '#eceff3',
477
- bg_light: '#f5f5f5',
478
- border_gray: '#e4ecf2',
479
- cancel_opacity: '1.0',
480
- mini_hover: '#fafafa',
481
- text_title: '#5c6578',
482
- text_main: '#8b949b',
483
- text_tagline: '#ced9e6',
484
- text_hover: '#7c8598'
485
- };
486
- }
487
- var shadow = '0px 0px 35px 0px rgba(45, 49, 56, 0.7)',
488
- video_shadow = shadow,
489
- mini_shadow = shadow,
490
- thumb_total_size = MixpanelNotification.THUMB_IMG_SIZE + MixpanelNotification.THUMB_BORDER_SIZE * 2,
491
- anim_seconds = (MixpanelNotification.ANIM_TIME / 1000) + 's';
492
- if (this.mini) {
493
- shadow = 'none';
494
- }
495
-
496
- // don't display on small viewports
497
- var notif_media_queries = {},
498
- min_width = MixpanelNotification.NOTIF_WIDTH_MINI + 20;
499
- notif_media_queries['@media only screen and (max-width: ' + (min_width - 1) + 'px)'] = {
500
- '#overlay': {
501
- 'display': 'none'
502
- }
503
- };
504
- var notif_styles = {
505
- '.flipped': {
506
- 'transform': 'rotateY(180deg)'
507
- },
508
- '#overlay': {
509
- 'position': 'fixed',
510
- 'top': '0',
511
- 'left': '0',
512
- 'width': '100%',
513
- 'height': '100%',
514
- 'overflow': 'auto',
515
- 'text-align': 'center',
516
- 'z-index': '10000',
517
- 'font-family': '"Helvetica", "Arial", sans-serif',
518
- '-webkit-font-smoothing': 'antialiased',
519
- '-moz-osx-font-smoothing': 'grayscale'
520
- },
521
- '#overlay.mini': {
522
- 'height': '0',
523
- 'overflow': 'visible'
524
- },
525
- '#overlay a': {
526
- 'width': 'initial',
527
- 'padding': '0',
528
- 'text-decoration': 'none',
529
- 'text-transform': 'none',
530
- 'color': 'inherit'
531
- },
532
- '#bgwrapper': {
533
- 'position': 'relative',
534
- 'width': '100%',
535
- 'height': '100%'
536
- },
537
- '#bg': {
538
- 'position': 'fixed',
539
- 'top': '0',
540
- 'left': '0',
541
- 'width': '100%',
542
- 'height': '100%',
543
- 'min-width': this.doc_width * 4 + 'px',
544
- 'min-height': this.doc_height * 4 + 'px',
545
- 'background-color': 'black',
546
- 'opacity': '0.0',
547
- '-ms-filter': 'progid:DXImageTransform.Microsoft.Alpha(Opacity=60)', // IE8
548
- 'filter': 'alpha(opacity=60)', // IE5-7
549
- 'transition': 'opacity ' + anim_seconds
550
- },
551
- '#bg.visible': {
552
- 'opacity': MixpanelNotification.BG_OPACITY
553
- },
554
- '.mini #bg': {
555
- 'width': '0',
556
- 'height': '0',
557
- 'min-width': '0'
558
- },
559
- '#flipcontainer': {
560
- 'perspective': '1000px',
561
- 'position': 'absolute',
562
- 'width': '100%'
563
- },
564
- '#flipper': {
565
- 'position': 'relative',
566
- 'transform-style': 'preserve-3d',
567
- 'transition': '0.3s'
568
- },
569
- '#takeover': {
570
- 'position': 'absolute',
571
- 'left': '50%',
572
- 'width': MixpanelNotification.NOTIF_WIDTH + 'px',
573
- 'margin-left': Math.round(-MixpanelNotification.NOTIF_WIDTH / 2) + 'px',
574
- 'backface-visibility': 'hidden',
575
- 'transform': 'rotateY(0deg)',
576
- 'opacity': '0.0',
577
- 'top': MixpanelNotification.NOTIF_START_TOP + 'px',
578
- 'transition': 'opacity ' + anim_seconds + ', top ' + anim_seconds
579
- },
580
- '#takeover.visible': {
581
- 'opacity': '1.0',
582
- 'top': MixpanelNotification.NOTIF_TOP + 'px'
583
- },
584
- '#takeover.exiting': {
585
- 'opacity': '0.0',
586
- 'top': MixpanelNotification.NOTIF_START_TOP + 'px'
587
- },
588
- '#thumbspacer': {
589
- 'height': MixpanelNotification.THUMB_OFFSET + 'px'
590
- },
591
- '#thumbborder-wrapper': {
592
- 'position': 'absolute',
593
- 'top': (-MixpanelNotification.THUMB_BORDER_SIZE) + 'px',
594
- 'left': (MixpanelNotification.NOTIF_WIDTH / 2 - MixpanelNotification.THUMB_OFFSET - MixpanelNotification.THUMB_BORDER_SIZE) + 'px',
595
- 'width': thumb_total_size + 'px',
596
- 'height': (thumb_total_size / 2) + 'px',
597
- 'overflow': 'hidden'
598
- },
599
- '#thumbborder': {
600
- 'position': 'absolute',
601
- 'width': thumb_total_size + 'px',
602
- 'height': thumb_total_size + 'px',
603
- 'border-radius': thumb_total_size + 'px',
604
- 'background-color': this.style_vals.bg_actions,
605
- 'opacity': '0.5'
606
- },
607
- '#thumbnail': {
608
- 'position': 'absolute',
609
- 'top': '0px',
610
- 'left': (MixpanelNotification.NOTIF_WIDTH / 2 - MixpanelNotification.THUMB_OFFSET) + 'px',
611
- 'width': MixpanelNotification.THUMB_IMG_SIZE + 'px',
612
- 'height': MixpanelNotification.THUMB_IMG_SIZE + 'px',
613
- 'overflow': 'hidden',
614
- 'z-index': '100',
615
- 'border-radius': MixpanelNotification.THUMB_IMG_SIZE + 'px'
616
- },
617
- '#mini': {
618
- 'position': 'absolute',
619
- 'right': '20px',
620
- 'top': MixpanelNotification.NOTIF_TOP + 'px',
621
- 'width': this.notif_width + 'px',
622
- 'height': MixpanelNotification.NOTIF_HEIGHT_MINI * 2 + 'px',
623
- 'margin-top': 20 - MixpanelNotification.NOTIF_HEIGHT_MINI + 'px',
624
- 'backface-visibility': 'hidden',
625
- 'opacity': '0.0',
626
- 'transform': 'rotateX(90deg)',
627
- 'transition': 'opacity 0.3s, transform 0.3s, right 0.3s'
628
- },
629
- '#mini.visible': {
630
- 'opacity': '1.0',
631
- 'transform': 'rotateX(0deg)'
632
- },
633
- '#mini.exiting': {
634
- 'opacity': '0.0',
635
- 'right': '-150px'
636
- },
637
- '#mainbox': {
638
- 'border-radius': '4px',
639
- 'box-shadow': shadow,
640
- 'text-align': 'center',
641
- 'background-color': this.style_vals.bg,
642
- 'font-size': '14px',
643
- 'color': this.style_vals.text_main
644
- },
645
- '#mini #mainbox': {
646
- 'height': MixpanelNotification.NOTIF_HEIGHT_MINI + 'px',
647
- 'margin-top': MixpanelNotification.NOTIF_HEIGHT_MINI + 'px',
648
- 'border-radius': '3px',
649
- 'transition': 'background-color ' + anim_seconds
650
- },
651
- '#mini-border': {
652
- 'height': (MixpanelNotification.NOTIF_HEIGHT_MINI + 6) + 'px',
653
- 'width': (MixpanelNotification.NOTIF_WIDTH_MINI + 6) + 'px',
654
- 'position': 'absolute',
655
- 'top': '-3px',
656
- 'left': '-3px',
657
- 'margin-top': MixpanelNotification.NOTIF_HEIGHT_MINI + 'px',
658
- 'border-radius': '6px',
659
- 'opacity': '0.25',
660
- 'background-color': '#fff',
661
- 'z-index': '-1',
662
- 'box-shadow': mini_shadow
663
- },
664
- '#mini-icon': {
665
- 'position': 'relative',
666
- 'display': 'inline-block',
667
- 'width': '75px',
668
- 'height': MixpanelNotification.NOTIF_HEIGHT_MINI + 'px',
669
- 'border-radius': '3px 0 0 3px',
670
- 'background-color': this.style_vals.bg_actions,
671
- 'background': 'linear-gradient(135deg, ' + this.style_vals.bg_light + ' 0%, ' + this.style_vals.bg_actions + ' 100%)',
672
- 'transition': 'background-color ' + anim_seconds
673
- },
674
- '#mini:hover #mini-icon': {
675
- 'background-color': this.style_vals.mini_hover
676
- },
677
- '#mini:hover #mainbox': {
678
- 'background-color': this.style_vals.mini_hover
679
- },
680
- '#mini-icon-img': {
681
- 'position': 'absolute',
682
- 'background-image': 'url(' + this.thumb_image_url + ')',
683
- 'width': '48px',
684
- 'height': '48px',
685
- 'top': '20px',
686
- 'left': '12px'
687
- },
688
- '#content': {
689
- 'padding': '30px 20px 0px 20px'
690
- },
691
- '#mini-content': {
692
- 'text-align': 'left',
693
- 'height': MixpanelNotification.NOTIF_HEIGHT_MINI + 'px',
694
- 'cursor': 'pointer'
695
- },
696
- '#img': {
697
- 'width': '328px',
698
- 'margin-top': '30px',
699
- 'border-radius': '5px'
700
- },
701
- '#title': {
702
- 'max-height': '600px',
703
- 'overflow': 'hidden',
704
- 'word-wrap': 'break-word',
705
- 'padding': '25px 0px 20px 0px',
706
- 'font-size': '19px',
707
- 'font-weight': 'bold',
708
- 'color': this.style_vals.text_title
709
- },
710
- '#body': {
711
- 'max-height': '600px',
712
- 'margin-bottom': '25px',
713
- 'overflow': 'hidden',
714
- 'word-wrap': 'break-word',
715
- 'line-height': '21px',
716
- 'font-size': '15px',
717
- 'font-weight': 'normal',
718
- 'text-align': 'left'
719
- },
720
- '#mini #body': {
721
- 'display': 'inline-block',
722
- 'max-width': '250px',
723
- 'margin': '0 0 0 30px',
724
- 'height': MixpanelNotification.NOTIF_HEIGHT_MINI + 'px',
725
- 'font-size': '16px',
726
- 'letter-spacing': '0.8px',
727
- 'color': this.style_vals.text_title
728
- },
729
- '#mini #body-text': {
730
- 'display': 'table',
731
- 'height': MixpanelNotification.NOTIF_HEIGHT_MINI + 'px'
732
- },
733
- '#mini #body-text div': {
734
- 'display': 'table-cell',
735
- 'vertical-align': 'middle'
736
- },
737
- '#tagline': {
738
- 'margin-bottom': '15px',
739
- 'font-size': '10px',
740
- 'font-weight': '600',
741
- 'letter-spacing': '0.8px',
742
- 'color': '#ccd7e0',
743
- 'text-align': 'left'
744
- },
745
- '#tagline a': {
746
- 'color': this.style_vals.text_tagline,
747
- 'transition': 'color ' + anim_seconds
748
- },
749
- '#tagline a:hover': {
750
- 'color': this.style_vals.text_hover
751
- },
752
- '#cancel': {
753
- 'position': 'absolute',
754
- 'right': '0',
755
- 'width': '8px',
756
- 'height': '8px',
757
- 'padding': '10px',
758
- 'border-radius': '20px',
759
- 'margin': '12px 12px 0 0',
760
- 'box-sizing': 'content-box',
761
- 'cursor': 'pointer',
762
- 'transition': 'background-color ' + anim_seconds
763
- },
764
- '#mini #cancel': {
765
- 'margin': '7px 7px 0 0'
766
- },
767
- '#cancel-icon': {
768
- 'width': '8px',
769
- 'height': '8px',
770
- 'overflow': 'hidden',
771
- 'background-image': 'url(' + this.cdn_host + '/site_media/images/icons/notifications/cancel-x.png)',
772
- 'opacity': this.style_vals.cancel_opacity
773
- },
774
- '#cancel:hover': {
775
- 'background-color': this.style_vals.bg_hover
776
- },
777
- '#button': {
778
- 'display': 'block',
779
- 'height': '60px',
780
- 'line-height': '60px',
781
- 'text-align': 'center',
782
- 'background-color': this.style_vals.bg_actions,
783
- 'border-radius': '0 0 4px 4px',
784
- 'overflow': 'hidden',
785
- 'cursor': 'pointer',
786
- 'transition': 'background-color ' + anim_seconds
787
- },
788
- '#button-close': {
789
- 'display': 'inline-block',
790
- 'width': '9px',
791
- 'height': '60px',
792
- 'margin-right': '8px',
793
- 'vertical-align': 'top',
794
- 'background-image': 'url(' + this.cdn_host + '/site_media/images/icons/notifications/close-x-' + this.style + '.png)',
795
- 'background-repeat': 'no-repeat',
796
- 'background-position': '0px 25px'
797
- },
798
- '#button-play': {
799
- 'display': 'inline-block',
800
- 'width': '30px',
801
- 'height': '60px',
802
- 'margin-left': '15px',
803
- 'background-image': 'url(' + this.cdn_host + '/site_media/images/icons/notifications/play-' + this.style + '-small.png)',
804
- 'background-repeat': 'no-repeat',
805
- 'background-position': '0px 15px'
806
- },
807
- 'a#button-link': {
808
- 'display': 'inline-block',
809
- 'vertical-align': 'top',
810
- 'text-align': 'center',
811
- 'font-size': '17px',
812
- 'font-weight': 'bold',
813
- 'overflow': 'hidden',
814
- 'word-wrap': 'break-word',
815
- 'color': this.style_vals.text_title,
816
- 'transition': 'color ' + anim_seconds
817
- },
818
- '#button:hover': {
819
- 'background-color': this.style_vals.bg_hover,
820
- 'color': this.style_vals.text_hover
821
- },
822
- '#button:hover a': {
823
- 'color': this.style_vals.text_hover
824
- },
825
-
826
- '#video-noflip': {
827
- 'position': 'relative',
828
- 'top': (-this.video_height * 2) + 'px'
829
- },
830
- '#video-flip': {
831
- 'backface-visibility': 'hidden',
832
- 'transform': 'rotateY(180deg)'
833
- },
834
- '#video': {
835
- 'position': 'absolute',
836
- 'width': (this.video_width - 1) + 'px',
837
- 'height': this.video_height + 'px',
838
- 'top': MixpanelNotification.NOTIF_TOP + 'px',
839
- 'margin-top': '100px',
840
- 'left': '50%',
841
- 'margin-left': Math.round(-this.video_width / 2) + 'px',
842
- 'overflow': 'hidden',
843
- 'border-radius': '5px',
844
- 'box-shadow': video_shadow,
845
- 'transform': 'translateZ(1px)', // webkit rendering bug http://stackoverflow.com/questions/18167981/clickable-link-area-unexpectedly-smaller-after-css-transform
846
- 'transition': 'opacity ' + anim_seconds + ', top ' + anim_seconds
847
- },
848
- '#video.exiting': {
849
- 'opacity': '0.0',
850
- 'top': this.video_height + 'px'
851
- },
852
- '#video-holder': {
853
- 'position': 'absolute',
854
- 'width': (this.video_width - 1) + 'px',
855
- 'height': this.video_height + 'px',
856
- 'overflow': 'hidden',
857
- 'border-radius': '5px'
858
- },
859
- '#video-frame': {
860
- 'margin-left': '-1px',
861
- 'width': this.video_width + 'px'
862
- },
863
- '#video-controls': {
864
- 'opacity': '0',
865
- 'transition': 'opacity 0.5s'
866
- },
867
- '#video:hover #video-controls': {
868
- 'opacity': '1.0'
869
- },
870
- '#video .video-progress-el': {
871
- 'position': 'absolute',
872
- 'bottom': '0',
873
- 'height': '25px',
874
- 'border-radius': '0 0 0 5px'
875
- },
876
- '#video-progress': {
877
- 'width': '90%'
878
- },
879
- '#video-progress-total': {
880
- 'width': '100%',
881
- 'background-color': this.style_vals.bg,
882
- 'opacity': '0.7'
883
- },
884
- '#video-elapsed': {
885
- 'width': '0',
886
- 'background-color': '#6cb6f5',
887
- 'opacity': '0.9'
888
- },
889
- '#video #video-time': {
890
- 'width': '10%',
891
- 'right': '0',
892
- 'font-size': '11px',
893
- 'line-height': '25px',
894
- 'color': this.style_vals.text_main,
895
- 'background-color': '#666',
896
- 'border-radius': '0 0 5px 0'
897
- }
898
- };
899
-
900
- // IE hacks
901
- if (this._browser_lte('ie', 8)) {
902
- _.extend(notif_styles, {
903
- '* html #overlay': {
904
- 'position': 'absolute'
905
- },
906
- '* html #bg': {
907
- 'position': 'absolute'
908
- },
909
- 'html, body': {
910
- 'height': '100%'
911
- }
912
- });
913
- }
914
- if (this._browser_lte('ie', 7)) {
915
- _.extend(notif_styles, {
916
- '#mini #body': {
917
- 'display': 'inline',
918
- 'zoom': '1',
919
- 'border': '1px solid ' + this.style_vals.bg_hover
920
- },
921
- '#mini #body-text': {
922
- 'padding': '20px'
923
- },
924
- '#mini #mini-icon': {
925
- 'display': 'none'
926
- }
927
- });
928
- }
929
-
930
- // add vendor-prefixed style rules
931
- var VENDOR_STYLES = [
932
- 'backface-visibility', 'border-radius', 'box-shadow', 'opacity',
933
- 'perspective', 'transform', 'transform-style', 'transition'
934
- ],
935
- VENDOR_PREFIXES = ['khtml', 'moz', 'ms', 'o', 'webkit'];
936
- for (var selector in notif_styles) {
937
- for (var si = 0; si < VENDOR_STYLES.length; si++) {
938
- var prop = VENDOR_STYLES[si];
939
- if (prop in notif_styles[selector]) {
940
- var val = notif_styles[selector][prop];
941
- for (var pi = 0; pi < VENDOR_PREFIXES.length; pi++) {
942
- notif_styles[selector]['-' + VENDOR_PREFIXES[pi] + '-' + prop] = val;
943
- }
944
- }
945
- }
946
- }
947
-
948
- var inject_styles = function(styles, media_queries) {
949
- var create_style_text = function(style_defs) {
950
- var st = '';
951
- for (var selector in style_defs) {
952
- var mp_selector = selector
953
- .replace(/#/g, '#' + MixpanelNotification.MARKUP_PREFIX + '-')
954
- .replace(/\./g, '.' + MixpanelNotification.MARKUP_PREFIX + '-');
955
- st += '\n' + mp_selector + ' {';
956
- var props = style_defs[selector];
957
- for (var k in props) {
958
- st += k + ':' + props[k] + ';';
959
- }
960
- st += '}';
961
- }
962
- return st;
963
- };
964
- var create_media_query_text = function(mq_defs) {
965
- var mqt = '';
966
- for (var mq in mq_defs) {
967
- mqt += '\n' + mq + ' {' + create_style_text(mq_defs[mq]) + '\n}';
968
- }
969
- return mqt;
970
- };
971
-
972
- var style_text = create_style_text(styles) + create_media_query_text(media_queries),
973
- head_el = document.head || document.getElementsByTagName('head')[0] || document.documentElement,
974
- style_el = document.createElement('style');
975
- head_el.appendChild(style_el);
976
- style_el.setAttribute('type', 'text/css');
977
- if (style_el.styleSheet) { // IE
978
- style_el.styleSheet.cssText = style_text;
979
- } else {
980
- style_el.textContent = style_text;
981
- }
982
- };
983
- inject_styles(notif_styles, notif_media_queries);
984
- };
985
-
986
- MixpanelNotification.prototype._init_video = _.safewrap(function() {
987
- if (!this.video_url) {
988
- return;
989
- }
990
- var self = this;
991
-
992
- // Youtube iframe API compatibility
993
- self.yt_custom = 'postMessage' in window;
994
-
995
- self.dest_url = self.video_url;
996
- var youtube_match = self.video_url.match(
997
- // http://stackoverflow.com/questions/2936467/parse-youtube-video-id-using-preg-match
998
- /(?:youtube(?:-nocookie)?\.com\/(?:[^/]+\/.+\/|(?:v|e(?:mbed)?)\/|.*[?&]v=)|youtu\.be\/)([^"&?/ ]{11})/i
999
- ),
1000
- vimeo_match = self.video_url.match(
1001
- /vimeo\.com\/.*?(\d+)/i
1002
- );
1003
- if (youtube_match) {
1004
- self.show_video = true;
1005
- self.youtube_video = youtube_match[1];
1006
-
1007
- if (self.yt_custom) {
1008
- window['onYouTubeIframeAPIReady'] = function() {
1009
- if (self._get_el('video-frame')) {
1010
- self._yt_video_ready();
1011
- }
1012
- };
1013
-
1014
- // load Youtube iframe API; see https://developers.google.com/youtube/iframe_api_reference
1015
- var tag = document.createElement('script');
1016
- tag.src = self.resource_protocol + 'www.youtube.com/iframe_api';
1017
- var firstScriptTag = document.getElementsByTagName('script')[0];
1018
- firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
1019
- }
1020
- } else if (vimeo_match) {
1021
- self.show_video = true;
1022
- self.vimeo_video = vimeo_match[1];
1023
- }
1024
-
1025
- // IE <= 7, FF <= 3: fall through to video link rather than embedded player
1026
- if (self._browser_lte('ie', 7) || self._browser_lte('firefox', 3)) {
1027
- self.show_video = false;
1028
- self.clickthrough = true;
1029
- }
1030
- });
1031
-
1032
- MixpanelNotification.prototype._mark_as_shown = _.safewrap(function() {
1033
- // click on background to dismiss
1034
- var self = this;
1035
- _.register_event(self._get_el('bg'), 'click', function() {
1036
- self.dismiss();
1037
- });
1038
-
1039
- var get_style = function(el, style_name) {
1040
- var styles = {};
1041
- if (document.defaultView && document.defaultView.getComputedStyle) {
1042
- styles = document.defaultView.getComputedStyle(el, null); // FF3 requires both args
1043
- } else if (el.currentStyle) { // IE
1044
- styles = el.currentStyle;
1045
- }
1046
- return styles[style_name];
1047
- };
1048
-
1049
- if (this.campaign_id) {
1050
- var notif_el = this._get_el('overlay');
1051
- if (notif_el && get_style(notif_el, 'visibility') !== 'hidden' && get_style(notif_el, 'display') !== 'none') {
1052
- this._mark_delivery();
1053
- }
1054
- }
1055
- });
1056
-
1057
- MixpanelNotification.prototype._mark_delivery = _.safewrap(function(extra_props) {
1058
- if (!this.marked_as_shown) {
1059
- this.marked_as_shown = true;
1060
-
1061
- if (this.campaign_id) {
1062
- // mark notification shown (local cache)
1063
- this._get_shown_campaigns()[this.campaign_id] = 1 * new Date();
1064
- this.persistence.save();
1065
- }
1066
-
1067
- // track delivery
1068
- this._track_event('$campaign_delivery', extra_props);
1069
-
1070
- // mark notification shown (mixpanel property)
1071
- this.mixpanel['people']['append']({
1072
- '$campaigns': this.campaign_id,
1073
- '$notifications': {
1074
- 'campaign_id': this.campaign_id,
1075
- 'message_id': this.message_id,
1076
- 'type': 'web',
1077
- 'time': new Date()
1078
- }
1079
- });
1080
- }
1081
- });
1082
-
1083
- MixpanelNotification.prototype._preload_images = function(all_loaded_cb) {
1084
- var self = this;
1085
- if (this.imgs_to_preload.length === 0) {
1086
- all_loaded_cb();
1087
- return;
1088
- }
1089
-
1090
- var preloaded_imgs = 0;
1091
- var img_objs = [];
1092
- var onload = function() {
1093
- preloaded_imgs++;
1094
- if (preloaded_imgs === self.imgs_to_preload.length && all_loaded_cb) {
1095
- all_loaded_cb();
1096
- all_loaded_cb = null;
1097
- }
1098
- };
1099
- for (var i = 0; i < this.imgs_to_preload.length; i++) {
1100
- var img = new Image();
1101
- img.onload = onload;
1102
- img.src = this.imgs_to_preload[i];
1103
- if (img.complete) {
1104
- onload();
1105
- }
1106
- img_objs.push(img);
1107
- }
1108
-
1109
- // IE6/7 doesn't fire onload reliably
1110
- if (this._browser_lte('ie', 7)) {
1111
- setTimeout(function() {
1112
- var imgs_loaded = true;
1113
- for (i = 0; i < img_objs.length; i++) {
1114
- if (!img_objs[i].complete) {
1115
- imgs_loaded = false;
1116
- }
1117
- }
1118
- if (imgs_loaded && all_loaded_cb) {
1119
- all_loaded_cb();
1120
- all_loaded_cb = null;
1121
- }
1122
- }, 500);
1123
- }
1124
- };
1125
-
1126
- MixpanelNotification.prototype._remove_notification_el = _.safewrap(function() {
1127
- window.clearInterval(this._video_progress_checker);
1128
- this.notification_el.style.visibility = 'hidden';
1129
- this.body_el.removeChild(this.notification_el);
1130
- });
1131
-
1132
- MixpanelNotification.prototype._set_client_config = function() {
1133
- var get_browser_version = function(browser_ex) {
1134
- var match = navigator.userAgent.match(browser_ex);
1135
- return match && match[1];
1136
- };
1137
- this.browser_versions = {};
1138
- this.browser_versions['chrome'] = get_browser_version(/Chrome\/(\d+)/);
1139
- this.browser_versions['firefox'] = get_browser_version(/Firefox\/(\d+)/);
1140
- this.browser_versions['ie'] = get_browser_version(/MSIE (\d+).+/);
1141
- if (!this.browser_versions['ie'] && !(window.ActiveXObject) && 'ActiveXObject' in window) {
1142
- this.browser_versions['ie'] = 11;
1143
- }
1144
-
1145
- this.body_el = document.body || document.getElementsByTagName('body')[0];
1146
- if (this.body_el) {
1147
- this.doc_width = Math.max(
1148
- this.body_el.scrollWidth, document.documentElement.scrollWidth,
1149
- this.body_el.offsetWidth, document.documentElement.offsetWidth,
1150
- this.body_el.clientWidth, document.documentElement.clientWidth
1151
- );
1152
- this.doc_height = Math.max(
1153
- this.body_el.scrollHeight, document.documentElement.scrollHeight,
1154
- this.body_el.offsetHeight, document.documentElement.offsetHeight,
1155
- this.body_el.clientHeight, document.documentElement.clientHeight
1156
- );
1157
- }
1158
-
1159
- // detect CSS compatibility
1160
- var ie_ver = this.browser_versions['ie'];
1161
- var sample_styles = document.createElement('div').style,
1162
- is_css_compatible = function(rule) {
1163
- if (rule in sample_styles) {
1164
- return true;
1165
- }
1166
- if (!ie_ver) {
1167
- rule = rule[0].toUpperCase() + rule.slice(1);
1168
- var props = ['O' + rule, 'Webkit' + rule, 'Moz' + rule];
1169
- for (var i = 0; i < props.length; i++) {
1170
- if (props[i] in sample_styles) {
1171
- return true;
1172
- }
1173
- }
1174
- }
1175
- return false;
1176
- };
1177
- this.use_transitions = this.body_el &&
1178
- is_css_compatible('transition') &&
1179
- is_css_compatible('transform');
1180
- this.flip_animate = (this.browser_versions['chrome'] >= 33 || this.browser_versions['firefox'] >= 15) &&
1181
- this.body_el &&
1182
- is_css_compatible('backfaceVisibility') &&
1183
- is_css_compatible('perspective') &&
1184
- is_css_compatible('transform');
1185
- };
1186
-
1187
- MixpanelNotification.prototype._switch_to_video = _.safewrap(function() {
1188
- var self = this,
1189
- anims = [
1190
- {
1191
- el: self._get_notification_display_el(),
1192
- attr: 'opacity',
1193
- start: 1.0,
1194
- goal: 0.0
1195
- },
1196
- {
1197
- el: self._get_notification_display_el(),
1198
- attr: 'top',
1199
- start: MixpanelNotification.NOTIF_TOP,
1200
- goal: -500
1201
- },
1202
- {
1203
- el: self._get_el('video-noflip'),
1204
- attr: 'opacity',
1205
- start: 0.0,
1206
- goal: 1.0
1207
- },
1208
- {
1209
- el: self._get_el('video-noflip'),
1210
- attr: 'top',
1211
- start: -self.video_height * 2,
1212
- goal: 0
1213
- }
1214
- ];
1215
-
1216
- if (self.mini) {
1217
- var bg = self._get_el('bg'),
1218
- overlay = self._get_el('overlay');
1219
- bg.style.width = '100%';
1220
- bg.style.height = '100%';
1221
- overlay.style.width = '100%';
1222
-
1223
- self._add_class(self._get_notification_display_el(), 'exiting');
1224
- self._add_class(bg, 'visible');
1225
-
1226
- anims.push({
1227
- el: self._get_el('bg'),
1228
- attr: 'opacity',
1229
- start: 0.0,
1230
- goal: MixpanelNotification.BG_OPACITY
1231
- });
1232
- }
1233
-
1234
- var video_el = self._get_el('video-holder');
1235
- video_el.innerHTML = self.video_iframe;
1236
-
1237
- var video_ready = function() {
1238
- if (window['YT'] && window['YT']['loaded']) {
1239
- self._yt_video_ready();
1240
- }
1241
- self.showing_video = true;
1242
- self._get_notification_display_el().style.visibility = 'hidden';
1243
- };
1244
- if (self.flip_animate) {
1245
- self._add_class('flipper', 'flipped');
1246
- setTimeout(video_ready, MixpanelNotification.ANIM_TIME);
1247
- } else {
1248
- self._animate_els(anims, MixpanelNotification.ANIM_TIME, video_ready);
1249
- }
1250
- });
1251
-
1252
- MixpanelNotification.prototype._track_event = function(event_name, properties, cb) {
1253
- if (this.campaign_id) {
1254
- properties = properties || {};
1255
- properties = _.extend(properties, {
1256
- 'campaign_id': this.campaign_id,
1257
- 'message_id': this.message_id,
1258
- 'message_type': 'web_inapp',
1259
- 'message_subtype': this.notif_type
1260
- });
1261
- this.mixpanel['track'](event_name, properties, cb);
1262
- } else if (cb) {
1263
- cb.call();
1264
- }
1265
- };
1266
-
1267
- MixpanelNotification.prototype._yt_video_ready = _.safewrap(function() {
1268
- var self = this;
1269
- if (self.video_inited) {
1270
- return;
1271
- }
1272
- self.video_inited = true;
1273
-
1274
- var progress_bar = self._get_el('video-elapsed'),
1275
- progress_time = self._get_el('video-time'),
1276
- progress_el = self._get_el('video-progress');
1277
-
1278
- new window['YT']['Player'](MixpanelNotification.MARKUP_PREFIX + '-video-frame', {
1279
- 'events': {
1280
- 'onReady': function(event) {
1281
- var ytplayer = event['target'],
1282
- video_duration = ytplayer['getDuration'](),
1283
- pad = function(i) {
1284
- return ('00' + i).slice(-2);
1285
- },
1286
- update_video_time = function(current_time) {
1287
- var secs = Math.round(video_duration - current_time),
1288
- mins = Math.floor(secs / 60),
1289
- hours = Math.floor(mins / 60);
1290
- secs -= mins * 60;
1291
- mins -= hours * 60;
1292
- progress_time.innerHTML = '-' + (hours ? hours + ':' : '') + pad(mins) + ':' + pad(secs);
1293
- };
1294
- update_video_time(0);
1295
- self._video_progress_checker = window.setInterval(function() {
1296
- var current_time = ytplayer['getCurrentTime']();
1297
- progress_bar.style.width = (current_time / video_duration * 100) + '%';
1298
- update_video_time(current_time);
1299
- }, 250);
1300
- _.register_event(progress_el, 'click', function(e) {
1301
- var clickx = Math.max(0, e.pageX - progress_el.getBoundingClientRect().left);
1302
- ytplayer['seekTo'](video_duration * clickx / progress_el.clientWidth, true);
1303
- });
1304
- }
1305
- }
1306
- });
1307
- });
1308
-
1309
- export { MixpanelNotification };