<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Strict//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<title>Progress Dialog Box - Test Page</title>
<link rel="stylesheet" type="text/css" href="common.css" />
<script type="text/javascript" src="common.js"></script>
<script type="text/javascript" src="EB_addin_Test.js"></script>
<script type="text/javascript">
function Test_ShowModelessDialog()
{
var p = new classProgressDialogModeless();
function loop()
{
var total /*: int*/ = 10000;
p.start();
for (var i /*: int*/ = 0; i < total; i++)
{
p.setBarOneProgress(i + 1, total);
if (p.stopped) { break; }
}
}
loop(); // no need for any window.setTimeout
}var classProgressDialogModeless /*: Function*/ = (function(){function classProgressDialogModeless(
config /*: Object*/
)
{
this.dialog /*: Window*/;
this.doc /*: HTMLDocument*/;
this.config /*: Object*/;
this.stopped /*: Boolean*/;
this.barOneUnits /*: int*/;
this.barOneTable /*: HTMLTableElement*/;
this.barOneRow /*: HTMLTableRowElement*/;
this.barOneLit /*: int*/;
this.barOneCountField /*: HTMLParagraphElement*/;
this.barOneCountFieldText /*: Text*/;
this.stopButton /*: HTMLInputElement*/;
this.initialise(config);
}
var constr /*: Function*/ = classProgressDialogModeless;
var proto /*: Object*/ = ExtendClass(classProgressDialogModeless, Object);function initialise(
config /*: Object*/
) /*: void*/
{
var me /*: classProgressDialog*/ = this;
var height /*: int*/;
var defaults /*: Object*/;
var dialogOptions /*: String*/;
var doc /*: HTMLDocument*/;
var style /*: CSSStyleDeclaration*/;
var elm /*: HTMLElement*/;
var elmInner /*: HTMLElement*/;
var table /*: HTMLTableElement*/;
var row /*: HTMLTableRowElement*/
var cell /*: HTMLTableCellElement*/;
var text /*: Text*/;
var tbody /*: HTMLTableSectionElement*/;
var hr /*: HTMLHRElement*/;
var times /*: int*/ = 5;
// DEFAULT CONFIGURATION
defaults = {
width : 400,
windowTitle : "Test 1 - showModelessDialog",
barOneUnits : 20,
stopButton : true,
closeButton: true
};
// DEFAULT APPLIES IF NOT SPECIFIED IN USER SUPPLIED CONFIG
if (!config) { config = {}; }
for (var k /*: String*/ in defaults)
{
if (typeof config[k] == typeof defaults[k]) { continue; }
config[k] = defaults[k];
}
this.config = config;
// OPEN MODELESS DIALOG
dialogOptions = "dialogHeight:10px; dialogWidth:" + config.width + "px; center:no; edge:raised; help:no; resizable:no; scroll:no; status:no; unadorned:no;";
this.dialog = window.showModelessDialog("046-stub.htm", this, dialogOptions);
while(times--)
{
doc = this.dialog.document;
if (doc) { break; }
Sleep(200);
}
this.doc = doc;
// STYLES
var head /*: HTMLHeadElement*/ = doc.getElementsByTagName("head")[0];
var link /*: HTMLLinkElement*/ = doc.createElement("link");
link.type = "text/css";
link.rel = "stylesheet";
link.href = "common.css";
link.media = "screen";
head.appendChild(link);
// DIALOG TITLE
this.setWindowTitle(config.windowTitle);
container = doc.createElement("div");
container.className = "classProgressDialogContainer";
doc.body.appendChild(container);
// BAR ONE
this.barOneUnits = (typeof config.barOneUnits == "number") ? Math.floor(config.barOneUnits) : 10;
// BAR ONE TABLE
table = doc.createElement("table");
table.className = "classProgressDialogBarOneTable";
table.style.width = config.width + "px";
table.cellPadding = "0";
table.cellSpacing = "2";
tbody = doc.createElement("tbody");
table.appendChild(tbody);
row = doc.createElement("tr");
tbody.appendChild(row);
for (var i /*: int*/ = 0; i < this.barOneUnits; i++)
{
cell = doc.createElement("td");
cell.className = "classProgressDialogBarOneCell";
row.appendChild(cell);
}
container.appendChild(table);
this.barOneTable = table;
this.barOneRow = row;
this.barOneLit = 0;
elm = doc.createElement("p");
elm.className = "classProgressDialogBarOneCount";
text = doc.createTextNode("0 of 0");
elm.appendChild(text);
container.appendChild(elm);
this.barOneCountField = elm;
this.barOneCountFieldText = text;
addSeparator();
// STOP BUTTON
if (config.stopButton)
{
elm = doc.createElement("input");
elm.type = "button";
elm.className = "classProgressDialogStopButton";
container.appendChild(elm);
elm.value = "Stop";
elm.onclick = function () { me.stop(); };
this.stopButton = elm;
}
// CLOSE BUTTON
if (config.closeButton)
{
elm = doc.createElement("input");
elm.type = "button";
elm.className = "classProgressDialogCloseButton";
container.appendChild(elm);
elm.value = "Close";
elm.onclick = function () { me.close(); };
this.closeButton = elm;
}
// DIMENSION WINDOW BASED ON CONTENT
this.dialog.dialogWidth = container.offsetWidth + "px";
this.dialog.dialogHeight = container.offsetHeight + "px";
// START
this.stopped = false;
// FUNCTIONS
function addSeparator()
{
hr = doc.createElement("hr");
container.appendChild(hr);
}
}
AddMethod(constr, initialise);function start() /*: void*/
{
HTMLElement_AddClassName(this.stopButton, "classProgressDialogStopButtonActive");
}
AddMethod(constr, start);function setWindowTitle(
s /*: String*/
) /*: void*/
{
if (!this.doc) { return; }
this.doc.title = s;
}
AddMethod(constr, setWindowTitle);function setBarOneProgress(
progress /*: int*/,
total /*: int*/
)/*: void*/
{
if (this.barOneCountFieldText)
{
this.barOneCountFieldText.nodeValue = progress + " of " + total;
}
if (!this.barOneRow) { return; }
var count /*: int*/ = Math.floor((progress/total) * this.barOneUnits);
if (count == this.barOneLit) { return; }
for (var i /*: int*/ = 0; i < count; i++)
{
HTMLElement_AddClassName(this.barOneRow.cells[i], "classProgressDialogBarOneCellHighlight");
}
this.barOneLit = count;
if (progress + 1 >= total)
{
HTMLElement_RemoveClassName(this.stopButton, "classProgressDialogStopButtonActive");
}
}
AddMethod(constr, setBarOneProgress);function resetBarOneProgress()/*: void*/
{
if (this.barOneCountFieldText)
{
this.barOneCountFieldText.nodeValue = "0 of 0";
}
if (!this.barOneRow) { return; }
for (var i /*: int*/ = 0; i < this.barOneRow.cells.length; i++)
{
HTMLElement_RemoveClassName(this.barOneRow.cells[i], "classProjectDialogBarOneCellHighlight");
}
this.barOneLit = 0;
}
AddMethod(constr, resetBarOneProgress);function close() /*: void*/
{
if (!this.dialog) { return; }
this.stop();
this.dialog.close();
}
AddMethod(constr, close);function stop() /*: void*/
{
HTMLElement_RemoveClassName(this.stopButton, "classProgressDialogStopButtonActive");
this.stopped = true;
}
AddMethod(constr, stop);return constr; })();
function Test_ShowModalDialog()
{
var p = new classProgressDialogModal();
p.initialise({
callFunction : loop
});
function loop()
{
var total /*: int*/ = 10000;
p.start();
for (var i /*: int*/ = 0; i < total; i++)
{
p.setBarOneProgress(i + 1, total);
if (p.stopped) { break; }
}
}
}var classProgressDialogModal /*: Function*/ = (function(){function classProgressDialogModal(
config /*: Object*/
)
{
this.dialog /*: Window*/;
this.doc /*: HTMLDocument*/;
this.config /*: Object*/;
this.stopped /*: Boolean*/;
this.barOneUnits /*: int*/;
this.barOneTable /*: HTMLTableElement*/;
this.barOneRow /*: HTMLTableRowElement*/;
this.barOneLit /*: int*/;
this.barOneCountField /*: HTMLParagraphElement*/;
this.barOneCountFieldText /*: Text*/;
this.dheight;
this.dwidth;
this.stopButton /*: HTMLInputElement*/;
this.closeButton /*: HTMLInputElement*/;
}
var constr /*: Function*/ = classProgressDialogModal;
var proto /*: Object*/ = ExtendClass(classProgressDialogModal, Object);function initialise(
config /*: Object*/
) /*: void*/
{
var me /*: classProgressDialog*/ = this;
var height /*: int*/;
var defaults /*: Object*/;
var dialogOptions /*: String*/;
var doc /*: HTMLDocument*/;
var style /*: CSSStyleDeclaration*/;
var elm /*: HTMLElement*/;
var elmInner /*: HTMLElement*/;
var table /*: HTMLTableElement*/;
var row /*: HTMLTableRowElement*/
var cell /*: HTMLTableCellElement*/;
var text /*: Text*/;
var tbody /*: HTMLTableSectionElement*/;
var hr /*: HTMLHRElement*/;
var times /*: int*/ = 5;
// DEFAULT CONFIGURATION
defaults = {
width : 400,
windowTitle : "Test 2 - showModalDialog",
barOneUnits : 20,
stopButton : true,
closeButton: true,
callFunction : function(){}
};
// DEFAULT APPLIES IF NOT SPECIFIED IN USER SUPPLIED CONFIG
if (!config) { config = {}; }
for (var k /*: String*/ in defaults)
{
if (typeof config[k] == typeof defaults[k]) { continue; }
config[k] = defaults[k];
}
this.config = config;
// OPEN MODAL DIALOG
dialogOptions = "dialogHeight:10px; dialogWidth:" + config.width + "px; center:no; edge:raised; help:no; resizable:no; scroll:no; status:no; unadorned:no;";
this.dialog = window.showModalDialog("046-modalstub.htm", this, dialogOptions);
}
AddMethod(constr, initialise);function initialise2(
win /*: Window*/,
doc /*: HTMLDocument*/
) /*: void*/
{
var me /*: classProgressDialog*/ = this;
var height /*: int*/;
var defaults /*: Object*/;
var dialogOptions /*: String*/;
var doc /*: HTMLDocument*/;
var style /*: CSSStyleDeclaration*/;
var elm /*: HTMLElement*/;
var elmInner /*: HTMLElement*/;
var table /*: HTMLTableElement*/;
var row /*: HTMLTableRowElement*/
var cell /*: HTMLTableCellElement*/;
var text /*: Text*/;
var tbody /*: HTMLTableSectionElement*/;
var hr /*: HTMLHRElement*/;
var times /*: int*/ = 5;
var config = this.config;
this.dialog = win;
this.doc = doc;
// STYLES
var head /*: HTMLHeadElement*/ = doc.getElementsByTagName("head")[0];
var link /*: HTMLLinkElement*/ = doc.createElement("link");
link.type = "text/css";
link.rel = "stylesheet";
link.href = "common.css";
link.media = "screen";
head.appendChild(link);
// DIALOG TITLE
this.setWindowTitle(config.windowTitle);
container = doc.createElement("div");
container.className = "classProgressDialogContainer";
doc.body.appendChild(container);
// BAR ONE
this.barOneUnits = (typeof config.barOneUnits == "number") ? Math.floor(config.barOneUnits) : 10;
// BAR ONE TABLE
table = doc.createElement("table");
table.className = "classProgressDialogBarOneTable";
table.style.width = config.width + "px";
table.cellPadding = "0";
table.cellSpacing = "2";
tbody = doc.createElement("tbody");
table.appendChild(tbody);
row = doc.createElement("tr");
tbody.appendChild(row);
for (var i /*: int*/ = 0; i < this.barOneUnits; i++)
{
cell = doc.createElement("td");
cell.className = "classProgressDialogBarOneCell";
row.appendChild(cell);
}
container.appendChild(table);
this.barOneTable = table;
this.barOneRow = row;
this.barOneLit = 0;
elm = doc.createElement("p");
elm.className = "classProgressDialogBarOneCount";
text = doc.createTextNode("0 of 0");
elm.appendChild(text);
container.appendChild(elm);
this.barOneCountField = elm;
this.barOneCountFieldText = text;
addSeparator();
// STOP BUTTON
if (config.stopButton)
{
elm = doc.createElement("input");
elm.type = "button";
elm.className = "classProgressDialogStopButton";
container.appendChild(elm);
elm.value = "Stop";
elm.onclick = function () { me.stop(); };
this.stopButton = elm;
}
// CLOSE BUTTON
if (config.closeButton)
{
elm = doc.createElement("input");
elm.type = "button";
elm.className = "classProgressDialogCloseButton";
container.appendChild(elm);
elm.value = "Close";
elm.onclick = function () { me.close(); };
this.closeButton = elm;
}
// DIMENSION WINDOW BASED ON CONTENT
this.dialog.dialogWidth = container.offsetWidth + "px";
this.dialog.dialogHeight = container.offsetHeight + "px";
this.dheight = this.dialog.dialogHeight;
this.dwidth = this.dialog.dialogWidth;
// START
this.stopped = false;
// does not work
if (this.config.callFunction) {
win.setTimeout(function(){me.config.callFunction()}, 200);
}
// FUNCTIONS
function addSeparator()
{
hr = doc.createElement("hr");
container.appendChild(hr);
}
}
AddMethod(constr, initialise2);function start() /*: void*/
{
HTMLElement_AddClassName(this.stopButton, "classProgressDialogStopButtonActive");
}
AddMethod(constr, start);function setWindowTitle(
s /*: String*/
) /*: void*/
{
if (!this.doc) { return; }
this.doc.title = s;
}
AddMethod(constr, setWindowTitle);function setBarOneProgress(
progress /*: int*/,
total /*: int*/
)/*: void*/
{
//this.dialog.dialogHeight = this.dheight;
//this.dialog.dialogWidth = this.dwidth;
if (this.barOneCountFieldText)
{
this.barOneCountFieldText.nodeValue = progress + " of " + total;
}
if (!this.barOneRow) { return; }
var count /*: int*/ = Math.floor((progress/total) * this.barOneUnits);
if (count == this.barOneLit) { return; }
for (var i /*: int*/ = 0; i < count; i++)
{
HTMLElement_AddClassName(this.barOneRow.cells[i], "classProgressDialogBarOneCellHighlight");
}
this.barOneLit = count;
if (progress + 1 >= total)
{
HTMLElement_RemoveClassName(this.stopButton, "classProgressDialogStopButtonActive");
}
}
AddMethod(constr, setBarOneProgress);function resetBarOneProgress()/*: void*/
{
if (this.barOneCountFieldText)
{
this.barOneCountFieldText.nodeValue = "0 of 0";
}
if (!this.barOneRow) { return; }
for (var i /*: int*/ = 0; i < this.barOneRow.cells.length; i++)
{
HTMLElement_RemoveClassName(this.barOneRow.cells[i], "classProjectDialogBarOneCellHighlight");
}
this.barOneLit = 0;
}
AddMethod(constr, resetBarOneProgress);function close(
timeout /*: int*/
) /*: void*/
{
if (!this.dialog) { return; }
this.stop();
if (typeof timeout == "number")
{
var me /*: classProgressDialog*/ = this;
window.setTimeout(function(){ me.dialog.close(); }, timeout);
}
else
{
this.dialog.close();
}
}
AddMethod(constr, close);function stop() /*: void*/
{
HTMLElement_RemoveClassName(this.stopButton, "classProgressDialogStopButtonActive");
this.stopped = true;
}
AddMethod(constr, stop);return constr; })();
function Test_WindowOpen_IE()
{
var p = new classProgressDialogOpenIE();
function loop()
{
var total /*: int*/ = 10000;
p.start();
for (var i /*: int*/ = 0; i < total; i++)
{
p.setBarOneProgress(i + 1, total);
if (p.stopped) { break; }
}
}
window.setTimeout(loop, 500);
}var classProgressDialogOpenIE /*: Function*/ = (function(){function classProgressDialogOpenIE(
config /*: Object*/
)
{
this.dialog /*: Window*/;
this.doc /*: HTMLDocument*/;
this.config /*: Object*/;
this.stopped /*: Boolean*/;
this.barOneUnits /*: int*/;
this.barOneTable /*: HTMLTableElement*/;
this.barOneRow /*: HTMLTableRowElement*/;
this.barOneLit /*: int*/;
this.barOneCountField /*: HTMLParagraphElement*/;
this.barOneCountFieldText /*: Text*/;
this.stopButton /*: HTMLInputElement*/;
this.closeButton /*: HTMLInputElement*/;
this.initialise(config);
}
var constr /*: Function*/ = classProgressDialogOpenIE;
var proto /*: Object*/ = ExtendClass(classProgressDialogOpenIE, Object);function initialise(
config /*: Object*/
) /*: void*/
{
var me /*: classProgressDialog*/ = this;
var height /*: int*/;
var defaults /*: Object*/;
var dialogOptions /*: String*/;
var doc /*: HTMLDocument*/;
var style /*: CSSStyleDeclaration*/;
var elm /*: HTMLElement*/;
var elmInner /*: HTMLElement*/;
var table /*: HTMLTableElement*/;
var row /*: HTMLTableRowElement*/
var cell /*: HTMLTableCellElement*/;
var text /*: Text*/;
var tbody /*: HTMLTableSectionElement*/;
var hr /*: HTMLHRElement*/;
var times /*: int*/ = 5;
// DEFAULT CONFIGURATION
defaults = {
width : 400,
windowTitle : "Test 3 - window.open (IE)",
barOneUnits : 20,
stopButton : true,
closeButton: true
};
// DEFAULT APPLIES IF NOT SPECIFIED IN USER SUPPLIED CONFIG
if (!config) { config = {}; }
for (var k /*: String*/ in defaults)
{
if (typeof config[k] == typeof defaults[k]) { continue; }
config[k] = defaults[k];
}
this.config = config;
// OPEN MODELESS DIALOG
dialogOptions = "height=100,width=" + config.width + ",menubar=no,resizable=no,scrollbars=no,location=no,status=no,chrome=no,dependent=no,dialog=no,directories=no,titlebar=no,close=no";
this.dialog = window.open("046-stub.htm", "TestWindow", dialogOptions);
while(times--)
{
doc = this.dialog.document;
if (doc) { break; }
Sleep(200);
}
this.doc = doc;
// STYLES
var head /*: HTMLHeadElement*/ = doc.getElementsByTagName("head")[0];
var link /*: HTMLLinkElement*/ = doc.createElement("link");
link.type = "text/css";
link.rel = "stylesheet";
link.href = "common.css";
link.media = "screen";
head.appendChild(link);
// DIALOG TITLE
this.setWindowTitle(config.windowTitle);
container = doc.createElement("div");
container.className = "classProgressDialogContainer";
doc.body.appendChild(container);
// BAR ONE
this.barOneUnits = (typeof config.barOneUnits == "number") ? Math.floor(config.barOneUnits) : 10;
// BAR ONE TABLE
table = doc.createElement("table");
table.className = "classProgressDialogBarOneTable";
table.style.width = config.width + "px";
table.cellPadding = "0";
table.cellSpacing = "2";
tbody = doc.createElement("tbody");
table.appendChild(tbody);
row = doc.createElement("tr");
tbody.appendChild(row);
for (var i /*: int*/ = 0; i < this.barOneUnits; i++)
{
cell = doc.createElement("td");
cell.className = "classProgressDialogBarOneCell";
row.appendChild(cell);
}
container.appendChild(table);
this.barOneTable = table;
this.barOneRow = row;
this.barOneLit = 0;
elm = doc.createElement("p");
elm.className = "classProgressDialogBarOneCount";
text = doc.createTextNode("0 of 0");
elm.appendChild(text);
container.appendChild(elm);
this.barOneCountField = elm;
this.barOneCountFieldText = text;
addSeparator();
// STOP BUTTON
if (config.stopButton)
{
elm = doc.createElement("input");
elm.type = "button";
elm.className = "classProgressDialogStopButton";
container.appendChild(elm);
elm.value = "Stop";
elm.onclick = function () { me.stop(); };
this.stopButton = elm;
}
// CLOSE BUTTON
if (config.closeButton)
{
elm = doc.createElement("input");
elm.type = "button";
elm.className = "classProgressDialogCloseButton";
container.appendChild(elm);
elm.value = "Close";
elm.onclick = function () { me.close(); };
this.closeButton = elm;
}
// DIMENSION WINDOW BASED ON CONTENT
this.dialog.dialogWidth = container.offsetWidth + "px";
this.dialog.dialogHeight = container.offsetHeight + "px";
// START
this.stopped = false;
// FUNCTIONS
function addSeparator()
{
hr = doc.createElement("hr");
container.appendChild(hr);
}
}
AddMethod(constr, initialise);function start() /*: void*/
{
HTMLElement_AddClassName(this.stopButton, "classProgressDialogStopButtonActive");
}
AddMethod(constr, start);function setWindowTitle(
s /*: String*/
) /*: void*/
{
if (!this.doc) { return; }
this.doc.title = s;
}
AddMethod(constr, setWindowTitle);function setBarOneProgress(
progress /*: int*/,
total /*: int*/
)/*: void*/
{
if (this.barOneCountFieldText)
{
this.barOneCountFieldText.nodeValue = progress + " of " + total;
}
if (!this.barOneRow) { return; }
var count /*: int*/ = Math.floor((progress/total) * this.barOneUnits);
if (count == this.barOneLit) { return; }
for (var i /*: int*/ = 0; i < count; i++)
{
HTMLElement_AddClassName(this.barOneRow.cells[i], "classProgressDialogBarOneCellHighlight");
}
this.barOneLit = count;
if (progress + 1 >= total)
{
HTMLElement_RemoveClassName(this.stopButton, "classProgressDialogStopButtonActive");
}
}
AddMethod(constr, setBarOneProgress);function resetBarOneProgress()/*: void*/
{
if (this.barOneCountFieldText)
{
this.barOneCountFieldText.nodeValue = "0 of 0";
}
if (!this.barOneRow) { return; }
for (var i /*: int*/ = 0; i < this.barOneRow.cells.length; i++)
{
HTMLElement_RemoveClassName(this.barOneRow.cells[i], "classProjectDialogBarOneCellHighlight");
}
this.barOneLit = 0;
}
AddMethod(constr, resetBarOneProgress);function close(
timeout /*: int*/
) /*: void*/
{
if (!this.dialog) { return; }
this.stop();
if (typeof timeout == "number")
{
var me /*: classProgressDialog*/ = this;
window.setTimeout(function(){ me.dialog.close(); }, timeout);
}
else
{
this.dialog.close();
}
}
AddMethod(constr, close);function stop() /*: void*/
{
HTMLElement_RemoveClassName(this.stopButton, "classProgressDialogStopButtonActive");
this.stopped = true;
}
AddMethod(constr, stop);return constr; })();
function Test_WindowOpen_Others()
{
var p = new classProgressDialogOpenOthers();
window.setTimeout(init, 200);
function init()
{
p.initialise2();
window.setTimeout(loop,200);
}
function loop()
{
var total /*: int*/ = 10000;
p.start();
for (var i /*: int*/ = 0; i < total; i++)
{
p.setBarOneProgress(i + 1, total);
if (p.stopped) { break; }
}
}
}var classProgressDialogOpenOthers /*: Function*/ = (function(){function classProgressDialogOpenOthers(
config /*: Object*/
)
{
this.dialog /*: Window*/;
this.doc /*: HTMLDocument*/;
this.config /*: Object*/;
this.stopped /*: Boolean*/;
this.barOneUnits /*: int*/;
this.barOneTable /*: HTMLTableElement*/;
this.barOneRow /*: HTMLTableRowElement*/;
this.barOneLit /*: int*/;
this.barOneCountField /*: HTMLParagraphElement*/;
this.barOneCountFieldText /*: Text*/;
this.stopButton /*: HTMLInputElement*/;
this.closeButton /*: HTMLInputElement*/;
this.initialise(config);
}
var constr /*: Function*/ = classProgressDialogOpenOthers;
var proto /*: Object*/ = ExtendClass(classProgressDialogOpenOthers, Object);function initialise(
config /*: Object*/
) /*: void*/
{
var me /*: classProgressDialog*/ = this;
var height /*: int*/;
var defaults /*: Object*/;
var dialogOptions /*: String*/;
var doc /*: HTMLDocument*/;
var style /*: CSSStyleDeclaration*/;
var elm /*: HTMLElement*/;
var elmInner /*: HTMLElement*/;
var table /*: HTMLTableElement*/;
var row /*: HTMLTableRowElement*/
var cell /*: HTMLTableCellElement*/;
var text /*: Text*/;
var tbody /*: HTMLTableSectionElement*/;
var hr /*: HTMLHRElement*/;
var times /*: int*/ = 5;
// DEFAULT CONFIGURATION
defaults = {
width : 400,
windowTitle : "Test 3 - window.open (Others)",
barOneUnits : 20,
stopButton : true,
closeButton: true
};
// DEFAULT APPLIES IF NOT SPECIFIED IN USER SUPPLIED CONFIG
if (!config) { config = {}; }
for (var k /*: String*/ in defaults)
{
if (typeof config[k] == typeof defaults[k]) { continue; }
config[k] = defaults[k];
}
this.config = config;
// OPEN MODELESS DIALOG
dialogOptions = "height=100,width=" + config.width + ",menubar=no,resizable=no,scrollbars=no,location=no,status=no,chrome=no,dependent=no,dialog=no,directories=no,titlebar=no,close=no";
this.dialog = window.open("046-stub.htm", "TestWindow", dialogOptions);
}
AddMethod(constr, initialise);function initialise2(
config /*: Object*/
) /*: void*/
{
var me /*: classProgressDialog*/ = this;
var height /*: int*/;
var defaults /*: Object*/;
var dialogOptions /*: String*/;
var doc /*: HTMLDocument*/;
var style /*: CSSStyleDeclaration*/;
var elm /*: HTMLElement*/;
var elmInner /*: HTMLElement*/;
var table /*: HTMLTableElement*/;
var row /*: HTMLTableRowElement*/
var cell /*: HTMLTableCellElement*/;
var text /*: Text*/;
var tbody /*: HTMLTableSectionElement*/;
var hr /*: HTMLHRElement*/;
var times /*: int*/ = 5;
var config /*: Object*/ = this.config;
doc = this.doc = this.dialog.document;
// STYLES
var head /*: HTMLHeadElement*/ = doc.getElementsByTagName("head")[0];
var link /*: HTMLLinkElement*/ = doc.createElement("link");
link.type = "text/css";
link.rel = "stylesheet";
link.href = "common.css";
link.media = "screen";
head.appendChild(link);
// DIALOG TITLE
this.setWindowTitle(config.windowTitle);
container = doc.createElement("div");
container.className = "classProgressDialogContainer";
doc.body.appendChild(container);
// BAR ONE
this.barOneUnits = (typeof config.barOneUnits == "number") ? Math.floor(config.barOneUnits) : 10;
// BAR ONE TABLE
table = doc.createElement("table");
table.className = "classProgressDialogBarOneTable";
table.style.width = config.width + "px";
table.cellPadding = "0";
table.cellSpacing = "2";
tbody = doc.createElement("tbody");
table.appendChild(tbody);
row = doc.createElement("tr");
tbody.appendChild(row);
for (var i /*: int*/ = 0; i < this.barOneUnits; i++)
{
cell = doc.createElement("td");
cell.className = "classProgressDialogBarOneCell";
row.appendChild(cell);
}
container.appendChild(table);
this.barOneTable = table;
this.barOneRow = row;
this.barOneLit = 0;
elm = doc.createElement("p");
elm.className = "classProgressDialogBarOneCount";
text = doc.createTextNode("0 of 0");
elm.appendChild(text);
container.appendChild(elm);
this.barOneCountField = elm;
this.barOneCountFieldText = text;
addSeparator();
// STOP BUTTON
if (config.stopButton)
{
elm = doc.createElement("input");
elm.type = "button";
elm.className = "classProgressDialogStopButton";
container.appendChild(elm);
elm.value = "Stop";
elm.onclick = function () { me.stop(); };
this.stopButton = elm;
}
// CLOSE BUTTON
if (config.closeButton)
{
elm = doc.createElement("input");
elm.type = "button";
elm.className = "classProgressDialogCloseButton";
container.appendChild(elm);
elm.value = "Close";
elm.onclick = function () { me.close(); };
this.closeButton = elm;
}
// DIMENSION WINDOW BASED ON CONTENT
this.dialog.dialogWidth = container.offsetWidth + "px";
this.dialog.dialogHeight = container.offsetHeight + "px";
// START
this.stopped = false;
// FUNCTIONS
function addSeparator()
{
hr = doc.createElement("hr");
container.appendChild(hr);
}
}
AddMethod(constr, initialise2);function start() /*: void*/
{
HTMLElement_AddClassName(this.stopButton, "classProgressDialogStopButtonActive");
}
AddMethod(constr, start);function setWindowTitle(
s /*: String*/
) /*: void*/
{
if (!this.doc) { return; }
this.doc.title = s;
}
AddMethod(constr, setWindowTitle);function setBarOneProgress(
progress /*: int*/,
total /*: int*/
)/*: void*/
{
if (this.barOneCountFieldText)
{
this.barOneCountFieldText.nodeValue = progress + " of " + total;
}
if (!this.barOneRow) { return; }
var count /*: int*/ = Math.floor((progress/total) * this.barOneUnits);
if (count == this.barOneLit) { return; }
for (var i /*: int*/ = 0; i < count; i++)
{
HTMLElement_AddClassName(this.barOneRow.cells[i], "classProgressDialogBarOneCellHighlight");
}
this.barOneLit = count;
if (progress + 1 >= total)
{
HTMLElement_RemoveClassName(this.stopButton, "classProgressDialogStopButtonActive");
}
}
AddMethod(constr, setBarOneProgress);function resetBarOneProgress()/*: void*/
{
if (this.barOneCountFieldText)
{
this.barOneCountFieldText.nodeValue = "0 of 0";
}
if (!this.barOneRow) { return; }
for (var i /*: int*/ = 0; i < this.barOneRow.cells.length; i++)
{
HTMLElement_RemoveClassName(this.barOneRow.cells[i], "classProjectDialogBarOneCellHighlight");
}
this.barOneLit = 0;
}
AddMethod(constr, resetBarOneProgress);function close(
timeout /*: int*/
) /*: void*/
{
if (!this.dialog) { return; }
this.stop();
if (typeof timeout == "number")
{
var me /*: classProgressDialog*/ = this;
window.setTimeout(function(){ me.dialog.close(); }, timeout);
}
else
{
this.dialog.close();
}
}
AddMethod(constr, close);function stop() /*: void*/
{
HTMLElement_RemoveClassName(this.stopButton, "classProgressDialogStopButtonActive");
this.stopped = true;
}
AddMethod(constr, stop);return constr; })();
function Test_Iframe()
{
var p = new classProgressDialogIframe({iframeId:"test4iframe"});
function loop()
{
var total /*: int*/ = 10000;
p.start();
for (var i /*: int*/ = 0; i < total; i++)
{
p.setBarOneProgress(i + 1, total);
if (p.stopped) { break; }
}
}
window.setTimeout(loop,15);
}var classProgressDialogIframe /*: Function*/ = (function(){function classProgressDialogIframe(
config /*: Object*/
)
{
this.iframe /*: HTMLIFrameElement*/;
this.dialog /*: Window*/;
this.doc /*: HTMLDocument*/;
this.config /*: Object*/;
this.stopped /*: Boolean*/;
this.barOneUnits /*: int*/;
this.barOneTable /*: HTMLTableElement*/;
this.barOneRow /*: HTMLTableRowElement*/;
this.barOneLit /*: int*/;
this.barOneCountField /*: HTMLParagraphElement*/;
this.barOneCountFieldText /*: Text*/;
this.stopButton /*: HTMLInputElement*/;
this.closeButton /*: HTMLInputElement*/;
this.initialise(config);
}
var constr /*: Function*/ = classProgressDialogIframe;
var proto /*: Object*/ = ExtendClass(classProgressDialogIframe, Object);function initialise(
config /*: Object*/
) /*: void*/
{
var me /*: classProgressDialog*/ = this;
var height /*: int*/;
var defaults /*: Object*/;
var dialogOptions /*: String*/;
var doc /*: HTMLDocument*/;
var style /*: CSSStyleDeclaration*/;
var elm /*: HTMLElement*/;
var elmInner /*: HTMLElement*/;
var table /*: HTMLTableElement*/;
var row /*: HTMLTableRowElement*/
var cell /*: HTMLTableCellElement*/;
var text /*: Text*/;
var tbody /*: HTMLTableSectionElement*/;
var hr /*: HTMLHRElement*/;
var times /*: int*/ = 5;
// DEFAULT CONFIGURATION
defaults = {
width : 400,
windowTitle : "Test 1 - showModelessDialog",
barOneUnits : 20,
stopButton : true
};
// DEFAULT APPLIES IF NOT SPECIFIED IN USER SUPPLIED CONFIG
if (!config) { config = {}; }
for (var k /*: String*/ in defaults)
{
if (typeof config[k] == typeof defaults[k]) { continue; }
config[k] = defaults[k];
}
this.config = config;
// GET IFRAME
this.iframe = document.getElementById(config.iframeId);
this.iframe.style.borderWidth = 0;
this.dialog = (document.frames && document.frames[config.iframeId]) || (window.frames && window.frames[config.iframeId]) || (this.iframe && this.iframe.contentWindow) || (this.iframe.contentDocument && (this.iframe.contentDocument.parentWindow || this.iframe.contentDocument.defaultView || this.iframe.contentDocument.contentWindow));
while(times--)
{
doc = this.dialog.document || this.iframe.contentDocument;
if (doc) { break; }
Sleep(200);
}
this.doc = doc;
// STYLES
var head /*: HTMLHeadElement*/ = doc.getElementsByTagName("head")[0];
var link /*: HTMLLinkElement*/ = doc.createElement("link");
link.type = "text/css";
link.rel = "stylesheet";
link.href = "common.css";
link.media = "screen";
head.appendChild(link);
// DIALOG TITLE
container = doc.createElement("div");
container.className = "classProgressDialogContainer";
doc.body.appendChild(container);
container.style.width = config.width + "px";
// BAR ONE
this.barOneUnits = (typeof config.barOneUnits == "number") ? Math.floor(config.barOneUnits) : 10;
// BAR ONE TABLE
table = doc.createElement("table");
table.className = "classProgressDialogBarOneTable";
table.style.width = config.width + "px";
table.cellPadding = "0";
table.cellSpacing = "2";
tbody = doc.createElement("tbody");
table.appendChild(tbody);
row = doc.createElement("tr");
tbody.appendChild(row);
for (var i /*: int*/ = 0; i < this.barOneUnits; i++)
{
cell = doc.createElement("td");
cell.className = "classProgressDialogBarOneCell";
row.appendChild(cell);
}
container.appendChild(table);
this.barOneTable = table;
this.barOneRow = row;
this.barOneLit = 0;
elm = doc.createElement("p");
elm.className = "classProgressDialogBarOneCount";
text = doc.createTextNode("0 of 0");
elm.appendChild(text);
container.appendChild(elm);
this.barOneCountField = elm;
this.barOneCountFieldText = text;
addSeparator();
// STOP BUTTON
if (config.stopButton)
{
elm = doc.createElement("input");
elm.type = "button";
elm.className = "classProgressDialogStopButton";
container.appendChild(elm);
elm.value = "Stop";
elm.onclick = function () { me.stop(); };
this.stopButton = elm;
}
// DIMENSION WINDOW BASED ON CONTENT
this.iframe.style.width = (container.offsetWidth + 20) + "px";
this.iframe.style.height = (container.offsetHeight + 20) + "px";
// START
this.stopped = false;
// FUNCTIONS
function addSeparator()
{
hr = doc.createElement("hr");
container.appendChild(hr);
}
}
AddMethod(constr, initialise);function start() /*: void*/
{
HTMLElement_AddClassName(this.stopButton, "classProgressDialogStopButtonActive");
}
AddMethod(constr, start);function setBarOneProgress(
progress /*: int*/,
total /*: int*/
)/*: void*/
{
//this.dialog.dialogHeight = this.dheight;
//this.dialog.dialogWidth = this.dwidth;
if (this.barOneCountFieldText)
{
this.barOneCountFieldText.nodeValue = progress + " of " + total;
}
if (!this.barOneRow) { return; }
var count /*: int*/ = Math.floor((progress/total) * this.barOneUnits);
if (count == this.barOneLit) { return; }
for (var i /*: int*/ = 0; i < count; i++)
{
HTMLElement_AddClassName(this.barOneRow.cells[i], "classProgressDialogBarOneCellHighlight");
}
this.barOneLit = count;
if (progress + 1 >= total)
{
HTMLElement_RemoveClassName(this.stopButton, "classProgressDialogStopButtonActive");
}
}
AddMethod(constr, setBarOneProgress);function resetBarOneProgress()/*: void*/
{
if (this.barOneCountFieldText)
{
this.barOneCountFieldText.nodeValue = "0 of 0";
}
if (!this.barOneRow) { return; }
for (var i /*: int*/ = 0; i < this.barOneRow.cells.length; i++)
{
HTMLElement_RemoveClassName(this.barOneRow.cells[i], "classProjectDialogBarOneCellHighlight");
}
this.barOneLit = 0;
}
AddMethod(constr, resetBarOneProgress);function stop() /*: void*/
{
HTMLElement_RemoveClassName(this.stopButton, "classProgressDialogStopButtonActive");
this.stopped = true;
}
AddMethod(constr, stop);return constr; })();
function Test_Continuation()
{
var p = new classProgressDialogContinuation();
p.initialise({
divId : "test5div",
width : 400,
barOneUnits : 20,
stopButton : true
});
var state /*: Object*/ = {};
state.progress = p;
Continuation_Run(1,10000,500,100,loop1, afterLoop1,state);
function loop1(i, total, state)
{
state.progress.setBarOneProgress(i, total);
if (state.progress.stopped) { return true; }
return false;
}
function afterLoop1(state)
{
state.progress.resetBarOneProgress();
Continuation_Run(1,5000,500,100,loop2,afterLoop2,state);
}
function loop2(i, total, state)
{
state.progress.setBarOneProgress(i, total);
if (state.progress.stopped) { return true; }
return false;
}
function afterLoop2(state)
{
alert("Done");
}
}
function Continuation_Run(
start /*: int*/,
end /*: int*/,
chunk /*: int*/,
timeout /*: int*/,
iteration /*: Function*/,
after /*: Function*/,
state /*: Object*/
) /*: void*/
{
var at /*: int*/ = start;
var stop /*: Boolean*/;
window.setTimeout(loopChunk, timeout);
function loopChunk()
{
if (at > end)
{
window.setTimeout(function(){ after(state); }, timeout);
return;
}
for (var i /*: int*/ = at; i <= end, i < at + chunk; i++)
{
stop = iteration(i, end, state);
if (stop) { return; }
}
at = at + chunk;
if (at >= end)
{
window.setTimeout(function(){ after(state); }, 15);
}
else
{
window.setTimeout(loopChunk,timeout);
}
}
}function Test_Continuation_ZeroTimeout()
{
var p = new classProgressDialogContinuation();
p.initialise({
divId : "test5div",
width : 400,
barOneUnits : 20,
stopButton : true
});
var state /*: Object*/ = {};
state.progress = p;
Continuation_Run_ZeroTimeout(1,10000,500,100,loop1, afterLoop1,state);
function loop1(i, total, state)
{
state.progress.setBarOneProgress(i, total);
if (state.progress.stopped) { return true; }
return false;
}
function afterLoop1(state)
{
alert("Done Loop 1");
state.progress.resetBarOneProgress();
Continuation_Run_ZeroTimeout(1,5000,500,100,loop2,afterLoop2,state);
}
function loop2(i, total, state)
{
state.progress.setBarOneProgress(i, total);
if (state.progress.stopped) { return true; }
return false;
}
function afterLoop2(state)
{
alert("Done Loop 2");
}
}
function Continuation_Run_ZeroTimeout(
start /*: int*/,
end /*: int*/,
chunk /*: int*/,
timeout /*: int*/,
iteration /*: Function*/,
after /*: Function*/,
state /*: Object*/
) /*: void*/
{
var at /*: int*/ = start;
var stop /*: Boolean*/;
ZeroTimeout(loopChunk);
function loopChunk()
{
if (at > end)
{
ZeroTimeout(function(){ after(state); });
return;
}
for (var i /*: int*/ = at; i <= end, i < at + chunk; i++)
{
stop = iteration(i, end, state);
if (stop) { return; }
}
at = at + chunk;
if (at >= end)
{
ZeroTimeout(function(){ after(state); });
}
else
{
ZeroTimeout(loopChunk);
}
}
}var classProgressDialogContinuation /*: Function*/ = (function(){function classProgressDialogContinuation(
config /*: Object*/
)
{
this.panel /*: HTMLDivElement*/;
this.config /*: Object*/;
this.stopped /*: Boolean*/;
this.barOneUnits /*: int*/;
this.barOneTable /*: HTMLTableElement*/;
this.barOneRow /*: HTMLTableRowElement*/;
this.barOneLit /*: int*/;
this.barOneCountField /*: HTMLParagraphElement*/;
this.barOneCountFieldText /*: Text*/;
this.stopButton /*: HTMLInputElement*/;
}
var constr /*: Function*/ = classProgressDialogContinuation;
var proto /*: Object*/ = ExtendClass(classProgressDialogContinuation, Object);function initialise(
config /*: Object*/
) /*: void*/
{
var me /*: classProgressDialog*/ = this;
var height /*: int*/;
var defaults /*: Object*/;
var dialogOptions /*: String*/;
var doc /*: HTMLDocument*/;
var style /*: CSSStyleDeclaration*/;
var elm /*: HTMLElement*/;
var elmInner /*: HTMLElement*/;
var table /*: HTMLTableElement*/;
var row /*: HTMLTableRowElement*/
var cell /*: HTMLTableCellElement*/;
var text /*: Text*/;
var tbody /*: HTMLTableSectionElement*/;
var hr /*: HTMLHRElement*/;
var times /*: int*/ = 5;
// DEFAULT CONFIGURATION
defaults = {
width : 200,
barOneUnits : 10,
stopButton : true
};
// DEFAULT APPLIES IF NOT SPECIFIED IN USER SUPPLIED CONFIG
if (!config) { config = {}; }
for (var k /*: String*/ in defaults)
{
if (typeof config[k] == typeof defaults[k]) { continue; }
config[k] = defaults[k];
}
this.config = config;
// GET IFRAME
this.panel = document.getElementById(config.divId);
this.panel.innerHTML = "";
var doc = this.doc = document;
// DIALOG TITLE
container = doc.createElement("div");
container.className = "classProgressDialogContainer";
this.panel.appendChild(container);
container.style.width = config.width + "px";
// BAR ONE
this.barOneUnits = (typeof config.barOneUnits == "number") ? Math.floor(config.barOneUnits) : 10;
// BAR ONE TABLE
table = doc.createElement("table");
table.className = "classProgressDialogBarOneTable";
table.style.width = config.width + "px";
table.cellPadding = "0";
table.cellSpacing = "2";
tbody = doc.createElement("tbody");
table.appendChild(tbody);
row = doc.createElement("tr");
tbody.appendChild(row);
for (var i /*: int*/ = 0; i < this.barOneUnits; i++)
{
cell = doc.createElement("td");
cell.className = "classProgressDialogBarOneCell";
row.appendChild(cell);
}
container.appendChild(table);
this.barOneTable = table;
this.barOneRow = row;
this.barOneLit = 0;
elm = doc.createElement("p");
elm.className = "classProgressDialogBarOneCount";
text = doc.createTextNode("0 of 0");
elm.appendChild(text);
container.appendChild(elm);
this.barOneCountField = elm;
this.barOneCountFieldText = text;
addSeparator();
// STOP BUTTON
if (config.stopButton)
{
elm = doc.createElement("input");
elm.type = "button";
elm.className = "classProgressDialogStopButton";
container.appendChild(elm);
elm.value = "Stop";
elm.onclick = function () { me.stop(); };
this.stopButton = elm;
}
// DIMENSION WINDOW BASED ON CONTENT
this.panel.style.width = (container.offsetWidth + 20) + "px";
this.panel.style.height = (container.offsetHeight + 20) + "px";
// START
this.stopped = false;
// FUNCTIONS
function addSeparator()
{
hr = doc.createElement("hr");
container.appendChild(hr);
}
}
AddMethod(constr, initialise);function start() /*: void*/
{
HTMLElement_AddClassName(this.stopButton, "classProgressDialogStopButtonActive");
}
AddMethod(constr, start);function setBarOneProgress(
progress /*: int*/,
total /*: int*/
)/*: void*/
{
//this.dialog.dialogHeight = this.dheight;
//this.dialog.dialogWidth = this.dwidth;
if (this.barOneCountFieldText)
{
this.barOneCountFieldText.nodeValue = progress + " of " + total;
}
if (!this.barOneRow) { return; }
var count /*: int*/ = Math.floor((progress/total) * this.barOneUnits);
if (count == this.barOneLit) { return; }
for (var i /*: int*/ = 0; i < count; i++)
{
HTMLElement_AddClassName(this.barOneRow.cells[i], "classProgressDialogBarOneCellHighlight");
}
this.barOneLit = count;
if (progress + 1 >= total)
{
HTMLElement_RemoveClassName(this.stopButton, "classProgressDialogStopButtonActive");
}
}
AddMethod(constr, setBarOneProgress);function resetBarOneProgress()/*: void*/
{
if (this.barOneCountFieldText)
{
this.barOneCountFieldText.nodeValue = "0 of 0";
}
if (!this.barOneRow) { return; }
for (var i /*: int*/ = 0; i < this.barOneRow.cells.length; i++)
{
HTMLElement_RemoveClassName(this.barOneRow.cells[i], "classProgressDialogBarOneCellHighlight");
}
this.barOneLit = 0;
}
AddMethod(constr, resetBarOneProgress);function stop() /*: void*/
{
HTMLElement_RemoveClassName(this.stopButton, "classProgressDialogStopButtonActive");
this.stopped = true;
}
AddMethod(constr, stop);return constr; })();
function Test_Worker()
{
var p = new classProgressDialogWorker();
p.initialise({
divId : "test6div",
width : 400,
barOneUnits : 20,
stopButton : true
});
var worker = new Worker("run.js");
worker.onmessage = function(event){
var data /*: Object*/ = event.data;
if (data.type == "Progress")
{
p.setBarOneProgress(data.i, data.total);
if (p.stopped) { worker.postMessage( {type : "Stop"} ); }
}
if (data.type == "Done")
{
alert("Done");
}
};
worker.postMessage( { type:"CompleteLoop" } );
}var classProgressDialogWorker /*: Function*/ = (function(){function classProgressDialogWorker(
config /*: Object*/
)
{
this.panel /*: HTMLDivElement*/;
this.config /*: Object*/;
this.stopped /*: Boolean*/;
this.barOneUnits /*: int*/;
this.barOneTable /*: HTMLTableElement*/;
this.barOneRow /*: HTMLTableRowElement*/;
this.barOneLit /*: int*/;
this.barOneCountField /*: HTMLParagraphElement*/;
this.barOneCountFieldText /*: Text*/;
this.stopButton /*: HTMLInputElement*/;
}
var constr /*: Function*/ = classProgressDialogWorker;
var proto /*: Object*/ = ExtendClass(classProgressDialogWorker, Object);function initialise(
config /*: Object*/
) /*: void*/
{
var me /*: classProgressDialog*/ = this;
var height /*: int*/;
var defaults /*: Object*/;
var dialogOptions /*: String*/;
var doc /*: HTMLDocument*/;
var style /*: CSSStyleDeclaration*/;
var elm /*: HTMLElement*/;
var elmInner /*: HTMLElement*/;
var table /*: HTMLTableElement*/;
var row /*: HTMLTableRowElement*/
var cell /*: HTMLTableCellElement*/;
var text /*: Text*/;
var tbody /*: HTMLTableSectionElement*/;
var hr /*: HTMLHRElement*/;
var times /*: int*/ = 5;
// DEFAULT CONFIGURATION
defaults = {
width : 200,
barOneUnits : 10,
stopButton : true
};
// DEFAULT APPLIES IF NOT SPECIFIED IN USER SUPPLIED CONFIG
if (!config) { config = {}; }
for (var k /*: String*/ in defaults)
{
if (typeof config[k] == typeof defaults[k]) { continue; }
config[k] = defaults[k];
}
this.config = config;
// GET IFRAME
this.panel = document.getElementById(config.divId);
this.panel.innerHTML = "";
var doc = this.doc = document;
// DIALOG TITLE
container = doc.createElement("div");
container.className = "classProgressDialogContainer";
this.panel.appendChild(container);
container.style.width = config.width + "px";
// BAR ONE
this.barOneUnits = (typeof config.barOneUnits == "number") ? Math.floor(config.barOneUnits) : 10;
// BAR ONE TABLE
table = doc.createElement("table");
table.className = "classProgressDialogBarOneTable";
table.style.width = config.width + "px";
table.cellPadding = "0";
table.cellSpacing = "2";
tbody = doc.createElement("tbody");
table.appendChild(tbody);
row = doc.createElement("tr");
tbody.appendChild(row);
for (var i /*: int*/ = 0; i < this.barOneUnits; i++)
{
cell = doc.createElement("td");
cell.className = "classProgressDialogBarOneCell";
row.appendChild(cell);
}
container.appendChild(table);
this.barOneTable = table;
this.barOneRow = row;
this.barOneLit = 0;
elm = doc.createElement("p");
elm.className = "classProgressDialogBarOneCount";
text = doc.createTextNode("0 of 0");
elm.appendChild(text);
container.appendChild(elm);
this.barOneCountField = elm;
this.barOneCountFieldText = text;
addSeparator();
// STOP BUTTON
if (config.stopButton)
{
elm = doc.createElement("input");
elm.type = "button";
elm.className = "classProgressDialogStopButton";
container.appendChild(elm);
elm.value = "Stop";
elm.onclick = function () { me.stop(); };
this.stopButton = elm;
}
// DIMENSION WINDOW BASED ON CONTENT
this.panel.style.width = (container.offsetWidth + 20) + "px";
this.panel.style.height = (container.offsetHeight + 20) + "px";
// START
this.stopped = false;
// FUNCTIONS
function addSeparator()
{
hr = doc.createElement("hr");
container.appendChild(hr);
}
}
AddMethod(constr, initialise);function start() /*: void*/
{
HTMLElement_AddClassName(this.stopButton, "classProgressDialogStopButtonActive");
}
AddMethod(constr, start);function setBarOneProgress(
progress /*: int*/,
total /*: int*/
)/*: void*/
{
//this.dialog.dialogHeight = this.dheight;
//this.dialog.dialogWidth = this.dwidth;
if (this.barOneCountFieldText)
{
this.barOneCountFieldText.nodeValue = progress + " of " + total;
}
if (!this.barOneRow) { return; }
var count /*: int*/ = Math.floor((progress/total) * this.barOneUnits);
if (count == this.barOneLit) { return; }
for (var i /*: int*/ = 0; i < count; i++)
{
HTMLElement_AddClassName(this.barOneRow.cells[i], "classProgressDialogBarOneCellHighlight");
}
this.barOneLit = count;
if (progress + 1 >= total)
{
HTMLElement_RemoveClassName(this.stopButton, "classProgressDialogStopButtonActive");
}
}
AddMethod(constr, setBarOneProgress);function resetBarOneProgress()/*: void*/
{
if (this.barOneCountFieldText)
{
this.barOneCountFieldText.nodeValue = "0 of 0";
}
if (!this.barOneRow) { return; }
for (var i /*: int*/ = 0; i < this.barOneRow.cells.length; i++)
{
HTMLElement_RemoveClassName(this.barOneRow.cells[i], "classProgressDialogBarOneCellHighlight");
}
this.barOneLit = 0;
}
AddMethod(constr, resetBarOneProgress);function stop() /*: void*/
{
HTMLElement_RemoveClassName(this.stopButton, "classProgressDialogStopButtonActive");
this.stopped = true;
}
AddMethod(constr, stop);return constr; })();
function Test_ProgressElement()
{
var progress = document.getElementById("idProgress");
function loop()
{
var total /*: int*/ = 1000000;
for (var i /*: int*/ = 0; i < total; i++)
{
progress.value = i + 1;
}
}
loop(); // no need for any window.setTimeout
}function AddMethod(
constructor /*: Function*/,
method /* Function*/,
methodName /*: Function*/
) /*: void*/
{
var methodName /*: String*/ = methodName || Function_GetIdentifier(method);
var proto /*: Object*/ = constructor.prototype;
method.name = methodName;
method.ownerProto = proto;
proto[methodName] = method;
method.constructorName = constructor.name || Function_GetIdentifier(constructor, true);
}<META> MODULE <core> INCLUDE <if_used> TYPE <module_public_function> NAME <AddMethod> CLASS <> EXTENDS <> REQUIRES < @core.Function_GetIdentifier >
function AddStaticMethod(
constructor /*: Function*/,
method /* Function*/,
methodName /*: Function*/
) /*: void*/
{
var methodName /*: String*/ = methodName || Function_GetIdentifier(method);
method.name = methodName;
constructor[methodName] = method;
method.constructorName = constructor.name || Function_GetIdentifier(constructor, true);
}<META> MODULE <core> INCLUDE <if_used> TYPE <module_public_function> NAME <AddMethod> CLASS <> EXTENDS <> REQUIRES < @core.Function_GetIdentifier >
function ExtendClass(
constructor /*: Function*/,
superConstructor /*: Function*/
) /*: Object*/
{
var f = function(){};
f.prototype = superConstructor.prototype;
var proto /*: Object*/ = constructor.prototype = new f();
proto.prototype /*: Object*/ = proto;
proto.superPrototype /*: Object*/ = f.prototype;
proto.constructor /*: Function*/ = constructor;
proto.superConstructor /*: Function*/ = superConstructor;
constructor.superConstructor = superConstructor;
var constructorName /*: String*/ = Function_GetIdentifier(constructor);
constructor.name = constructorName;
proto.constructorName = constructorName;
return proto;
}<META> MODULE <core> INCLUDE <if_used> TYPE <module_public_function> NAME <ExtendClass> CLASS <> EXTENDS <> REQUIRES < >
function GetAppFolder() /*: String*/
{
var index /*: int*/;
var url /*: String*/ = document.URL;
if (url.indexOf("%") > -1)
{
url = unescape(url);
}
url = url.replace(/^\s*file:(\/+)/, "");
index = url.lastIndexOf("\\");
if (index > - 1)
{
url = url.substring(0, index + 1);
}
index = url.lastIndexOf("\/");
if (index > - 1)
{
url = url.substring(0, index + 1);
}
return url;
}function HTMLElement_RemoveClassName(
element /*: HTMLElement*/,
className /*: String*/
) /*: void*/
{
var current /*: String*/ = String_Trim(element.className) || "";
if (!current)
{
return;
}
else if (current.indexOf(className) == -1)
{
return;
}
else
{
var pattern /*: String*/ = "(^|\\s)" + className + "(\\s|$)";
var re /*: RegExp*/ = new RegExp(pattern);
re.lastIndex = 0;
current = current.replace(re, "$1$2").replace(/\s+/g, " ");
element.className = String_Trim(current);
}
}function HTMLElement_AddClassName(
element /*: HTMLElement*/,
className /*: String*/
) /*: void*/
{
var current /*: String*/ = String_Trim(element.className) || "";
if (!current)
{
element.className = className;
return;
}
else if (current.indexOf(className) == -1)
{
element.className += " " + className;
}
else
{
var pattern /*: String*/ = "(^|\\s)" + className + "(\\s|$)";
var re /*: RegExp*/ = new RegExp(pattern);
re.lastIndex = 0;
if (!re.test(current))
{
element.className += " " + className;
}
}
}function String_Trim(
s /*: String*/
) /*: String*/
{
return s.replace(/^\s+|\s+$/g, "");
}function Sleep(
ms /*: Milliseconds*/
) /*: void*/
{
var start /*: int*/ = new Date().getTime();
while (new Date().getTime() < start + ms);
}// http://dbaron.org/log/20100309-faster-timeouts
function ZeroTimeout(f /*: Function*/)
{
if (!ZeroTimeout.init ) { ZeroTimeout_Init(); }
if (!ZeroTimeout.available) { throw Error("ZeroTimeout not available"); }
ZeroTimeout.timeouts.push(f);
window.postMessage(ZeroTimeout.messageName, "*");
}
function ZeroTimeout_Init()
{
ZeroTimeout.init = true;
ZeroTimeout.available = true;
if (typeof window.postMessage == "undefined")
{
ZeroTimeout.available = false;
return;
}
ZeroTimeout.timeouts = [];
ZeroTimeout.messageName = "zero-timeout";
function ZeroTimeout_MessageHandler(event /*: Any*/)
{
var f /*: Function*/;
if (event.source == window && event.data == ZeroTimeout.messageName)
{
event.stopPropagation();
if (ZeroTimeout.timeouts.length > 0)
{
f = ZeroTimeout.timeouts.shift();
f();
}
}
}
window.addEventListener("message", ZeroTimeout_MessageHandler, true);
}http://dbaron.org/log/20100309-faster-timeouts
// Only add setZeroTimeout to the window object, and hide everything
// else in a closure.
(function() {
var timeouts = [];
var messageName = "zero-timeout-message";
// Like setTimeout, but only takes a function argument. There's
// no time argument (always zero) and no arguments (you have to
// use a closure).
function setZeroTimeout(fn) {
timeouts.push(fn);
window.postMessage(messageName, "*");
}
function handleMessage(event) {
if (event.source == window && event.data == messageName) {
event.stopPropagation();
if (timeouts.length > 0) {
var fn = timeouts.shift();
fn();
}
}
}
window.addEventListener("message", handleMessage, true);
// Add the one thing we want added to the window object.
window.setZeroTimeout = setZeroTimeout;
})();</script>
</head>
<body>
<h1>Progress Bar Tests</h1> <br> <br> <p>Tested in IE 6-8, Opera 11, Chrome 9, Safari 4, Firefox 3.5</p> <hr> <br>
<h2>Test 1 - showModelessDialog (PASS - IE ONLY)</h2> <p>Works perfectly; my ideal solution.</p> <input type=button value="Run Test" onclick="Test_ShowModelessDialog();"> <br> <br> <hr> <br>
<h2>Test 2 - showModalDialog (FAIL - ALL BROWSERS)</h2> <input type=button value="Run Test" onclick="Test_ShowModalDialog();"> <br> <br> <hr> <br>
<h2>Test 3 - window.open (PASS - IE, FAIL - ALL OTHERS)</h2> <input type=button value="Run Test (IE)" onclick="Test_WindowOpen_IE();"> <input type=button value="Run Test (OTHERS)" onclick="Test_WindowOpen_Others();"> <br> <br> <hr> <br>
<h2>Test 4 - iframe (FAIL - ALL BROWSERS)</h2> <input type=button value="Run Test" onclick="Test_Iframe();"> <br> <iframe id=test4iframe name=test4iframe src="046-stub.htm" style='width: 200px; height:40px' scrolling="no" frameborder="1"></iframe> <br> <br> <hr> <br>
<h2>Test 5 - setTimeout and continuation (PASS - ALL BROWSERS)</h2> <input type=button value="Run Test" onclick="Test_Continuation();"> <input type=button value="Run Test (Zero Timeout)" onclick="Test_Continuation_ZeroTimeout();"> <p>Note that zero timeout can be instantaneous on some browsers in relation to the loop I am running.</p> <br> <div id=test5div></div> <br> <br> <hr> <br>
<h2>Test 6 - Worker (PASS - OPERA + FIREFOX, FAIL - OTHER BROWSERS)</h2> <input type=button value="Run Test" onclick="Test_Worker();"> <br> <div id=test6div></div> <br> <br> <hr> <br>
<h2>Test 7 - Progress (PASS - OPERA, FAIL - ALL OTHER BROWSERS)</h2> <input type=button value="Run Test" onclick="Test_ProgressElement();"> <br> <br> <progress id=idProgress value="0" max="1000000" style="width:400px; height:30px;"></progress> <br> <br> <hr> <br>
</body>
</html>
var stopped /*: Boolean*/ = false;
self.onmessage = function(event)
{
var data /*: Object*/ = event.data;
if (event.data.type == "CompleteLoop")
{
CompleteLoop();
}
else if (event.data.type == "Stop")
{
stopped = true;
}
};
function CompleteLoop()
{
var total /*: int*/ = 10000;
for (var i /*: int*/ = 0; i < total; i++)
{
if (stopped) { break; }
self.postMessage ({type : "Progress", i : i + 1, total : total});
}
self.postMessage ({type : "Done"} );
}