-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathviewsaurus.js
More file actions
992 lines (858 loc) · 41.9 KB
/
viewsaurus.js
File metadata and controls
992 lines (858 loc) · 41.9 KB
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
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
/**
* Featherlight - ultra slim jQuery lightbox
* Version 1.2.3 - http://noelboss.github.io/featherlight/
*
* Copyright 2015, Noël Raoul Bossart (http://www.noelboss.com)
* MIT Licensed.
**/
!function(a){"use strict";function b(a,c){if(!(this instanceof b)){var d=new b(a,c);return d.open(),d}this.id=b.id++,this.setup(a,c),this.chainCallbacks(b._callbackChain)}if("undefined"==typeof a)return void("console"in window&&window.console.info("Too much lightness, Featherlight needs jQuery."));var c=[],d=function(b){return c=a.grep(c,function(a){return a!==b&&a.$instance.closest("body").length>0})},e=function(a,b){var c={},d=new RegExp("^"+b+"([A-Z])(.*)");for(var e in a){var f=e.match(d);if(f){var g=(f[1]+f[2].replace(/([A-Z])/g,"-$1")).toLowerCase();c[g]=a[e]}}return c},f={keyup:"onKeyUp",resize:"onResize"},g=function(c){a.each(b.opened().reverse(),function(){return c.isDefaultPrevented()||!1!==this[f[c.type]](c)?void 0:(c.preventDefault(),c.stopPropagation(),!1)})},h=function(c){if(c!==b._globalHandlerInstalled){b._globalHandlerInstalled=c;var d=a.map(f,function(a,c){return c+"."+b.prototype.namespace}).join(" ");a(window)[c?"on":"off"](d,g)}};b.prototype={constructor:b,namespace:"featherlight",targetAttr:"data-featherlight",variant:null,resetCss:!1,background:null,openTrigger:"click",closeTrigger:"click",filter:null,root:"body",openSpeed:250,closeSpeed:250,closeOnClick:"background",closeOnEsc:!0,closeIcon:"✕",loading:"",otherClose:null,beforeOpen:a.noop,beforeContent:a.noop,beforeClose:a.noop,afterOpen:a.noop,afterContent:a.noop,afterClose:a.noop,onKeyUp:a.noop,onResize:a.noop,type:null,contentFilters:["jquery","image","html","ajax","iframe","text"],setup:function(b,c){"object"!=typeof b||b instanceof a!=!1||c||(c=b,b=void 0);var d=a.extend(this,c,{target:b}),e=d.resetCss?d.namespace+"-reset":d.namespace,f=a(d.background||['<div class="'+e+"-loading "+e+'">','<div class="'+e+'-content">','<span class="'+e+"-close-icon "+d.namespace+'-close">',d.closeIcon,"</span>",'<div class="'+d.namespace+'-inner">'+d.loading+"</div>","</div>","</div>"].join("")),g="."+d.namespace+"-close"+(d.otherClose?","+d.otherClose:"");return d.$instance=f.clone().addClass(d.variant),d.$instance.on(d.closeTrigger+"."+d.namespace,function(b){var c=a(b.target);("background"===d.closeOnClick&&c.is("."+d.namespace)||"anywhere"===d.closeOnClick||c.closest(g).length)&&(b.preventDefault(),d.close())}),this},getContent:function(){var b=this,c=this.constructor.contentFilters,d=function(a){return b.$currentTarget&&b.$currentTarget.attr(a)},e=d(b.targetAttr),f=b.target||e||"",g=c[b.type];if(!g&&f in c&&(g=c[f],f=b.target&&e),f=f||d("href")||"",!g)for(var h in c)b[h]&&(g=c[h],f=b[h]);if(!g){var i=f;if(f=null,a.each(b.contentFilters,function(){return g=c[this],g.test&&(f=g.test(i)),!f&&g.regex&&i.match&&i.match(g.regex)&&(f=i),!f}),!f)return"console"in window&&window.console.error("Featherlight: no content filter found "+(i?' for "'+i+'"':" (no target specified)")),!1}return g.process.call(b,f)},setContent:function(b){var c=this;return(b.is("iframe")||a("iframe",b).length>0)&&c.$instance.addClass(c.namespace+"-iframe"),c.$instance.removeClass(c.namespace+"-loading"),c.$instance.find("."+c.namespace+"-inner").slice(1).remove().end().replaceWith(a.contains(c.$instance[0],b[0])?"":b),c.$content=b.addClass(c.namespace+"-inner"),c},open:function(b){var d=this;if(d.$instance.hide().appendTo(d.root),!(b&&b.isDefaultPrevented()||d.beforeOpen(b)===!1)){b&&b.preventDefault();var e=d.getContent();if(e)return c.push(d),h(!0),d.$instance.fadeIn(d.openSpeed),d.beforeContent(b),a.when(e).always(function(a){d.setContent(a),d.afterContent(b)}).then(d.$instance.promise()).done(function(){d.afterOpen(b)})}return d.$instance.detach(),a.Deferred().reject().promise()},close:function(b){var c=this,e=a.Deferred();return c.beforeClose(b)===!1?e.reject():(0===d(c).length&&h(!1),c.$instance.fadeOut(c.closeSpeed,function(){c.$instance.detach(),c.afterClose(b),e.resolve()})),e.promise()},chainCallbacks:function(b){for(var c in b)this[c]=a.proxy(b[c],this,a.proxy(this[c],this))}},a.extend(b,{id:0,autoBind:"[data-featherlight]",defaults:b.prototype,contentFilters:{jquery:{regex:/^[#.]\w/,test:function(b){return b instanceof a&&b},process:function(b){return a(b).clone(!0)}},image:{regex:/\.(png|jpg|jpeg|gif|tiff|bmp)(\?\S*)?$/i,process:function(b){var c=this,d=a.Deferred(),e=new Image,f=a('<img src="'+b+'" alt="" class="'+c.namespace+'-image" />');return e.onload=function(){f.naturalWidth=e.width,f.naturalHeight=e.height,d.resolve(f)},e.onerror=function(){d.reject(f)},e.src=b,d.promise()}},html:{regex:/^\s*<[\w!][^<]*>/,process:function(b){return a(b)}},ajax:{regex:/./,process:function(b){var c=a.Deferred(),d=a("<div></div>").load(b,function(a,b){"error"!==b&&c.resolve(d.contents()),c.fail()});return c.promise()}},iframe:{process:function(b){var c=new a.Deferred,d=a("<iframe/>").hide().attr("src",b).css(e(this,"iframe")).on("load",function(){c.resolve(d.show())}).appendTo(this.$instance.find("."+this.namespace+"-content"));return c.promise()}},text:{process:function(b){return a("<div>",{text:b})}}},functionAttributes:["beforeOpen","afterOpen","beforeContent","afterContent","beforeClose","afterClose"],readElementConfig:function(b,c){var d=this,e=new RegExp("^data-"+c+"-(.*)"),f={};return b&&b.attributes&&a.each(b.attributes,function(){var b=this.name.match(e);if(b){var c=this.value,g=a.camelCase(b[1]);if(a.inArray(g,d.functionAttributes)>=0)c=new Function(c);else try{c=a.parseJSON(c)}catch(h){}f[g]=c}}),f},extend:function(b,c){var d=function(){this.constructor=b};return d.prototype=this.prototype,b.prototype=new d,b.__super__=this.prototype,a.extend(b,this,c),b.defaults=b.prototype,b},attach:function(b,c,d){var e=this;"object"!=typeof c||c instanceof a!=!1||d||(d=c,c=void 0),d=a.extend({},d);var f=d.namespace||e.defaults.namespace,g=a.extend({},e.defaults,e.readElementConfig(b[0],f),d);return b.on(g.openTrigger+"."+g.namespace,g.filter,function(f){var h=a.extend({$source:b,$currentTarget:a(this)},e.readElementConfig(b[0],g.namespace),e.readElementConfig(this,g.namespace),d);new e(c,h).open(f)}),b},current:function(){var a=this.opened();return a[a.length-1]||null},opened:function(){var b=this;return d(),a.grep(c,function(a){return a instanceof b})},close:function(){var a=this.current();return a?a.close():void 0},_onReady:function(){var b=this;b.autoBind&&(b.attach(a(document),{filter:b.autoBind}),a(b.autoBind).filter("[data-featherlight-filter]").each(function(){b.attach(a(this))}))},_callbackChain:{onKeyUp:function(a,b){return 27===b.keyCode?(this.closeOnEsc&&this.$instance.find("."+this.namespace+"-close:first").click(),!1):a(b)},onResize:function(a,b){if(this.$content.naturalWidth){var c=this.$content.naturalWidth,d=this.$content.naturalHeight;this.$content.css("width","").css("height","");var e=Math.max(c/parseInt(this.$content.parent().css("width"),10),d/parseInt(this.$content.parent().css("height"),10));e>1&&this.$content.css("width",""+c/e+"px").css("height",""+d/e+"px")}return a(b)},afterContent:function(a,b){var c=a(b);return this.onResize(b),c}}}),a.featherlight=b,a.fn.featherlight=function(a,c){return b.attach(this,a,c)},a(document).ready(function(){b._onReady()})}(jQuery);
var Base64={_keyStr:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",encode:function(r){var t,e,o,a,h,n,c,d="",C=0;for(r=Base64._utf8_encode(r);C<r.length;)t=r.charCodeAt(C++),e=r.charCodeAt(C++),o=r.charCodeAt(C++),a=t>>2,h=(3&t)<<4|e>>4,n=(15&e)<<2|o>>6,c=63&o,isNaN(e)?n=c=64:isNaN(o)&&(c=64),d=d+this._keyStr.charAt(a)+this._keyStr.charAt(h)+this._keyStr.charAt(n)+this._keyStr.charAt(c);return d},decode:function(r){var t,e,o,a,h,n,c,d="",C=0;for(r=r.replace(/[^A-Za-z0-9\+\/\=]/g,"");C<r.length;)a=this._keyStr.indexOf(r.charAt(C++)),h=this._keyStr.indexOf(r.charAt(C++)),n=this._keyStr.indexOf(r.charAt(C++)),c=this._keyStr.indexOf(r.charAt(C++)),t=a<<2|h>>4,e=(15&h)<<4|n>>2,o=(3&n)<<6|c,d+=String.fromCharCode(t),64!=n&&(d+=String.fromCharCode(e)),64!=c&&(d+=String.fromCharCode(o));return d=Base64._utf8_decode(d)},_utf8_encode:function(r){r=r.replace(/\r\n/g,"\n");for(var t="",e=0;e<r.length;e++){var o=r.charCodeAt(e);128>o?t+=String.fromCharCode(o):o>127&&2048>o?(t+=String.fromCharCode(o>>6|192),t+=String.fromCharCode(63&o|128)):(t+=String.fromCharCode(o>>12|224),t+=String.fromCharCode(o>>6&63|128),t+=String.fromCharCode(63&o|128))}return t},_utf8_decode:function(r){for(var t="",e=0,o=c1=c2=0;e<r.length;)o=r.charCodeAt(e),128>o?(t+=String.fromCharCode(o),e++):o>191&&224>o?(c2=r.charCodeAt(e+1),t+=String.fromCharCode((31&o)<<6|63&c2),e+=2):(c2=r.charCodeAt(e+1),c3=r.charCodeAt(e+2),t+=String.fromCharCode((15&o)<<12|(63&c2)<<6|63&c3),e+=3);return t}};
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
var GoogleAnalytics = function (id) {
(function (i, s, o, g, r, a, m) {
i['GoogleAnalyticsObject'] = r;
i[r] = i[r] || function () {
(i[r].q = i[r].q || []).push(arguments)
}, i[r].l = 1 * new Date();
a = s.createElement(o),
m = s.getElementsByTagName(o)[0];
a.async = 1;
a.src = g;
m.parentNode.insertBefore(a, m)
})(window, document, 'script', '//www.google-analytics.com/analytics.js', 'ga');
ga('create', id, 'auto');
this.trackPage = function (url, percentage, step, totalSteps) {
var title = window.tutorialName || document.title;
ga('set', 'dimension1', title);
ga('set', 'dimension2', percentage);
ga('set', 'dimension3', url);
ga('set', 'dimension4', step);
ga('set', 'dimension5', totalSteps);
ga(function() {
var clientId = ga.getAll()[0].get('clientId');
ga('set', 'dimension6', clientId);
ga('send', 'pageview',{'dimension6' : clientId})
});
ga('send', 'pageview', {
'dimension1': title,
'dimension2': percentage,
'dimension3': url,
'dimension4': step,
'dimension5': totalSteps
});
};
};
module.exports = GoogleAnalytics;
},{}],2:[function(require,module,exports){
var Router = Backbone.Router.extend({
routes: {
':stepIndex': 'doRoute'
},
// Initialize router with handle to Viewsaurus model
initialize: function(options) {
var self = this;
self.app = options.app;
},
// Handle step route
doRoute: function(stepIndex) {
var self = this;
var si = Number(stepIndex);
if (si < 0) {
si = 0;
} else if (si >= self.app.totalSteps) {
si = self.app.totalSteps - 1;
}
self.app.set('stepIndex', si);
if (si === self.app.totalSteps - 1) {
setTimeout(function () {
mixpanelClient.track(mixpanelClient.eventNames.COMPLETE_TUTORIAL, {
'Tutorial Name': window.tutorialName
});
});
}
}
});
module.exports = Router;
},{}],3:[function(require,module,exports){
var ViewsaurusView = require('./views/ViewsaurusView');
var Router = require('./Router');
// Window-scoped viewsaurus object is an event emitter and namespace for public
// API functions (when needed)
module.exports = Backbone.Model.extend({// Initialize model and app
initialize: function() {
var self = this;
// Determine how many steps there are in the tutorial total
var $steps = $('.saurus-prose .step');
self.totalSteps = $steps.length;
// Create main app view
self.mainView = new ViewsaurusView({
el: '#viewsaurus',
app: self
});
// Create and start router
self.router = new Router({ app: self });
Backbone.history.start();
},
// Determine if there is a next step
hasNext: function() {
var self = this;
return self.get('stepIndex')+1 < self.totalSteps;
},
// Determine if there is a previous step
hasPrevious: function() {
var self = this;
return self.get('stepIndex') !== 0;
},
// Show file explorer (public API)
showExplorer: function() {
var self = this;
self.set('explorerShown', true);
},
// Hide file explorer (public API)
hideExplorer: function() {
var self = this;
self.set('explorerShown', false);
}
});
},{"./Router":2,"./views/ViewsaurusView":10}],4:[function(require,module,exports){
var dpwMenu = function () {
var items = [
{
title: 'API Product',
items: [
{
title: 'Voice',
link: 'https://developer.ringcentral.com/api-products/voice'
},
{
title: 'SMS/MMS',
link: 'https://developer.ringcentral.com/api-products/sms'
},
{
title: 'Fax',
link: 'https://developer.ringcentral.com/api-products/fax'
},
{
title: 'Glip - Team Messaging',
link: 'https://developer.ringcentral.com/api-products/team-messaging'
},
{
title: 'Data',
link: 'https://developer.ringcentral.com/api-products/data'
},
{
title: 'Configuration',
link: 'https://developer.ringcentral.com/api-products/configuration'
}
]
},
{
title: 'Use Cases',
link: 'https://developer.ringcentral.com/overview.html',
items: [
{
title: 'CRM Integration',
link: 'https://developer.ringcentral.com/overview/crm-integration.html'
},
{
title: 'Send SMS and Fax',
link: 'https://developer.ringcentral.com/overview/sms-fax.html'
},
{
title: 'Click to Dial',
link: 'https://developer.ringcentral.com/overview/click-to-dial.html'
},
{
title: 'Call Reporting',
link: 'https://developer.ringcentral.com/overview/call-reporting.html'
},
{
title: 'WebRTC Voice',
link: 'https://developer.ringcentral.com/overview/webrtc-voice.html'
},
{
title: 'Data Sync',
link: 'https://developer.ringcentral.com/overview/data-sync.html'
},
{
title: 'Team Messaging',
link: 'https://developer.ringcentral.com/overview/team-messaging.html'
}
]
},
{
title: 'API & Docs',
link: 'https://developer.ringcentral.com/api-and-docs.html',
items: [
{
title: 'Getting Started',
link: 'https://developer.ringcentral.com/library/getting-started.html'
},
{
title: 'Developer Guide',
link: 'http://ringcentral-api-docs.readthedocs.io/',
external: true
},
{
title: 'Tutorials',
link: 'https://ringcentral.github.io/tutorials/'
},
{
title: 'API Reference',
link: 'https://developer.ringcentral.com/api-docs/latest/index.html'
},
{
title: 'Changelog',
link: 'http://ringcentral-api-changelog.readthedocs.io/en/latest/',
external: true
},
{
title: 'SDKs',
link: 'https://developer.ringcentral.com/library/sdks.html'
},
{
title: 'Chatbots',
link: 'https://developer.ringcentral.com/library/chatbots.html'
},
{
title: 'API Explorer',
link: 'https://developer.ringcentral.com/api-explorer/latest/index.html'
}
]
},
{
title: 'App Gallery',
link: 'https://developer.ringcentral.com/app-gallery.html',
external: true
},
{
title: 'Services & Support',
link: 'https://developer.ringcentral.com/support.html',
items: [
{
title: 'Services',
link: 'https://developer.ringcentral.com/support/services.html'
},
{
title: 'Community',
link: 'https://devcommunity.ringcentral.com/',
external: true
},
{
title: 'FAQ',
link: 'http://ringcentral-faq.readthedocs.io/',
external: true
},
{
title: 'Blog',
link: 'https://medium.com/ringcentral-developers',
external: true
},
{
title: 'Stack Overflow',
link: 'http://stackoverflow.com/questions/tagged/ringcentral',
external: true,
notRCLink: true
}
]
}
];
this.render = function () {
var html = '<ul class="nav-top-menus-list">';
items.forEach(function (item) {
html += '<li class="nav-top-menus-item">';
if (item.link) {
html += '<a class="menu-title" href="' + item.link + '" target="' + getLinkTarget(item) + '">' + item.title + '</a>';
}
else {
html += '<a class="menu-title no-links">' + item.title + '</a>';
}
if (item.items) {
html += '<ul class="nav-top-menus-item-submenu header-top-menus-arrow">';
item.items.forEach(function (subItem) {
html += subItem.notRCLink ? '<li class="external-link">' : '<li>';
html += '<a href="' + subItem.link + '" target="' + getLinkTarget(subItem) + '">' + subItem.title + '</a>';
html += '</li>';
});
html += '</ul>';
}
html += '</li>';
});
html += '</ul>';
$(".nav-top-menus").html(html);
};
function getLinkTarget(item) {
return item.external ? "_blank" : "";
}
};
module.exports = dpwMenu;
},{}],5:[function(require,module,exports){
var Viewsaurus = require('./Viewsaurus');
var GoogleAnalytics = require('./GoogleAnalytics');
var Mixpanel = require('./mixpanel');
var dpwMenu = require('./dpwMenu');
$(function () {
new dpwMenu().render();
// create GA client
window.GAClient = new GoogleAnalytics("UA-57519112-3");
var totalSteps = $('.saurus-prose .step').length;
GAClient.trackPage(location.href, 0, 0, totalSteps);
// create global viewsaurus object
window.viewsaurus = new Viewsaurus();
var $prose = $(".saurus-prose");
var minHeight = $prose.height();
var minWidth = $prose.width();
$prose.resizable({
resize: function () {
$(".saurus-code").css('left', $prose.width());
},
minHeight: minHeight,
minWidth: minWidth
});
$(window).resize(function (event) {
if (event.target === window) {
$prose.resizable("option", "minHeight", $prose.height());
}
});
// Create Mixpanel client
window.mixpanelClient = new Mixpanel('60593de695a204f03647d2fb95d96313');
mixpanelClient.identifyUserFromURL();
mixpanelClient.track(mixpanelClient.eventNames.PAGE_VIEW, {
'Page Name': 'Tutorials: ' + window.tutorialName
});
viewsaurus.mainView.proseView.$start.find('a').click(function () {
mixpanelClient.track(mixpanelClient.eventNames.START_TUTORIAL, {
'Tutorial Name': window.tutorialName
});
});
});
},{"./GoogleAnalytics":1,"./Viewsaurus":3,"./dpwMenu":4,"./mixpanel":6}],6:[function(require,module,exports){
var Mixpanel = function (token) {
(function(e,a){if(!a.__SV){var b=window;try{var c,l,i,j=b.location,g=j.hash;c=function(a,b){return(l=a.match(RegExp(b+"=([^&]*)")))?l[1]:null};g&&c(g,"state")&&(i=JSON.parse(decodeURIComponent(c(g,"state"))),"mpeditor"===i.action&&(b.sessionStorage.setItem("_mpcehash",g),history.replaceState(i.desiredHash||"",e.title,j.pathname+j.search)))}catch(m){}var k,h;window.mixpanel=a;a._i=[];a.init=function(b,c,f){function e(b,a){var c=a.split(".");2==c.length&&(b=b[c[0]],a=c[1]);b[a]=function(){b.push([a].concat(Array.prototype.slice.call(arguments,
0)))}}var d=a;"undefined"!==typeof f?d=a[f]=[]:f="mixpanel";d.people=d.people||[];d.toString=function(b){var a="mixpanel";"mixpanel"!==f&&(a+="."+f);b||(a+=" (stub)");return a};d.people.toString=function(){return d.toString(1)+".people (stub)"};k="disable time_event track track_pageview track_links track_forms register register_once alias unregister identify name_tag set_config reset people.set people.set_once people.unset people.increment people.append people.union people.track_charge people.clear_charges people.delete_user".split(" ");
for(h=0;h<k.length;h++)e(d,k[h]);a._i.push([b,c,f])};a.__SV=1.2;b=e.createElement("script");b.type="text/javascript";b.async=!0;b.src="undefined"!==typeof MIXPANEL_CUSTOM_LIB_URL?MIXPANEL_CUSTOM_LIB_URL:"file:"===e.location.protocol&&"//cdn.mxpnl.com/libs/mixpanel-2-latest.min.js".match(/^\/\//)?"https://cdn.mxpnl.com/libs/mixpanel-2-latest.min.js":"//cdn.mxpnl.com/libs/mixpanel-2-latest.min.js";c=e.getElementsByTagName("script")[0];c.parentNode.insertBefore(b,c)}})(document,window.mixpanel||[]);
mixpanel.init(token, {autotrack: false});
};
Mixpanel.prototype.eventNames = {
PAGE_VIEW: 'Pageviews',
START_TUTORIAL: 'Start Tutorial',
COMPLETE_TUTORIAL: 'Complete Tutorial'
};
Mixpanel.prototype.distinctIdUrlSearchKey = 'distinctId';
Mixpanel.prototype.track = function (eventName, properties) {
mixpanel.track(eventName, properties);
};
Mixpanel.prototype.identifyUserFromURL = function () {
var searchParamPairs = location.search.substring(1).split('&');
var searchParams = _.reduce(searchParamPairs, function (accumulated, pair) {
var keyValueGroup = pair.split('=');
var key = _.first(keyValueGroup);
accumulated[key] = _.last(keyValueGroup);
return accumulated;
}, {});
var distinctId = searchParams[this.distinctIdUrlSearchKey];
if (distinctId) {
mixpanel.identify(distinctId);
}
};
module.exports = Mixpanel;
},{}],7:[function(require,module,exports){
var Range = ace.require('ace/range').Range;
var explorerWidth = 270;
// Generate HTML string for breadcrumbs
function breadcrumbHtml(filePath) {
var separator = ' / ';
var filePieces = filePath.split(/[\/\\]/);
var html = separator;
for (var i = 0, l = filePieces.length; i<l; i++) {
html += '<span>' + filePieces[i] + '</span>';
if (i+1 < l) {
html += separator;
}
}
return html;
}
var CodeView = Backbone.View.extend({
// Mount on the Code section
el: '#viewsaurus .saurus-code',
events: {
'click .file-path i': 'toggleExplorer'
},
// Initialize UI
initialize: function(options) {
var self = this;
// Store a reference to main app model
self.app = options.app;
// Create editor widget
var ta = self.$el.find('.saurus-editor').get(0);
self.editor = ace.edit(ta);
self.editor.setFontSize(14);
self.editor.setAnimatedScroll(true);
self.editor.setReadOnly(true);
self.editor.setHighlightActiveLine(false);
self.editor.setShowPrintMargin(false);
self.editor.$blockScrolling = Infinity;
self.editor.setBehavioursEnabled(false);
self.editor.setWrapBehavioursEnabled(false);
self.editor.setTheme('ace/theme/ringcentral');
self.editor.renderer.setScrollMargin(0,8, 0, 8);
self.editor.getSession().setWrapLimitRange();
// Disable syntax checker
self.editor.getSession().setUseWorker(false);
// Grab useful DOM references
self.$steps = $('#viewsaurus .saurus-content .step');
self.$files = $('#viewsaurus .saurus-file');
self.$breadcrumbs = self.$el.find('.file-path .crumb-container');
self.$editor = self.$el.find('.saurus-editor');
self.$folder = self.$el.find('.file-path i');
// listen for update events
self.app.on('change:stepIndex', self.stepChange, self);
self.app.on('change:currentFile', self.currentFileChange, self);
self.app.on('change:explorerShown', self.showExplorer, self);
self.app.on('resize', function() {
self.editor.resize(true);
});
// Initialize with the first code file
self.showFile(self.$files.first());
},
// Change the contents of the editor if the current file is changed
// elsewhere
currentFileChange: function() {
var self = this;
var currentFile = self.app.get('currentFile');
var $file = $('.saurus-file[data-file="' + currentFile + '"]');
self.showFile($file);
},
// Get current step index and update code
stepChange: function() {
var self = this;
// Get file for current step
var $step = self.$steps.eq(self.app.get('stepIndex'));
var stepFile = $step.attr('data-file');
var highlightString = $step.attr('data-highlight');
if (stepFile) {
var $file = $('.saurus-file[data-file="' + stepFile + '"]');
self.showFile($file, highlightString);
} else {
// Remove highlighting if no file, and force redraw
self.editor.getSession().setActiveLines('');
self.editor.setValue(self.editor.getValue());
self.editor.clearSelection();
}
},
// Toggle file explorer
toggleExplorer: function() {
var self = this;
var shown = self.app.get('explorerShown');
// analytics
if (!shown) {
self.app.trigger('show_explorer');
}
self.app.set('explorerShown', !shown);
},
// Show/hide file explorer
showExplorer: function() {
var self = this;
var shown = self.app.get('explorerShown');
var offset = shown ? explorerWidth : 0;
var addedClass = shown ? 'fa-folder-open' : 'fa-folder';
var removedClass = !shown ? 'fa-folder-open' : 'fa-folder';
self.$folder.removeClass(removedClass).addClass(addedClass);
self.$el.animate({
right: offset
}, function() {
self.editor.resize(true);
});
},
// Show the given file, optionally applying a highlight and scrolling
// to the first line of the highlight.
showFile: function($file, highlightString) {
var self = this;
var mode = $file.attr('data-mode');
var filePath = $file.attr('data-file');
// Update editor content and editing mode
self.app.set({
currentFile: filePath
});
self.editor.getSession().setMode('ace/mode/'+mode);
// Update file breadcrumbs
self.$breadcrumbs.html(breadcrumbHtml(filePath));
// Handle highlight
self.editor.getSession().setActiveLines(highlightString);
// Update content
var src = Base64.decode($file.val()).trim();
self.editor.setValue(src);
self.editor.clearSelection();
// Manually trigger resize to fix scroll bar locations
self.editor.resize();
// helper to scroll to a line
function scrollTo(line, animated) {
// Give file time to render before attempting scroll to prevent
// scrolling from beyond the top of the document (just trust me,
// without this files short enough to have no scroll slide in
// weird from the top)
setTimeout(function() {
self.editor.scrollToLine(line, false, animated);
},50);
}
// If there was no highlight, we're done
if (!highlightString) {
scrollTo(0, false);
return self.$editor.removeClass('saurus-highlighted');
}
// Scroll to the first highlighted line
self.$editor.addClass('saurus-highlighted');
var highlightParts = highlightString.split(',');
var firstLine = Number(highlightParts[0].split('-')[0])-4;
if (firstLine < 0) firstLine = 0;
scrollTo(firstLine, true);
}
});
module.exports = CodeView;
},{}],8:[function(require,module,exports){
var explorerWidth = -270;
var autoShowExplorer = 1280;
// Helper to generate an HTML string for a leaf file in the explorer
function createFileListItem(fileName, fullPath) {
// create truncated file name
var truncFileName = fileName;
if (truncFileName.length > 30) {
truncFileName = '...' + fileName.substring(fileName.length-30);
}
var html = '<li class="saurus-explorer-file" data-file="' + fullPath + '">';
html += '<i class="fa fa-fw fa-file-text-o"></i> '
+ truncFileName + '</li>';
return html;
}
var ExplorerView = Backbone.View.extend({
// Mount on the Explorer section
el: '#viewsaurus .saurus-explorer',
events: {
'click .saurus-explorer-file': 'selectFile'
},
// Initialize UI
initialize: function(options) {
var self = this;
// Store a reference to main app model
self.app = options.app;
// Grab useful DOM chunks
self.$inner = self.$el.find('.saurus-file-list');
self.$files = $('#viewsaurus .saurus-file');
self.$steps = $('#viewsaurus .saurus-content .step');
// Subscribe to model updates
self.app.on('change:explorerShown', self.toggleExplorer, self);
self.app.on('change:stepIndex', self.selectCurrent, self);
// Populate file explorer
self.createExplorer();
// Check initial size of Viewsaurus to see if the explorer should be
// initially open
_.defer(function() {
if ($('#viewsaurus').outerWidth() >= autoShowExplorer) {
self.app.set('explorerShown', true);
}
});
},
// Create file explorer contents
createExplorer: function() {
var self = this;
// Collect file data
var folderPaths = [], leafPaths = [], folders = {};
self.$files.each(function() {
var $file = $(this);
var p = $file.attr('data-file');
var parts = p.split(/[\/\\]/);
if (parts.length > 1) {
folderPaths.push(p);
} else {
leafPaths.push(p);
}
});
folderPaths.sort();
leafPaths.sort();
// collect files into common folders
for (var i = 0, l = folderPaths.length; i<l; i++) {
var filePath = folderPaths[i];
var currentPath = filePath.split(/[\/\\]/);
var leaf = currentPath.pop();
var folderPath = currentPath.join('/');
if (!folders[folderPath]) folders[folderPath] = [];
folders[folderPath].push({
fileName: leaf,
fullPath: filePath
});
}
var html = '<ul>';
// Iterate folders to create HTML structure
for (var folder in folders) {
html += '<li class="saurus-explorer-folder">';
html += '<i class="fa fa-fw fa-folder-o"></i>';
html += ' ' + folder + '<ul>';
var files = folders[folder];
for (var i = 0, l = files.length; i<l; i++) {
var fileData = files[i];
html += createFileListItem(fileData.fileName,
fileData.fullPath);
}
html += '</ul></li>';
}
// Iterate leaf files
for (var i = 0, l = leafPaths.length; i<l; i++) {
html += createFileListItem(leafPaths[i], leafPaths[i]);
}
html += '</ul>';
self.$inner.html(html);
},
// show/hide the explorer
toggleExplorer: function() {
var self = this;
var offset = self.app.get('explorerShown') ? 0 : explorerWidth;
self.$el.animate({
right: offset
});
},
// Highlight the currently selected file based on step index
selectCurrent: function() {
var self = this;
// Get file for current step
var $step = self.$steps.eq(self.app.get('stepIndex'));
var stepFile = $step.attr('data-file');
// Highlight current step file or keep current selection
if (stepFile) {
var $file = self.$el.find('li[data-file="' + stepFile + '"]');
self.$el.find('li').removeClass('current');
$file.addClass('current');
}
},
// Manually select a file from the explorer
selectFile: function(e) {
var self = this;
var $selected = $(e.target);
self.app.set('currentFile', $selected.attr('data-file'));
self.$el.find('li').removeClass('current');
$selected.addClass('current');
}
});
module.exports = ExplorerView;
},{}],9:[function(require,module,exports){
// Get Title for a step either from a data attribute or the first title tag
function titleForStep($e) {
var title = $e.attr('data-title');
if (!title) title = $e.find('h1, h2, h3, h4, h5').first().text();
return title;
}
// Represent UI state for prose view
var ProseModel = Backbone.Model.extend({
defaults: {
overviewShown: false
}
});
// Prose View - manages currently visible prose and tutorial overview
var ProseView = Backbone.View.extend({
// Mount on the prose section
el: '#viewsaurus .saurus-prose',
// track if start event was fired
startFired: false,
// track whether or not the last step has been reached
lastStepReached: false,
// UI events
events: {
'click .nav-overview': 'toggleOverview',
'click .saurus-overview a': 'toggleOverview',
'click .saurus-start a': 'hideStart',
'click .saurus-content img': 'showLightbox',
'click .nav-previous': 'previous',
'click .nav-next': 'next'
},
// Initialize UI
initialize: function (options) {
var self = this;
// Store a reference to main app model and create view model
self.app = options.app;
self.model = new ProseModel();
// Grab references to useful nodes
self.$next = self.$el.find('.nav-next');
self.$previous = self.$el.find('.nav-previous');
self.$overviewNav = self.$el.find('.nav-overview i');
self.$content = self.$el.find('.saurus-content');
self.$overviewContent = self.$el.find('.saurus-overview');
self.$total = self.$el.find('.total');
self.$title = self.$el.find('.step-title');
self.$overviewList = self.$el.find('.saurus-overview ul');
self.$progressBar = self.$el.find('.saurus-progress-bar');
self.$nextTitle = self.$el.find('.next-title-inner');
self.$start = self.$el.find('.saurus-start');
// Populate overview from tutorial data in the dom
self.populateOverview();
// Determine the initial next step title
self.showNextStep(1);
// On any history event, we want to hide the start screen
Backbone.history.on('all', self.hideStart, self);
// Subscribe to model updates
self.app.on('change:stepIndex', self.stepChanged, self);
self.model.on('change:overviewShown', self.overviewChanged, self);
},
// Analytics - fire event on main app for next/previous
next: function () {
var self = this;
self.app.trigger('next');
},
previous: function () {
var self = this;
self.app.trigger('previous');
},
// Show a lightbox when an image is clicked
showLightbox: function (e) {
var $img = $(e.currentTarget);
$.featherlight($img.attr('src'));
},
// Hide the initial start prompt
hideStart: function () {
var self = this;
if (!self.startFired) {
// Defer to allow page listeners to register
_.defer(function () {
self.app.trigger('start');
});
self.startFired = false;
}
self.$start.fadeOut();
},
// Show the next step title
showNextStep: function (index) {
var self = this;
var text = "You did it! Good for you :)";
if (index < self.app.totalSteps) {
var $next = self.$content.find('.step').eq(index);
var truncated = titleForStep($next).substring(0, 35);
if (truncated.length > 34) {
truncated += '...';
}
text = 'Next: ' + truncated;
}
self.$nextTitle.html(text);
},
// toggle overview shown on view model on button click
toggleOverview: function () {
var self = this;
if (!self.model.get('overviewShown')) {
self.app.trigger('show_overview');
}
self.model.set('overviewShown', !self.model.get('overviewShown'));
},
// Handle an updated step
stepChanged: function () {
var self = this;
var stepIndex = self.app.get('stepIndex');
var $step = self.$el.find('.step').eq(stepIndex);
// Update next step text
self.showNextStep(stepIndex + 1);
// Hide overview if it is showing
self.model.set('overviewShown', false);
// Update progress bar
self.$progressBar.animate({
width: (((stepIndex + 1) / self.app.totalSteps) * 100) + '%'
});
// Update to the proper prose section
self.$el.find('.step').hide();
$step.show();
self.$content.scrollTop(0);
// Update section title
// self.$title.html($step.attr('data-title'));
// Update current link in overview
self.$overviewList.find('li').removeClass('current');
self.$overviewList.find('li[data-step="' + stepIndex + '"]')
.addClass('current');
// Update next nav link
if (self.app.hasNext()) {
self.$next.addClass('clickable')
.find('a').attr('href', '#' + (self.app.get('stepIndex') + 1));
} else {
// If there's no next step, we've reached the end for the first time
if (!self.lastStepReached) {
self.lastStepReached = true;
self.app.trigger('project_completed');
}
self.$next.removeClass('clickable')
.find('a').attr('href', '#' + self.app.get('stepIndex'));
}
// Update previous nav link
if (self.app.hasPrevious()) {
self.$previous.addClass('clickable')
.find('a').attr('href', '#' + (self.app.get('stepIndex') - 1));
} else {
self.$previous.removeClass('clickable')
.find('a').attr('href', '#0');
}
if (window.GAClient) {
var currentStep = stepIndex + 1;
window.GAClient.trackPage(location.href, ((currentStep / self.app.totalSteps).toFixed(3) * 100) + '%', currentStep, self.app.totalSteps);
}
},
// Handle overview show/hide
overviewChanged: function () {
var self = this;
var shown = self.model.get('overviewShown');
if (shown) {
self.$overviewContent.animate({
left: 0
});
self.$overviewNav.addClass('fa-close')
.removeClass('icon-menu');
} else {
self.$overviewContent.animate({
left: '-100%'
});
self.$overviewNav.removeClass('fa-close')
.addClass('icon-menu');
}
},
// populate overview from data in the DOM
populateOverview: function () {
var self = this;
var html = '';
var firstChapter = true;
var stepIndex = 0;
// Iterate over chapters, extract data, build overview HTML
self.$content.find('.chapter, .step').each(function () {
var $thing = $(this);
if ($thing.hasClass('chapter')) {
if (!firstChapter) {
// end previous chapter
html += '</ul></li>';
}
firstChapter = false;
html += '<li class="chapter"><span>';
html += $thing.attr('data-title') + '</span><ul>';
} else {
html += '<li data-step="' + stepIndex + '">';
html += '<a href="#' + stepIndex + '">';
html += titleForStep($thing) + '</a></li>';
stepIndex++;
}
});
// close off final chapter li
html += '</ul></li>';
// Append generated overview HTML
self.$overviewList.html(html);
}
});
module.exports = ProseView;
},{}],10:[function(require,module,exports){
var ProseView = require('./ProseView');
var CodeView = require('./CodeView');
var ExplorerView = require('./ExplorerView');
// Main Viewsaurus app view
var ViewsaurusView = Backbone.View.extend({
// Initialize UI
initialize: function(options) {
var self = this;
// Store a reference to main app model
this.app = options.app;
// Create sub views
self.proseView = new ProseView({ app: options.app });
self.codeView = new CodeView({ app: options.app });
self.explorerView = new ExplorerView({ app: options.app });
}
});
module.exports = ViewsaurusView;
},{"./CodeView":7,"./ExplorerView":8,"./ProseView":9}]},{},[5]);