alert.js
来自「Java的框架」· JavaScript 代码 · 共 105 行
JS
105 行
var alertPollURI = '/alert.srv';
var alertPushURI = '/alert_push.srv';
var alertAjaxURI = '/alert_ajax.srv';
var alertURI = null;
var alertLayer = '<iframe id="alertFrame" name="alertFrame" src="" style="visibility: hidden; width: 0px; height: 0px; border: 0px;"></iframe>';
var timer = null;
var alertWebRoot = null;
var isLoaded = false;
var alertType = null;
function startAlertListener (webRoot, alertRequestType) {
self.document.write(alertLayer);
alertType = alertRequestType;
alertWebRoot = webRoot;
if (alertRequestType == "poll") {
alertURI = webRoot + alertPollURI;
reloadFrame ();
}
else if (alertRequestType == 'push') {
alertURI = webRoot + alertPushURI;
timer = window.window.setTimeout('testDocumentLoaded()', 100);
}
else if (alertRequestType == 'ajax') {
alertURI = webRoot + alertAjaxURI;
makeAjaxRequest ();
}
}
function testDocumentLoaded () {
if (isLoaded) {
reloadFrame ();
}
else {
timer = window.window.setTimeout('testDocumentLoaded()', 100);
}
}
function startPollTimer () {
timer = window.window.setTimeout('reloadFrame()', 2000);
}
function stopPollTimer () {
if (timer != null) {
window.clearTimeout (timer);
timer = null;
}
}
function reloadFrame () {
stopPollTimer ();
self.alertFrame.location.replace (alertURI);
}
function hasAlert () {
stopPollTimer ();
elm = window.document.getElementById ('alertImage');
elm.style.visibility = 'visible';
}
function showAlertReturnFunc () {
elm = window.document.getElementById ('alertImage');
elm.style.visibility = 'hidden';
if (alertType == "poll") {
reloadFrame ();
}
else if (alertType == 'push') {
reloadFrame ();
}
else if (alertType == 'ajax') {
makeAjaxRequest ();
}
}
function showAlert () {
showPopWin(alertWebRoot + '/alert/viewAlert.action', 400, 300, showAlertReturnFunc);
}
function makeAjaxRequest () {
stopPollTimer ();
new net.ContentLoader (alertURI, handleAjaxResponse, null, "POST");
}
function handleAjaxResponse () {
var response = this.req.responseText;
if (response.length >= 3) {
hasAlert ();
}
else {
startAjaxTimer ();
}
}
function startAjaxTimer () {
timer = window.window.setTimeout('makeAjaxRequest()', 2000);
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?