Menu

[r15]: / javascript / general.js  Maximize  Restore  History

Download this file

647 lines (548 with data), 18.1 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
<!--
//GLOBALS
var w3c = (document.getElementById) ? 1:0
var ns4 = (document.layers) ? 1:0 //browser detect for NS4 & W3C standards
var hasCookies = false;
// tests whether the user accepts cookies, and sets a flag.
if(document.cookie == '') {
document.cookie = 'hasCookies=yes';
if (document.cookie.indexOf('hasCookies=yes') != -1) hasCookies = true;
}
else hasCookies = true;
// returns an object reference.
function getObject(obj) {
if (w3c)
var theObj = document.getElementById(obj);
else
if (ns4)
var theObj = eval("document." + obj);
return theObj;
}
// swaps text in a layer.
function swapText(text, divID, innerDivID) {
var content = "<span class=\"commandDesc\">" + text + "</span>";
if (w3c) {
var theObj = getObject(divID);
if (theObj) theObj.innerHTML = text;
}
else if (ns4) {
var innerObj = divID + ".document." + innerDivID;
var theObj = getObject(innerObj);
if (theObj) {
theObj.document.open();
theObj.document.write(content);
theObj.document.close();
}
}
}
// sets a cookie in the browser.
function setCookie (name, value, hours, path) {
if (hasCookies) {
if(hours) {
if ( (typeof(hours) == 'string') && Date.parse(hours) ) var numHours = hours;
else if (typeof(hours) == 'number') var numHours = (new Date((new Date()).getTime() + hours*3600000)).toGMTString();
}
document.cookie = name + '=' + escape(value) + ((numHours)?(';expires=' + numHours):'') + ((path)?';path=' + path:'');
}
}
// reads a cookie from the browser
function readCookie(name) {
if (document.cookie == '') return '';
else {
var firstChar, lastChar;
var theBigCookie = document.cookie;
firstChar = theBigCookie.indexOf(name);
if (firstChar != -1) {
firstChar += name.length + 1;
lastChar = theBigCookie.indexOf(';', firstChar);
if (lastChar == -1) lastChar = theBigCookie.length;
return unescape(theBigCookie.substring(firstChar, lastChar));
}
else return '';
}
}
/* Netscape 4 resize fix */
function WM_netscapeCssFix() {
if (document.WM.WM_netscapeCssFix.initWindowWidth != window.innerWidth || document.WM.WM_netscapeCssFix.initWindowHeight != window.innerHeight) {
document.location = document.location;
}
}
function WM_netscapeCssFixCheckIn() {
if ((navigator.appName == 'Netscape') && (parseInt(navigator.appVersion) == 4)) {
if (typeof document.WM == 'undefined'){
document.WM = new Object;
}
if (typeof document.WM.WM_scaleFont == 'undefined') {
document.WM.WM_netscapeCssFix = new Object;
document.WM.WM_netscapeCssFix.initWindowWidth = window.innerWidth;
document.WM.WM_netscapeCssFix.initWindowHeight = window.innerHeight;
}
window.onresize = WM_netscapeCssFix;
}
}
WM_netscapeCssFixCheckIn();
function showHideModuleMouseOver(divID) {
var theCookie = readCookie(divID);
if ((theCookie=="e") || (theCookie=="")) {
window.status="Collapse";
}
else {
window.status="Expand";
}
}
function showHideModule(divID, theme) {
var state = toggleFoldyPersistState(divID);
var ok=false;
if(w3c) {
var divIDobj = MM_findObj(divID);
var tlobj = MM_findObj(divID +"tl");
var toggleobj = MM_findObj(divID +"Toggle");
if(divIDobj != null && tlobj != null && toggleobj != null) {
ok=true;
if(state=="c") {
tlobj.src = "../themes/"+theme+"/spacer.gif";
toggleobj.src = "../themes/"+theme+"/module_toggle_closed.gif";
divIDobj.style.display = "none";
} else {
tlobj.src = "../themes/"+theme+"/spacer.gif";
toggleobj.src = "../themes/"+theme+"/module_toggle_open.gif";
divIDobj.style.display = "";
}
}
}
if(!ok){
document.location = document.location;
}
showHideModuleMouseOver(divID);
//window.status = '';
}
function toggleFoldyPersistState(divID) {
var theCookie = readCookie(divID);
var state="e";
if ((theCookie == "e") || (theCookie == "")) {
state="c";
}
setCookie(divID,state,'Wed 01 Jan 2020 00:00:00 GMT','/');
return state;
}
function MM_swapImgRestore() { //v3.0
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_findObj(n, d) { //v4.0
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && document.getElementById) x=document.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
// Remove an array item at n
// 0-based
function MM_removeNthArrayItem(array, n) {
var lhs = new Array();
if (n > 0)
lhs = array.slice(0, n);
var rhs = new Array();
if (n < array.length)
rhs = array.slice(n + 1);
var result = lhs.concat(rhs);
return result;
}
// Does the array contain the given string?
function MM_arrayContainsString(array, item) {
if (array == null)
return false;
var count = array.length;
for (i = 0; i < count; i++) {
if (array[i] == item)
return true;
}
return false;
}
// remove the given string from the array of strings
function MM_removeStringFromArray(array, item) {
if (array == null)
return null;
var count = array.length;
for (i = 0; i < count; i++) {
if (array[i] == item)
return MM_removeNthArrayItem(array, i);
}
return array;
}
// a selectedItems array is kept in the form. It is an array of strings, each
// string being the name of a checkbox image. It doesn't actually have to be
// the name="foo" attribute of the HTML object itself, just any arbitrary name
// that is associated with this checkbox. The image name is the actual name of the image.
function MM_toggleItem(form, itemName, imageName, theme) {
if (form.selectedItems == null)
form.selectedItems = new Array();
if (MM_arrayContainsString(form.selectedItems, itemName)) {
form.selectedItems = MM_removeStringFromArray(form.selectedItems, itemName);
document[imageName].src = '../themes/'+theme+'/checkbox_off_16.gif';
//MM_swapImage(imageName, '', '../themes/'+theme+'/checkbox_off_16.gif', '1');
} else {
form.selectedItems[form.selectedItems.length] = itemName;
document[imageName].src = '../themes/'+theme+'/checkbox_on_16.gif';
//MM_swapImage(imageName, '', '../themes/'+theme+'/checkbox_on_16.gif', '1');
}
MM_updateButtons2(form, form.selectedItems);
}
function MM_selectAllItems(form, theme) {
form.selectedItems = new Array();
if (form.checkboxes) {
var checkboxCount = form.checkboxes.length;
for (i = 0; i < checkboxCount; i++) {
var checkbox = form.checkboxes[i];
if (-1 == document[checkbox.mImageName].src.indexOf('dim_16.gif')) {
document[checkbox.mImageName].src = '../themes/'+theme+'/checkbox_on_16.gif';
form.selectedItems[form.selectedItems.length] = checkbox.mName;
}
}
}
MM_updateButtons2(form, form.selectedItems);
}
function MM_deselectAllItems(form, theme) {
form.selectedItems = new Array();
if (form.checkboxes) {
var checkboxCount = form.checkboxes.length;
for (i = 0; i < checkboxCount; i++) {
var checkbox = form.checkboxes[i];
if (-1 == document[checkbox.mImageName].src.indexOf('dim_16.gif')) {
document[checkbox.mImageName].src = '../themes/'+theme+'/checkbox_off_16.gif';
}
}
}
MM_updateButtons2(form, form.selectedItems);
}
// If all items are selected, deselect all. Otherwise select all.
function MM_toggleSelectedItems(form, theme) {
if (!form.selectedItems)
form.selectedItems = new Array();
if (form.checkboxes) {
if (form.selectedItems.length == form.checkboxes.length - MM_countDisabledCheckboxes(form))
MM_deselectAllItems(form, theme);
else
MM_selectAllItems(form, theme);
}
}
// counts the number of disabled checkboxes - used for deselect all
function MM_countDisabledCheckboxes(form) {
var disabledCount = 0;
if (form.checkboxes) {
var checkboxCount = form.checkboxes.length;
for (i = 0; i < checkboxCount; i++) {
var checkbox = form.checkboxes[i];
if (-1 != document[checkbox.mImageName].src.indexOf('dim_16.gif')) {
disabledCount++;
}
}
}
return disabledCount;
}
// See SELECTIONPARAMNAME and SELECTIONPARAMDELIMITER in ListModuleTagBase.java.
function MM_doButtonAction(action, selectedItems) {
// THESE MUST BE IN SYNC WITH ListModuleTagBase.java
var SELECTIONPARAMNAME = 'id';
var SELECTIONPARAMDELIMITER = '**';
// If the action is a javascript action (starts with 'javascript')
// then execute it immediately.
if ((action.indexOf('javascript') == 0) || (action.indexOf('Javascript') == 0)) {
eval(action);
} else {
var okay = true;
// if action starts with "function:" call the function on the selection to see
// if we can continue
if ((action.indexOf('function:') == 0)) {
okay = false;
var idx = action.indexOf(":");
if(idx + 1 < action.length) {
action = action.substr(idx+1);
idx = action.indexOf(",");
if(idx + 1 < action.length) {
var fxn = action.substr(0, idx);
action = action.substr(idx+1);
fxn = eval(fxn);
if(typeof(fxn) == "function") {
okay = fxn(selectedItems);
}
}
}
}
if(okay) {
var params = new String();
if (selectedItems) {
for (i = 0; i < selectedItems.length; i++) {
if (i > 0)
params = params.concat("**");
params = params.concat(selectedItems[i]);
}
}
var url = action;
if (params.length > 0) {
if (url.indexOf('?') == -1)
url = url + '?';
else
url = url + '&';
url = url + 'id=' + params;
}
window.location = url;
}
}
}
function MM_updateButtons(form) {
var dummy = new Array();
MM_updateButtons2(form, dummy);
}
function MM_updateButtons2(form, selectedItems) {
if (form.buttons) {
var buttonCount = form.buttons.length;
for (i = 0; i < buttonCount; i++) {
var button = form.buttons[i];
if (button) {
button.update(selectedItems);
}
}
}
}
function MM_getButtonWithName(form, buttonName) {
if (form.buttons) {
var buttonCount = form.buttons.length;
for (i = 0; i < buttonCount; i++) {
var button = form.buttons[i];
if (button.mName == buttonName) {
return button;
}
}
}
return null;
}
function MM_countFilesFolders(selectedItems) {
var ret_obj = new Object();
ret_obj["files"] = 0;
ret_obj["folders"] = 0;
var i = 0;
for(i=0;i<selectedItems.length;i++) {
var ftype = null;
if((ftype = MM_findObj(selectedItems[i]+"ftype")) != null) {
if(ftype.value == "file") ret_obj["files"]++;
else if(ftype.value == "folder") ret_obj["folders"]++;
}
}
return ret_obj;
}
function MM_oneFileOnly(selectedItems) {
var ret = false;
if(selectedItems.length == 1) {
var ftype = null;
if((ftype = MM_findObj(selectedItems[0]+"ftype")) != null) {
if(ftype.value == "file") ret = true;
}
}
return ret;
}
function MM_atLeastOneFile(selectedItems) {
var ret = false;
if(selectedItems.length > 0) {
var i = 0;
while(!ret && i < selectedItems.length) {
var ftype = null;
if((ftype = MM_findObj(selectedItems[i]+"ftype")) != null) {
if(ftype.value == "file") ret = true;
}
++i;
}
}
return ret;
}
function MMCommandButton(name,
form,
action,
enabledImage,
overImage,
downImage,
disabledImage,
enableOnNoSelection,
enableOnSingleSelection,
enableOnMultipleSelection,
enabledCheckSelectionJS,
altText,
confirmation,
confirmationMessage) {
this.mName = name; // Name of the image
this.mForm = form; // The form object enclosing this button (to retrieve selections)
this.mAction = action; // Action to perform when clicking
this.mEnabledImage = enabledImage; // enabled image (String)
this.mOverImage = overImage; // over image (String)
//this.mDownImage = downImage; // down image (String)
this.mDisabledImage = disabledImage; // disabled image (String)
this.mEnableOnNoSelection = enableOnNoSelection;
this.mEnableOnSingleSelection = enableOnSingleSelection;
this.mEnableOnMultipleSelection = enableOnMultipleSelection;
this.mEnabledCheckSelectionJS = null;
if(enabledCheckSelectionJS !='') {
this.mEnabledCheckSelectionJS = eval(enabledCheckSelectionJS);
}
this.mAltText = altText;
this.mConfirmation = confirmation;
this.mConfirmationMessage = confirmationMessage;
this.mEnabled = false;
this.update = MMCommandButton_update;
this.over = MMCommandButton_over;
this.out = MMCommandButton_out;
this.click = MMCommandButton_click;
}
function MMCommandButton_update(selectedItems) {
if(this.mEnabledCheckSelectionJS != '' &&
typeof(this.mEnabledCheckSelectionJS) == "function") {
var isEnabled = this.mEnabledCheckSelectionJS(selectedItems);
if (isEnabled == true) {
document[this.mName].src = this.mEnabledImage;
this.mEnabled = true;
} else {
document[this.mName].src = this.mDisabledImage;
this.mEnabled = false;
}
}
else {
if (selectedItems.length == 0) {
if (this.mEnableOnNoSelection == true) {
document[this.mName].src = this.mEnabledImage;
this.mEnabled = true;
} else {
document[this.mName].src = this.mDisabledImage;
this.mEnabled = false;
}
}
if (selectedItems.length == 1) {
if (this.mEnableOnSingleSelection == true) {
document[this.mName].src = this.mEnabledImage;
this.mEnabled = true;
} else {
document[this.mName].src = this.mDisabledImage;
this.mEnabled = false;
}
}
if (selectedItems.length > 1) {
if (this.mEnableOnMultipleSelection == true) {
document[this.mName].src = this.mEnabledImage;
this.mEnabled = true;
} else {
document[this.mName].src = this.mDisabledImage;
this.mEnabled = false;
}
}
}
}
function MMCommandButton_over() {
if (this.mEnabled) {
document[this.mName].src = this.mOverImage;
}
// To whom it may concern. If you are revisiting this code in order
// to speed it up, note that the thing slowing down the rollovers is
// this call to swapText.
swapText(this.mAltText, this.mForm.tt, this.mForm.tt + "i");
window.status= this.mAltText;
}
function MMCommandButton_out() {
if (this.mEnabled) {
document[this.mName].src = this.mEnabledImage;
}
swapText('', this.mForm.tt, this.mForm.tt + "i");
window.status = '';
}
function MMCommandButton_click() {
if (this.mEnabled) {
//document[this.mName].src = this.mDownImage;
if (this.mConfirmation) {
if (!confirm(this.mConfirmationMessage)) {
return;
}
}
MM_doButtonAction(this.mAction, this.mForm.selectedItems);
}
swapText('', this.mForm.tt, this.mForm.tt + "i");
window.status = '';
}
function MMCheckbox(name,
form,
imageName) {
// The mName is the name of the checkbox that is passed on via POST
this.mName = name;
this.mForm = form;
this.mImageName = imageName;
}
// A popup window for general use, but for invoking the content ui in particular
// For other purposes, a 500x350 window size is reasonable
function popUp( loc, w, h, menubar ) {
if( w == null ) { w = 700; }
if( h == null ) { h = 500; }
if( menubar == null || menubar == false ) {
menubar = "";
} else {
menubar = "menubar,";
}
//if( NS ) { w += 50; }
// Need the var or else IE4 blows up not recognizing editorWin
var editorWin = window.open(loc,'editWin', menubar + 'resizable,scrollbars,width=' + w + ',height=' + h);
//editorWin.focus(); //causing intermittent errors
}
// Used to submit a form if the user hits ENTER in the form - BAH
function submitOnEnter(form, e) {
if (document.all) e = window.event;
key = (document.layers) ? e.which : e.keyCode;
if (13 == key) {
if (form) form.submit();
return false;
}
return true;
}
// Used to kill a key press event from bubbling up - BAH
function killKeyEvent(e) {
if (document.all) e = window.event;
key = (document.layers) ? e.which : e.keyCode;
if (13 == key) e.cancelBubble = true;
}
// Used to limit the chars in a text or textarea input - BAH
// Must define variable maxChars & maxCharsError in the HTML tag or via javascript
function checkMaxChars(obj) {
// current key is not counted in length yet
if (obj.value.length >= obj.maxChars) {
alert(obj.maxCharsError + ': ' + obj.maxChars);
obj.value = obj.value.substr(0, obj.maxChars);
return false;
}
return true;
}
function doSitespringHelper(url, msg, installurl) {
var doIt = true;
if(!gSitespringHelperOK && !confirm(msg)) {
doIt = false;
}
if(doIt) window.location = url;
return;
}
function doHelpWindow(helpURL) {
mmHelpWindow = window.open(helpURL,"mmHelp");
// Quarter second pause before focus to avoid JS errors
setTimeout('mmHelpWindow.focus();',250);
}
function focusAndSelect(fld) {
var ualc = navigator.userAgent.toLowerCase();
if(ualc.indexOf('compatible') > -1 || ualc.indexOf("macin") < 0 ||
parseFloat(navigator.appVersion) >= 5.0) {
var fldobj = MM_findObj(fld);
if(fldobj != null) {
fldobj.focus(); fldobj.select();
}
}
}
//-->
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.