-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathe107helper.js
1511 lines (1410 loc) · 53.9 KB
/
e107helper.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
/*
* e107Helper
* Miscellaneous JS helper object for functions that don't fit anywhere else
*/
var e107Helper = {
// Useful keycodes
KEY_TAB : 9,
KEY_ENTER : 13,
KEY_ESC : 27,
KEY_PAGE_UP : 33,
KEY_PAGE_DOWN : 34,
KEY_END : 35,
KEY_HOME : 36,
KEY_UP : 38,
KEY_DOWN : 40,
// Holder for main page HMTL whilst a dialog is displayed
bodyhtml : "",
// Log message counter
logcount : 0,
/**
*
*/
addTextToField : function(txt, fieldid) {
$(fieldid).value = txt;
expandit(fieldid+"_box")
},
/**
* Used to confirm an action
* Normally action is some sort of destroy (e.g. delete row from DB). A Javascript confirm
* dialog is displayed, if positive response button is selected thenh action is allowed to happen, thenh
* action being to load the next page (which should effect the destroy)
* @param string the message to be displayed in the confirm dialog
* @param string string representing the URL of the page to load is positive response button selected
* @return boolean true if positive response button selected, otherwise false
*/
confirmDelete : function (msg, loc){
if (confirm(msg)) {
document.location = loc;
return true;
} else {
return false;
}
},
/**
* Displays a dialog
* A dialog, in this scenario, is normally a form of some sort. Before the dialog is displayed
* the page is faded (using CSS opacity). It is up to the caller to call the <code>killDialog</code> function is called
* when the dialog is completed or cancelled.
* @param string the HTML ID attribute to be given to the dialog (actually the DIV that the dialog is dispalyed in)
* @param html the HTML representing the dialog (form) to be displayed
* @param width the width of the dialog in pixels
* @param focus id of copntrol to be given focus when dialog is loaded
* @param key keyboard handler object, will be attached to the onkeypress, onkeydown and onkeyup events of the dialog DIV
*/
dialog : function (id, html, width, focus, key) {
var dialog = document.createElement("DIV");
dialog.style.visibility = "hidden";
dialog.id = id;
dialog.style.position = 'absolute';
dialog.style.top = '25px';
dialog.innerHTML = html;
dialog.style.zIndex = '9999';
if (typeof key != undefined && key != null) {
dialog.onkeydown = function(ev) { eval(key+"(ev)");};
//dialog.onkeyup = function(ev) { eval(key+"(ev)");};
//dialog.onkeypress = function(ev) { eval(key+"(ev)");};
}
var mask = document.createElement("DIV");
mask.id = id+"_mask";
mask.style.position = 'absolute';
mask.style.top = '0px';
mask.style.left = '0px';
mask.style.height = '100%';
mask.style.width = (e107HelperBrowser.isIE) ? '110%' : '100%';
mask.style.backgroundColor = 'black';
mask.style.zIndex = '9998';
document.body.appendChild(mask);
document.body.appendChild(dialog);
if (e107HelperBrowser.isIE) {
mask.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=66)';
} else {
mask.style.opacity = '0.66';
}
var vpsize = e107HelperSize.getViewportSize();
if (typeof width != "undefined" && width != null) {
dialog.style.width = width + 'px';
}
var left = (vpsize.width - dialog.offsetWidth) / 2;
var top = (vpsize.height - dialog.offsetHeight) / 3;
if (e107HelperBrowser.isIE) {
dialog.style.pixelTop = top;
dialog.style.pixelLeft = left;
} else {
dialog.style.top = top+"px";
dialog.style.left = left+"px";
}
dialog.style.visibility = "";
mask.style.visibility = "";
if ($(focus) && $(focus).focus()) {
$(focus).focus();
}
},
dialogKeyHandler : function(event, cancel_event, ok_event) {
var ev = e107HelperEvents.getEvent(event);
var key = e107HelperEvents.getKeyCode(ev);
var tgt = ev.srcElement;
switch(key) {
case e107Helper.KEY_ENTER: {
if (typeof tgt != "undefined" && typeof tgt.type != "undefined" && tgt.type != "button") {
eval(ok_event);
ev.returnValue = false;
}
break;
}
case e107Helper.KEY_ESC: {
eval(cancel_event);
ev.returnValue = false;
break;
}
default:
// let the system handle the key
ev.returnValue = true;
return;
}
},
/**
* Stores the current page
* To be used before displaying a dialog to save the current page
*/
killDialog : function (id) {
var el = $(id);
if (el) {
document.body.removeChild(el)
el = $(id+"_mask");
document.body.removeChild(el)
}
},
/**
* Stores the current page
* To be used before displaying a dialog to save the current page
* @deprecated
*/
storeBodyHTML : function () {
this.bodyhtml = document.body.innerHTML;
},
/**
* Restores the current page
* To be used after a dialog has been completed or cancelled to restore the current page
* @deprecated
*/
restoreBodyHTML : function() {
document.body.innerHTML = this.bodyhtml;
},
/**
* Display a 'popup' message
* Generates a 'popup' message on the current page. The 'popup' cannot be closed by the user, it must be closed programatically.
* The aim of this 'popup' is to indicate to the user that something is happening (e.g. "Processing, please wait...")
* @param string the HTML ID attribute to be given to the message (actually the DIV that the message is dispalyed in)
* @param text the text of the message to be displayed
*/
message : function (id, text) {
var msgdiv1 = document.createElement("DIV");
var msgdiv2 = document.createElement("DIV");
var msgdiv3 = document.createElement("DIV");
var br = document.createElement("BR");
var button = document.createElement("INPUT");
var msgdiv = document.createElement("DIV");
e107HelperStyle.addClass(msgdiv1, "forumheader");
e107HelperStyle.addClass(msgdiv2, "forumheader2");
e107HelperStyle.addClass(msgdiv3, "forumheader3");
e107HelperStyle.addClass(button, "button");
msgdiv1.style.visibility = "hidden";
msgdiv1.style.position = "absolute";
msgdiv1.id = id;
msgdiv3.style.margin = "10px";
msgdiv3.style.padding = "10px";
button.type = "button";
button.value = "OK";
button.style.textAlign = "right";
msgdiv.innerHTML = text;
msgdiv3.appendChild(msgdiv);
msgdiv2.appendChild(msgdiv3);
msgdiv1.appendChild(msgdiv2);
document.body.appendChild(msgdiv1);
var vpsize = e107HelperSize.getViewportSize();
var left = (vpsize.width - msgdiv1.offsetWidth) / 2;
var top = (vpsize.height - msgdiv1.offsetHeight) / 3;
if (e107HelperBrowser.isIE) {
msgdiv1.style.pixelTop = top;
msgdiv1.style.pixelLeft = left;
} else {
msgdiv1.style.top = top+"px";
msgdiv1.style.left = left+"px";
}
msgdiv1.style.visibility = "";
},
/**
* Display a timed 'popup' message (@see e107Helper.message)
* Additionally, this method will cancel the 'popup' after the sepcified number of milliseconds
* @param string the message text to be displayed
* @param integer the numbner of milliseconds that the message should be displayed for (defaults to 2500 = 2.5 seconds if not supplied)
*/
timedMessage : function (msg, msecs) {
this.message("e107HelperTimedMessage", msg)
if (msecs == null) {
msecs = 2500;
}
var timer = setTimeout(
function () {
var el = $("e107HelperTimedMessage");
el.parentNode.removeChild(el);
}
, msecs);
},
/**
* Kills (cancels) a 'popup' message (@see e107Helper.message)
* Used to kill a 'poup' message once processing has finished
* @param string the HTML ID attribute of the message to be killed
*/
killmessage : function (id) {
var elem = $(id)
if (elem) {
elem.parentNode.removeChild(elem);
}
},
/**
* Displays a tooltip
* A dialog, in this scenario, is normally a form of some sort. Before the dialog is displayed
* the page is faded (using CSS opacity). It is up to the caller to call the <code>killDialog</code> function is called
* when the dialog is completed or cancelled.
* @param string the HTML ID attribute to be given to the dialog (actually the DIV that the dialog is dispalyed in)
* @param html the HTML representing the dialog (form) to be displayed
*/
tooltipTimeoutId : 0,
tooltipDisplay : function (evt, parent, id, html, clazz, minwidth, maxwidth) {
//this.log("Entering e107Helper.tooltipDisplay()");
// Remember some info before setting timeout as this is not available in context that timeout function is run
var vpsize = e107HelperSize.getViewportSize();
var mousep = e107HelperEvents.getPosition(evt);
this.tooltipTimeoutId = setTimeout(function tt() {
//e107Helper.log("Entering tooltipDisplay.tt()");
//this.log("parent="+parent);
//this.log("id="+id);
//this.log("html="+html);
//this.log("clazz="+clazz);
//this.log("minwidth="+minwidth);
//this.log("maxwidth="+maxwidth);
if ($(id)) {
this.log("Leaving e107Helper.tooltipDisplay():already displaying tooltip");
return;
}
evt = e107HelperEvents.getEvent(evt);
var tooltip = document.createElement("DIV");
tooltip.style.visibility = "hidden";
tooltip.id = id;
tooltip.style.position = 'absolute';
tooltip.innerHTML = unescape(html);
tooltip.style.zIndex = '-1'; // effectively hidded, but we can get it's size information for positioning;
e107HelperStyle.addClass(tooltip, clazz);
document.body.appendChild(tooltip);
// Make this themeable
if (e107HelperBrowser.isIE) {
tooltip.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=85)';
} else {
tooltip.style.opacity = '0.85';
}
var ttsize = e107HelperSize.getElementSize(tooltip);
// Fiddle with width before positioning
if (typeof minwidth != "undefined" && minwidth > 0 && ttsize.width < minwidth) {
tooltip.style.width = minwidth+"px";
}
if (typeof maxwidth != "undefined" && maxwidth > 0 && ttsize.width > maxwidth) {
tooltip.style.width = maxwidth+"px";
}
var ttsize = e107HelperSize.getElementSize(tooltip);
// TODO Fairly crude postition calculation, needs tidying up
ttsize.left = mousep.x - ttsize.width/2;
ttsize.top = mousep.y - ttsize.height - 6;
ttsize.left = ttsize.left < 0 ? 0 : ttsize.left;
ttsize.top = ttsize.top < 0 ? 0 : ttsize.top;
ttsize.left = ttsize.left+ttsize.width > vpsize.width ? vpsize.width-ttsize.width : ttsize.left;
ttsize.top = ttsize.top < mousep.scrollY ? mousep.scrollY : ttsize.top;
if (e107HelperBrowser.isIE) {
tooltip.style.pixelLeft = ttsize.left;
tooltip.style.pixelTop = ttsize.top;
} else {
tooltip.style.left = ttsize.left+"px";
tooltip.style.top = ttsize.top+"px";
}
tooltip.style.visibility = "";
tooltip.style.zIndex = '9999';
//this.log(tooltip);
//e107Helper.log("Leaving e107Helper.tooltipDisplay():displayed tooltip");
}, 1000);
},
tooltipMove : function (evt, id) {
// TODO - not yet implemented
var posx=0;
var posy=0;
if (e==null) {
e=window.event;
}
if (e.pageX || e.pageY) {
posx=e.pageX; posy=e.pageY;
}
else if (e.clientX || e.clientY) {
if (document.documentElement.scrollTop) {
posx=e.clientX+document.documentElement.scrollLeft;
posy=e.clientY+document.documentElement.scrollTop;
} else {
posx=e.clientX+document.body.scrollLeft;
posy=e.clientY+document.body.scrollTop;
}
}
$("btc").style.top=(posy+10)+"px";
$("btc").style.left=(posx-20)+"px";
},
tooltipDestroy : function (evt, id) {
//this.log("Entering e107Helper.tooltipDestroy()");
//this.log("id="+id);
var tooltip = $(id);
if (this.tooltipTimeoutId != 0) {
clearTimeout(this.tooltipTimeoutId);
this.tooltipTimeoutId = 0;
//this.log("cleraing tooltip timout");
}
if (tooltip) {
var ttsize = e107HelperSize.getElementSize(tooltip);
var mousep = e107HelperEvents.getPosition(evt);
if ((ttsize.left < mousep.x && mousep.x < ttsize.right)
&& (ttsize.top < mousep.y && mousep.y < ttsize.bottom))
{
// Mouse is still over 'hotspot', tooltip has most likely caused mouseout as it's covering the hotspot.
// Don't kill the tooltip yet, transfer the mouseout to the tooltip instead.
tooltip.onmouseout = function () {e107Helper.tooltipDestroy2(evt, id);};
tooltip.onclick = function () {e107Helper.tooltipDestroy2(evt, id);};
return;
}
tooltip.parentNode.removeChild(tooltip);
}
//this.log("Leaving e107Helper.tooltipDestroy():destroyed tooltip");
return;
},
tooltipDestroy2 : function (evt, id) {
//this.log("Entering e107Helper.tooltipDestroy():destroyed tooltip");
//this.log("id="+id);
var tooltip = $(id);
tooltip.parentNode.removeChild(tooltip);
//this.log("Leaving e107Helper.tooltipDestroy():destroyed tooltip");
return;
},
/**
* setvalue
* Set the value of a form field
* @param string text to be set
* @param string a value to be used as a delimiter - will append the supplied text to existing text,
* empty string (or not set) to just replace value
*/
setvalue : function(id, txt, append) {
if (typeof append == "string" && append.length > 0) {
if ($(id).value.length > 0) {
$(id).value = $(id).value+append+txt;
} else {
$(id).value = txt;
}
} else {
$(id).value = txt;
}
},
/**
* rateStars
*/
rateStars : function(path, prefix, id, what) {
var src = path+'/star_rating.gif';
if (what) {
src = path+'/star_rating_selected.gif';
}
for (var i=1; i<=id; i++) {
var obj = $(prefix+i);
if (obj) {
obj.src = src;
}
}
},
/**
* editInline
* Allows a display only fieldto be turned in to an edit field when clicked
* @param string the field type to convert to. Supported types are: text, textarea
* @param string id of the database item to update
* @param string id of the fields container outer container
* @param string javascript function to be called on field update (blur)
*/
editInline : function(fieldType, itemId, fieldName, jsfunc, prefix, postfix) {
this.logDebug("editInline(fieldType="+fieldType+", itemId="+itemId+", fieldName="+fieldName+", jsfunc="+jsfunc+")");
var thespan = "e107helper_"+fieldName;
var thetextspan = "e107helper_"+fieldName+"_text";
var thehiddentextspan = "e107helper_"+fieldName+"_hiddentext";
var el = $(thehiddentextspan);
if (!el) {
el = $(thetextspan);
}
var oldText = el.firstChild.nodeValue;
//var oldText = $(thespan).firstChild.firstChild.nodeValue;
////var oldText = $(thespan).firstChild.innerHTML;
var newId = fieldName+"_input";
//var commonattribs = "class='tbox' style='width:100%' id='"+newId+"' onblur='"+jsfunc+"(\""+itemId+"\", \""+fieldName+"\", \""+newId+"\", \""+thespan+"\");return false;'";
var commonattribs = "class='tbox' style='width:100%' id='"+newId+"'";
var inlineField = "";
if (prefix.length > 0) {
inlineField += prefix;
}
switch (fieldType) {
case "textarea" : {
// Guess the number of rows
inlineField += "<textarea "+commonattribs+" rows='3' onkeyup='resizeTextArea(this);'></textarea>";
break;
}
case "text" : {
inlineField += "<input type='text' "+commonattribs+">";
break;
}
}
if (postfix.length > 0) {
inlineField += postfix;
}
inlineField += "<input type='button' class='button' onclick='"+jsfunc+"(\""+itemId+"\", \""+fieldName+"\", \""+newId+"\", \""+thespan+"\");return false;' value='OK'>";
inlineField += " ";
inlineField += "<input type='button' class='button' onclick='e107Helper.editInlineCancel(\""+fieldName+"\");' value='Cancel'>";
$(thespan).oldHTML = $(thespan).innerHTML;
$(thespan).innerHTML = inlineField;
$(newId).value = oldText;
resizeTextArea($(newId));
$(newId).focus();
},
/**
* editInlineCancel
* Cancel an inline edit and restore the original HTML
* @param string id of the fields container outer container
*/
editInlineCancel : function(fieldName) {
this.logDebug("editInline(fieldName="+fieldName+")");
var thespan = $("e107helper_"+fieldName);
thespan.innerHTML = thespan.oldHTML;
$("e107helper_"+fieldName+"_a").focus();
},
parseForm : function(fieldType, fieldName) {
this.logDebug("parseForm("+fieldType+", "+fieldName+")");
//var st = $(inputID).value + '~~|~~' + cellID;
var newHTML = "<span onclick='e107Helper.editInline(\""+fieldType+"\", \""+fieldName+"\");'>";
var newId = fieldName+"input";
newHTML += $(newId).value;
newHTML += "</span>";
$(fieldName).innerHTML = newHTML;
},
/**
* Dual list item moving
* - 1 move all items from left to right
* - 2 move selected item from left to right
* - 3 move selected item from right to left
* - 4 move all items from right to left
*/
dualListMove : function(type, id) {
var list = $(id+"_list").value.evalJSON();
//list.each(function(item, ix) {
// alert(item);
// alert(ix);
//});
var left = $(id+"_left");
var right = $(id+"_right");
if (type==1 || type==2) {
var src = $(id+"_left");
var tgt = $(id+"_right");
} else {
var src = $(id+"_right");
var tgt = $(id+"_left");
}
if (type==2 || type==3) {
if (src.selectedIndex != -1) {
var src_value = src.options[src.selectedIndex].value;
var src_text = src.options[src.selectedIndex].text;
tgt.options[tgt.length] = new Option(src_text, src_value, false, false);
src.remove(src.selectedIndex);
var current = new Array(0);
current[0] = "0";
for (ix=0; ix<right.length; ix++) {
current[current.length] = right.options[ix].value;
}
$(id).value = current.toString();
}
} else {
while (src.length) {
var src_value = src.options[0].value;
var src_text = src.options[0].text;
tgt.options[tgt.length] = new Option(src_text, src_value, false, false);
src.remove(0);
}
var current = new Array(0);
current[0] = "0";
for (ix=0; ix<right.length; ix++) {
current[current.length] = right.options[ix].value;
}
$(id).value = current.toString();
}
},
/**
* Firebug wrappers
* Wrappers for firebug calls to allow conditional logging based on log level
* Requires firebug lite (which is included by e107 Helper) for browsers other than Firefox
*/
log : function(message) {
//window.console.log(message);
},
logDebug : function(message) {
//window.console.debug(message);
},
logInfo : function(message) {
//window.console.info(message);
},
logWarn : function(message) {
//window.console.warn(message);
},
logError : function(message) {
//window.console.error(message);
},
logTrace : function() {
//window.console.trace();
},
logEnter : function(fname) {
//window.console.time(fname);
//window.console.group(fname);
},
logExit : function(fname, ret) {
if (ret == "undefined") {
ret = "No return value set";
}
//window.console.debug(ret);
//window.console.timeEnd(fname);
//window.console.groupEnd();
},
logTime : function(name) {
//window.console.time(name);
},
logTimeEnd : function(name) {
//window.console.timeEnd(name);
},
/**
* A doNothing function
*/
doNothing : function() {
},
/**
* alert
* Duplicates the Javascript alert functionality - may be expanded to allow alerts to be turned on/off for debugging.
*/
alert : function(txt) {
alert(txt);
}
};
/*
* e107HelperStyle
* Helper object for style handling
*/
var e107HelperStyle = {
addClass : function(el, clazz) {
if (!this.hasClass(el, clazz)) {
el.className += (" " + clazz);
}
},
removeClass : function(el, clazz) {
if (el.className == null) {
return;
}
var list = el.className.split(" ");
for (var i=0; i<list.length; ++i ) {
if (list[i] == clazz) {
list[i] = "";
}
}
el.className = list.join(" ");
},
hasClass : function(el, clazz) {
var list = el.className.split(" ");
for (var i=0; i<list.length; ++i ) {
if (list[i] == clazz) {
return true;
}
}
return false;
}
}
/*
* e107HelperSize
* Helper object for size information
*/
var e107HelperSize = {
getViewportSize : function() {
function isMozHorizScollBarShowing() {
return ((document.body.offsetWidth < window.innerWidth ) && ( document.documentElement.offsetWidth > document.body.offsetWidth));
}
return {
width : document.body.clientWidth,
height: e107HelperBrowser.isIE ? document.body.clientHeight : window.innerHeight - (isMozHorizScollBarShowing() ? 15 : 0)
}
},
getElementSize : function(elem) {
var x = (e107HelperBrowser.isIE) ? elem.style.pixelLeft : elem.style.left.replace("px", "");
var y = (e107HelperBrowser.isIE) ? elem.style.pixelTop : elem.style.top.replace("px", "");
var w = elem.offsetWidth;
var h = elem.offsetHeight;
var r = parseInt(x)+parseInt(w);
var b = parseInt(y)+parseInt(h);
//e107Helper.log("getElementSize("+elem.id+") : x="+x+" y="+y+" w="+w+" h="+h+" r="+r+" b="+b)
return {
left : x,
top : y,
width : w,
height : h,
right : r,
bottom : b
};
}
}
/*
* e107HelperEvent
* Helper object for event handling (onclick, onkeydown, etc.)
*/
var e107HelperEvents = {
getEvent : function(evt) {
if (typeof window.event != "undefined") {
evt = window.event;
}
return evt;
},
getCharCode : function( evt ) {
// Old versions of IWB populate keyCode incorrectly.
var cc = evt.charCode;
if ( e107HelperBrowser.isIWB ) {
// for Ctrl+cursor key/Insert/Delete/Home/End/Page Up/Page Down we
// get cc of 945 instead of 0. The keyCode is correct.
if ( cc == 945 && evt.type == "keypress" && evt.ctrlKey ) {
cc = 0;
}
}
return cc;
},
getKeyCode : function( evt ) {
// Old versions of IWB populate keyCode incorrectly.
var kc = evt.keyCode;
if ( e107HelperBrowser.isIWB20 ) {
// The VKs for lowercase should be the same as uppercase
if ( evt.type == "keyup" ) {
// kc has flags in high byte
if ( kc > 255 ) {
kc &= 0xff;
if ( 97 <= kc && kc <= 122 ) {
kc -= 32;
}
}
} else if ( evt.type == "keydown" ) {
// This is not perfect e.g. lowercase W is the same as F8
if ( 97 <= kc && kc <= 122 ) {
kc -= 32;
}
}
}
return kc;
},
getTarget : function (event) {
return ( (e107HelperBrowser.isMoz) ? event.target : window.event.srcElement)
},
getPosition : function (evt) {
// IE varies depending on standard compliance mode
if (e107HelperBrowser.isIE) {
var doc = ((document.compatMode && document.compatMode == 'CSS1Compat') ? document.documentElement : document.body);
if (doc) {
var x = evt.clientX + doc.scrollLeft;
var y = evt.clientY + doc.scrollTop;
var scrollX = doc.scrollLeft;
var scrollY = doc.scrollTop;
}
} else {
var x = evt.pageX;
var y = evt.pageY;
var scrollX = evt.pageX - evt.clientX;
var scrollY = evt.pageY - evt.clientY;
}
//e107Helper.log("getPostion() : evt.screenY="+evt.screenY+", evt.pageY="+evt.pageY+", evt.clientY="+evt.clientY)
//e107Helper.log("getPostion() : x="+x+" y="+y+" scrollX="+scrollX+" scrollY="+scrollY+", evt.clientX="+evt.clientX+", evt.clientY="+evt.clientY)
return {x:x, y:y, scrollX:scrollX, scrollY:scrollY};
},
boundEvents : [],
bindHandler : function( target, eventName, handler ) {
if ( target.addEventListener ) {
target.addEventListener( eventName, handler, false );
} else if ( target.attachEvent ) {
target.attachEvent( "on" + eventName, handler );
}
e107HelperEvents.boundEvents.push( arguments );
},
unbindHandler : function( target, eventName, handler ) {
if ( target.removeEventListener ) {
target.removeEventListener( eventName, handler, false );
} else if ( target.removeEvent ) {
target.removeEvent( "on" + eventName, handler );
}
},
dispose : function() {
for(var i = e107HelperEvents.boundEvents.length - 1; i >= 0; --i ) {
var be = e107HelperEvents.boundEvents[i];
if (be[1] != "unload") {
e107HelperEvents.unbindHandler( be[0], be[1], be[2] );
}
be[i] = null;
}
}
}
e107HelperEvents.bindHandler(window, "unload", e107HelperEvents.dispose);
/*
* e107HelperBrowser
* Helper object to determine the client browser
*/
var e107HelperBrowser = {
ua : navigator.userAgent,
isMoz : /Gecko/i.test(navigator.userAgent),
isIE55 : /msie 5\.5/i.test(navigator.userAgent),
isIE6 : /msie 6/i.test(navigator.userAgent),
isIE : /msie/i.test(navigator.userAgent),
isIWB : /Gecko/i.test(navigator.userAgent) && (/OS\/2/.test(navigator.platform) || /^Warp/.test(navigator.platform)),
isIWB20 : /Gecko/i.test(navigator.userAgent) && /^Warp/.test(navigator.platform),
platform : navigator.platform
}
/*
* e107HelperColor
* Helper object for color picker 'widget'
*/
var e107HelperColor = {
view : function(field,color) {
var fieldname = 'ColorPreview_' + field;
if (this.validateColor(color)) {
$(fieldname).style.backgroundColor = '#' + color;
$(field).value = color;
} else {
alert('Your color-code is not valid');
$(field).focus();
}
},
set : function(field,string) {
var color = this.validateColor(string);
if (color == null) {
alert('Invalid color code: ' + string);
}
else {
this.view(field,color);
$(field).value = color;
}
},
validateColor : function(string) {
string = string || '';
string = string + "";
string = string.toUpperCase();
var chars = '0123456789ABCDEF';
var out = '';
for (var i=0; i<string.length; i++) {
var schar = string.charAt(i);
if (chars.indexOf(schar) != -1) {
out += schar;
}
}
if (out.length != 6) {
return null;
}
return out;
}
}
/*
* e107HelperAutoSuggest
* Ajax helper object for auto suggest text fields
* Based on code from http://gadgetopia.com/autosuggest/
*/
var e107HelperAutoSuggest = {
suggestions : new Array(), // Array to store suggestions that match the user's input
urls : new Array(), // List of URL's that are the Ajax request processors
inputText : null, // The text input by the user.
highlighted : -1, // A pointer to the index of the highlighted suggestions item. -1 means nothing highlighted.
div : null, // A div to use to create the dropdown, set in add function
/**
* Adds the auto suggest functionality to a text input control.
* @param elem the text input control that is to get auto suggest functionality
* @param url the URL of the Ajax request processor
*/
add : function(elem, url) {
if (this.div == null) {
// First time in so create a hidden DIV which we wil luse to display suggestions
//this.div = document.createElement("DIV");
//var emptyList = document.createElement("UL");
//this.div.id = "e107helperautosuggest";
//this.div.style.visibility = "hidden";
//this.div.appendChild(emptyList);
//document.body.appendChild(this.div);
document.writeln("<div id='e107helperautosuggest' style='height:200px;overflow:scroll;display:none;'><ul></ul></div>");
this.div = $("e107helperautosuggest");
}
e107HelperAutoSuggest.urls[elem.id] = url;
/**
* Key down event handler for the input element.
* Enter use the highlighted suggestion, if there is one.
* Esc hide the suggestion dropdown
* Up/down/page up/page down Move the highlight up and down in the suggestions.
* @param event the event object
*/
elem.onkeydown = function(event) {
var ev = e107HelperEvents.getEvent(event);
var key = e107HelperEvents.getKeyCode(ev);
var tgt = ev.srcElement;
switch(key) {
case e107Helper.KEY_TAB :
// if (!ev.isAlt && !ev.isCtrl) {
// for Opera
if (!ev.altKey && !ev.ctrlKey) {
// Only do this if tab navigation is to another control on this page
e107HelperAutoSuggest.showDiv(false);
this.focus();
}
break;
case e107Helper.KEY_ENTER :
e107HelperAutoSuggest.useSuggestion(tgt);
e107HelperAutoSuggest.showDiv(false);
ev.returnValue = false;
break;
case e107Helper.KEY_ESC :
e107HelperAutoSuggest.showDiv(false);
break;
case e107Helper.KEY_UP :
if (e107HelperAutoSuggest.highlighted > 0) {
e107HelperAutoSuggest.highlighted--;
}
e107HelperAutoSuggest.changeHighlight();
break;
case e107Helper.KEY_DOWN :
if (e107HelperAutoSuggest.highlighted == -1 && e107HelperAutoSuggest.suggestions.length > 0) {
e107HelperAutoSuggest.getSuggestions(tgt);
} else if (e107HelperAutoSuggest.highlighted < (e107HelperAutoSuggest.suggestions.length - 1)) {
e107HelperAutoSuggest.highlighted++;
}
e107HelperAutoSuggest.changeHighlight();
break;
case e107Helper.KEY_HOME :
if (e107HelperAutoSuggest.highlighted > 0) {
e107HelperAutoSuggest.highlighted = 0;
}
e107HelperAutoSuggest.changeHighlight();
break;
case e107Helper.KEY_END :
if (e107HelperAutoSuggest.highlighted < e107HelperAutoSuggest.suggestions.length-1) {
e107HelperAutoSuggest.highlighted = e107HelperAutoSuggest.suggestions.length-1;
}
e107HelperAutoSuggest.changeHighlight();
break;
}
};
/**
* Key up event handler for the input element.
* If there is some text and it has changed from the last time we got a keyup event display a list of suggestions.
* @param ev the event Object
*/
elem.onkeyup = function(evt) {
var ev = e107HelperEvents.getEvent(evt);
var key = e107HelperEvents.getKeyCode(ev);
var tgt = ev.srcElement;
switch(key) {
// The control keys were already handled by onkeydown, so do nothing.
case e107Helper.KEY_ENTER:
case e107Helper.KEY_ESC:
case e107Helper.KEY_UP:
case e107Helper.KEY_DOWN:
case e107Helper.KEY_PAGE_UP:
case e107Helper.KEY_PAGE_DOWN:
case e107Helper.KEY_HOME:
case e107Helper.KEY_END:
return;
default:
if (this.value.length > 0) {
if (this.value != e107HelperAutoSuggest.inputText) {
e107HelperAutoSuggest.inputText = this.value;
e107HelperAutoSuggest.getSuggestions(tgt);
}
} else {
e107HelperAutoSuggest.inputText = "";
e107HelperAutoSuggest.showDiv(false);
}
}
};
/**
* Insert the highlighted suggestion into the input box, and remove the suggestion dropdown.
*/
this.useSuggestion = function(tgt) {
if (this.highlighted > -1) {
tgt.value = this.suggestions[this.highlighted];
this.showDiv(false);
}
};
/**
* Show or hide the DIV used to display suggestions.
* @param showit true to show DIV, false to hide it
*/
this.showDiv = function(showit) {
if (showit) {
e107HelperAutoSuggest.div.style.display = 'block';
e107HelperAutoSuggest.div.style.visibility = '';
} else {
e107HelperAutoSuggest.div.style.display = 'none';
e107HelperAutoSuggest.div.style.visibility = 'hidden';
this.highlighted = -1;
}
};
/**
* Modify the HTML in the dropdown to move the highlight.
*/
this.changeHighlight = function() {
var lis = e107HelperAutoSuggest.div.getElementsByTagName('LI');
for (i in lis) {
var li = lis[i];
if (this.highlighted == i) {
li.style.backgroundColor = "Highlight";
li.firstChild.style.color = "HighlightText";