home *** CD-ROM | disk | FTP | other *** search
- /**
- * dialog.js 0.4 97/Nov/15
- *
- * Copyright (c) 1997 Netscape Communications Corp. All Rights Reserved.
- *
- * Netscape grants you a non-exclusive, royalty free, license to use,
- * modify and redistribute this software in source and binary code form,
- * provided that this copyright notice and license appear on all copies of
- * the software.
- *
- * This software is provided "AS IS," without a warranty of any kind.
- *
- * author: gary smith
- * for sample code (still under construction)
- */
-
- /**
- * Constructs a Dialog object
- */
- function Dialog() {
- this.dialogTitle = "Dialog";
- this.dialogContent = "";
- this.dialogSRC = "URL";
- this.dialogPageX = (100 + self.pageXOffset) || 100;
- this.dialogPageY = (100 + self.pageYOffset) || 100;
- this.dialogWidth = null;
- this.dialogHeight = null;
- this.dialogMorph = false;
- this.dialogBgColor = "#C1CDCD"; //C1CDCD
- this.dialogMainBgColor = "#C1CDCD"; //cool colors: D2B48C 9AC0CD 5F9EA0 B4CDCD A2B5CD 9FB6CD D2B48C 6CA6CD 66CDAA 458B74
- this.dialogButtonBgColor = "#CDB79E"; //9FB6CD CDC9A5 CDCDC1 CDC0B0 D2B48C BDB76B CDB79E CDB7B5
- this.dialogButtonHiliteBgColor = "#999999";
- this.dialogTitleBgColor = "#000084";
- this.dialogButtons = new Array();
- this.dialogButtonsCentered = new Array();
- this.dialogButtonsCenteredWidth = 0;
-
- //methods
- this.openDialog = openDialog;
- this.exampleDialog = exampleDialog;
- this.setDialogContent = setDialogContent;
- this.setDialogTitle = setDialogTitle;
- this.setDialogPageX = setDialogPageX;
- this.setDialogPageY = setDialogPageY;
- this.setDialogWidth = setDialogWidth;
- this.setDialogHeight = setDialogHeight;
- this.setDialogBgColor = setDialogBgColor;
- this.setDialogMainBgColor = setDialogMainBgColor;
- this.setDialogButtonBgColor = setDialogButtonBgColor;
- this.setDialogTitleBgColor = setDialogTitleBgColor;
- this.setDialogMorph = setDialogMorph;
-
- //button methods
- this.dialogButton = dialogButton;
- this.setDialogBase = setDialogBase;
- this.setDialogButton = setDialogButton;
- this.setTitleBarButton = setTitleBarButton;
- this.addDialogButton = addDialogButton;
- this.onDialogButton = onDialogButton;
- this.dialogButtonMouseOver = dialogButtonMouseOver;
- this.dialogButtonMouseOut = dialogButtonMouseOut;
- this.dialogTitleMouseOver = dialogTitleMouseOver;
- this.dialogTitleMouseOut = dialogTitleMouseOut;
-
- this.cDrag = cDrag;
- this.cDragStart = cDragStart;
- this.cDragEnd = cDragEnd;
- this.cDragSet = cDragSet;
- this.dialogWinMorph = dialogWinMorph;
- this.nsDialogObject = nsDialogObject;
- this.nsDialogObject();
- }
-
- function openDialog(label, arbitrary) {
- if(window.NdialogLabel == label) return;
- window.NdialogLabel = label;
-
- if(window.Ndialog) {
- this.win = window.Ndialog;
- if(this.win.base.visibility == 'hide') {
- //java.lang.System.out.println("activeD");
- this.win.title.document.open('text/html');
- this.win.title.document.writeln('<BODY><NOBR><FONT COLOR="#FFFFFF"><B><SPAN ID=font14> '+ this.dialogTitle +'</SPAN></B></FONT></BODY>');
- this.win.title.document.close();
- this.win.doc.visibility = "hide";
- this.win.doc = null;
- } else {
- this.setDialogBase(label);
- }
- } else {
- this.setDialogBase(label);
- }
-
- var temp = makeLayer(label, this.dialogContent, this.win.base, 0,0, 4,4, "", "hide");
- if(temp.clip.width < 100)
- temp.clip.width = 100;
- this.boxW = 100;
- if(this.dialogWidth == null)
- this.boxW = temp.clip.width;
- else this.boxW = this.dialogWidth -10;
- this.win.main.document.open('text/html');
- this.win.main.document.writeln(" ");
- this.win.main.document.close();
- this.win.doc = makeLayer('ddoc', this.dialogContent, this.win.base, this.boxW,0, 4,25, this.dialogBgColor);
- if(this.win.doc.clip.width > this.boxW)
- this.boxW = this.win.doc.clip.width +5;
- this.boxW += 10;
- this.boxH = 100;
- if(this.dialogHeight == null)
- this.boxH = this.win.title.clip.height + this.win.doc.clip.height;
- else this.boxH = this.dialogHeight;
- //this.win.doc.clip.height = this.boxH;
- if(this.dialogButtons.length > 0)
- this.boxH += 40;
- this.boxW += 10;
- this.boxH += 10;
- this.dialogWidth = this.boxW;
- this.dialogHeight = this.boxH;
- this.win.doc.clip.width = this.boxW -4;
- this.win.base.clip.width = this.boxW +4;
- this.win.base.clip.height = this.boxH +4;
- this.win.edge.clip.width = this.boxW +4;
- this.win.edge.clip.height = this.boxH +4;
- this.win.base.visibility = 'inherit';
- this.win.dark.clip.width = this.boxW +2;
- this.win.dark.clip.height = this.boxH +2;
- this.win.lite.clip.width = this.boxW +1;
- this.win.lite.clip.height = this.boxH +1;
- this.win.main.clip.width = this.boxW;
- this.win.main.clip.height = this.boxH;
- this.win.title.clip.width = this.boxW -4;
- this.win.title.clip.height = 20;
- this.win.title.saveBgColor = this.dialogTitleBgColor;
- this.win.titleBarButton.left = this.win.title.clip.width -15;
- this.win.title.cDragSet = this.cDragSet;
- this.win.title.cDragLayer = this.win.base;
- this.win.title.onMouseOver = this.dialogTitleMouseOver;
- this.win.title.onMouseOut = this.dialogTitleMouseOut;
- this.win.base.that = this;
- this.win.base.moveTo(this.dialogPageX,this.dialogPageY);
-
- if(this.dialogButtons.length > 0) {
- //this.win.button.visibility = "hide";
- this.win.button.dialogButtons = new Array();
- for(var i=0; i<this.dialogButtons.length; i++) {
- var b = this.dialogButtons[i];
- this.win.button.dialogButtons[i] = this.setDialogButton(b.label, b.value, this.win.main, null, null, b.x, b.y, this.win, b.onDialogButton);
- }
- var centeredBase = (this.boxW - this.dialogButtonsCenteredWidth) /2;
- for(var i=0; i<this.dialogButtonsCentered.length; i++) {
- if(this.dialogButtonsCentered[i -1])
- centeredBase += this.dialogButtonsCentered[i -1].clip.width +1;
- this.dialogButtonsCentered[i].left = centeredBase;
- }
- for(var i=0; i<this.dialogButtons.length; i++) {
- this.win.button.dialogButtons[i].visibility = "inherit";
- }
- }
- //if(this.dialogButtons.length <= 0) {
- //this.boxH = this.win.title.clip.height + this.win.doc.clip.height +5;
- //} else {
- //this.boxH = this.win.title.clip.height + this.win.doc.clip.height + this.win.buttonsHeight +5;
- //Ndialog.button.left = (this.boxW - Ndialog.button.clip.width) /2;
- //Ndialog.button.top = this.boxH - Ndialog.button.clip.height -5;
- //Ndialog.button.visibility = "inherit";
- //}
- window.captureEvents(Event.RESIZE);
- window.onresize=resetDialog;
- eval( arbitrary );
- if(this.dialogSRC != "URL")
- this.win.doc.src = this.dialogSRC;
- }
-
- function setDialogBase(label) {
- //java.lang.System.out.println("no activeD");
- this.win = new Object();
- this.win.base = new Layer(100);
- this.win.base.bgColor = '#000000';
- this.win.base = makeLayer(label, "", null, 0,0, -1,-1, '#000000');
- this.win.edge = makeLayer(label, "", this.win.base, 0,0, -1,-1, '#DDDDDD');
- this.win.dark = makeLayer(label, "", this.win.base, 0,0, 1,1, '#888888');
- this.win.lite = makeLayer(label, "", this.win.base, 0,0, 1,1, '#FFFFFF');
- this.win.main = makeLayer(label, "", this.win.base, 0,0, 2,2, this.dialogMainBgColor);
- this.win.title = makeLayer('title', '<BODY><NOBR><FONT COLOR="#FFFFFF"><B><SPAN ID=font14> '+ this.dialogTitle +'</SPAN></B></FONT></BODY>', this.win.base, 0,0, 4,4, this.dialogTitleBgColor);
- this.win.titleBarButton = this.setTitleBarButton('titleX', "", this.win.base, null,null, 177, null, this.win);
- this.win.button = new Layer();
- window.Ndialog = this.win;
- }
-
- function addDialogButton(label, value, x, y, onDialogButton) {
- newDialogButton = new this.dialogButton(label, value, x, y, onDialogButton);
- this.dialogButtons[this.dialogButtons.length++] = newDialogButton;
- }
-
- function dialogButton(label, value, x, y, onDialogButton) {
- this.label = label;
- this.value = value;
- this.x = x;
- this.y = y;
- this.onDialogButton = onDialogButton;
- }
-
- function setDialogButton(label, value, parentLyr, width, height, x, y, dialogObj, onDialogButton) {
- if(typeof(x) != 'number')
- var trueX = x; x = 0;
- if(typeof(y) != 'number')
- y = 0;
- value = ' '+ value +' ';
- var button = makeLayer(label, value, parentLyr, 0,0, x,y, '#000000', "hide");
- //this.boxH = dialogObj.title.clip.height + dialogObj.doc.clip.height + button.clip.height +10;
- button.clip.width += 4;
- button.clip.height += 4;
- button.lite = makeLayer(label, "", button, button.clip.width -1, button.clip.height -1, 0,0, '#FFFFFF');
- button.dark = makeLayer(label, "", button, button.clip.width -2, button.clip.height -2, 1,1, '#666666');
- button.shade = makeLayer(label, "", button, button.clip.width -3, button.clip.height -3, 1,1, '#CCCCCC');
- button.value = makeLayer(label, value, button, button.clip.width -4, button.clip.height -4, 2,2, this.dialogButtonBgColor);
- button.value.saveBgColor = this.dialogButtonBgColor;
- button.value.saveHiliteBgColor = this.dialogButtonHiliteBgColor;
- button.value.win = dialogObj;
- button.value.dialogButtons = this.dialogButtons;
- button.value.label = label;
- button.value.onDialogButton = onDialogButton;
- button.value.onFocus = this.onDialogButton;
- button.value.onMouseOver = this.dialogButtonMouseOver;
- button.value.onMouseOut = this.dialogButtonMouseOut;
- button.top = dialogObj.title.clip.height + dialogObj.doc.clip.height +5;
- if(trueX == 'center' && this.dialogButtons) {
- this.dialogButtonsCentered[this.dialogButtonsCentered.length++] = button;
- this.dialogButtonsCenteredWidth += button.clip.width;
- }
- if(trueX == 'right')
- button.left = this.boxW - (button.clip.width +5);
- button.top += 7;
- dialogObj.buttonsHeight = button.clip.height +12;
- return button;
- }
-
- function setTitleBarButton(label, value, parentLyr, width, height, x, y, dialogObj, onDialogButton) {
- if(typeof(x) != 'number')
- var trueX = x; x = 0;
- if(typeof(y) != 'number')
- y = 0;
- var button = makeLayer(label, value, parentLyr, 0,0, x,y, '#000000');
- button.clip.width = 16;
- button.clip.height = 14;
- button.lite = makeLayer(label, "", button, button.clip.width -1, button.clip.height -1, 0,0, '#FFFFFF');
- button.dark = makeLayer(label, "", button, button.clip.width -2, button.clip.height -2, 1,1, '#666666');
- button.shade = makeLayer(label, "", button, button.clip.width -3, button.clip.height -3, 1,1, '#CCCCCC');
- button.value = makeLayer(label, value, button, button.clip.width -4, button.clip.height -4, 2,2, this.dialogMainBgColor);
- button.value.saveBgColor = this.dialogMainBgColor;
- button.value.win = dialogObj;
- button.value.label = button;
- button.value.onDialogButton = onDialogButton;
- button.value.onFocus = this.onDialogButton;
- button.value.onMouseOver = this.dialogButtonMouseOver;
- button.value.onMouseOut = this.dialogButtonMouseOut;
- button.value.top -= 5;
- button.value.clip.top += 5;
- button.value.clip.height += 5;
- button.value.left += 3;
- button.value.clip.left -= 3;
- button.value.clip.width -= 3;
- button.top = 7;
- return button;
- }
-
- function onDialogButton(e) {
- this.bgColor='#888888';
- this.dialog = this.win.doc;
- this.win.base.visibility = 'hide';
- eval( this.onDialogButton );
- //this.win = null;
- window.NdialogLabel = null;
- }
-
- function dialogButtonMouseOver(e) {
- this.bgColor = this.saveHiliteBgColor || "#999999";
- }
-
- function dialogButtonMouseOut(e) {
- this.bgColor = this.saveBgColor;
- }
-
- function dialogTitleMouseOver(e) {
- this.cDragSet(this);
- this.bgColor = '#0000CD';
- }
-
- function dialogTitleMouseOut(e) {
- this.bgColor = this.saveBgColor;
- }
-
- function setDialogContent(str) {
- this.dialogContent = str;
- }
-
- function setDialogTitle(str) {
- this.dialogTitle = str;
- }
-
- function setDialogPageX(i) {
- this.dialogPageX = i;
- }
-
- function setDialogPageY(i) {
- this.dialogPageY = i;
- }
-
- function setDialogWidth(i) {
- this.dialogWidth = i;
- }
-
- function setDialogHeight(i) {
- this.dialogHeight = i;
- }
-
- function setDialogBgColor(str) {
- this.dialogBgColor = str;
- }
-
- function setDialogMainBgColor(str) {
- this.dialogMainBgColor = str;
- }
-
- function setDialogButtonBgColor(str) {
- this.dialogButtonBgColor = str;
- }
-
- function setDialogButtonHiliteBgColor(str) {
- this.dialogButtonHiliteBgColor = str;
- }
-
- function setDialogTitleBgColor(str) {
- this.dialogTitleBgColor = str;
- }
-
- function setDialogMorph(boo) {
- this.dialogMorph = boo;
- }
-
- function cDragSet(l) {
- d = this;
- d.cDragLayer = l.cDragLayer || l.parentLayer || l;
- d.captureEvents(Event.MOUSEUP|Event.MOUSEDOWN|Event.MOUSEDRAG);
- d.onmousedown=cDragStart;
- d.onmouseup=cDragEnd;
- }
-
- function cDrag(e) {
- var x = window.innerWidth;
- var y = window.innerHeight;
- if(e.pageX > -5 && e.pageY > -5 && e.pageX < x && e.pageY < y) {
- d.cDragLayer.moveBy(e.pageX-d.offX,e.pageY-d.offY);
- } else {
- if(d.cDragLayer.that.dialogMorph) {
- cDragEnd(e);
- dialogWinMorph(e, this);
- }
- }
- d.offX = e.pageX;
- d.offY = e.pageY;
- d.dragged = true;
- }
-
- function dialogWinMorph(e, l) {
- //java.lang.System.out.println("value=" + l.that.dialogContent);
- //java.lang.System.out.println("l.pageX=" + l.pageX);
- if(!l.that) return;
- if(!window.dialogWinMorphs)
- window.dialogWinMorphs = new Array();
- java.lang.System.out.println("len=" + window.dialogWinMorphs.length);
- l.that.win.base.visibility = "hide";
- //if(!l.that.dialogMorphWin) l.that.dialogMorphWin = {};
- //if(!l.that.dialogMorphWin.close) {
- var width = l.that.dialogWidth +20;
- var height = l.that.dialogHeight +20;
- var y = l.pageY + window.screenY + window.outerHeight - window.innerHeight -20;
- if(l.pageX > 0)
- var x = window.screenX + window.outerWidth;
- else
- var x = window.screenX - 100;
- var id = window.dialogWinMorphs.length;
- var win = window.open("",'win' + id,'outerWidth='+ width +',outerHeight='+ height +',left='+ x +',top='+ y);
- win.document.open("text/html");
- win.document.writeln('<BODY BGCOLOR="'+ l.that.dialogBgColor +'">');
- win.document.writeln('<TITLE>'+ l.that.dialogTitle +'</TITLE>');
- win.document.writeln(l.that.dialogContent +'</BODY>');
- win.document.close();
- NdialogLabel = null;
- if(window.dev)
- win.dev = window.dev;
- win.focus();
- window.dialogWinMorphs[l.that.dialogTitle] = win;
- window.dialogWinMorphs[id] = win;
- //}
- }
-
- function cDragStart(e) {
- //java.lang.System.out.println("this=" + this);
- d.cDragLayer.captureEvents(Event.MOUSEMOVE);
- d.cDragLayer.onmousemove=cDrag;
- d.offX=e.pageX;
- d.offY=e.pageY;
- }
-
- function cDragEnd(e) {
- d.cDragLayer.onmousemove=0;
- if(d.dragged == true) {
- if(d.refresh) {
- d.cDragLayer.visibility="hide";
- setTimeout('if(d.cDragLayer) d.cDragLayer.visibility="inherit";',1);
- }
- d.cDragLayer.releaseEvents(Event.MOUSEDOWN|Event.MOUSEUP|Event.MOUSEMOVE|Event.MOUSEDRAG);
- d.dragged = false;
- if(e.pageY < 0)
- d.cDragLayer.top = -5;
- //if(e.pageX > window.width) d.cDragLayer.top = window.width -20;
- }
- }
-
- function nsDialogObject() {
- if(!window.nsDialogObjects) {
- window.nsDialogObjects = new Array();
- window.nsDialogObjects[0] = this;
- } else {
- window.nsDialogObjects[window.nsDialogObjects.length++] = this;
- }
- }
-
- function resetDialog(e) {
- for(var i=0; i < window.nsDialogObjects.length; i++) {
- if(window.nsDialogObjects[i].win)
- window.nsDialogObjects[i].openDialog();
- }
- }
-
- function exampleDialog(str) {
- var dialog = new Dialog();
- var value = (str || '<CENTER><BR>Enter a local <B>filename</B>: <FORM><INPUT TYPE=FILE NAME="fileName" VALUE="" SIZE=40> </FORM></CENTER>');
- dialog.setDialogContent(value);
- dialog.setDialogTitle('Dialog');
- dialog.setDialogBgColor("#DDDDDD");
- //dialog.setDialogWidth(600);
- //dialog.setDialogHeight(150);
- //dialog.setDialogPageX(200);
- //dialog.setDialogPageY(250);
- //dialog.dialogSRC = "../../";
- dialog.addDialogButton("OKlabel", " OK ", "center", 3, "alert('You entered filename: ' + this.dialog.document.forms[0].fileName.value)");
- dialog.addDialogButton("CancelLabel", "Cancel", "center", 3, "");
- //dialog.addDialogButton("AnotherLabel", "Another", "right", 3, "");
- dialog.openDialog('exampleLabel');
- }
-
- function makeLayer(label, value, parentLyr, width, height, x, y, color, viso) {
- //java.lang.System.out.println(""+ parentLyr);
- if(!value)
- value = " ";
- if(parentLyr)
- var l = new Layer(width, parentLyr);
- else var l = new Layer(width);
- l.document.ids.font14.fontSize = 14;
- l.document.ids.sysFont.fontSize = 12;
- l.document.ids.sysFont.fontFamily = "Arial, Espy, sans-serif";
- l.document.open("text/html");
- l.document.writeln(value);
- l.document.close();
- l.label = label;
- l.moveTo(x,y);
- if(color != "")
- l.bgColor = color;
- if(width)
- l.clip.width = width;
- if(height)
- l.clip.height = height;
- if(!viso)
- l.visibility = "inherit";
- return l;
- }
-