/*
* File: popUpWindow.js
*
* Open a new window with the specified content
*
* Usage:
*
* <script type="text/javascript"
* src="http://www.bgsu.edu/scripts/popUpWindow.js">
* </script>
*
* Insert the <script> element into the <head> or <body> of your document.
*
* Constructors: PopUpWindow() create an empty PopUpWindow object
* suitable for writing
* PopUpWindow( url ) create a PopUpWindow object and
* load the specified URL
*
* Methods: open() open the new window
* close() close the new window
*
* Window feature methods:
* setWidth( pixels )
* setHeight( pixels )
* setDirectories( boolean )
* setLocation( boolean )
* setMenubar( boolean )
* setResizable( boolean )
* setScrollbars( boolean )
* setStatus( boolean )
* setToolbar( boolean )
*
* Note: A "boolean" value is either true or false (see Example 2 below).
*
* Example 1: popUpWindowTest1.html
*
* <script type="text/javascript"
* src="http://www.bgsu.edu/scripts/popUpWindow.js">
* </script>
* <script type="text/javascript">
* var newWindow = new PopUpWindow( "http://www.bgsu.edu/" );
* newWindow.open();
* </script>
*
* Example 2: popUpWindowTest2.html
*
* <script type="text/javascript"
* src="http://www.bgsu.edu/scripts/popUpWindow.js">
* </script>
* <script type="text/javascript">
* var url = "http://www.bgsu.edu/scripts/contact.html";
* var newWindow = new PopUpWindow( url );
* newWindow.setWidth( 465 );
* newWindow.setHeight( 375 );
* newWindow.setScrollbars( true );
* newWindow.setResizable( true );
* </script>
* <!-- Insert this link in the <body> of your document -->
* <a href="javascript:newWindow.open()"
* onmouseover="window.status = 'Click to open a new window'; return true"
* onmouseout="window.status = ''">Contact BGSU!</a>
*
* Example 3: popUpWindowTest3.html
*
* <!-- General test of PopUpWindow( url ) constructor -->
*
* Example 4: popUpWindowTest4.html
*
* <script type="text/javascript"
* src="http://www.bgsu.edu/scripts/popUpWindow.js">
* </script>
* <script type="text/javascript">
* var win = new PopUpWindow();
* win.setWidth( 300 );
* win.setHeight( 200 );
* win.open(); // open an empty window
* win.document.open(); // open document for writing
* win.document.write( "<p>This is a test. " );
* win.document.writeln( "It is <em>only</em> a test!</p>" );
* win.document.close(); // close document for writing
* </script>
*
* Example 5: popUpWindowTest5.html
*
* <!-- General test of PopUpWindow() constructor -->
*
*/
// PopUpWindow constructor:
function PopUpWindow( url ) {
// URL of the page to be loaded into the new window:
if ( url == null ) url = "";
this.url = url;
// Private reference to the new window:
this.winHandle = null;
// Private window name:
this.winName = "newWin";
// Width and height of the new window:
this.width = null;
this.height = null;
// Other window features (alphabetically):
this.directories = null;
this.location = null;
this.menubar = null;
this.resizable = null;
this.scrollbars = null;
this.status = null;
this.toolbar = null;
}
// Method to open a new window:
function PUW_open() {
//if ( this.winHandle != null && this.winHandle.closed ) this.winHandle = null;
//if ( this.winHandle != null ) return;
var features = "";
// Process each feature of this window:
for ( var prop in this ) {
with ( this ) {
// Ignore PopUpWindow methods:
if ( typeof eval( prop ) != "function" ) {
// Ignore PopUpWindow properties that are not window features:
if ( prop != "url" && prop != "winHandle" ) {
if ( eval( prop ) != null ) {
if ( prop == "width" || prop == "height" ) {
features += prop + "=" + eval( prop ) + ",";
} else if ( eval( prop ) ) {
features += prop + "=yes,";
} else {
features += prop + "=no,";
}
}
}
}
}
}
//window.alert( "url = " + this.url ); // debugging
//window.alert( "features = " + features ); // debugging
// Open a new window:
this.winHandle = window.open( this.url, this.winName, features );
// The document property may only be captured by an empty window:
if ( this.url == "" ) this.document = this.winHandle.document;
// Browser bug fix:
if ( !this.winHandle.opener ) this.winHandle.opener = self;
}
PopUpWindow.prototype.open = PUW_open;
// Close the window:
function PUW_close() {
if ( this.winHandle != null ) this.winHandle.close();
this.winHandle = null;
}
PopUpWindow.prototype.close = PUW_close;
// Method to set the width of the new window:
function PUW_setWidth( pixels ) {
// Try to parse the argument as an integer:
pixels = parseInt( pixels );
// Test for a non-negative integer:
if ( !isNaN( pixels ) && pixels >= 0 ) this.width = pixels;
}
PopUpWindow.prototype.setWidth = PUW_setWidth;
// Method to set the height of the new window:
function PUW_setHeight( pixels ) {
// Try to parse the argument as an integer:
pixels = parseInt( pixels );
// Test for a non-negative integer:
if ( !isNaN( pixels ) && pixels >= 0 ) this.height = pixels;
}
PopUpWindow.prototype.setHeight = PUW_setHeight;
// Method to specify directories feature:
function PUW_setDirectories( booleanValue ) {
this.directories = booleanValue;
}
PopUpWindow.prototype.setDirectories = PUW_setDirectories;
// Method to specify location feature:
function PUW_setLocation( booleanValue ) {
this.location = booleanValue;
}
PopUpWindow.prototype.setLocation = PUW_setLocation;
// Method to specify menubar feature:
function PUW_setMenubar( booleanValue ) {
this.menubar = booleanValue;
}
PopUpWindow.prototype.setMenubar = PUW_setMenubar;
// Method to specify resizable feature:
function PUW_setResizable( booleanValue ) {
this.resizable = booleanValue;
}
PopUpWindow.prototype.setResizable = PUW_setResizable;
// Method to specify scrollbars feature:
function PUW_setScrollbars( booleanValue ) {
this.scrollbars = booleanValue;
}
PopUpWindow.prototype.setScrollbars = PUW_setScrollbars;
// Method to specify status feature:
function PUW_setStatus( booleanValue ) {
this.status = booleanValue;
}
PopUpWindow.prototype.setStatus = PUW_setStatus;
// Method to specify toolbar feature:
function PUW_setToolbar( booleanValue ) {
this.toolbar = booleanValue;
}
PopUpWindow.prototype.setToolbar = PUW_setToolbar;