/************************************************************************
* openFrame *
* *
* This is a utility function to display the page generated by a URL *
* in an IFRAME occupying the half of the window. *
* *
* Input: *
* name name of the frame *
* url URL of the page to display, if null the current contents*
* of the frame are left unchanged, but the dimensions may *
* be changed if the dimensions of the window have changed.*
* side which half to open in: "left" or "right" *
* *
* Returns: *
* the instance of Window for the <iframe> *
************************************************************************/
function openFrame(name, url, side)
{
// accept mixed case side indicator
side = side.toLowerCase();
// this this function may be invoked within a child frame
// locate the window and document instances for the top window
var win = window;
while(win.frameElement)
win = win.parent;
var doc = win.document;
var iframes = doc.getElementsByTagName("IFRAME");
var zindex = 0;
for (var ii = 0; ii < iframes.length; ii++)
{ // get the highest zindex
var element = iframes[ii];
if (element.style.position == "fixed" &&
element.className == side &&
element.style.zIndex > zindex)
zindex = element.style.zIndex;
} // get the highest zindex
// get the instance of <iframe> to display by name
iframe = doc.getElementById(name);
if (iframe)
{ // have existing element by name
if (iframe.nodeName !== 'IFRAME')
throw "util.js: openFrame: the element with id='" + name +
"' is not an <iframe>";
else
iframe.className = side;
} // have existing element by name
else
{ // need to create new frame
iframe = doc.createElement("IFRAME");
iframe.name = name;
iframe.id = name;
iframe.className = side;
iframe.onerror = openFrameError;
doc.body.appendChild(iframe);
} // need to create new frame
iframe.opener = window;
iframe.style.zIndex = zindex + 2; // move iframe to front
// identify the page to load into the frame
if (url !== null && url != iframe.src)
{
if (url.substring(0,5) == 'http:')
iframe.src = '/badUrlForIFrame.php?src=' + url;
else
iframe.src = url;
}
if (side != "left")
side = "right";
// resize the display of the transcription
var w = doc.documentElement.clientWidth;
var h = doc.documentElement.clientHeight;
var transcription = doc.getElementById('transcription');
if (transcription)
{ // frame for left side of window
transcription.style.width = w/2 + "px";
transcription.style.height = h + "px";
} // frame for left side of window
// size to half the width of the window and position the document in
// the right hand half of the window
iframe.style.width = w/2 + "px";
iframe.style.height = h + "px";
iframe.style.position = "fixed";
if (side == "left")
iframe.style.left = "0px";
else
iframe.style.left = w/2 + "px";
iframe.style.top = 0 + "px";
iframe.style.visibility = "visible";
return iframe.contentWindow;
} // openFrame
function openFrameError()
{
alert("open frame id='" + this.id + "' failed");
}
/************************************************************************
* closeFrame *
* *
* This is a utility function to close the current frame. It handles *
* the case where the current window is in an <iframe> *
************************************************************************/
function closeFrame()
{
var iframe = window.frameElement;
if (iframe)
{ // current window is in an iframe
var msg = '';
// locate the window and document instances for the top window
var win = window;
while(win.frameElement)
win = win.parent;
var doc = win.document;
var iframes = doc.getElementsByTagName("IFRAME");
var sideCount = 0;
for(var fi = 0; fi < iframes.length; fi++)
{
var iframe = iframes[fi];
var className = iframe.className;
// var className = iframe.className;
msg += " <iframe src='" + iframe.src + "' class='" + className + "'>, ";
if (className == 'right' || className == 'left')
sideCount++;
}
if (sideCount == 1)
{ // closing last dialog
// resize the display of the transcription
var w = doc.documentElement.clientWidth;
var h = doc.documentElement.clientHeight;
var transcription = doc.getElementById('transcription');
if (transcription)
{ // restore to full width
transcription.style.width = w + "px";
transcription.style.height = h + "px";
} // restore to full width
} // closing last dialog
var father = iframe.parentNode;
father.removeChild(iframe);
} // current window is in an iframe
else
window.close();
} // closeFrame
برچسب:
نویسنده: آیلین رضوانی