-
Notifications
You must be signed in to change notification settings - Fork 16
/
index.html
8855 lines (7926 loc) · 411 KB
/
index.html
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
993
994
995
996
997
998
999
1000
<html lang="en">
<head>
<title>ChiliPepr - Hardware Fiddle</title>
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
<script async="" src="//www.google-analytics.com/analytics.js"></script><script src="js/require.js"></script>
<script type="text/javascript">
cprequire(["chilipeppr_ready"], function() {
console.log("seeing if chilipeppr is globally defined...");
console.log(chilipeppr);
chilipeppr.load("root", "http://fiddle.jshell.net/chilipeppr/2H9us/show/light/");
});
</script>
<script type="text/javascript" charset="utf-8" async="" data-requirecontext="_" data-requiremodule="jquery" src="//code.jquery.com/jquery-2.1.0.min.js"></script><script type="text/javascript" charset="utf-8" async="" data-requirecontext="_" data-requiremodule="bootstrap" src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script><script type="text/javascript" charset="utf-8" async="" data-requirecontext="_" data-requiremodule="amplify" src="//www.chilipeppr.com/js/amplify-1.1.2/amplify.js"></script><script type="text/javascript" charset="utf-8" async="" data-requirecontext="_" data-requiremodule="chilipeppr_init" src="//www.chilipeppr.com/js/app.js"></script><script type="text/javascript" charset="utf-8" async="" data-requirecontext="_" data-requiremodule="google" src="//www.google-analytics.com/analytics.js"></script><script type="text/javascript" charset="utf-8" async="" data-requirecontext="_" data-requiremodule="chilipeppr_init2" src="//www.chilipeppr.com/js/app2.js"></script><script type="text/javascript" charset="utf-8" async="" data-requirecontext="_" data-requiremodule="chilipeppr_ready" src="//www.chilipeppr.com/js/main.js"></script><script type="text/javascript" charset="utf-8" async="" data-requirecontext="_" data-requiremodule="jquerycookie" src="//www.chilipeppr.com/js/jquery-cookie/jquery.cookie.js"></script><script type="text/javascript" charset="utf-8" async="" data-requirecontext="_" data-requiremodule="jqueryui" src="//chilipeppr.com/js/jquery-ui-1.10.4/ui/jquery.ui.core.js"></script><script type="text/javascript" charset="utf-8" async="" data-requirecontext="_" data-requiremodule="Three" src="http://threejs.org/build/three.min.js"></script><script type="text/javascript" charset="utf-8" async="" data-requirecontext="_" data-requiremodule="ThreeDetector" src="http://threejs.org/examples/js/Detector.js"></script><script type="text/javascript" charset="utf-8" async="" data-requirecontext="_" data-requiremodule="waypoints" src="//cdnjs.cloudflare.com/ajax/libs/waypoints/2.0.4/waypoints.min.js"></script><script type="text/javascript" charset="utf-8" async="" data-requirecontext="_" data-requiremodule="jqueryuiWidget" src="//chilipeppr.com/js/jquery-ui-1.10.4/ui/jquery.ui.widget.js"></script><script type="text/javascript" charset="utf-8" async="" data-requirecontext="_" data-requiremodule="jqueryuiMouse" src="//chilipeppr.com/js/jquery-ui-1.10.4/ui/jquery.ui.mouse.js"></script><script type="text/javascript" charset="utf-8" async="" data-requirecontext="_" data-requiremodule="jqueryuiResizeable" src="//chilipeppr.com/js/jquery-ui-1.10.4/ui/jquery.ui.resizable.js"></script><link type="text/css" rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css"><script type="text/javascript" charset="utf-8" async="" data-requirecontext="_" data-requiremodule="ThreeTrackballControls" src="//threejs.org/examples/js/controls/TrackballControls.js"></script><script type="text/javascript" charset="utf-8" async="" data-requirecontext="_" data-requiremodule="ThreeTween" src="http://www.chilipeppr.com/js/three/tween.min.js"></script></head>
<body><!-- start chilipeppr.load() url: http://fiddle.jshell.net/chilipeppr/zMbL9/show/light/ -->
<style type="text/css">
</style>
<div class="modal fade " id="com-chilipeppr-elem-pubsubviewer-modal" tabindex="-1" role="dialog">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">Modal title</h4>
</div>
<div class="modal-body">
<table class="table table-bordered table-striped">
<!-- <thead>
<tr>
<th style="">Signal</th>
<th style="">Description</th>
</tr>
</thead> -->
<tbody>
<tr>
<td>ID</td>
<td class="pubsub-id">
com-chilipeppr-widget-tinyg
</td>
</tr>
<tr>
<td>Standalone URL</td>
<td class="pubsub-url">
http://fiddle.jshell.net/chilipeppr/zMbL9/show/light/
</td>
</tr>
<tr>
<td>Fiddle URL</td>
<td class="pubsub-fiddleurl">
http://jsfiddle.net/chilipeppr/zMbL9/
</td>
</tr>
<tr>
<td>Description</td>
<td class="pubsub-desc">
This element shows a modal of a widget's/element's pubsub so the user can see how this widget/element interacts with other widgets/elements.
</td>
</tr>
</tbody>
</table>
<div class="pubsub-interface hidden">
<h4>Interface Implementation</h4>
<p>This widget/element implements an interface specification. Since Javascript does not have the notion of interfaces like the way languages such as Java have native support for interfaces, ChiliPeppr has defined its own loose version of an interface. If this widget/element has implemented an interface, it means it has followed a general standard set of pubsub signals that other widgets/elements should follow as well to make them swappable.</p>
<table id="com-chilipeppr-elem-pubsubviewer-interface" class="table table-bordered table-striped">
<thead>
<tr>
<th style="">Interface Implementation</th>
<th style="">Description</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div><!-- interface -->
<h4>Publish</h4>
<p>This widget/element publishes the following signals. These signals are owned by this widget/element and are published to all objects inside the ChiliPeppr environment that listen to them via the chilipeppr.subscribe(signal, callback) method.</p>
<table id="com-chilipeppr-elem-pubsubviewer-pub" class="table table-bordered table-striped">
<thead>
<tr>
<th style="">Signal</th>
<th style="">Description</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
<h4>Subscribe</h4>
<p>This widget/element subscribes to the following signals. These signals are owned by this widget/element. Other objects inside the ChiliPeppr environment can publish to these signals via the chilipeppr.publish(signal, data) method.</p>
<table id="com-chilipeppr-elem-pubsubviewer-sub" class="table table-bordered table-striped">
<thead>
<tr>
<th style="">Signal</th>
<th style="">Description</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
<h4>Foreign Publish</h4>
<p>This widget/element publishes to the following signals that are owned by other objects.</p>
<table id="com-chilipeppr-elem-pubsubviewer-foreignpub" class="table table-bordered table-striped">
<thead>
<tr>
<th style="">Signal</th>
<th style="">Description</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
<h4>Foreign Subscribe</h4>
<p>This widget/element subscribes to the following signals owned by other objects.</p>
<table id="com-chilipeppr-elem-pubsubviewer-foreignsub" class="table table-bordered table-striped">
<thead>
<tr>
<th style="">Signal</th>
<th style="">Description</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal" data-original-title="" title="">Close</button>
<!-- <button type="button" class="btn btn-primary">Save changes</button> -->
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<script type="text/javascript">//<![CDATA[
cpdefine("inline:com-chilipeppr-elem-pubsubviewer", ["chilipeppr_ready"], function () {
return {
id: "com-chilipeppr-elem-pubsubviewer",
url: "http://fiddle.jshell.net/chilipeppr/zMbL9/show/light/",
fiddleurl: "http://jsfiddle.net/chilipeppr/zMbL9/",
name: "Element / Pubsub Viewer",
desc: "This element shows a modal of a widget's/element's pubsub so the user can see how this widget/element interacts with other widgets/elements.",
isInitted: false,
init: function () {
//var that = this;
$('#com-chilipeppr-elem-pubsubviewer-modal').on('show.bs.modal', this.onShow.bind(this));
$('#com-chilipeppr-elem-pubsubviewer-modal').on('hidden.bs.modal', function (e) {
console.log("modal hidden");
})
//this.show();
this.isInitted = true;
console.log(this.name + " done initting.");
},
cpobject: null, // the object we're showing pubsub for
pubsubClick: function(evt) {
console.log("got pubsub click in dropdown. evt:", evt);
if (evt.data) {
console.log("evt had correct object so showing modal:", evt.data);
this.show(evt.data);
}
},
show: function(cpobject) {
this.cpobject = cpobject;
if (!this.isInitted) this.init();
$('#com-chilipeppr-elem-pubsubviewer-modal').modal('show');
},
onShow: function() {
console.log("modal show pre");
var o = this.cpobject;
$('#com-chilipeppr-elem-pubsubviewer-modal .modal-title')
.text("PubSub Viewer for \"" +
o.name + "\"");
// do pre-amble info
$('#com-chilipeppr-elem-pubsubviewer-modal .pubsub-id').html(o.id);
$('#com-chilipeppr-elem-pubsubviewer-modal .pubsub-url').html('<a href="' + o.url + '" target="_blank">' + o.url + '</a>');
$('#com-chilipeppr-elem-pubsubviewer-modal .pubsub-fiddleurl').html('<a href="' + o.fiddleurl + '" target="_blank">' + o.fiddleurl + '</a>');
$('#com-chilipeppr-elem-pubsubviewer-modal .pubsub-desc').html(o.desc);
// do interface implementations
if (o.implements && o.implements != null) {
$('#com-chilipeppr-elem-pubsubviewer-modal .pubsub-interface').removeClass('hidden');
$('#com-chilipeppr-elem-pubsubviewer-modal #com-chilipeppr-elem-pubsubviewer-interface > tbody > tr').remove();
if (Object.keys(o.implements).length > 0) {
var keys = Object.keys(o.implements);
$.each(keys, function(i, key) {
$('#com-chilipeppr-elem-pubsubviewer-modal #com-chilipeppr-elem-pubsubviewer-interface > tbody').append('<tr><td>' + key + '</td><td>' + o.implements[key] + '</td></tr>');
});
}
} else {
// hide the interface section
$('#com-chilipeppr-elem-pubsubviewer-modal .pubsub-interface').addClass('hidden');
}
// do publish
this.appendKeyVal(o.publish, "#com-chilipeppr-elem-pubsubviewer-pub");
this.appendKeyVal(o.subscribe, "#com-chilipeppr-elem-pubsubviewer-sub");
this.appendKeyVal(o.foreignPublish, "#com-chilipeppr-elem-pubsubviewer-foreignpub");
this.appendKeyVal(o.foreignSubscribe, "#com-chilipeppr-elem-pubsubviewer-foreignsub");
},
appendKeyVal: function(data, id) {
// remove rows from previous rendering
$('#com-chilipeppr-elem-pubsubviewer-modal ' + id + ' > tbody > tr').remove();
if (data !== null && typeof data === 'object' && Object.keys(data).length > 0) {
var keys = Object.keys(data);
$.each(keys, function(i, key) {
$('#com-chilipeppr-elem-pubsubviewer-modal ' + id + ' > tbody').append('<tr><td>' + key + '</td><td>' + data[key] + '</td></tr>');
});
} else {
$('#com-chilipeppr-elem-pubsubviewer-modal ' + id + ' > tbody').append('<tr><td colspan="2">(No signals defined in this widget/element)</td></tr>');
}
},
attachTo: function(dropdownMenuEl, cpobject, altTitle) {
var el = dropdownMenuEl;
var o = cpobject;
// this method let's you pass in a dropdown-menu
// and we'll attach a new section with a divider,
// the id of the widget, a link to the pubsub vieweer,
// a linke to the standalone widget, and a link to fork
// the widget
// see if there's any <li> items. if there are add a divider
// <li class="divider"></li>
if (el.children('li').length > 0) {
// has li's, so add divider
el.append('<li class="divider"></li>');
}
// allow user to override the name Widget, i.e. set it to Workspace or Element
var title = "Widget";
if (altTitle != null && altTitle.length > 0) title = altTitle;
/*
<li role="presentation" class="dropdown-header fork-name"></li>
<li><a href="" target="_blank" class="standalone">View Widget Standalone</a></li>
<li><a href="" target="_blank" class="fork">Fork Widget</a></li>
*/
el.append('<li role="presentation" class="dropdown-header fork-name">' + o.id + '</li>');
var pslink = $('<li><a href="javascript:" class="pubsublink">PubSub for this ' + title + '</a></li>').click(o, this.pubsubClick.bind(this));
el.append(pslink);
el.append('<li><a href="' + o.url + '" target="_blank" class="standalone">View ' + title + ' Standalone</a></li>');
var fork = $('<li><a href="' + o.fiddleurl + '" target="_blank" class="fork">Fork ' + title + '</a></li>').click(o, function() {
console.log("Got fork click. object:", o);
ga('send', 'event', 'button', 'click', 'fork' + title + '-' + o.id );
});
el.append(fork);
el.children('.panel-title').popover({
title: this.name,
content: this.desc,
html: true,
delay: 200,
animation: true,
trigger: 'hover',
placement: 'auto'
});
}
}
});
//]]>
</script>
<!-- end chilipeppr.load() url: http://fiddle.jshell.net/chilipeppr/zMbL9/show/light/ -->
<div id="root"><!-- start chilipeppr.load() url: http://fiddle.jshell.net/chilipeppr/2H9us/show/light/ -->
<style type="text/css">
#pnlBody .container-fluid {
}
#pnlBody .pnlWorkspaceRtSidebarCollapsed {
/* padding-right: 45px; */
padding-right: 10px;
}
#pnlBody .pnlWorkspaceRtSidebarExpanded {
padding-right: 0;
}
#pnlRtSidebar {
position: relative;
}
#pnlWorkspace {
padding-left: 10px;
}
</style>
<script type="text/javascript">//<![CDATA[
// Make sure ChiliPeppr is ready to run and fully instantiated
// including all of its dependencies like jquery, bootstrap, etc.
cprequire(["chilipeppr_ready"], function () {
// Element / Flash Message
// http://jsfiddle.net/jlauer/qp7Em/
// "inline:com-chilipeppr-elem-flashmsg"
chilipeppr.load("#com-chilipeppr-flash",
"http://fiddle.jshell.net/jlauer/qp7Em/show/light/",
function () {
console.log("mycallback got called after loading flash msg module");
console.log(chilipeppr);
require(["inline:com-chilipeppr-elem-flashmsg"], function (fm) {
//console.log("inside require of " + fm.id);
fm.init();
//console.log(fm.publish);
//chilipeppr.publish(fm.subscribe, "Loaded", "The ChiliPeppr Hardware Fiddle main app is loaded.");
//chilipeppr.publish(fm.subscribe, "", "The ChiliPeppr Hardware Fiddle main app is loaded.");
//chilipeppr.publish(fm.subscribe, "", "Third time is a charm");
//console.log(fm);
// Panel / Header
//http://jsfiddle.net/chilipeppr/7aX6x/
chilipeppr.load(
"#pnlHeader",
"http://fiddle.jshell.net/chilipeppr/7aX6x/show/light/",
function () {
//setTimeout(function() {
cprequire(
["inline:com-chilipeppr-hdr"],
function (hdr) {
console.log("running of " + hdr.id);
hdr.init();
// LOAD THE WORKSPACE NOW
// Now analyze the window.location URL and load the base boot Javascript
// for this particular url from the data storage
console.log("window.location", window.location.pathname);
var path = window.location.pathname;
if (path == "/_display/") {
// we're inside jsfiddle, so pretend root
path = "";
} else {
path = path.replace(/^\//, "");
path = path.replace(/\/$/, "");
}
console.log("path of this workspace:", path);
var jqxhr = $.getJSON("http://www.chilipeppr.com/dataget?key=userUrl:" + path + "&callback=?")
.done(function (data) {
console.log("got jsnop callback", data);
if (data.KeyExists != undefined && data.KeyExists == false) {
console.log("this is a url that doesn't exist. show modal to define page.");
//chilipeppr.publish("/com-chilipeppr-elem-flashmsg/flashmsg", "No Workspace Exists Here", "You can go ahead and create a workspace here.");
$('#pnlWorkspace').text("No workspace exists at \"" + path + "\", therefore you may use it by clicking Edit Boot Javascript from the upper right corner menu.");
// Load the edit boot dialog
//cprequire(["inline:com-chilipeppr-hdr"], function(hdr) {
hdr.editBoot();
//});
} else if (data.Error && data.Error == true) {
//chilipeppr.publish("/com-chilipeppr-elem-flashmsg/flashmsg", "Error Retrieving Workspace", data.Msg);
$('#pnlWorkspace').text("Error retrieving workspace. " + data.Msg);
} else {
var p = path;
if (p == "") p = "(Default)";
$('#pnlWorkspace').text("Loading the workspace for path " + p + "...");
chilipeppr.publish("/com-chilipeppr-elem-flashmsg/flashmsg", "Loading Workspace", "Loading the workspace for path " + p + "...");
eval(data.Value);
}
})
.fail(function (data) {
console.log("failed. data:", data);
$('#pnlWorkspace').text("Error retrieving workspace. " + JSON.stringify(data));
})
});
//}, 1000);
});
});
});
/*
chilipeppr.load("pnlRtSidebar",
"http://fiddle.jshell.net/jlauer/WXN8J/show/light/");
*/
});
//]]>
</script>
<div id="pnlHeader"><!-- start chilipeppr.load() url: http://fiddle.jshell.net/chilipeppr/7aX6x/show/light/ -->
<style type="text/css">
#mainnav {
margin-bottom: 10px;
}
.com-chilipeppr-mainnav .navbar-collapse {
/* height:30px; */
}
a.navbar-brand.main-brand {
color:#bebebe;
padding-right:10px;
}
a.navbar-brand.subbrand {
margin-bottom:0;
padding-left:10px;
}
/* .nav li:hover{
color: #555;
background-color: #e7e7e7;
} */
</style>
<script type="text/javascript">//<![CDATA[
// //www.google-analytics.com/analytics.js
requirejs.config({
paths: {
google: '//www.google-analytics.com/analytics'
}
});
cpdefine("inline:com-chilipeppr-hdr", ["chilipeppr_ready", "google"], function (cp, google) {
return {
id: "com-chilipeppr-hdr",
url: "http://fiddle.jshell.net/jlauer/Qheec/show/light/",
fiddleurl: "http://jsfiddle.net/jlauer/Qheec/",
name: "Widget / Header",
desc: "This widget is the header panel.",
publish: null,
subscribe: null,
isConnected: false,
init: function () {
this.setupLinks();
this.checkLogin();
this.editBootSetup();
//this.doAnalytics();
//this.editBoot();
console.log(this.name + " done loading.");
},
doFork: function() {
//this.editBoot();
cprequire(['inline:com-chilipeppr-widget-editbootscript'], function (editboot) {
console.log("Since we're reopening edit boot dialog in fork mode, need to tell it");
editboot.init();
editboot.doFork();
$('#com-chilipeppr-hdr-editbootmodal').modal({show: true});
//console.log("re-initted");
});
},
editBootSetup: function() {
var that = this;
chilipeppr.load("com-chilipeppr-hdr-editbootmodalbody", "http://fiddle.jshell.net/chilipeppr/uNALR/show/light/", function () {
console.log("Done lazy loading edit boot jscript content");
$("#com-chilipeppr-topbar-menu-editboot").click(that.editBoot);
});
},
editBoot: function() {
console.log("editing boot");
cprequire(['inline:com-chilipeppr-widget-editbootscript'], function (editboot) {
console.log("Since we're reopening edit boot dialog, reinitting");
editboot.init();
$('#com-chilipeppr-hdr-editbootmodal').modal({show: true});
console.log("re-initted");
});
},
currentUser: null,
checkLogin: function () {
var that = this;
var jqxhr = $.getJSON("http://www.chilipeppr.com/datalogin?callback=?")
.done(function (data) {
console.log(data);
if (data.CurrentUser != undefined && data.CurrentUser != null) {
console.log("user logged in ", data.CurrentUser);
that.currentUser = data.CurrentUser;
$('#com-chilipeppr-hdr-login').text(data.CurrentUser.Email);
$('#com-chilipeppr-hdr-dd-login').addClass("hidden");
$('#com-chilipeppr-hdr-dd-logout').prop('href', data.LogoutUrl);
// if they click their login id log them out
$('#com-chilipeppr-hdr-login').prop('href', data.LogoutUrl);
} else {
console.log("user NOT logged in");
$('#com-chilipeppr-hdr-login').text("Login");
$('#com-chilipeppr-hdr-dd-login').removeClass("hidden");
$('#com-chilipeppr-hdr-dd-logout').addClass("hidden");
$('#com-chilipeppr-hdr-dd-login').prop('href', data.LoginUrl);
$('#com-chilipeppr-hdr-dd-login').prop('target', "new");
$('#com-chilipeppr-hdr-login').prop('href', data.LoginUrl);
$('#com-chilipeppr-hdr-login').prop('target', "new");
}
that.doAnalytics();
})
.fail(function () {
that.doAnalytics();
})
},
doAnalytics: function() {
//console.log("Doing Google Analytics");
//console.log("google:", google, "ga:", ga);
ga('create', 'UA-51962619-1', 'chilipeppr.com');
ga('require', 'displayfeatures');
// Set the user ID using signed-in user_id.
//console.log("currentUser", this.currentUser);
if (this.currentUser != undefined
&& this.currentUser != null
&& this.currentUser.Email != undefined
&& this.currentUser.Email != null) {
//console.log("Passing user id to Google");
ga('set', '&uid', this.currentUser.Email);
}
ga('send', 'pageview');
// resend this every 15 mins
setTimeout(this.doAnalytics.bind(this), 15 * 60 * 1000);
},
setupLinks: function () {
$('#com-chilipeppr-hdr-wspick').click(this.onWsPick);
var that = this;
$('#com-chilipeppr-topbar-menu-forkws').click(function() {
that.doFork();
});
},
onWsPick: function () {
console.log("Got into onWsPick");
// lazy load the picker
chilipeppr.load("#com-chilipeppr-hdr-modalbody", "http://fiddle.jshell.net/chilipeppr/8UwSX/show/light/", function () {
console.log("Done lazy loading workspace picker content");
});
}
}
});
//]]>
</script>
<nav id="mainnav" class="com-chilipeppr-mainnav navbar navbar-default" role="navigation">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1"> <span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button> <a class="navbar-brand main-brand" href="http://chilipeppr.com/"><img src="http://www.chilipeppr.com/img/chilipeppr_logo.png" style="max-height:22px;padding-right:3px;">ChiliPeppr</a> <a class="navbar-brand subbrand" href="http://chilipeppr.com/">Hardware Fiddle</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li class=""><a id="com-chilipeppr-hdr-wspick" href="#" data-toggle="modal" data-target="#com-chilipeppr-hdr-wspickmodal">Workspaces</a>
</li>
</ul>
<form class="navbar-form navbar-left" role="search">
<!-- <div class="form-group">
<input type="text" class="form-control" placeholder="Search" />
</div> -->
<!-- <button type="submit" class="btn btn-default">Submit</button> -->
</form>
<ul class="nav navbar-nav navbar-right">
<li><a id="com-chilipeppr-hdr-login" href="http://www.chilipeppr.com/_ah/logout?continue=https://www.google.com/accounts/Logout%3Fcontinue%3Dhttps://appengine.google.com/_ah/logout%253Fcontinue%253Dhttp://www.chilipeppr.com/%26service%3Dah" style="padding-right:5px;">[email protected]</a>
</li>
<li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown" style="padding-left:5px;"> <b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a id="com-chilipeppr-hdr-dd-login" href="javascript:" class="hidden">Login</a>
</li>
<li><a id="com-chilipeppr-hdr-dd-logout" href="http://www.chilipeppr.com/_ah/logout?continue=https://www.google.com/accounts/Logout%3Fcontinue%3Dhttps://appengine.google.com/_ah/logout%253Fcontinue%253Dhttp://www.chilipeppr.com/%26service%3Dah">Logout</a>
</li>
<!-- <li><a id="com-chilipeppr-hdr-dd-yourws" href="javascript:">Your Workspaces</a>
</li> -->
<li class="divider"></li>
<li><a href="javascript:" id="com-chilipeppr-topbar-menu-editboot">Edit Boot Javascript</a>
</li>
<li class="divider"></li>
<li><a href="javascript:" id="com-chilipeppr-topbar-menu-forkws">Fork Boot Script</a>
</li>
<!-- <li><a href="javascript:">Create New Workspace</a>
</li> -->
</ul>
</li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container-fluid -->
</nav>
<!-- Workspace Picker Modal -->
<!-- Modal -->
<div class="modal fade" id="com-chilipeppr-hdr-wspickmodal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title" id="myModalLabel">Workspace Picker</h4>
</div>
<div class="modal-body" id="com-chilipeppr-hdr-modalbody">...</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal" data-original-title="" title="">Close</button>
<!-- <button type="button" class="btn btn-primary">Save changes</button> -->
</div>
</div>
</div>
</div>
<!-- End Workspace Picker Modal -->
<!-- Edit Boot Javascript Modal -->
<div class="modal fade" id="com-chilipeppr-hdr-editbootmodal" tabindex="-1" role="dialog" aria-labelledby="editboot-myModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title" id="editboot-myModalLabel">Edit Boot Javascript</h4>
</div>
<div class="modal-body" id="com-chilipeppr-hdr-editbootmodalbody"><!-- start chilipeppr.load() url: http://fiddle.jshell.net/chilipeppr/uNALR/show/light/ -->
<style type="text/css">
.modal-body #com-chilipeppr-widget-editbootscript-body {
padding:0;
}
#com-chilipeppr-widget-editbootscript-body .alert {
margin-top:0;
}
</style>
<div id="com-chilipeppr-widget-editbootscript-body" class="panel-body">
<form role="form">
<div class="form-group">
<div id="forking-panel" class="well hidden"></div>
<div class="alert alert-warning hidden"></div>
<label for="inputUrl">URL</label>
<table>
<tbody><tr>
<td>http://chilipeppr.com/ </td>
<td>
<input type="text" class="form-control" id="com-chilipeppr-widget-editbootscript-inputUrl" placeholder="Pick your URL">
</td>
</tr>
</tbody></table>
</div>
<div class="form-group">
<label for="com-chilipeppr-widget-editbootscript-inputScript">Base Boot Javascript</label>
<textarea id="com-chilipeppr-widget-editbootscript-inputScript" class="form-control" rows="5"></textarea>
</div>
<div id="com-chilipeppr-widget-editbootscript-inputScriptExample" class="hidden">// Sample Base Boot Javascript
// ----------------------
// You should create a JSFiddle that loads your content
// by forking an existing workspace to get started. Then
// you can also fork any widgets, elements, or other
// JSFiddles that you need to modify so that others can
// benefit from your modifications.
// The chilipeppr.load() method is used to load a
// JSFiddle and inject it's HTML (inluding its
// CSS/Javascript) into a DOM element. The first
// parament must be the HTML ID of the DOM element.
chilipeppr.load("pnlWorkspace",
// Edit URL below to your JSFiddle
"http://fiddle.jshell.net/myfiddlenuser/n3DLs/show/light/", function() {
console.log("My workspace done loading.");
// This is an example of publishing to the flash message
// feature that is loaded by the root panel. Chilipeppr
// Hardware Fiddle recommends you loosely couple your
// widgets/elements by using the pubsub calls built
// into the top-level chilipeppr object.
// Parameters: pubsub-channel (string), title (string), body (string)
chilipeppr.publish("/com-chilipeppr-elem-flashmsg/flashmsg", "My Workspace Loaded", "I just loaded my workspace.");
// You can run other code here once your workspace is loaded
// however it's more likely you will run init() code inside each
// of your widgets inside your workspace JSFiddle rather than here
}
);</div>
<button id="com-chilipeppr-widget-editbootscript-submitBtn" class="btn btn-primary pull-right" data-original-title="" title="">Save Changes</button>
</form>
</div>
<script type="text/javascript">//<![CDATA[
cpdefine('inline:com-chilipeppr-widget-editbootscript', ['chilipeppr_ready'], function () {
return {
id: 'com-chilipeppr-widget-editbootscript',
url: "http://fiddle.jshell.net/chilipeppr/uNALR/show/light/",
fiddleurl: "http://jsfiddle.net/chilipeppr/uNALR/",
name: "Widget / Edit Boot Javascript",
desc: "This widget lets you define your base Javascript that gets executed when your URL is entered. The root panel is loaded first by ChiliPeppr and then you can load your own content in the body area. Your code is only executed once the root panel is loaded.",
publish: [''],
subscribe: [''],
isForkMode: false,
init: function () {
this.isForkMode = false;
this.urlSetup();
this.formSetup();
var url = this.extractUrl();
var forkDom = $('#com-chilipeppr-widget-editbootscript-body #forking-panel');
forkDom.addClass("hidden");
//if (!url) url = "asdf";
if (url) {
// perform submit
this.urlSubmit();
} else {
// this is root
var that = this;
this.urlSubmit(null, function() {
if (!that.isForkMode) {
var warningDom = $('#com-chilipeppr-widget-editbootscript-body .alert');
warningDom.text("This is the root URL. You may not edit it, but you may copy the Javascript for your own Hardware Fiddle. It would be best to fork the workspace in JSFiddle and modify your boot script to reference your new fork.");
}
});
}
},
doFork: function() {
console.log("entering fork mode");
this.isForkMode = true;
// we're letting the user pick a new url, but copying the javascript
// from the current page
var forkDom = $('#com-chilipeppr-widget-editbootscript-body #forking-panel');
forkDom.removeClass("hidden");
forkDom.text("We are going to fork this current boot script for you. Please pick a new URL for your workspace, keep or edit the Javascript, and then hit Save Changes. The Base Boot Javascript contains the code for the current page " + this.extractUrl("(root)") + " that you are on. You'll notice the base Javascript loads an external URL (which is most likely a JSFiddle). You should navigate directly to that URL in another tab and fork it. Then place a URL to your new code in this boot script.");
},
extractUrl: function(ifNullStr) {
// read the window.location to extract the url for this fiddle
console.log("window.location", window.location.pathname);
var path = window.location.pathname;
if (path == "/_display/") {
// we're inside jsfiddle, so ignore
//return "(inside jsfiddle)";
path = null;
} else {
path = path.replace(/^\//, "");
path = path.replace(/\/$/, "");
//return path;
}
if (ifNullStr && path == null) path = ifNullStr;
return path;
},
copyExampleJscript: function() {
var jscriptDom = $('#com-chilipeppr-widget-editbootscript-inputScript');
var jscriptExampleDom = $('#com-chilipeppr-widget-editbootscript-inputScriptExample');
jscriptDom.val(jscriptExampleDom.text());
},
urlSetup: function () {
var that = this;
$('#com-chilipeppr-widget-editbootscript-inputUrl').blur(function(e) {
that.urlSubmit(e);
});
var url = this.extractUrl();
console.log("url for this fiddle", url);
if (url) {
$('#com-chilipeppr-widget-editbootscript-inputUrl').val(url);
}
},
urlSubmit: function (e, callback) {
var that = this;
if (e) e.preventDefault();
console.log("url submit. e:", e, " isForkMode:", this.isForkMode);
var warningDom = $('#com-chilipeppr-widget-editbootscript-body .alert');
var jscriptDom = $('#com-chilipeppr-widget-editbootscript-inputScript');
var jscriptExampleDom = $('#com-chilipeppr-widget-editbootscript-inputScriptExample');
warningDom.removeClass("hidden");
warningDom.text("Checking URL availability...");
var userUrl = $('#com-chilipeppr-widget-editbootscript-inputUrl').val();
console.log("user url:", userUrl);
var jqxhr = $.getJSON("http://www.chilipeppr.com/dataget?key=userUrl:" + userUrl + "&callback=?")
.done(function (data) {
console.log("got jsnop callback", data);
if (data.KeyExists != undefined && data.KeyExists == false) {
warningDom.removeClass("alert-warning");
warningDom.addClass("alert-info");
if (that.isForkMode) {
warningDom.text("URL is available for your use. Since we're in forking mode, the base boot Javascript is a copy of the script used on this page and you may keep it or edit it for your new workspace.");
} else {
warningDom.text("URL is available for your use. Showing you sample Javascript for your boot script.");
jscriptDom.val(jscriptExampleDom.text());
}
} else if (data.Error && data.Error == true) {
warningDom.removeClass("alert-info");
warningDom.addClass("alert-warning");
warningDom.text(data.Msg);
} else {
// this url is taken, but see if we own it
var jqxhr = $.getJSON("http://www.chilipeppr.com/datalogin?callback=?")
.done(function (logindata) {
console.log("logindata", logindata);
if (logindata.CurrentUser != undefined && logindata.CurrentUser != null) {
console.log("user logged in ", logindata.CurrentUser);
if (data.User == logindata.CurrentUser.Email) {
warningDom.removeClass("alert-warning");
warningDom.addClass("alert-info");
warningDom.text("You own this URL, so you can edit the base boot Javascript.");
} else {
warningDom.removeClass("alert-info");
warningDom.addClass("alert-warning");
warningDom.text("This URL is taken by another user already, so you may not use it.");
}
} else {
console.log("user NOT logged in");
warningDom.removeClass("alert-info");
warningDom.addClass("alert-warning");
warningDom.text("You must be logged in to create/edit a URL and edit the base boot Javascript.");
}
if (callback) callback.apply(null);
})
//warningDom.text("URL is available. " + JSON.stringify(data));
// place jscript into box (everything is public)
jscriptDom.val(data.Value);
}
})
.fail(function (data) {
console.log("failed. data:", data);
warningDom.text("Failed to execute Ajax call. Huh?");
})
},
formSetup: function() {
$('#com-chilipeppr-widget-editbootscript-submitBtn').click(this.formSubmit);
$('#com-chilipeppr-widget-editbootscript-body input,select').keypress(function(event) { return event.keyCode != 13; });
},
formSubmit: function (e) {
console.log("e:", e);
e.preventDefault();
console.log("form submit");
var warningDom = $('#com-chilipeppr-widget-editbootscript-body .alert');
warningDom.text("Submitting form...");
var userUrl = $('#com-chilipeppr-widget-editbootscript-inputUrl').val();
var userScript = $('#com-chilipeppr-widget-editbootscript-inputScript').val();
console.log("user url:", userUrl);
console.log("user script:", userScript);
var jqxhr = $.getJSON("http://www.chilipeppr.com/dataput?callback=?", { key: "userUrl:" + userUrl, val: userScript })
.done(function (data) {
console.log("got jsnop callback", data);
if (data.Error && data.Error == true) {
warningDom.text(data.Msg);
} else {
//warningDom.text("Successfully saved record. " + JSON.stringify(data));
warningDom.html("Successfully saved URL and base boot script. Navigate to your new workspace <a href=\"http://chilipeppr.com/" + userUrl + "\">http://chilipeppr.com/" + userUrl + "</a>");
}
})
.fail(function (data) {
console.log("failed. data:", data);
warningDom.text("Failed to execute Ajax call. Huh?");
})
},
checkLogin: function () {
var jqxhr = $.getJSON("http://www.chilipeppr.com/datalogin?callback=?")
.done(function (data) {
console.log(data);
if (data.CurrentUser != undefined && data.CurrentUser != null) {
console.log("user logged in ", data.CurrentUser);
} else {
console.log("user NOT logged in");
}
})
.fail(function () {
})
},
}
});
//]]>
</script>
<!-- end chilipeppr.load() url: http://fiddle.jshell.net/chilipeppr/uNALR/show/light/ -->
</div>
<div class="modal-footer hidden">
<button type="button" class="btn btn-default" data-dismiss="modal" data-original-title="" title="">Close</button>
<button type="button" class="btn btn-primary" data-original-title="" title="">Save changes</button>
</div>
</div>
</div>
</div>
<!-- End Edit Boot Javascript Modal -->
<!-- end chilipeppr.load() url: http://fiddle.jshell.net/chilipeppr/7aX6x/show/light/ -->
</div>
<div id="pnlBody">
<div class="container-fluid">
<div class="row">
<!-- Flash Message -->
<div id="com-chilipeppr-flash"><!-- start chilipeppr.load() url: http://fiddle.jshell.net/jlauer/qp7Em/show/light/ -->
<style type="text/css">
.com-chilipeppr-elem-flashmsg .popover .arrow {
display:none;
}
.com-chilipeppr-elem-flashmsg .popover {
max-width: none;
}
</style>
<script type="text/javascript">//<![CDATA[
cpdefine("inline:com-chilipeppr-elem-flashmsg", ["chilipeppr_ready"], function () {
//console.log("Inside of define for com-chilipeppr-elem-flashmsg");
return {
id: "com-chilipeppr-elem-flashmsg",
url: "http://fiddle.jshell.net/jlauer/qp7Em/show/light/",
fiddleurl: "http://jsfiddle.net/jlauer/qp7Em/",
name: "Element / Flash Messsage",
desc: "This element shows a flash message at the top of the browser.",
publish: null,
subscribe: "/com-chilipeppr-elem-flashmsg/flashmsg",
queue: [],
init: function () {
//console.log("init called");
chilipeppr.subscribe(this.subscribe, this, this.showQueue);
},