-
Notifications
You must be signed in to change notification settings - Fork 0
/
socialcalcpopup.js
1620 lines (1183 loc) · 40.8 KB
/
socialcalcpopup.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
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
//
/*
// The module of the SocialCalc package for the optional popup menus in socialcalcspreadsheetcontrol.js
//
// (c) Copyright 2009 Socialtext, Inc.
// All Rights Reserved.
//
// The contents of this file are subject to the Artistic License 2.0; you may not
// use this file except in compliance with the License. You may obtain a copy of
// the License at http://socialcalc.org/licenses/al-20/.
//
// Some of the other files in the SocialCalc package are licensed under
// different licenses. Please note the licenses of the modules you use.
//
// Code History:
//
// Initially coded by Dan Bricklin of Software Garden, Inc., for Socialtext, Inc.
//
*/
var SocialCalc; // All values are stored in the master SocialCalc object
if (!SocialCalc) {
SocialCalc = {};
}
// The main Popup data -- there is only one set
SocialCalc.Popup = {};
// Routines and values for each type of control, indexed by type name
// The value for each is an object constructed as follows:
//
// Create = function(type, id, attribs)
// Initialize = function(type, id, data)
// SetValue = function(type, id, value)
// GetValue = function(type, id) returns value
// SetDisabled = function(type, id, t/f)
// Show = function(type, id)
// Hide = function(type, id)
// Cancel = function(type, id)
// Reset = function(type)
//
// data = object to hold type-specific data
//
SocialCalc.Popup.Types = {};
// Definitions for each individual control, indexed by id
// The value for each is an object constructed as follows:
//
// type: type name of the control
// value: current value of the control (usually a string, but can depend on type)
// data: object with type-specific items
//
SocialCalc.Popup.Controls = {};
// System-wide values of currently active control
//
// id: id of current control or null
//
SocialCalc.Popup.Current = {};
// Override this for localization
SocialCalc.Popup.LocalizeString = function(str) {return str;};
// * * * * * * * * * * * * * * * *
//
// GENERAL ROUTINES
//
// * * * * * * * * * * * * * * * *
//
// SocialCalc.Popup.Create(type, id, attribs)
//
// Creates a control of type "type" as the children of document element "id" using "attribs"
//
SocialCalc.Popup.Create = function(type, id, attribs) {
var pt = SocialCalc.Popup.Types[type];
if (pt && pt.Create) {
pt.Create(type, id, attribs);
}
SocialCalc.Popup.imagePrefix = SocialCalc.Constants.defaultImagePrefix; // image prefix
}
//
// SocialCalc.Popup.SetValue(id, value)
//
// Sets the value of control.
//
SocialCalc.Popup.SetValue = function(id, value) {
var sp = SocialCalc.Popup;
var spt = sp.Types;
var spc = sp.Controls;
if (!spc[id]) {alert("Unknown control "+id);return;}
var type = spc[id].type;
var pt = spt[type];
var spcdata = spc[id].data;
if (pt && pt.Create) {
pt.SetValue(type, id, value);
if (spcdata.attribs && spcdata.attribs.changedcallback) {
spcdata.attribs.changedcallback(spcdata.attribs, id, value);
}
}
}
//
// SocialCalc.Popup.SetDisabled(id, disabled)
//
// Sets whether the control is disabled (true) or not (false).
//
SocialCalc.Popup.SetDisabled = function(id, disabled) {
var sp = SocialCalc.Popup;
var spt = sp.Types;
var spc = sp.Controls;
if (!spc[id]) {alert("Unknown control "+id);return;}
var type = spc[id].type;
var pt = spt[type];
if (pt && pt.Create) {
if (sp.Current.id && id == sp.Current.id) {
pt.Hide(type, sp.Current.id);
sp.Current.id = null;
}
pt.SetDisabled(type, id, disabled);
}
}
//
// SocialCalc.Popup.GetValue(id)
//
// Returns the value of control.
//
SocialCalc.Popup.GetValue = function(id) {
var sp = SocialCalc.Popup;
var spt = sp.Types;
var spc = sp.Controls;
if (!spc[id]) {alert("Unknown control "+id);return;}
var type = spc[id].type;
var pt = spt[type];
if (pt && pt.Create) {
return pt.GetValue(type, id);
}
return null;
}
//
// SocialCalc.Popup.Initialize(id, data)
//
// Gives "data" to the appropriate initialization code.
//
SocialCalc.Popup.Initialize = function(id, data) {
var sp = SocialCalc.Popup;
var spt = sp.Types;
var spc = sp.Controls;
if (!spc[id]) {alert("Unknown control "+id);return;}
var type = spc[id].type;
var pt = spt[type];
if (pt && pt.Initialize) {
pt.Initialize(type, id, data);
}
}
//
// SocialCalc.Popup.Reset(type)
//
// Resets Popup, such as when turning to page.
//
SocialCalc.Popup.Reset = function(type) {
var sp = SocialCalc.Popup;
var spt = sp.Types;
var spc = sp.Controls;
if (spt[type].Reset) spt[type].Reset(type);
}
//
// SocialCalc.Popup.CClick(id)
//
// Should be called when the user clicks on a control to do the popup
//
SocialCalc.Popup.CClick = function(id) {
var sp = SocialCalc.Popup;
var spt = sp.Types;
var spc = sp.Controls;
if (!spc[id]) {alert("Unknown control "+id);return;}
if (spc[id].data && spc[id].data.disabled) return;
var type = spc[id].type;
var pt = spt[type];
if (sp.Current.id) {
spt[spc[sp.Current.id].type].Hide(type, sp.Current.id);
if (id == sp.Current.id) { // same one - done
sp.Current.id = null;
return;
}
}
if (pt && pt.Show) {
pt.Show(type, id);
}
sp.Current.id = id;
}
//
// SocialCalc.Popup.Close()
//
// Used to close any open popup.
//
SocialCalc.Popup.Close = function() {
var sp = SocialCalc.Popup;
var spt = sp.Types;
var spc = sp.Controls;
if (!sp.Current.id) return;
sp.CClick(sp.Current.id);
}
//
// SocialCalc.Popup.Cancel()
//
// Closes Popup and restores old value
//
SocialCalc.Popup.Cancel = function() {
var sp = SocialCalc.Popup;
var spt = sp.Types;
var spc = sp.Controls;
if (!sp.Current.id) return;
var type = spc[sp.Current.id].type;
var pt = spt[type];
pt.Cancel(type, sp.Current.id);
sp.Current.id = null;
}
//
// ele = SocialCalc.Popup.CreatePopupDiv(id, attribs)
//
// Utility function to create the main popup div of width attribs.width.
// If attribs.title, create one with that text, and optionally attribs.moveable.
//
SocialCalc.Popup.CreatePopupDiv = function(id, attribs) {
var pos, ele;
var sp = SocialCalc.Popup;
var spc = sp.Controls;
var spcdata = spc[id].data;
var main = document.createElement("div");
main.style.position = "absolute";
pos = SocialCalc.GetElementPosition(spcdata.mainele);
main.style.top = (pos.top+spcdata.mainele.offsetHeight)+"px";
main.style.left = pos.left+"px";
main.style.zIndex = 100;
main.style.backgroundColor = "#FFF";
main.style.border = "1px solid black";
if (attribs.width) {
main.style.width = attribs.width;
}
spcdata.mainele.appendChild(main);
if (attribs.title) {
main.innerHTML = '<table cellspacing="0" cellpadding="0" style="border-bottom:1px solid black;"><tr>'+
'<td style="font-size:10px;cursor:default;width:100%;background-color:#999;color:#FFF;">'+attribs.title+'</td>'+
'<td style="font-size:10px;cursor:default;color:#666;" onclick="SocialCalc.Popup.Cancel();"> X </td></tr></table>';
if (attribs.moveable) {
spcdata.dragregistered = main.firstChild.firstChild.firstChild.firstChild;
SocialCalc.DragRegister(spcdata.dragregistered, true, true,
{MouseDown: SocialCalc.DragFunctionStart,
MouseMove: SocialCalc.DragFunctionPosition,
MouseUp: SocialCalc.DragFunctionPosition,
Disabled: null, positionobj: main},
spcdata.mainele);
}
}
return main;
}
//
// SocialCalc.Popup.EnsurePosition(id, container)
//
// Utility function to make sure popup is positioned completely within container (both element objects)
// and appropriate with respect to the main element controlling the popup.
//
SocialCalc.Popup.EnsurePosition = function(id, container) {
var sp = SocialCalc.Popup;
var spc = sp.Controls;
var spcdata = spc[id].data;
var main = spcdata.mainele.firstChild;
if (!main) {alert("No main popup element firstChild.");return};
var popup = spcdata.popupele;
function GetLayoutValues(ele) {
var r = SocialCalc.GetElementPosition(ele);
r.height = ele.offsetHeight;
r.width = ele.offsetWidth;
r.bottom = r.top+r.height;
r.right = r.left+r.width;
return r;
}
var p = GetLayoutValues(popup);
var c = GetLayoutValues(container);
var m = GetLayoutValues(main);
var t = 0; // type of placement
//addmsg("popup t/r/b/l/h/w= "+p.top+"/"+p.right+"/"+p.bottom+"/"+p.left+"/"+p.height+"/"+p.width);
//addmsg("container t/r/b/l/h/w= "+c.top+"/"+c.right+"/"+c.bottom+"/"+c.left+"/"+c.height+"/"+c.width);
//addmsg("main t/r/b/l/h/w= "+m.top+"/"+m.right+"/"+m.bottom+"/"+m.left+"/"+m.height+"/"+m.width);
// Check various layout cases in priority order
if (m.bottom+p.height < c.bottom && m.left+p.width < c.right) { // normal case: room on bottom and right
popup.style.top = m.bottom + "px";
popup.style.left = m.left + "px";
t = 1;
}
else if (m.top-p.height > c.top && m.left+p.width < c.right) { // room on top and right
popup.style.top = (m.top-p.height) + "px";
popup.style.left = m.left + "px";
t = 2;
}
else if (m.bottom+p.height < c.bottom && m.right-p.width > c.left) { // room on bottom and left
popup.style.top = m.bottom + "px";
popup.style.left = (m.right-p.width) + "px";
t = 3;
}
else if (m.top-p.height > c.top && m.right-p.width > c.left) { // room on top and left
popup.style.top = (m.top-p.height) + "px";
popup.style.left = (m.right-p.width) + "px";
t = 4;
}
else if (m.bottom+p.height < c.bottom && p.width < c.width) { // room on bottom and middle
popup.style.top = m.bottom + "px";
popup.style.left = (c.left+Math.floor((c.width-p.width)/2)) + "px";
t = 5;
}
else if (m.top-p.height > c.top && p.width < c.width) { // room on top and middle
popup.style.top = (m.top-p.height) + "px";
popup.style.left = (c.left+Math.floor((c.width-p.width)/2)) + "px";
t = 6;
}
else if (p.height < c.height && m.right+p.width < c.right) { // room on middle and right
popup.style.top = (c.top+Math.floor((c.height-p.height)/2)) + "px";
popup.style.left = m.right + "px";
t = 7;
}
else if (p.height < c.height && m.left-p.width > c.left) { // room on middle and left
popup.style.top = (c.top+Math.floor((c.height-p.height)/2)) + "px";
popup.style.left = (m.left-p.width) + "px";
t = 8;
}
else { // nothing works, so leave as it is
}
//addmsg("Popup layout "+t);
}
//
// ele = SocialCalc.Popup.DestroyPopupDiv(ele, dragregistered)
//
// Utility function to get rid of the main popup div.
//
SocialCalc.Popup.DestroyPopupDiv = function(ele, dragregistered) {
if (!ele) return;
ele.innerHTML = "";
SocialCalc.DragUnregister(dragregistered); // OK to do this even if not registered
if (ele.parentNode) {
ele.parentNode.removeChild(ele);
}
}
//
// Color Utility Functions
//
SocialCalc.Popup.RGBToHex = function(val) {
var sp = SocialCalc.Popup;
if (val=="") {
return "000000";
}
var rgbvals = val.match(/(\d+)\D+(\d+)\D+(\d+)/);
if (rgbvals) {
return sp.ToHex(rgbvals[1])+sp.ToHex(rgbvals[2])+sp.ToHex(rgbvals[3]);
}
else {
return "000000";
}
}
SocialCalc.Popup.HexDigits="0123456789ABCDEF";
SocialCalc.Popup.ToHex = function(num) {
var sp = SocialCalc.Popup;
var first=Math.floor(num / 16);
var second=num % 16;
return sp.HexDigits.charAt(first)+sp.HexDigits.charAt(second);
}
SocialCalc.Popup.FromHex = function(str) {
var sp = SocialCalc.Popup;
var first = sp.HexDigits.indexOf(str.charAt(0).toUpperCase());
var second = sp.HexDigits.indexOf(str.charAt(1).toUpperCase());
return ((first>=0)?first:0)*16+((second>=0)?second:0);
}
SocialCalc.Popup.HexToRGB = function(val) {
var sp = SocialCalc.Popup;
return "rgb("+sp.FromHex(val.substring(1,3))+","+sp.FromHex(val.substring(3,5))+","+sp.FromHex(val.substring(5,7))+")";
}
SocialCalc.Popup.makeRGB = function(r, g, b) {
return "rgb("+(r>0?r:0)+","+(g>0?g:0)+","+(b>0?b:0)+")";
}
SocialCalc.Popup.splitRGB = function(rgb) {
var parts = rgb.match(/(\d+)\D+(\d+)\D+(\d+)\D/);
if (!parts) {
return {r:0, g:0, b:0};
}
else {
return {r: parts[1]-0, g: parts[2]-0, b: parts[3]-0};
}
}
// * * * * * * * * * * * * * * * *
//
// ROUTINES FOR EACH TYPE
//
// * * * * * * * * * * * * * * * *
//
// List
//
// type: List
// value: value of control,
// display: "value to display",
// custom: true if custom value,
// disabled: t/f,
// attribs: {
// title: "popup title string",
// moveable: t/f,
// width: optional width, e.g., "100px",
// ensureWithin: optional element object to ensure popup fits within if possible
// changedcallback: optional function(attribs, id, newvalue),
// ...
// }
// data: {
// ncols: calculated number of columns
// options: [
// {o: option-name, v: value-to-return,
// a: {option attribs} // optional: {skip: true, custom: true, cancel: true, newcol: true}
// },
// ...]
// }
//
// popupele: gets popup element object when created
// contentele: gets element created with all the content
// listdiv: gets div with list of items
// customele: gets input element with custom value
// dragregistered: gets element, if any, registered as draggable
//
SocialCalc.Popup.Types.List = {};
SocialCalc.Popup.Types.List.Create = function(type, id, attribs) {
var sp = SocialCalc.Popup;
var spt = sp.Types;
var spc = sp.Controls;
var spcid = {type: type, value: "", display: "", data: {}};
//if (spc[id]) {alert("Already created "+id); return;}
spc[id] = spcid;
var spcdata = spcid.data;
spcdata.attribs = attribs || {};
var ele = document.getElementById(id);
if (!ele) {alert("Missing element "+id); return;}
spcdata.mainele = ele;
ele.innerHTML = '<input style="cursor:pointer;width:100px;font-size:smaller;" onfocus="this.blur();" onclick="SocialCalc.Popup.CClick(\''+id+'\');" value="">';
spcdata.options = []; // set to nothing - use Initialize to fill
}
SocialCalc.Popup.Types.List.SetValue = function(type, id, value) {
var i;
var sp = SocialCalc.Popup;
var spt = sp.Types;
var spc = sp.Controls;
var spcdata = spc[id].data;
spcdata.value = value;
spcdata.custom = false;
for (i=0; i<spcdata.options.length; i++) {
o = spcdata.options[i];
if (o.a) {
if (o.a.skip || o.a.custom || o.a.cancel) {
continue;
}
}
if (o.v == spcdata.value) { // matches value
spcdata.display = o.o;
break;
}
}
if (i==spcdata.options.length) { // none found
spcdata.display = "Custom";
spcdata.custom = true;
}
if (spcdata.mainele && spcdata.mainele.firstChild) {
spcdata.mainele.firstChild.value = spcdata.display;
}
}
SocialCalc.Popup.Types.List.SetDisabled = function(type, id, disabled) {
var i;
var sp = SocialCalc.Popup;
var spt = sp.Types;
var spc = sp.Controls;
var spcdata = spc[id].data;
spcdata.disabled = disabled;
if (spcdata.mainele && spcdata.mainele.firstChild) {
spcdata.mainele.firstChild.disabled = disabled;
}
}
SocialCalc.Popup.Types.List.GetValue = function(type, id) {
var sp = SocialCalc.Popup;
var spt = sp.Types;
var spc = sp.Controls;
var spcdata = spc[id].data;
return spcdata.value;
}
// data is: {value: initial value, attribs: {attribs stuff}, options: [{o: option-name, v: value-to-return, a: optional-attribs}, ...]}
SocialCalc.Popup.Types.List.Initialize = function(type, id, data) {
var a;
var sp = SocialCalc.Popup;
var spt = sp.Types;
var spc = sp.Controls;
var spcdata = spc[id].data;
for (a in data.attribs) {
spcdata.attribs[a] = data.attribs[a];
}
spcdata.options = data ? data.options : [];
if (data.value) { // if has a value, set to it
sp.SetValue(id, data.value);
}
}
SocialCalc.Popup.Types.List.Reset = function(type) {
var sp = SocialCalc.Popup;
var spt = sp.Types;
var spc = sp.Controls;
if (sp.Current.id && spc[sp.Current.id].type == type) { // we have a popup
spt[type].Hide(type, sp.Current.id);
sp.Current.id = null;
}
}
SocialCalc.Popup.Types.List.Show = function(type, id) {
var i, ele, o, bg;
var sp = SocialCalc.Popup;
var spt = sp.Types;
var spc = sp.Controls;
var spcdata = spc[id].data
var str = "";
spcdata.popupele = sp.CreatePopupDiv(id, spcdata.attribs);
if (spcdata.custom) {
str = SocialCalc.Popup.Types.List.MakeCustom(type, id);
ele = document.createElement("div");
ele.innerHTML = '<div style="cursor:default;padding:4px;background-color:#CCC;">'+str+'</div>';
spcdata.customele = ele.firstChild.firstChild.childNodes[1];
spcdata.listdiv = null;
spcdata.contentele = ele;
}
else {
str = SocialCalc.Popup.Types.List.MakeList(type, id);
ele = document.createElement("div");
ele.innerHTML = '<div style="cursor:default;padding:4px;">'+str+'</div>';
spcdata.customele = null;
spcdata.listdiv = ele.firstChild;
spcdata.contentele = ele;
}
if (spcdata.mainele && spcdata.mainele.firstChild) {
spcdata.mainele.firstChild.disabled = true;
}
spcdata.popupele.appendChild(ele);
if (spcdata.attribs.ensureWithin) {
SocialCalc.Popup.EnsurePosition(id, spcdata.attribs.ensureWithin);
}
}
SocialCalc.Popup.Types.List.MakeList = function(type, id) {
var i, ele, o, bg;
var sp = SocialCalc.Popup;
var spt = sp.Types;
var spc = sp.Controls;
var spcdata = spc[id].data
var str = '<table cellspacing="0" cellpadding="0"><tr>';
var td = '<td style="vertical-align:top;">';
str += td;
spcdata.ncols = 1;
for (i=0; i<spcdata.options.length; i++) {
o = spcdata.options[i];
if (o.a) {
if ( o.a.newcol) {
str += '</td>'+td+" "+'</td>'+td;
spcdata.ncols += 1;
continue;
}
if (o.a.skip) {
str += '<div style="font-size:x-small;white-space:nowrap;">'+o.o+'</div>';
continue;
}
}
if (o.v == spcdata.value && !(o.a && (o.a.custom || o.a.cancel))) { // matches value
bg = "background-color:#DDF;";
}
else {
bg = "";
}
str += '<div style="font-size:x-small;white-space:nowrap;'+bg+'" onclick="SocialCalc.Popup.Types.List.ItemClicked(\''+id+'\',\''+i+'\');" onmousemove="SocialCalc.Popup.Types.List.MouseMove(\''+id+'\',this);">'+o.o+'</div>';
}
str += "</td></tr></table>";
return str;
}
SocialCalc.Popup.Types.List.MakeCustom = function(type, id) {
var SPLoc = SocialCalc.Popup.LocalizeString;
var i, ele, o, bg;
var sp = SocialCalc.Popup;
var spt = sp.Types;
var spc = sp.Controls;
var spcdata = spc[id].data;
var style = 'style="font-size:smaller;"';
var str = "";
var val = spcdata.value;
val = SocialCalc.special_chars(val);
str = '<div style="white-space:nowrap;"><br>'+
'<input id="customvalue" value="'+val+'"><br><br>'+
'<input '+style+' type="button" value="'+SPLoc("OK")+'" onclick="SocialCalc.Popup.Types.List.CustomOK(\''+id+'\');return false;">'+
'<input '+style+' type="button" value="'+SPLoc("List")+'" onclick="SocialCalc.Popup.Types.List.CustomToList(\''+id+'\');">'+
'<input '+style+' type="button" value="'+SPLoc("Cancel")+'" onclick="SocialCalc.Popup.Close();">'+
'<br></div>';
return str;
}
SocialCalc.Popup.Types.List.ItemClicked = function(id, num) {
var oele, str, nele;
var sp = SocialCalc.Popup;
var spt = sp.Types;
var spc = sp.Controls;
var spcdata = spc[id].data;
var a = spcdata.options[num].a;
if (a && a.custom) {
oele = spcdata.contentele;
str = SocialCalc.Popup.Types.List.MakeCustom("List", id);
nele = document.createElement("div");
nele.innerHTML = '<div style="cursor:default;padding:4px;background-color:#CCC;">'+str+'</div>';
spcdata.customele = nele.firstChild.firstChild.childNodes[1];
spcdata.listdiv = null;
spcdata.contentele = nele;
spcdata.popupele.replaceChild(nele, oele);
if (spcdata.attribs.ensureWithin) {
SocialCalc.Popup.EnsurePosition(id, spcdata.attribs.ensureWithin);
}
return;
}
if (a && a.cancel) {
SocialCalc.Popup.Close();
return;
}
SocialCalc.Popup.SetValue(id, spcdata.options[num].v);
SocialCalc.Popup.Close();
}
SocialCalc.Popup.Types.List.CustomToList = function(id) {
var oele, str, nele;
var sp = SocialCalc.Popup;
var spt = sp.Types;
var spc = sp.Controls;
var spcdata = spc[id].data;
oele = spcdata.contentele;
str = SocialCalc.Popup.Types.List.MakeList("List", id);
nele = document.createElement("div");
nele.innerHTML = '<div style="cursor:default;padding:4px;">'+str+'</div>';
spcdata.customele = null;
spcdata.listdiv = nele.firstChild;
spcdata.contentele = nele;
spcdata.popupele.replaceChild(nele, oele);
if (spcdata.attribs.ensureWithin) {
SocialCalc.Popup.EnsurePosition(id, spcdata.attribs.ensureWithin);
}
}
SocialCalc.Popup.Types.List.CustomOK = function(id) {
var i, c;
var sp = SocialCalc.Popup;
var spt = sp.Types;
var spc = sp.Controls;
var spcdata = spc[id].data;
SocialCalc.Popup.SetValue(id, spcdata.customele.value);
SocialCalc.Popup.Close();
}
SocialCalc.Popup.Types.List.MouseMove = function(id, ele) {
var col, i, c;
var sp = SocialCalc.Popup;
var spt = sp.Types;
var spc = sp.Controls;
var spcdata = spc[id].data;
var list = spcdata.listdiv;
if (!list) return;
var rowele = list.firstChild.firstChild.firstChild; // div.table.tbody.tr
for (col=0; col<spcdata.ncols; col++) {
for (i=0; i<rowele.childNodes[col*2].childNodes.length; i++) {
rowele.childNodes[col*2].childNodes[i].style.backgroundColor = "#FFF";
}
}
ele.style.backgroundColor = "#DDF";
}
SocialCalc.Popup.Types.List.Hide = function(type, id) {
var sp = SocialCalc.Popup;
var spt = sp.Types;
var spc = sp.Controls;
var spcdata = spc[id].data;
sp.DestroyPopupDiv(spcdata.popupele, spcdata.dragregistered);
spcdata.popupele = null;
if (spcdata.mainele && spcdata.mainele.firstChild) {
spcdata.mainele.firstChild.disabled = false;
}
}
SocialCalc.Popup.Types.List.Cancel = function(type, id) {
SocialCalc.Popup.Types.List.Hide(type, id);
}
//
// ColorChooser
//
// type: ColorChooser
// value: value of control as "rgb(r,g,b)" or "" if default,
// oldvalue: starting value to reset to on close,
// display: "value to display" as hex color value,
// custom: true if custom value,
// disabled: t/f,
// attribs: {
// title: "popup title string",
// moveable: t/f,
// width: optional width, e.g., "100px", of popup chooser
// ensureWithin: optional element object to ensure popup fits within if possible
// sampleWidth: optional width, e.g., "20px",
// sampleHeight: optional height, e.g., "20px",
// backgroundImage: optional background image for sample (transparent where want to show current color), e.g., "colorbg.gif"
// backgroundImageDefault: optional background image for sample when default (transparent shows white)
// backgroundImageDisabled: optional background image for sample when disabled (transparent shows gray)
// changedcallback: optional function(attribs, id, newvalue),
// ...
// }
// data: {
// }
//
// popupele: gets popup element object when created
// contentele: gets element created with all the content
// customele: gets input element with custom value
//
SocialCalc.Popup.Types.ColorChooser = {};
SocialCalc.Popup.Types.ColorChooser.Create = function(type, id, attribs) {
var sp = SocialCalc.Popup;
var spt = sp.Types;
var spc = sp.Controls;
var spcid = {type: type, value: "", display: "", data: {}};
//if (spc[id]) {alert("Already created "+id); return;}
spc[id] = spcid;
var spcdata = spcid.data;
spcdata.attribs = attribs || {};
var spca = spcdata.attribs;
spcdata.value = "";
var ele = document.getElementById(id);
if (!ele) {alert("Missing element "+id); return;}
spcdata.mainele = ele;
ele.innerHTML = '<div style="cursor:pointer;border:1px solid black;vertical-align:top;width:'+
(spca.sampleWidth || '15px')+';height:'+(spca.sampleHeight || '15px')+
';" onclick="SocialCalc.Popup.Types.ColorChooser.ControlClicked(\''+id+'\');"> </div>';
}
SocialCalc.Popup.Types.ColorChooser.SetValue = function(type, id, value) {
var i, img, pos;
var sp = SocialCalc.Popup;
var spt = sp.Types;
var spc = sp.Controls;
var spcdata = spc[id].data;
var spca = spcdata.attribs;
spcdata.value = value;
spcdata.custom = false;