home *** CD-ROM | disk | FTP | other *** search
- /**
- * button.js
- * author: gary smith 15 Nov 97
- * @see: dialog.js
- * modified: 30 Nov 97
- * for sample code (still under construction)
- */
-
- /**
- * Constructs a Button object
- */
-
- function Button() {
- this.buttonValue = "Button";
- this.buttonAction = "";
- this.buttonPageX = 0;
- this.buttonPageY = 0;
- this.buttonWidth = 0;
- this.buttonHeight = 0;
- this.buttonColor = "#CDB79E";
- this.buttonHeightColor = "#999999";
- this.buttonWrap = false;
- this.buttonParentLayer = null;
-
- //methods
- this.showButton = showButton;
- this.exampleButton = exampleButton;
- this.setButtonValue = setButtonValue;
- this.setButtonAction = setButtonAction;
- this.setButtonPageX = setButtonPageX;
- this.setButtonPageY = setButtonPageY;
- this.setButtonWidth = setButtonWidth;
- this.setButtonHeight = setButtonHeight;
- this.setButtonColor = setButtonColor;
- this.setButtonWrap = setButtonWrap;
- this.setButtonParentLayer = setButtonParentLayer;
-
- //button methods
- this.onButton = onButton;
- this.onButton_MouseOver = onButton_MouseOver;
- this.onButton_MouseOut = onButton_MouseOut;
-
- this.DragButton = DragButton;
- this.startDragButton = startDragButton;
- this.endDragButton = endDragButton;
- this.setDragButton = setDragButton;
- this.nsButtonObject = nsButtonObject;
- this.nsButtonObject();
- }
- function showButton() {
- var label = this.buttonValue;
- var value = '<NOBR> '+ this.buttonValue +' </NOBR>';
- if(this.buttonWrap)
- value = this.buttonValue;
- var l = makeLayer(label, value, this.buttonParentLayer, this.buttonWidth,this.buttonHeight, this.buttonPageX,this.buttonPageY, '#000000', "hide");
- l.clip.width += 4;
- l.clip.height += 4;
- l.lite = makeLayer(label, "", l, l.clip.width -1, l.clip.height -1, 0,0, '#FFFFFF');
- l.dark = makeLayer(label, "", l, l.clip.width -2, l.clip.height -2, 1,1, '#666666');
- l.shade = makeLayer(label, "", l, l.clip.width -3, l.clip.height -3, 1,1, '#CCCCCC');
- l.main = makeLayer(label, value, l, l.clip.width -4, l.clip.height -4, 2,2, this.buttonColor);
- if(!this.buttonFocusValue)
- this.buttonFocusValue = '<FONT COLOR="white">'+ value +'</FONT>';
- l.hilite = makeLayer(label, this.buttonFocusValue, l, l.clip.width -4, l.clip.height -4, 2,2, this.buttonHeightColor, "hide");
- l.focus = makeLayer(label, "", l, l.clip.width -4, l.clip.height -4, 2,2);
- l.visibility = "inherit";
- l.focus.focus = true;
- l.main.saveBgColor = this.buttonColor;
- l.hilite.saveBgColor = this.buttonHiliteColor;
- l.main.onMouseOver = this.onButton_MouseOver;
- l.focus.onMouseOver = this.onButton_MouseOver;
- l.focus.onMouseOut = this.onButton_MouseOut;
- l.hilite.onMouseOut = this.onButton_MouseOut;
- l.focus.onFocus = this.onButton;
- l.hilite.onFocus = this.onButton;
- l.focus.buttonAction = this.buttonAction;
- l.hilite.buttonAction = this.buttonAction;
- l.that = this;
- //return l;
- this.l = l;
- }
-
- function onButton(e) {
- if(this.focus) {
- this.parentLayer.hilite.visibility = "hide";
- this.visibility = "hide";
- } else {
- this.parentLayer.focus.visibility = "inherit";
- this.visibility = "hide";
- }
- eval( this.buttonAction );
- window.NbuttonLabel = null;
- //this.bgColor=this.color;
- }
-
- function onButton_MouseOver(e) {
- //this.bgColor='#0000CD';
- this.parentLayer.hilite.visibility = "inherit";
- }
-
- function onButton_MouseOut(e) {
- if(this.focus)
- this.parentLayer.hilite.visibility = "hide";
- else
- this.visibility = "hide";
- }
-
- function setButtonValue(str) {
- this.buttonValue = str;
- }
-
- function setButtonFocusValue(str) {
- this.buttonFocusValue = str;
- }
-
- function setButtonAction(str) {
- this.buttonAction = str;
- }
-
- function setButtonPageX(i) {
- this.buttonPageX = i;
- }
-
- function setButtonPageY(i) {
- this.buttonPageY = i;
- }
-
- function setButtonWidth(i) {
- this.buttonWidth = i;
- }
-
- function setButtonHeight(i) {
- this.buttonHeight = i;
- }
-
- function setButtonColor(str) {
- this.buttonColor = str;
- }
-
- function setButtonHeightColor(str) {
- this.buttonHeightColor = str;
- }
-
- function setButtonWrap(boo) {
- this.buttonWrap = boo;
- }
-
- function setButtonParentLayer(str) {
- this.buttonParentLayer = str;
- }
-
- function setDragButton(l) {
- d = this;
- d.dragLayer = l.dragLayer;
- d.captureEvents(Event.MOUSEUP|Event.MOUSEDOWN|Event.MOUSEDRAG);
- d.onmousedown=startDragButton;
- d.onmouseup=endDragButton;
- }
- function DragButton(e) {
- //java.lang.System.out.println(e.pageX +" - "+ window.innerWidth);
- if(e.pageX > -5 && e.pageY > -5 && e.pageX < window.innerWidth && e.pageY < window.innerHeight) {
- d.dragLayer.moveBy(e.pageX-d.offX,e.pageY-d.offY);
- } else {
- windowMetamorph(e, this);
- }
- d.offX = e.pageX;
- d.offY = e.pageY;
- d.dragged = true;
- }
-
- function windowMetamorph(e, l) {
- //under construction
- //java.lang.System.out.println("e.pageY=" + e.pageY);
- //java.lang.System.out.println("value=" + l.that.buttonValue);
- if(!window.morphWin)
- window.morphWin = {};
- if(!window.morphWin.close) {
- var width = l.that.buttonWidth;
- var height = l.that.buttonHeight;
- var x = window.screenX -100;
- var y = l.pageY + window.screenY + window.outerHeight - window.innerHeight -20;
- window.morphWin = window.open("",'morph','outerWidth='+ width +',outerHeight='+ height +',left='+ x +',top='+ y);
- window.morphWin.document.open("text/html");
- window.morphWin.document.writeln(l.that.buttonValue);
- window.morphWin.document.close();
- //e.that.buttonValue;
- }
- }
-
- function startDragButton(e) {
- //java.lang.System.out.println("this=" + this);
- d.dragLayer.captureEvents(Event.MOUSEMOVE);
- d.dragLayer.onmousemove=DragButton;
- d.offX=e.pageX;
- d.offY=e.pageY;
- }
- function endDragButton(e) {
- d.dragLayer.onmousemove=0;
- if(d.dragged == true) {
- d.dragLayer.visibility="hide";
- setTimeout('if(d.dragLayer) d.dragLayer.visibility="inherit";',1);
- d.dragLayer.releaseEvents(Event.MOUSEDOWN|Event.MOUSEUP|Event.MOUSEMOVE|Event.MOUSEDRAG);
- d.dragged = false;
- if(e.pageY < 0)
- d.dragLayer.top = -5;
- //if(e.pageX > window.width) d.dragLayer.top = window.width -20;
- }
- }
-
- function nsButtonObject() {
- if(!window.nsButtonObjects) {
- window.nsButtonObjects = new Array();
- window.nsButtonObjects[0] = this;
- } else {
- window.nsButtonObjects[window.nsButtonObjects.length++] = this;
- }
- }
-
- function resetButton(e) {
- for(var i=0; i < window.nsButtonObjects.length; i++) {
- if(window.nsButtonObjects[i].that)
- window.nsButtonObjects[i].openButton();
- }
- }
-
- function exampleButton(str) {
- var sample = (str || 'Change document bgColor!');
- var myButton = new Button();
- //var myLayer = makeLayer('id', "<BR>testing.........<P>testing<P>", null, 0,0, 1,1, 'green');
- //myButton.setButtonParentLayer(myLayer);
- myButton.setButtonValue(sample);
- myButton.setButtonAction('window.document.bgColor="red";');
- myButton.setButtonPageX(10);
- myButton.setButtonPageY(10);
- //myButton.setButtonWidth(200);
- //myButton.setButtonHeight();
- //myButton.setButtonColor('red');
- //myButton.setButtonWrap(true);
- myButton.showButton();
- }
-
- function makeLayer(label, content, parentLyr, width, height, x, y, color, viso) {
- //java.lang.System.out.println(""+ parentLyr);
- if(!content)
- content = " ";
- 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(content);
- 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;
- }
-