| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
function mainInit() |
| 13 |
{ |
| 14 |
|
| 15 |
pageName = "main"; |
| 16 |
|
| 17 |
|
| 18 |
if (getFlashPlayerVersion()) |
| 19 |
{ |
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
$("__TADS_swf_div.<DIV>").innerHTML = |
| 27 |
"<object id='__TADS_swf' " |
| 28 |
+ "classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' " |
| 29 |
+ "codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0' " |
| 30 |
+ "width='0' height='0' align='middle' tabindex='-1'>" |
| 31 |
+ "<param name='movie' value='/webuires/TADS.swf'/>" |
| 32 |
+ "<param name='quality' value='high'/>" |
| 33 |
+ "<param name='bgcolor' value='#ffffff'/>" |
| 34 |
+ "<param name='allowScriptAccess' value='always'/>" |
| 35 |
+ "<param name='FlashVars' value='onload=TADS_swf.loaded.fire'/>" |
| 36 |
+ "<embed name='__TADS_swf' src='/webuires/TADS.swf' " |
| 37 |
+ "width='0' height='0' quality='high' bgcolor='#ffffff' " |
| 38 |
+ "allowScriptAccess='always' align='middle' " |
| 39 |
+ "type='application/x-shockwave-flash' " |
| 40 |
+ "pluginspage='http://www.macromedia.com/go/getflashplayer' " |
| 41 |
+ "FlashVars='onload=TADS_swf.loaded.fire'/>" |
| 42 |
+ "</object>"; |
| 43 |
} |
| 44 |
else |
| 45 |
{ |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
TADS_swf.loaded.fire(); |
| 50 |
} |
| 51 |
|
| 52 |
|
| 53 |
utilInit(); |
| 54 |
layoutInit(); |
| 55 |
|
| 56 |
|
| 57 |
initXmlFrame(); |
| 58 |
|
| 59 |
|
| 60 |
window.onresize = mainResize; |
| 61 |
window.onGameEvent = mainGameEvent; |
| 62 |
window.onGameState = mainGameState; |
| 63 |
window.onUload = mainUnload; |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
serverRequest("/webui/flushEvents"); |
| 70 |
|
| 71 |
|
| 72 |
getInitState(); |
| 73 |
|
| 74 |
|
| 75 |
cacheImage("/webuires/dlg-corners.gif"); |
| 76 |
cacheImage("/webuires/dlg-title-corners.gif"); |
| 77 |
cacheImage("/webuires/modal-cover.png"); |
| 78 |
cacheImage("/webuires/errorPopupBkg.gif"); |
| 79 |
cacheImage("/webuires/warningPopupBkg.gif"); |
| 80 |
cacheImage("/webuires/modal-cover.png"); |
| 81 |
} |
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
var wantInputEvent = false; |
| 90 |
|
| 91 |
|
| 92 |
function mainGameEvent(req, resp) |
| 93 |
{ |
| 94 |
|
| 95 |
if (xmlHasChild(resp, "setTitle")) |
| 96 |
document.title = xmlChildText(resp, "setTitle"); |
| 97 |
|
| 98 |
|
| 99 |
if (xmlHasChild(resp, "setPrefs")) |
| 100 |
xmlToPrefs(xmlChild(resp, "setPrefs")[0]); |
| 101 |
|
| 102 |
|
| 103 |
if (xmlHasChild(resp, "showPrefsDialog")) |
| 104 |
showPrefsDialog(); |
| 105 |
|
| 106 |
|
| 107 |
if (xmlHasChild(resp, "fileDialog")) |
| 108 |
showFileDialog(xmlChild(resp, "fileDialog")[0]); |
| 109 |
else if (xmlHasChild(resp, "uploadFileDialog")) |
| 110 |
showUploadDialog(xmlChild(resp, "uploadFileDialog")[0]); |
| 111 |
|
| 112 |
|
| 113 |
if (xmlHasChild(resp, "offerDownload")) |
| 114 |
{ |
| 115 |
var file = xmlChildText(resp, "offerDownload"); |
| 116 |
addDownloadFile(file); |
| 117 |
addDownloadFrame(file); |
| 118 |
} |
| 119 |
if (xmlHasChild(resp, "cancelDownload")) |
| 120 |
{ |
| 121 |
var file = xmlChildText(resp, "cancelDownload"); |
| 122 |
removeDownloadFile(file); |
| 123 |
removeDownloadFrame(file); |
| 124 |
} |
| 125 |
|
| 126 |
|
| 127 |
if (xmlHasChild(resp, "inputDialog")) |
| 128 |
showInputDialog(xmlChild(resp, "inputDialog")[0]); |
| 129 |
|
| 130 |
|
| 131 |
if (xmlHasChild(resp, "getInputEvent")) |
| 132 |
wantInputEvent = true; |
| 133 |
else if (xmlHasChild(resp, "cancelInputEvent")) |
| 134 |
wantInputEvent = false; |
| 135 |
|
| 136 |
|
| 137 |
if (xmlHasChild(resp, "menusys")) |
| 138 |
showMenuSys(xmlChild(resp, "menusys")[0]); |
| 139 |
|
| 140 |
|
| 141 |
layoutGameEvent(req, resp); |
| 142 |
} |
| 143 |
|
| 144 |
|
| 145 |
function mainGameState(req, resp) |
| 146 |
{ |
| 147 |
|
| 148 |
if (xmlHasChild(resp, "title")) |
| 149 |
document.title = xmlChildText(resp, "title"); |
| 150 |
|
| 151 |
|
| 152 |
if (xmlHasChild(resp, "prefs")) |
| 153 |
xmlToPrefs(xmlChild(resp, "prefs")[0]); |
| 154 |
|
| 155 |
|
| 156 |
layoutGameState(req, resp); |
| 157 |
|
| 158 |
|
| 159 |
if (xmlHasChild(resp, "fileDialog")) |
| 160 |
showFileDialog(xmlChild(resp, "fileDialog")[0]); |
| 161 |
else if (xmlHasChild(resp, "uploadFileDialog")) |
| 162 |
showUploadDialog(xmlChild(resp, "uploadFileDialog")[0]); |
| 163 |
|
| 164 |
|
| 165 |
if (xmlHasChild(resp, "inputDialog")) |
| 166 |
showInputDialog(xmlChild(resp, "inputDialog")[0]); |
| 167 |
|
| 168 |
|
| 169 |
if (xmlHasChild(resp, "getInputEvent")) |
| 170 |
wantInputEvent = true; |
| 171 |
|
| 172 |
|
| 173 |
if (xmlHasChild(resp, "offerDownload")) |
| 174 |
{ |
| 175 |
var lst = xmlChild(resp, "offerDownload"); |
| 176 |
for (var i = 0 ; i < lst.length ; ++i) |
| 177 |
addDownloadFile(xmlNodeText(lst[i])); |
| 178 |
} |
| 179 |
|
| 180 |
|
| 181 |
if (xmlHasChild(resp, "menusys")) |
| 182 |
showMenuSys(xmlChild(resp, "menusys")[0]); |
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
setTimeout(function() { |
| 200 |
serverRequest( |
| 201 |
"/webui/getEvent", ServerRequest.Subscription, cbGetEvent); |
| 202 |
}, 0); |
| 203 |
} |
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
function cbGetEvent(req, resp) |
| 210 |
{ |
| 211 |
|
| 212 |
var w = getEventWin(req, resp); |
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
if (w && w.onGameEvent) |
| 220 |
w.onGameEvent(req, resp); |
| 221 |
|
| 222 |
|
| 223 |
if (xmlHasChild(resp, "shutdown")) |
| 224 |
{ |
| 225 |
|
| 226 |
showDialog({ |
| 227 |
title: "TADS", |
| 228 |
id: "shutdown", |
| 229 |
contents: "The game server has terminated the connection." |
| 230 |
}); |
| 231 |
|
| 232 |
|
| 233 |
return; |
| 234 |
} |
| 235 |
|
| 236 |
|
| 237 |
serverRequest("/webui/getEvent", |
| 238 |
ServerRequest.Subscription, cbGetEvent); |
| 239 |
} |
| 240 |
|
| 241 |
|
| 242 |
function getEventWin(req, resp) |
| 243 |
{ |
| 244 |
|
| 245 |
|
| 246 |
if (xmlHasChild(resp, "window")) |
| 247 |
{ |
| 248 |
|
| 249 |
return windowFromAbsPath(xmlChildText(resp, "window")); |
| 250 |
} |
| 251 |
else |
| 252 |
{ |
| 253 |
|
| 254 |
return window; |
| 255 |
} |
| 256 |
} |
| 257 |
|
| 258 |
|
| 259 |
function windowFromAbsPath(path) |
| 260 |
{ |
| 261 |
|
| 262 |
if (typeof(path) == "string") |
| 263 |
path = path.split("."); |
| 264 |
|
| 265 |
|
| 266 |
if (path.shift() != pageName) |
| 267 |
return null; |
| 268 |
|
| 269 |
|
| 270 |
if (path.length == 0) |
| 271 |
return window; |
| 272 |
|
| 273 |
|
| 274 |
return windowFromPath(path); |
| 275 |
} |
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
function keyToServer(desc) |
| 294 |
{ |
| 295 |
|
| 296 |
if (desc && wantInputEvent) |
| 297 |
{ |
| 298 |
|
| 299 |
var key = DOM3toTADSKey[desc.keyName] || desc.ch; |
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
if (!key) |
| 304 |
return; |
| 305 |
|
| 306 |
|
| 307 |
var ch = key.charCodeAt(0); |
| 308 |
if (ch == 10 || ch == 13) |
| 309 |
ch = '\n'; |
| 310 |
else if (ch < 32) |
| 311 |
key = "[ctrl-" + String.fromCharCode(ch + 64) + "]"; |
| 312 |
|
| 313 |
|
| 314 |
serverRequest("/webui/inputEvent?type=key¶m=" |
| 315 |
+ encodeURIComponent(key)); |
| 316 |
|
| 317 |
|
| 318 |
wantInputEvent = false; |
| 319 |
|
| 320 |
|
| 321 |
preventDefault(desc.event); |
| 322 |
} |
| 323 |
} |
| 324 |
|
| 325 |
|
| 326 |
var DOM3toTADSKey = { |
| 327 |
"U+001B": "[esc]", |
| 328 |
"Up": "[up]", |
| 329 |
"Down": "[down]", |
| 330 |
"Left": "[left]", |
| 331 |
"Right": "[right]", |
| 332 |
"Home": "[home]", |
| 333 |
"End": "[end]", |
| 334 |
"U+007F": "[del]", |
| 335 |
"Insert": "[insert]", |
| 336 |
"ScrollLock": "[scroll]", |
| 337 |
"PageUp": "[page up]", |
| 338 |
"PageDown": "[page down]", |
| 339 |
"F1": "[f1]", |
| 340 |
"F2": "[f2]", |
| 341 |
"F3": "[f3]", |
| 342 |
"F4": "[f4]", |
| 343 |
"F5": "[f5]", |
| 344 |
"F6": "[f6]", |
| 345 |
"F7": "[f7]", |
| 346 |
"F8": "[f8]", |
| 347 |
"F9": "[f9]", |
| 348 |
"F10": "[f10]", |
| 349 |
"F11": "[f11]", |
| 350 |
"F12": "[f12]", |
| 351 |
"U+0008": "[bksp]" |
| 352 |
}; |
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
|
| 358 |
|
| 359 |
function clickToServer(ev, href,ele) |
| 360 |
{ |
| 361 |
|
| 362 |
if (wantInputEvent) |
| 363 |
{ |
| 364 |
|
| 365 |
serverRequest("/webui/inputEvent?type=href¶m=" |
| 366 |
+ encodeURIComponent(href)); |
| 367 |
|
| 368 |
|
| 369 |
wantInputEvent = false; |
| 370 |
} |
| 371 |
} |
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
function mainResize() |
| 379 |
{ |
| 380 |
|
| 381 |
if (errorPopupVis) |
| 382 |
{ |
| 383 |
var rc = getWindowRect(); |
| 384 |
var ediv = $("errorPopupDiv"); |
| 385 |
ediv.style.left = (rc.width - ediv.offsetWidth) + "px"; |
| 386 |
ediv.style.top = (rc.height - ediv.offsetHeight) + "px"; |
| 387 |
} |
| 388 |
if (downloadFiles.length) |
| 389 |
{ |
| 390 |
var rc = getWindowRect(); |
| 391 |
var ddiv = $("downloadPopupDiv"); |
| 392 |
ddiv.style.left = (rc.width - ddiv.offsetWidth) + "px"; |
| 393 |
var top = rc.height - ddiv.offsetHeight; |
| 394 |
if (errorPopupVis) |
| 395 |
top -= ediv.offsetHeight; |
| 396 |
ddiv.style.top = top + "px"; |
| 397 |
} |
| 398 |
|
| 399 |
|
| 400 |
for (var i = 0 ; i < dialogStack.length ; ++i) |
| 401 |
{ |
| 402 |
if (!dialogStack[i].manuallyPositioned) |
| 403 |
positionDialog(dialogStack[i].ele, false); |
| 404 |
} |
| 405 |
|
| 406 |
|
| 407 |
calcLayout(); |
| 408 |
} |
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
|
| 414 |
function mainUnload() |
| 415 |
{ |
| 416 |
if (debugLogWin) |
| 417 |
{ |
| 418 |
debugLogWin.close(); |
| 419 |
debugLogWin = null; |
| 420 |
} |
| 421 |
} |
| 422 |
|
| 423 |
|
| 424 |
|
| 425 |
|
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
|
| 430 |
|
| 431 |
|
| 432 |
|
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
var errorLog = []; |
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
var errorPopupVis = false; |
| 445 |
|
| 446 |
|
| 447 |
|
| 448 |
|
| 449 |
|
| 450 |
|
| 451 |
|
| 452 |
|
| 453 |
|
| 454 |
|
| 455 |
|
| 456 |
|
| 457 |
|
| 458 |
|
| 459 |
|
| 460 |
|
| 461 |
|
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
|
| 469 |
|
| 470 |
function logError(msg, detail, id) |
| 471 |
{ |
| 472 |
|
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
|
| 478 |
if (!id) |
| 479 |
id = new LogErrorID(); |
| 480 |
|
| 481 |
|
| 482 |
errorLog.unshift({msg: msg, detail: detail, id: id, viewed: false, |
| 483 |
timestamp: new Date()}); |
| 484 |
|
| 485 |
|
| 486 |
if (!errorPopupVis) |
| 487 |
{ |
| 488 |
|
| 489 |
errorPopupVis = true; |
| 490 |
var d = $("errorPopupDiv"); |
| 491 |
setAlpha(d, 0); |
| 492 |
|
| 493 |
|
| 494 |
mainResize(); |
| 495 |
|
| 496 |
|
| 497 |
startFade(d, 1, 700); |
| 498 |
} |
| 499 |
|
| 500 |
|
| 501 |
|
| 502 |
var allRetry = true; |
| 503 |
for (var i = 0 ; i < errorLog.length ; ++i) |
| 504 |
{ |
| 505 |
|
| 506 |
var e = errorLog[i]; |
| 507 |
|
| 508 |
|
| 509 |
|
| 510 |
if (!e.viewed && e.id.failed) |
| 511 |
{ |
| 512 |
allRetry = false; |
| 513 |
break; |
| 514 |
} |
| 515 |
} |
| 516 |
|
| 517 |
|
| 518 |
$("errorPopupDiv.[content]").style.background = |
| 519 |
(allRetry ? "#ff8000" : "#ff0000"); |
| 520 |
$("errorPopupDiv.[icon]").style.backgroundImage = |
| 521 |
(allRetry ? "url(/webuires/warningPopupBkg.gif)" |
| 522 |
: "url(/webuires/errorPopupBkg.gif)"); |
| 523 |
} |
| 524 |
|
| 525 |
function LogErrorID() |
| 526 |
{ |
| 527 |
this.succeeded = false; |
| 528 |
this.failed = true; |
| 529 |
} |
| 530 |
|
| 531 |
function openErrorDetail(i) |
| 532 |
{ |
| 533 |
$("errorDetailDiv-" + i).style.display = "block"; |
| 534 |
$("openErrorDetailLink-" + i).style.display = "none"; |
| 535 |
} |
| 536 |
|
| 537 |
|
| 538 |
|
| 539 |
function unlogError(id) |
| 540 |
{ |
| 541 |
|
| 542 |
var openCnt = 0; |
| 543 |
for (var i = 0 ; i < errorLog.length ; ++i) |
| 544 |
{ |
| 545 |
|
| 546 |
var e = errorLog[i]; |
| 547 |
|
| 548 |
|
| 549 |
|
| 550 |
if (!e.id.succeeded && !e.viewed) |
| 551 |
++openCnt; |
| 552 |
} |
| 553 |
|
| 554 |
|
| 555 |
if (openCnt == 0) |
| 556 |
hideErrorPopup(); |
| 557 |
} |
| 558 |
|
| 559 |
|
| 560 |
var errorLogViewCount = 0; |
| 561 |
function showErrorLog() |
| 562 |
{ |
| 563 |
|
| 564 |
var lst = []; |
| 565 |
for (var i = 0 ; i < errorLog.length ; ++i) |
| 566 |
{ |
| 567 |
var msg = errorLog[i].msg; |
| 568 |
var id = errorLog[i].id; |
| 569 |
var detail = errorLog[i].detail; |
| 570 |
var ts = errorLog[i].timestamp; |
| 571 |
if (detail) |
| 572 |
{ |
| 573 |
msg += |
| 574 |
"<div class=\"errorFooter\">" |
| 575 |
+ ts.toLocaleTimeString() |
| 576 |
+ (errorLogViewCount == 0 ? "" : |
| 577 |
errorLog[i].viewed ? " | Previously viewed" : " | New") |
| 578 |
+ (id.succeeded |
| 579 |
? " | Error was resolved automatically" : |
| 580 |
!id.failed |
| 581 |
? " | Request is being retried automatically" : |
| 582 |
"") |
| 583 |
+ "<span id=\"openErrorDetailLink-" + i + "\"> | " |
| 584 |
+ "<a href=\"#\" onclick=\"javascript:openErrorDetail(" |
| 585 |
+ i + ");return false;\">View Details</a></span>" |
| 586 |
+ "</div>" |
| 587 |
+ "<div class=\"errorDetail\" id=\"errorDetailDiv-" |
| 588 |
+ i + "\">" + detail |
| 589 |
+ "</div>"; |
| 590 |
} |
| 591 |
lst.push(msg); |
| 592 |
} |
| 593 |
|
| 594 |
|
| 595 |
errorLogViewCount++; |
| 596 |
|
| 597 |
|
| 598 |
for (var i = 0 ; i < errorLog.length ; ++i) |
| 599 |
errorLog[i].viewed = true; |
| 600 |
|
| 601 |
|
| 602 |
|
| 603 |
var cont; |
| 604 |
if (errorLog.length == 0) |
| 605 |
{ |
| 606 |
cont = "This window shows any errors encountered in the browser " |
| 607 |
+ "since you loaded the page, including network problems " |
| 608 |
+ "and javascript errors. So far, no errors have occurred " |
| 609 |
+ "since you loaded or refreshed the page."; |
| 610 |
} |
| 611 |
else if (errorLog.length == 1) |
| 612 |
{ |
| 613 |
|
| 614 |
cont = lst[0]; |
| 615 |
} |
| 616 |
else |
| 617 |
{ |
| 618 |
|
| 619 |
cont = "The game encountered the following errors (the most " |
| 620 |
+ "recent is listed first):" |
| 621 |
+ "<div class='errorListDiv'>" |
| 622 |
+ lst.join("<hr>") |
| 623 |
+ "</div>"; |
| 624 |
} |
| 625 |
|
| 626 |
|
| 627 |
hideErrorPopup(); |
| 628 |
|
| 629 |
|
| 630 |
showDialog({ title: "Error Log", id: 'errorLog', contents: cont }); |
| 631 |
} |
| 632 |
|
| 633 |
|
| 634 |
function hideErrorPopup() |
| 635 |
{ |
| 636 |
|
| 637 |
errorPopupVis = false; |
| 638 |
var d = $("errorPopupDiv"); |
| 639 |
startFade(d, -1, 250, function() { |
| 640 |
d.style.top = "-1000px"; |
| 641 |
mainResize(); |
| 642 |
}); |
| 643 |
} |
| 644 |
|
| 645 |
|
| 646 |
|
| 647 |
|
| 648 |
|
| 649 |
|
| 650 |
|
| 651 |
|
| 652 |
|
| 653 |
var downloadFiles = []; |
| 654 |
|
| 655 |
|
| 656 |
function addDownloadFile(fname) |
| 657 |
{ |
| 658 |
|
| 659 |
downloadFiles.push(fname); |
| 660 |
|
| 661 |
|
| 662 |
var d = $("downloadPopupDiv"); |
| 663 |
|
| 664 |
|
| 665 |
rebuildDownloadDiv(); |
| 666 |
|
| 667 |
|
| 668 |
if (downloadFiles.length == 1) |
| 669 |
{ |
| 670 |
|
| 671 |
setAlpha(d, 0); |
| 672 |
startFade(d, 1, 700); |
| 673 |
} |
| 674 |
|
| 675 |
|
| 676 |
mainResize(); |
| 677 |
} |
| 678 |
|
| 679 |
|
| 680 |
function removeDownloadFile(fname) |
| 681 |
{ |
| 682 |
|
| 683 |
var idx = downloadFiles.indexOf(fname); |
| 684 |
if (idx >= 0) |
| 685 |
{ |
| 686 |
|
| 687 |
downloadFiles.splice(idx, 1); |
| 688 |
|
| 689 |
|
| 690 |
rebuildDownloadDiv(); |
| 691 |
|
| 692 |
|
| 693 |
var cnt = downloadFiles.length; |
| 694 |
var d = $("downloadPopupDiv"); |
| 695 |
if (cnt == 0) |
| 696 |
{ |
| 697 |
|
| 698 |
startFade(d, -1, 250, function() { |
| 699 |
d.style.top = "-1000px"; |
| 700 |
}); |
| 701 |
} |
| 702 |
else |
| 703 |
{ |
| 704 |
|
| 705 |
mainResize(); |
| 706 |
} |
| 707 |
} |
| 708 |
} |
| 709 |
|
| 710 |
|
| 711 |
function rebuildDownloadDiv() |
| 712 |
{ |
| 713 |
var s = ["<b>Download Files</b>"]; |
| 714 |
downloadFiles.forEach(function(fname) { |
| 715 |
var shortName = fname.replace(/^.*\//, "").htmlify(); |
| 716 |
var href = encodeURI(fname); |
| 717 |
s.push("<div class='dlfile'>• " |
| 718 |
+ "<a href=\"#\" onclick=\"javascript:addDownloadFrame('" |
| 719 |
+ href + "');return false;\">" + shortName + "</a>" |
| 720 |
+ " | <a href=\"#\" onclick=\"javascript:cancelDownloadFile('" |
| 721 |
+ href + "');return false;\">Cancel</a>" |
| 722 |
+ "</div>"); |
| 723 |
}); |
| 724 |
|
| 725 |
$("downloadPopupDiv.[content]").innerHTML = s.join(""); |
| 726 |
} |
| 727 |
|
| 728 |
function cancelDownloadFile(fname) |
| 729 |
{ |
| 730 |
serverRequest(fname + "?cancel"); |
| 731 |
} |
| 732 |
|
| 733 |
|
| 734 |
|
| 735 |
|
| 736 |
|
| 737 |
|
| 738 |
|
| 739 |
|
| 740 |
var debugLogWin = null, debugLogLoaded = new AbsEvent(); |
| 741 |
function debugLog(msg) |
| 742 |
{ |
| 743 |
|
| 744 |
if (!debugLogWin || debugLogWin.closed) |
| 745 |
{ |
| 746 |
debugLogLoaded.isDone = false; |
| 747 |
debugLogWin = window.open( |
| 748 |
"/webuires/debuglog.htm", "tadsDebugLog", |
| 749 |
"location=no, resizable=yes, scrollbars=yes, status=yes, " |
| 750 |
+ "width=550, height=400"); |
| 751 |
} |
| 752 |
|
| 753 |
|
| 754 |
debugLogLoaded.whenDone(function() { |
| 755 |
debugLogWin.debugLogPrint(msg); |
| 756 |
}); |
| 757 |
} |
| 758 |
|
| 759 |
|
| 760 |
|
| 761 |
|
| 762 |
|
| 763 |
|
| 764 |
|
| 765 |
|
| 766 |
|
| 767 |
|
| 768 |
|
| 769 |
|
| 770 |
|
| 771 |
|
| 772 |
|
| 773 |
|
| 774 |
|
| 775 |
|
| 776 |
|
| 777 |
|
| 778 |
|
| 779 |
|
| 780 |
|
| 781 |
|
| 782 |
|
| 783 |
|
| 784 |
|
| 785 |
|
| 786 |
|
| 787 |
|
| 788 |
|
| 789 |
|
| 790 |
|
| 791 |
|
| 792 |
|
| 793 |
|
| 794 |
|
| 795 |
|
| 796 |
|
| 797 |
|
| 798 |
|
| 799 |
|
| 800 |
|
| 801 |
|
| 802 |
|
| 803 |
|
| 804 |
|
| 805 |
|
| 806 |
|
| 807 |
|
| 808 |
|
| 809 |
|
| 810 |
|
| 811 |
|
| 812 |
|
| 813 |
|
| 814 |
|
| 815 |
|
| 816 |
|
| 817 |
|
| 818 |
|
| 819 |
|
| 820 |
|
| 821 |
|
| 822 |
|
| 823 |
|
| 824 |
|
| 825 |
var dialogStack = []; |
| 826 |
var fontSelectorOptions = null; |
| 827 |
function showDialog(params) |
| 828 |
{ |
| 829 |
|
| 830 |
var contents = params.contents; |
| 831 |
if (typeof(contents) == "object") |
| 832 |
contents = contents.innerHTML; |
| 833 |
|
| 834 |
|
| 835 |
var go = function() { showDialogMain(params); }; |
| 836 |
|
| 837 |
|
| 838 |
if (contents.match(/\$\[fontpicker([^\]]*)\]/)) |
| 839 |
{ |
| 840 |
|
| 841 |
|
| 842 |
var go1 = go; |
| 843 |
go = function() { TADS_swf.waitForFontList(go1); }; |
| 844 |
} |
| 845 |
|
| 846 |
|
| 847 |
go(); |
| 848 |
} |
| 849 |
|
| 850 |
|
| 851 |
function showDialogMain(params) |
| 852 |
{ |
| 853 |
|
| 854 |
var z = 10500 + dialogStack.length*10; |
| 855 |
var dlgID = "dialogDiv" + (dialogStack.length + 1); |
| 856 |
|
| 857 |
|
| 858 |
var dlgDesc = { |
| 859 |
title: params.title, |
| 860 |
dd: dlgID, |
| 861 |
manuallyPositioned: false, |
| 862 |
dismiss: params.dismiss, |
| 863 |
initFocus: params.initFocus, |
| 864 |
id: params.id |
| 865 |
}; |
| 866 |
|
| 867 |
|
| 868 |
dialogStack.push(dlgDesc); |
| 869 |
|
| 870 |
|
| 871 |
var bkg = dlgDesc.bkg = document.createElement("div"); |
| 872 |
bkg.className = "dialogCoverDiv"; |
| 873 |
bkg.style.zIndex = z; |
| 874 |
document.body.appendChild(bkg); |
| 875 |
|
| 876 |
|
| 877 |
var canvas = dlgDesc.canvas = document.createElement("div"); |
| 878 |
canvas.className = "dialogCanvas"; |
| 879 |
canvas.style.zIndex = "" + (z + 1); |
| 880 |
document.body.appendChild(canvas); |
| 881 |
|
| 882 |
|
| 883 |
var dlg = dlgDesc.ele = document.createElement("div"); |
| 884 |
dlg.id = dlgID; |
| 885 |
dlg.innerHTML = $("dialogTemplate").innerHTML; |
| 886 |
dlg.className = "dialogDiv"; |
| 887 |
dlg.style.zIndex = "" + (z + 1); |
| 888 |
dlg.onkeydown = function(ev) { return $kd(ev, dlgKey, dlgDesc); }; |
| 889 |
dlg.onkeypress = function(ev) { return $kp(ev, dlgKey, dlgDesc); }; |
| 890 |
canvas.appendChild(dlg); |
| 891 |
|
| 892 |
|
| 893 |
if (params.dimensions && params.dimensions.height) |
| 894 |
dlg.style.height = params.dimensions.height; |
| 895 |
if (params.dimensions && params.dimensions.width) |
| 896 |
dlg.style.width = params.dimensions.width; |
| 897 |
|
| 898 |
|
| 899 |
var ttl = $(dlg, "[dialogTitle]"); |
| 900 |
var cont = $(dlg, "[dialogContent]"); |
| 901 |
|
| 902 |
|
| 903 |
if (params.fillWidth) |
| 904 |
cont.style.width = "100%"; |
| 905 |
|
| 906 |
|
| 907 |
ttl.innerHTML = params.title; |
| 908 |
|
| 909 |
|
| 910 |
var buttons = params.buttons; |
| 911 |
if (!buttons) |
| 912 |
buttons = [{name: "OK", isDefault: true, isCancel: true}]; |
| 913 |
|
| 914 |
|
| 915 |
dlgDesc.buttons = buttons || []; |
| 916 |
|
| 917 |
|
| 918 |
var contents = params.contents; |
| 919 |
if (typeof(contents) == "object") |
| 920 |
contents = contents.innerHTML; |
| 921 |
|
| 922 |
|
| 923 |
var fontSizeOptions = |
| 924 |
[8, 9, 10, 11, 12, 14, 16, 18, 20, |
| 925 |
22, 24, 26, 28, 30, 32, 36, 48, 72] |
| 926 |
.map(function(x) { |
| 927 |
return "<option value=\"" + x + "pt\">" + x + "pt</option>"; |
| 928 |
}).join(""); |
| 929 |
fontSizeOptions = "<option value=\"*\">(Default)</option>" |
| 930 |
+ fontSizeOptions; |
| 931 |
var fontPickers = []; |
| 932 |
var preFontCont = contents; |
| 933 |
contents = contents.replace( |
| 934 |
/\$\[fontpicker([^\]]*)\]/gm, function(match, attrs) { |
| 935 |
|
| 936 |
|
| 937 |
var pattrs = parseTagAttrs(attrs); |
| 938 |
|
| 939 |
|
| 940 |
fontPickers.push({ attrs: attrs, pattrs: pattrs }); |
| 941 |
|
| 942 |
|
| 943 |
|
| 944 |
|
| 945 |
|
| 946 |
return createCombo(pattrs.id, 40, "") |
| 947 |
+ createCombo(pattrs.id + "Size", 5, fontSizeOptions); |
| 948 |
}); |
| 949 |
|
| 950 |
|
| 951 |
|
| 952 |
var needFonts = (contents != preFontCont); |
| 953 |
|
| 954 |
|
| 955 |
var colorPickers = []; |
| 956 |
contents = contents.replace( |
| 957 |
/\$\[colorpicker([^\]]*)\]/gm, function(match, attrs) { |
| 958 |
var pattrs = parseTagAttrs(attrs); |
| 959 |
var btnID = dlgID + "." + pattrs.id; |
| 960 |
colorPickers[pattrs.id] = pattrs; |
| 961 |
return "<a href=\"#\" " + attrs + " class=\"colorbutton\" " |
| 962 |
+ "onclick=\"javascript:openColorPicker(event, '" + btnID |
| 963 |
+ "', true);return false;\" " |
| 964 |
+ "onkeydown=\"javascript:return $kd(event, colorbuttonKey, ['" |
| 965 |
+ btnID + "',true]);\" " |
| 966 |
+ "onkeypress=\"javascript:return $kp(event, colorbuttonKey, ['" |
| 967 |
+ btnID + "',true]);\">" |
| 968 |
+ "<span></span></a>"; |
| 969 |
}); |
| 970 |
|
| 971 |
|
| 972 |
contents = contents.replace( |
| 973 |
/\$\[checkbox([^\]]*)\]/gm, function(match, attrs) { |
| 974 |
var pattrs = parseTagAttrs(attrs); |
| 975 |
return "<label><nobr><input type=\"checkbox\" " + attrs |
| 976 |
+ "><label for=\"" + pattrs.id + "\"> " + pattrs.label |
| 977 |
+ "</label></nobr></label>"; |
| 978 |
}); |
| 979 |
|
| 980 |
|
| 981 |
if (buttons.length) |
| 982 |
{ |
| 983 |
contents += "<div class=\"dialogButtons\">"; |
| 984 |
for (var i = 0 ; i < buttons.length ; ++i) |
| 985 |
{ |
| 986 |
var b = buttons[i]; |
| 987 |
if (b.name) |
| 988 |
{ |
| 989 |
contents += "<span style='padding: 0 1em 0 1em;'>" |
| 990 |
+ "<a href='#' " |
| 991 |
+ "onclick='javscript:clickDialogButton(" |
| 992 |
+ i + ");return false;'>" + b.name |
| 993 |
+ "</a></span>"; |
| 994 |
} |
| 995 |
} |
| 996 |
contents += "</div>"; |
| 997 |
} |
| 998 |
|
| 999 |
|
| 1000 |
cont.innerHTML = |
| 1001 |
"<div class=\"" |
| 1002 |
+ (params.fillWidth ? "dialogZeroMarginDiv" : "dialogMarginDiv") |
| 1003 |
+ "\">" + contents + "</div>"; |
| 1004 |
|
| 1005 |
|
| 1006 |
if (params.init) |
| 1007 |
params.init(dlg, params); |
| 1008 |
|
| 1009 |
|
| 1010 |
positionDialog(dlg, true); |
| 1011 |
|
| 1012 |
|
| 1013 |
|
| 1014 |
setTimeout(function() { |
| 1015 |
|
| 1016 |
positionDialog(dlg, true); |
| 1017 |
|
| 1018 |
|
| 1019 |
setAlpha(canvas, 100); |
| 1020 |
|
| 1021 |
|
| 1022 |
initDialogFocus(); |
| 1023 |
|
| 1024 |
|
| 1025 |
if (params.initAfterVisible) |
| 1026 |
setTimeout( |
| 1027 |
function() { params.initAfterVisible(dlg, params); }, |
| 1028 |
10); |
| 1029 |
}, 1); |
| 1030 |
|
| 1031 |
|
| 1032 |
|
| 1033 |
if (needFonts) |
| 1034 |
{ |
| 1035 |
|
| 1036 |
var fonts = TADS_swf.fontList; |
| 1037 |
|
| 1038 |
|
| 1039 |
fontSelectorOptions = fonts.map(function(ele) { |
| 1040 |
ele = ele.htmlify(); |
| 1041 |
return "<option value=\"" + ele + "\">" + ele + "</option>" |
| 1042 |
}).join(""); |
| 1043 |
|
| 1044 |
|
| 1045 |
fontSelectorOptions = "<option value=\"*\">(Default)</option>" |
| 1046 |
+ fontSelectorOptions; |
| 1047 |
|
| 1048 |
|
| 1049 |
for (var i = 0 ; i < fontPickers.length ; ++i) |
| 1050 |
{ |
| 1051 |
|
| 1052 |
var f = fontPickers[i]; |
| 1053 |
var fld = $(dlg, f.pattrs.id); |
| 1054 |
var sel = comboGetElement(fld, "SELECT"); |
| 1055 |
|
| 1056 |
|
| 1057 |
|
| 1058 |
|
| 1059 |
|
| 1060 |
|
| 1061 |
|
| 1062 |
|
| 1063 |
|
| 1064 |
|
| 1065 |
|
| 1066 |
|
| 1067 |
|
| 1068 |
|
| 1069 |
|
| 1070 |
if (sel.outerHTML) |
| 1071 |
{ |
| 1072 |
|
| 1073 |
sel.outerHTML = sel.outerHTML.replace( |
| 1074 |
/<\/select>/im, fontSelectorOptions + "</SELECT>") |
| 1075 |
.replace(/size=("[^"]+"|'[^']'|[^'"][^\s>]*)/im, |
| 1076 |
"size=\"20\""); |
| 1077 |
} |
| 1078 |
else |
| 1079 |
{ |
| 1080 |
|
| 1081 |
sel.innerHTML = fontSelectorOptions; |
| 1082 |
sel.size = "20"; |
| 1083 |
} |
| 1084 |
} |
| 1085 |
} |
| 1086 |
} |
| 1087 |
|
| 1088 |
|
| 1089 |
|
| 1090 |
|
| 1091 |
function initDialogFocus() |
| 1092 |
{ |
| 1093 |
|
| 1094 |
if (dialogStack.length == 0) |
| 1095 |
return; |
| 1096 |
|
| 1097 |
|
| 1098 |
var desc = dialogStack.top(); |
| 1099 |
var dlg = desc.ele; |
| 1100 |
|
| 1101 |
|
| 1102 |
var f; |
| 1103 |
if (desc.initFocus) |
| 1104 |
f = $(dlg, desc.initFocus); |
| 1105 |
|
| 1106 |
|
| 1107 |
|
| 1108 |
if (!f) |
| 1109 |
{ |
| 1110 |
f = breadthSearch(dlg, function(ele) { |
| 1111 |
return (ele.focus |
| 1112 |
&& (ele.nodeName == "INPUT" |
| 1113 |
|| ele.nodeName == "TEXTAREA" |
| 1114 |
|| ele.nodeName == "SELECT" |
| 1115 |
|| ele.nodeName == "A")); |
| 1116 |
}); |
| 1117 |
} |
| 1118 |
|
| 1119 |
|
| 1120 |
|
| 1121 |
|
| 1122 |
if (f) |
| 1123 |
{ |
| 1124 |
|
| 1125 |
f.focus(); |
| 1126 |
|
| 1127 |
|
| 1128 |
if (f.nodeName == "INPUT" || f.nodeName == "TEXTAREA") |
| 1129 |
setSelRangeInEle(f); |
| 1130 |
} |
| 1131 |
else if (dlg.focus) |
| 1132 |
dlg.focus(); |
| 1133 |
else if (document.activeElement) |
| 1134 |
document.activeElement.blur(); |
| 1135 |
} |
| 1136 |
|
| 1137 |
|
| 1138 |
|
| 1139 |
|
| 1140 |
function positionDialog(dlg, init) |
| 1141 |
{ |
| 1142 |
|
| 1143 |
var drc = getObjectRect(dlg); |
| 1144 |
var wrc = getWindowRect(); |
| 1145 |
|
| 1146 |
|
| 1147 |
var x = (wrc.width - drc.width)/2, y = (wrc.height - drc.height)/2; |
| 1148 |
|
| 1149 |
|
| 1150 |
|
| 1151 |
if (init && dialogStack.length > 1) |
| 1152 |
{ |
| 1153 |
|
| 1154 |
var par = dialogStack[dialogStack.length - 2]; |
| 1155 |
var prc = getObjectRect(par.ele); |
| 1156 |
|
| 1157 |
|
| 1158 |
x = prc.x + 25; |
| 1159 |
y = prc.y + 25; |
| 1160 |
|
| 1161 |
|
| 1162 |
par.manuallyPositioned = true; |
| 1163 |
dialogStack.top().manuallyPositioned = true; |
| 1164 |
} |
| 1165 |
|
| 1166 |
|
| 1167 |
dlg.style.left = (x > 0 ? x : 0) + "px"; |
| 1168 |
dlg.style.top = (y > 0 ? y : 0) + "px"; |
| 1169 |
} |
| 1170 |
|
| 1171 |
|
| 1172 |
|
| 1173 |
|
| 1174 |
var dlgTrackInfo = null; |
| 1175 |
function dlgTitleDown(ev) |
| 1176 |
{ |
| 1177 |
|
| 1178 |
if (dialogStack.length == 0) |
| 1179 |
return; |
| 1180 |
|
| 1181 |
|
| 1182 |
var dlg = dialogStack.top().ele; |
| 1183 |
var rc = getObjectRect(dlg); |
| 1184 |
|
| 1185 |
|
| 1186 |
ev = getEvent(ev); |
| 1187 |
|
| 1188 |
|
| 1189 |
dlgTrackInfo = { x: ev.clientX - rc.x, y: ev.clientY - rc.y, dlg: dlg }; |
| 1190 |
|
| 1191 |
|
| 1192 |
addEventHandler(document, "mousemove", dlgTitleMove); |
| 1193 |
addEventHandler(document, "mouseup", dlgTitleUp); |
| 1194 |
addEventHandler(document, "selectstart", dlgTitleSelect); |
| 1195 |
|
| 1196 |
|
| 1197 |
|
| 1198 |
|
| 1199 |
|
| 1200 |
|
| 1201 |
|
| 1202 |
|
| 1203 |
|
| 1204 |
|
| 1205 |
|
| 1206 |
|
| 1207 |
|
| 1208 |
var cover = $(dlg, "[dialogMoveCover]"); |
| 1209 |
cover.style.display = "block"; |
| 1210 |
cover.style.width = rc.width + "px"; |
| 1211 |
cover.style.height = rc.height + "px"; |
| 1212 |
|
| 1213 |
|
| 1214 |
return false; |
| 1215 |
} |
| 1216 |
|
| 1217 |
|
| 1218 |
function dlgTitleSelect(ev) |
| 1219 |
{ |
| 1220 |
return false; |
| 1221 |
} |
| 1222 |
|
| 1223 |
function dlgTitleMove(ev) |
| 1224 |
{ |
| 1225 |
|
| 1226 |
if (!dlgTrackInfo) |
| 1227 |
return; |
| 1228 |
|
| 1229 |
|
| 1230 |
ev = getEvent(ev); |
| 1231 |
|
| 1232 |
|
| 1233 |
var dlg = dlgTrackInfo.dlg; |
| 1234 |
dlg.style.left = (ev.clientX - dlgTrackInfo.x) + "px"; |
| 1235 |
dlg.style.top = (ev.clientY - dlgTrackInfo.y) + "px"; |
| 1236 |
|
| 1237 |
|
| 1238 |
dialogStack.top().manuallyPositioned = true; |
| 1239 |
|
| 1240 |
|
| 1241 |
preventDefault(ev); |
| 1242 |
cancelBubble(ev); |
| 1243 |
return false; |
| 1244 |
} |
| 1245 |
|
| 1246 |
function dlgTitleUp(ev) |
| 1247 |
{ |
| 1248 |
|
| 1249 |
if (!dlgTrackInfo) |
| 1250 |
return; |
| 1251 |
|
| 1252 |
|
| 1253 |
removeEventHandler(document, "mousemove", dlgTitleMove); |
| 1254 |
removeEventHandler(document, "mouseup", dlgTitleUp); |
| 1255 |
removeEventHandler(document, "selectstart", dlgTitleSelect); |
| 1256 |
|
| 1257 |
|
| 1258 |
$(dlgTrackInfo.dlg, "[dialogMoveCover]").style.display = "none"; |
| 1259 |
|
| 1260 |
|
| 1261 |
dlgTrackInfo = null; |
| 1262 |
|
| 1263 |
|
| 1264 |
preventDefault(ev); |
| 1265 |
cancelBubble(ev); |
| 1266 |
return false; |
| 1267 |
} |
| 1268 |
|
| 1269 |
|
| 1270 |
|
| 1271 |
|
| 1272 |
|
| 1273 |
|
| 1274 |
|
| 1275 |
function colorbuttonKey(desc, ctx) |
| 1276 |
{ |
| 1277 |
var ele = ctx[0]; |
| 1278 |
var hasDefault = ctx[1]; |
| 1279 |
if (desc.keyName == "Enter" || desc.keyName == "U+0020") |
| 1280 |
{ |
| 1281 |
openColorPicker(desc.event, ele, hasDefault); |
| 1282 |
cancelBubble(desc.event); |
| 1283 |
preventDefault(desc.event); |
| 1284 |
return false; |
| 1285 |
} |
| 1286 |
return true; |
| 1287 |
} |
| 1288 |
|
| 1289 |
|
| 1290 |
|
| 1291 |
|
| 1292 |
var colorPickerBuilt = false; |
| 1293 |
var colorPickerTarget = null; |
| 1294 |
function openColorPicker(ev, ele, hasDefault) |
| 1295 |
{ |
| 1296 |
|
| 1297 |
ele = $(ele); |
| 1298 |
var cp = $("colorPicker"); |
| 1299 |
|
| 1300 |
|
| 1301 |
if (cp.style.display == "block") |
| 1302 |
{ |
| 1303 |
closePopup(cp); |
| 1304 |
return; |
| 1305 |
} |
| 1306 |
|
| 1307 |
|
| 1308 |
if (!colorPickerBuilt) |
| 1309 |
{ |
| 1310 |
var colors = ["ff8080", "ffff80", "80ff80", "ff80ff", |
| 1311 |
"80ffff", "0080ff", "ff80c0", "ff80ff", |
| 1312 |
"ff0000", "ffff00", "80ff00", "00ff40", |
| 1313 |
"00ffff", "0080c0", "8080c0", "ff00ff", |
| 1314 |
"804040", "ff8040", "00ff00", "008080", |
| 1315 |
"004080", "8080ff", "800040", "ff0080", |
| 1316 |
"800000", "ff8000", "008000", "008040", |
| 1317 |
"0000ff", "0000A0", "800080", "8000ff", |
| 1318 |
"400000", "804000", "004000", "004040", |
| 1319 |
"000080", "000040", "400040", "400080", |
| 1320 |
"000000", "808000", "808040", "808080", |
| 1321 |
"408080", "C0C0C0", "400000", "ffffff"]; |
| 1322 |
|
| 1323 |
|
| 1324 |
var keyTpl = "\"javascript:return @FUNC@" |
| 1325 |
+ "(event,colorBtnKey,['#@COLOR@',this]);\""; |
| 1326 |
var btnTpl = "<a class=\"colorPickerButton\" href=\"#\" " |
| 1327 |
+ "id=\"colorPickerButton#@I@\" " |
| 1328 |
+ "style=\"background-color:#@COLOR@;\" " |
| 1329 |
+ "onclick=\"javascript:return colorBtnClick(" |
| 1330 |
+ "event,'#@COLOR@',this);\" " |
| 1331 |
+ " onkeydown=" + keyTpl.replace(/@FUNC@/m, "$kd") |
| 1332 |
+ " onkeypress=" + keyTpl.replace(/@FUNC@/m, "$kp") |
| 1333 |
+ "></a>"; |
| 1334 |
|
| 1335 |
|
| 1336 |
for (var i = 0, s = [] ; i < colors.length ; ) |
| 1337 |
{ |
| 1338 |
|
| 1339 |
for (var j = 0, sl = [] ; j < 8 ; ++j, ++i) |
| 1340 |
{ |
| 1341 |
|
| 1342 |
sl.push(btnTpl |
| 1343 |
.replace(/@COLOR@/gm, colors[i]) |
| 1344 |
.replace(/@I@/gm, i)); |
| 1345 |
} |
| 1346 |
|
| 1347 |
|
| 1348 |
s.push("<nobr>" + sl.join("") + "</nobr><br>"); |
| 1349 |
} |
| 1350 |
|
| 1351 |
|
| 1352 |
s.push("<div><nobr>Custom (rrggbb): <input type=\"text\" size=\"6\" " |
| 1353 |
+ "id=\"colorPickerCustom\" " |
| 1354 |
+ "onkeydown=\"javascript:return $kd(event,colorPickFldKey);\" " |
| 1355 |
+ "onkeypress=\"javascript:return $kp(event,colorPickFldKey);\">" |
| 1356 |
+ "</nobr></div>"); |
| 1357 |
|
| 1358 |
|
| 1359 |
s.push("<div id=\"colorPickerDefault\" class=\"colorPickerDefault\">" |
| 1360 |
+ "<div class=\"off\" " |
| 1361 |
+ "onmouseover=\"javascript:" |
| 1362 |
+ "this.style.borderColor='#ffffff';\" " |
| 1363 |
+ "onmouseout=\"javascript:" |
| 1364 |
+ "this.style.borderColor='transparent';\" " |
| 1365 |
+ "style=\"border: 1px solid transparent;\">" |
| 1366 |
+ "<a href=\"#\" onclick=\"javascript:" |
| 1367 |
+ "return colorDefaultClick(event,this);\">" |
| 1368 |
+ "<img src=\"/webuires/ckbox8pt-off.gif\">Use default color</a>" |
| 1369 |
+ "</div></div>"); |
| 1370 |
|
| 1371 |
|
| 1372 |
|
| 1373 |
cp.innerHTML = s.join(""); |
| 1374 |
|
| 1375 |
|
| 1376 |
colorPickerBuilt = true; |
| 1377 |
} |
| 1378 |
|
| 1379 |
|
| 1380 |
colorPickerTarget = ele; |
| 1381 |
|
| 1382 |
|
| 1383 |
var rc = getObjectRect(ele); |
| 1384 |
cp.style.left = rc.x + "px"; |
| 1385 |
cp.style.top = (rc.y + rc.height) + "px"; |
| 1386 |
cp.style.display = "block"; |
| 1387 |
openPopup(ev, cp, null, ele, ele); |
| 1388 |
|
| 1389 |
|
| 1390 |
|
| 1391 |
|
| 1392 |
|
| 1393 |
setTimeout(function() { |
| 1394 |
cp.style.width = getObjectRect(cp).width + "px"; |
| 1395 |
}, 1); |
| 1396 |
|
| 1397 |
|
| 1398 |
var curColor = canonicalizeColor(getStyle(ele, "background-color")); |
| 1399 |
|
| 1400 |
|
| 1401 |
var customFld = $("colorPickerCustom"); |
| 1402 |
customFld.value = curColor.substr(1); |
| 1403 |
|
| 1404 |
|
| 1405 |
var sel = breadthSearch(cp, function(ele) { |
| 1406 |
return (ele.nodeName == "A" |
| 1407 |
&& ele.className == "colorPickerButton" |
| 1408 |
&& ele.style.backgroundColor == curColor); |
| 1409 |
}); |
| 1410 |
|
| 1411 |
|
| 1412 |
var dflt = $("colorPicker.colorPickerDefault"); |
| 1413 |
if (hasDefault) |
| 1414 |
{ |
| 1415 |
dflt.style.display = "block"; |
| 1416 |
checkColorPickerDefault(ele.useDefaultColor); |
| 1417 |
} |
| 1418 |
else |
| 1419 |
dflt.style.display = "none"; |
| 1420 |
|
| 1421 |
|
| 1422 |
|
| 1423 |
if (sel) |
| 1424 |
sel.focus(); |
| 1425 |
else |
| 1426 |
{ |
| 1427 |
customFld.focus(); |
| 1428 |
setSelRangeInEle(customFld); |
| 1429 |
} |
| 1430 |
} |
| 1431 |
|
| 1432 |
|
| 1433 |
|
| 1434 |
|
| 1435 |
function colorPopupKey(desc) |
| 1436 |
{ |
| 1437 |
switch (desc.keyName) |
| 1438 |
{ |
| 1439 |
case "Up": |
| 1440 |
case "Down": |
| 1441 |
case "Left": |
| 1442 |
case "Right": |
| 1443 |
|
| 1444 |
|
| 1445 |
if (document.activeElement == $("colorPicker")) |
| 1446 |
$("colorPicker.<A>").focus(); |
| 1447 |
break; |
| 1448 |
} |
| 1449 |
|
| 1450 |
|
| 1451 |
return false; |
| 1452 |
} |
| 1453 |
|
| 1454 |
|
| 1455 |
|
| 1456 |
|
| 1457 |
function colorBtnClick(ev, color) |
| 1458 |
{ |
| 1459 |
|
| 1460 |
colorPickerApply(color, false); |
| 1461 |
|
| 1462 |
|
| 1463 |
closePopup(); |
| 1464 |
|
| 1465 |
|
| 1466 |
return false; |
| 1467 |
} |
| 1468 |
|
| 1469 |
|
| 1470 |
|
| 1471 |
|
| 1472 |
function colorPickerApply(color, useDefault) |
| 1473 |
{ |
| 1474 |
|
| 1475 |
setColorButton(colorPickerTarget, color, useDefault); |
| 1476 |
|
| 1477 |
|
| 1478 |
sendEvent(colorPickerTarget, createEvent("Event", "change")); |
| 1479 |
} |
| 1480 |
|
| 1481 |
|
| 1482 |
|
| 1483 |
|
| 1484 |
function colorDefaultClick(ev, ele) |
| 1485 |
{ |
| 1486 |
|
| 1487 |
colorPickerApply(null, true); |
| 1488 |
closePopup(); |
| 1489 |
return false; |
| 1490 |
} |
| 1491 |
|
| 1492 |
function checkColorPickerDefault(checked) |
| 1493 |
{ |
| 1494 |
var span = $("colorPicker.colorPickerDefault.<DIV>"); |
| 1495 |
var img = $("colorPicker.colorPickerDefault.<IMG>"); |
| 1496 |
if (checked) |
| 1497 |
{ |
| 1498 |
span.className = "on"; |
| 1499 |
img.src = "/webuires/ckbox8pt-on.gif"; |
| 1500 |
} |
| 1501 |
else |
| 1502 |
{ |
| 1503 |
span.className = "off"; |
| 1504 |
img.src = "/webuires/ckbox8pt-off.gif"; |
| 1505 |
} |
| 1506 |
} |
| 1507 |
|
| 1508 |
|
| 1509 |
|
| 1510 |
|
| 1511 |
function colorBtnKey(desc, ctx) |
| 1512 |
{ |
| 1513 |
var color = ctx[0], ele = ctx[1]; |
| 1514 |
var b = null; |
| 1515 |
var nextButton = function(b, dir) |
| 1516 |
{ |
| 1517 |
var idx = parseInt(b.id.substr(18)); |
| 1518 |
return $("colorPicker.colorPickerButton#" + (idx + dir)); |
| 1519 |
}; |
| 1520 |
switch (desc.keyName) |
| 1521 |
{ |
| 1522 |
case "Up": |
| 1523 |
for (var i = 0, b = ele ; i < 8 && b ; ++i) |
| 1524 |
b = nextButton(b, -1); |
| 1525 |
break; |
| 1526 |
|
| 1527 |
case "Down": |
| 1528 |
for (var i = 0, b = ele ; i < 8 && b ; ++i) |
| 1529 |
b = nextButton(b, 1); |
| 1530 |
break; |
| 1531 |
|
| 1532 |
case "Left": |
| 1533 |
b = nextButton(ele, -1); |
| 1534 |
break; |
| 1535 |
|
| 1536 |
case "Right": |
| 1537 |
b = nextButton(ele, 1); |
| 1538 |
break; |
| 1539 |
|
| 1540 |
case "U+0020": |
| 1541 |
case "Enter": |
| 1542 |
|
| 1543 |
colorPickerApply(color, false); |
| 1544 |
|
| 1545 |
|
| 1546 |
closePopup(); |
| 1547 |
cancelBubble(desc.event); |
| 1548 |
preventDefault(desc.event); |
| 1549 |
break; |
| 1550 |
|
| 1551 |
case "U+0009": |
| 1552 |
|
| 1553 |
var fld = $("colorPickerCustom"); |
| 1554 |
fld.focus(); |
| 1555 |
setSelRangeInEle(fld); |
| 1556 |
|
| 1557 |
|
| 1558 |
cancelBubble(desc.event); |
| 1559 |
preventDefault(desc.event); |
| 1560 |
return false; |
| 1561 |
} |
| 1562 |
|
| 1563 |
|
| 1564 |
if (b) |
| 1565 |
{ |
| 1566 |
|
| 1567 |
b.focus(); |
| 1568 |
$("colorPickerCustom").value = b.style.backgroundColor.substr(1); |
| 1569 |
|
| 1570 |
|
| 1571 |
checkColorPickerDefault(false); |
| 1572 |
} |
| 1573 |
|
| 1574 |
|
| 1575 |
return false; |
| 1576 |
} |
| 1577 |
|
| 1578 |
|
| 1579 |
|
| 1580 |
|
| 1581 |
function colorPickFldKey(desc) |
| 1582 |
{ |
| 1583 |
switch (desc.keyName) |
| 1584 |
{ |
| 1585 |
case "Enter": |
| 1586 |
var v = $("colorPickerCustom").value; |
| 1587 |
if (v.charAt(0) != '#') |
| 1588 |
v = '#' + v; |
| 1589 |
if (v.match(/^#[0-9a-f]{6}$/i)) |
| 1590 |
{ |
| 1591 |
|
| 1592 |
colorPickerApply(v, false); |
| 1593 |
|
| 1594 |
|
| 1595 |
closePopup(); |
| 1596 |
} |
| 1597 |
else |
| 1598 |
{ |
| 1599 |
cancelBubble(desc.event); |
| 1600 |
alert("Please use the HTML-style hexadecimal RRGGBB format. " |
| 1601 |
+ "For example, for bright red, enter FF0000."); |
| 1602 |
} |
| 1603 |
|
| 1604 |
|
| 1605 |
cancelBubble(desc.event); |
| 1606 |
preventDefault(desc.event); |
| 1607 |
return false; |
| 1608 |
|
| 1609 |
case "U+0009": |
| 1610 |
|
| 1611 |
var fld = $("colorPickerCustom"); |
| 1612 |
var val = parseColor(fld.value); |
| 1613 |
var b = breadthSearch($("colorPicker"), function(ele) { |
| 1614 |
return (ele.nodeName == "A" |
| 1615 |
&& ele.className == "colorPickerButton" |
| 1616 |
&& parseColor(ele.style.backgroundColor) == val); |
| 1617 |
}); |
| 1618 |
if (b) |
| 1619 |
{ |
| 1620 |
b.focus(); |
| 1621 |
fld.value = b.style.backgroundColor.substr(1); |
| 1622 |
} |
| 1623 |
|
| 1624 |
|
| 1625 |
cancelBubble(desc.event); |
| 1626 |
preventDefault(desc.event); |
| 1627 |
return false; |
| 1628 |
|
| 1629 |
default: |
| 1630 |
|
| 1631 |
return true; |
| 1632 |
} |
| 1633 |
} |
| 1634 |
|
| 1635 |
|
| 1636 |
|
| 1637 |
|
| 1638 |
function clickDialogButton(n) |
| 1639 |
{ |
| 1640 |
|
| 1641 |
var b = dialogStack.top().buttons[n]; |
| 1642 |
|
| 1643 |
|
| 1644 |
if (b.onclick) |
| 1645 |
b.onclick(); |
| 1646 |
else |
| 1647 |
dismissDialog(b); |
| 1648 |
} |
| 1649 |
|
| 1650 |
|
| 1651 |
|
| 1652 |
|
| 1653 |
function dismissDialog(btn) |
| 1654 |
{ |
| 1655 |
|
| 1656 |
var dinfo = dialogStack.top(); |
| 1657 |
var dlg = dinfo.ele; |
| 1658 |
var bkg = dinfo.bkg; |
| 1659 |
|
| 1660 |
|
| 1661 |
|
| 1662 |
if (!btn) |
| 1663 |
btn = { name: "(Close Box)", isCancel: true }; |
| 1664 |
|
| 1665 |
|
| 1666 |
if (dinfo.dismiss && !dinfo.dismiss(dlg, btn)) |
| 1667 |
return; |
| 1668 |
|
| 1669 |
|
| 1670 |
dialogStack.pop(); |
| 1671 |
|
| 1672 |
|
| 1673 |
if (document.activeElement) |
| 1674 |
document.activeElement.blur(); |
| 1675 |
|
| 1676 |
|
| 1677 |
document.body.removeChild(dinfo.canvas); |
| 1678 |
document.body.removeChild(bkg); |
| 1679 |
|
| 1680 |
|
| 1681 |
setDefaultFocus(); |
| 1682 |
} |
| 1683 |
|
| 1684 |
|
| 1685 |
|
| 1686 |
|
| 1687 |
|
| 1688 |
function dismissDialogById(id, btn) |
| 1689 |
{ |
| 1690 |
|
| 1691 |
for (var i = 0 ; i < dialogStack.length ; ++i) |
| 1692 |
{ |
| 1693 |
if (dialogStack[i].id == id) |
| 1694 |
{ |
| 1695 |
|
| 1696 |
while (dialogStack.length > i) |
| 1697 |
dismissDialog(btn); |
| 1698 |
|
| 1699 |
|
| 1700 |
break; |
| 1701 |
} |
| 1702 |
} |
| 1703 |
} |
| 1704 |
|
| 1705 |
|
| 1706 |
|
| 1707 |
|
| 1708 |
|
| 1709 |
|
| 1710 |
function setDefaultFocus(desc, fromWin) |
| 1711 |
{ |
| 1712 |
|
| 1713 |
|
| 1714 |
if (evtKeepsFocus(desc)) |
| 1715 |
return; |
| 1716 |
|
| 1717 |
|
| 1718 |
|
| 1719 |
if (dialogStack.length) |
| 1720 |
initDialogFocus(); |
| 1721 |
else |
| 1722 |
setDefaultFocusChild(desc, fromWin); |
| 1723 |
|
| 1724 |
|
| 1725 |
|
| 1726 |
|
| 1727 |
|
| 1728 |
bufferKey(desc); |
| 1729 |
} |
| 1730 |
|
| 1731 |
|
| 1732 |
|
| 1733 |
|
| 1734 |
|
| 1735 |
|
| 1736 |
|
| 1737 |
|
| 1738 |
|
| 1739 |
|
| 1740 |
|
| 1741 |
|
| 1742 |
|
| 1743 |
|
| 1744 |
var keybuf = []; |
| 1745 |
function bufferKey(desc) |
| 1746 |
{ |
| 1747 |
|
| 1748 |
|
| 1749 |
if (wantInputEvent) |
| 1750 |
return; |
| 1751 |
|
| 1752 |
|
| 1753 |
if (!desc) |
| 1754 |
return; |
| 1755 |
|
| 1756 |
|
| 1757 |
if (desc.keyBufferedInMain) |
| 1758 |
return; |
| 1759 |
|
| 1760 |
|
| 1761 |
if (desc.keyCode == 13) |
| 1762 |
return; |
| 1763 |
|
| 1764 |
|
| 1765 |
desc.keyBufferedInMain = true; |
| 1766 |
|
| 1767 |
|
| 1768 |
|
| 1769 |
|
| 1770 |
|
| 1771 |
|
| 1772 |
|
| 1773 |
|
| 1774 |
|
| 1775 |
|
| 1776 |
|
| 1777 |
|
| 1778 |
|
| 1779 |
if (keybuf.length >= 16) |
| 1780 |
keybuf.shift(); |
| 1781 |
|
| 1782 |
|
| 1783 |
|
| 1784 |
var d = desc.copy(false); |
| 1785 |
d.event = { }; |
| 1786 |
|
| 1787 |
|
| 1788 |
keybuf.push(d); |
| 1789 |
} |
| 1790 |
|
| 1791 |
|
| 1792 |
|
| 1793 |
|
| 1794 |
|
| 1795 |
|
| 1796 |
|
| 1797 |
|
| 1798 |
|
| 1799 |
|
| 1800 |
|
| 1801 |
|
| 1802 |
function mainBodyKey(desc) |
| 1803 |
{ |
| 1804 |
|
| 1805 |
|
| 1806 |
if (isFieldKey(desc) && document.activeElement == document.body) |
| 1807 |
setDefaultFocus(desc, window); |
| 1808 |
|
| 1809 |
|
| 1810 |
genericDocKey(desc); |
| 1811 |
|
| 1812 |
|
| 1813 |
return true; |
| 1814 |
} |
| 1815 |
|
| 1816 |
|
| 1817 |
|
| 1818 |
|
| 1819 |
function popupDivKey(desc) |
| 1820 |
{ |
| 1821 |
|
| 1822 |
if (isFieldKey(desc)) |
| 1823 |
setDefaultFocus(desc, window); |
| 1824 |
|
| 1825 |
|
| 1826 |
return true; |
| 1827 |
} |
| 1828 |
|
| 1829 |
|
| 1830 |
|
| 1831 |
|
| 1832 |
function dlgKey(desc, dlg) |
| 1833 |
{ |
| 1834 |
|
| 1835 |
|
| 1836 |
|
| 1837 |
|
| 1838 |
|
| 1839 |
var idx, ch = desc.ch ? desc.ch.toUpperCase() : ""; |
| 1840 |
if (!eleKeepsFocus(document.activeElement, desc) |
| 1841 |
&& (idx = dlg.buttons.indexWhich(function(b) { |
| 1842 |
return b.key && (b.key == ch || b.key == desc.keyName); |
| 1843 |
})) >= 0) |
| 1844 |
{ |
| 1845 |
|
| 1846 |
clickDialogButton(idx); |
| 1847 |
|
| 1848 |
|
| 1849 |
cancelBubble(desc.event); |
| 1850 |
preventDefault(desc.event); |
| 1851 |
return false; |
| 1852 |
} |
| 1853 |
|
| 1854 |
|
| 1855 |
switch (desc.keyName) |
| 1856 |
{ |
| 1857 |
case "Enter": |
| 1858 |
|
| 1859 |
var e = document.activeElement; |
| 1860 |
if ((e.nodeName == "INPUT" && e.type == "submit") |
| 1861 |
|| e.nodeName == "A") |
| 1862 |
{ |
| 1863 |
|
| 1864 |
cancelBubble(desc.event); |
| 1865 |
return true; |
| 1866 |
} |
| 1867 |
|
| 1868 |
|
| 1869 |
for (var i = 0 ; i < dlg.buttons.length ; ++i) |
| 1870 |
{ |
| 1871 |
|
| 1872 |
if (dlg.buttons[i].isDefault) |
| 1873 |
{ |
| 1874 |
|
| 1875 |
clickDialogButton(i); |
| 1876 |
break; |
| 1877 |
} |
| 1878 |
} |
| 1879 |
|
| 1880 |
|
| 1881 |
cancelBubble(desc.event); |
| 1882 |
preventDefault(desc.event); |
| 1883 |
return false; |
| 1884 |
|
| 1885 |
case "U+001B": |
| 1886 |
|
| 1887 |
for (var i = 0 ; i < dlg.buttons.length ; ++i) |
| 1888 |
{ |
| 1889 |
|
| 1890 |
if (dlg.buttons[i].isCancel) |
| 1891 |
{ |
| 1892 |
|
| 1893 |
clickDialogButton(i); |
| 1894 |
break; |
| 1895 |
} |
| 1896 |
} |
| 1897 |
|
| 1898 |
|
| 1899 |
cancelBubble(desc.event); |
| 1900 |
preventDefault(desc.event); |
| 1901 |
return false; |
| 1902 |
|
| 1903 |
case "U+0009": |
| 1904 |
|
| 1905 |
|
| 1906 |
setTimeout(function() { |
| 1907 |
|
| 1908 |
|
| 1909 |
var f = document.activeElement; |
| 1910 |
|
| 1911 |
|
| 1912 |
for ( ; f && f != dlg.ele ; f = f.parentNode) ; |
| 1913 |
|
| 1914 |
|
| 1915 |
if (dlg.ele && !f) |
| 1916 |
dlg.ele.focus(); |
| 1917 |
|
| 1918 |
}, 0); |
| 1919 |
|
| 1920 |
|
| 1921 |
return true; |
| 1922 |
|
| 1923 |
default: |
| 1924 |
|
| 1925 |
return true; |
| 1926 |
} |
| 1927 |
} |
| 1928 |
|
| 1929 |
|
| 1930 |
|
| 1931 |
|
| 1932 |
|
| 1933 |
|
| 1934 |
|
| 1935 |
|
| 1936 |
|
| 1937 |
|
| 1938 |
|
| 1939 |
|
| 1940 |
|
| 1941 |
|
| 1942 |
|
| 1943 |
|
| 1944 |
|
| 1945 |
|
| 1946 |
|
| 1947 |
|
| 1948 |
|
| 1949 |
|
| 1950 |
|
| 1951 |
|
| 1952 |
|
| 1953 |
var TADS_swf = { |
| 1954 |
|
| 1955 |
|
| 1956 |
|
| 1957 |
|
| 1958 |
|
| 1959 |
|
| 1960 |
|
| 1961 |
loaded: new AbsEvent(), |
| 1962 |
|
| 1963 |
|
| 1964 |
fontList: null, |
| 1965 |
|
| 1966 |
|
| 1967 |
|
| 1968 |
|
| 1969 |
|
| 1970 |
|
| 1971 |
|
| 1972 |
|
| 1973 |
|
| 1974 |
|
| 1975 |
|
| 1976 |
|
| 1977 |
waitForFontList: function(doneFunc) |
| 1978 |
{ |
| 1979 |
|
| 1980 |
|
| 1981 |
|
| 1982 |
TADS_swf.loaded.whenDone(function() { |
| 1983 |
|
| 1984 |
|
| 1985 |
if (!TADS_swf.fontList) |
| 1986 |
{ |
| 1987 |
|
| 1988 |
|
| 1989 |
|
| 1990 |
|
| 1991 |
var fonts; |
| 1992 |
try |
| 1993 |
{ |
| 1994 |
|
| 1995 |
var ie = navigator.userAgent.indexOf("Microsoft") != -1; |
| 1996 |
var mobj = (ie ? window["__TADS_swf"] : |
| 1997 |
document["__TADS_swf"]); |
| 1998 |
|
| 1999 |
|
| 2000 |
var sfonts = mobj.getFonts(); |
| 2001 |
|
| 2002 |
|
| 2003 |
|
| 2004 |
|
| 2005 |
|
| 2006 |
|
| 2007 |
|
| 2008 |
fonts = []; |
| 2009 |
for (var i = 0 ; i < sfonts.length ; ++i) |
| 2010 |
{ |
| 2011 |
|
| 2012 |
if (sfonts[i].fontStyle == "regular") |
| 2013 |
fonts.push(sfonts[i].fontName); |
| 2014 |
} |
| 2015 |
} |
| 2016 |
catch (e) |
| 2017 |
{ |
| 2018 |
|
| 2019 |
|
| 2020 |
|
| 2021 |
|
| 2022 |
|
| 2023 |
|
| 2024 |
|
| 2025 |
|
| 2026 |
|
| 2027 |
|
| 2028 |
|
| 2029 |
|
| 2030 |
|
| 2031 |
fonts = [ |
| 2032 |
"Arial", |
| 2033 |
"Arial Black", |
| 2034 |
"Book Antiqua", |
| 2035 |
"Charcoal", |
| 2036 |
"Comic Sans MS", |
| 2037 |
"Courier", |
| 2038 |
"Courier New", |
| 2039 |
"Gadget", |
| 2040 |
"Geneva", |
| 2041 |
"Georgia", |
| 2042 |
"Helvetica", |
| 2043 |
"Impact", |
| 2044 |
"Lucida Console", |
| 2045 |
"Lucida Grande", |
| 2046 |
"Lucida Sans Unicode", |
| 2047 |
"Monaco", |
| 2048 |
"MS Sans Serif", |
| 2049 |
"MS Serif", |
| 2050 |
"New York", |
| 2051 |
"Palatino", |
| 2052 |
"Palatino Linotype", |
| 2053 |
"Symbol", |
| 2054 |
"Tahoma", |
| 2055 |
"Times", |
| 2056 |
"Times New Roman", |
| 2057 |
"Trebuchet MS", |
| 2058 |
"Verdana", |
| 2059 |
"Webdings", |
| 2060 |
"Wingdings", |
| 2061 |
"Zapf Chancery", |
| 2062 |
"ZapfChancery", |
| 2063 |
"Zapf Dingbats" |
| 2064 |
]; |
| 2065 |
} |
| 2066 |
|
| 2067 |
|
| 2068 |
fonts.sort(function(a, b) { |
| 2069 |
return a.toLowerCase().localeCompare(b.toLowerCase()); |
| 2070 |
}); |
| 2071 |
|
| 2072 |
|
| 2073 |
TADS_swf.fontList = fonts; |
| 2074 |
} |
| 2075 |
|
| 2076 |
|
| 2077 |
doneFunc(); |
| 2078 |
}); |
| 2079 |
} |
| 2080 |
}; |
| 2081 |
|
| 2082 |
|
| 2083 |
|
| 2084 |
|
| 2085 |
|
| 2086 |
function showPrefsDialog() |
| 2087 |
{ |
| 2088 |
showDialog({ |
| 2089 |
id: 'prefs', |
| 2090 |
title: "Customize Display", |
| 2091 |
contents: $("prefsDialog"), |
| 2092 |
buttons: [ |
| 2093 |
{ name: "OK", isDefault: true, save: true }, |
| 2094 |
{ name: "Cancel", isCancel: true } |
| 2095 |
], |
| 2096 |
init: initPrefsDialog, |
| 2097 |
dismiss: onClosePrefsDialog |
| 2098 |
}); |
| 2099 |
} |
| 2100 |
|
| 2101 |
|
| 2102 |
|
| 2103 |
var prefProfiles = { }; |
| 2104 |
|
| 2105 |
|
| 2106 |
|
| 2107 |
|
| 2108 |
var curPrefProfile = 0; |
| 2109 |
|
| 2110 |
|
| 2111 |
|
| 2112 |
|
| 2113 |
var nextPrefProfile = 1; |
| 2114 |
|
| 2115 |
|
| 2116 |
|
| 2117 |
|
| 2118 |
|
| 2119 |
|
| 2120 |
|
| 2121 |
|
| 2122 |
|
| 2123 |
|
| 2124 |
|
| 2125 |
|
| 2126 |
|
| 2127 |
|
| 2128 |
|
| 2129 |
|
| 2130 |
|
| 2131 |
|
| 2132 |
|
| 2133 |
|
| 2134 |
|
| 2135 |
|
| 2136 |
|
| 2137 |
|
| 2138 |
|
| 2139 |
|
| 2140 |
|
| 2141 |
|
| 2142 |
|
| 2143 |
|
| 2144 |
|
| 2145 |
|
| 2146 |
|
| 2147 |
|
| 2148 |
|
| 2149 |
|
| 2150 |
|
| 2151 |
|
| 2152 |
|
| 2153 |
var prefsMapper = { |
| 2154 |
mainFont: { |
| 2155 |
selector: "body", |
| 2156 |
style: "fontFamily", |
| 2157 |
type: "font" |
| 2158 |
}, |
| 2159 |
mainFontSize: { |
| 2160 |
selector: "body", |
| 2161 |
style: "fontSize", |
| 2162 |
type: "fontsize" |
| 2163 |
}, |
| 2164 |
mainColor: { |
| 2165 |
selector: "body", |
| 2166 |
style: "color", |
| 2167 |
type: "color" |
| 2168 |
}, |
| 2169 |
mainBkg: { |
| 2170 |
selector: "body", |
| 2171 |
style: "backgroundColor", |
| 2172 |
type: "color" |
| 2173 |
}, |
| 2174 |
|
| 2175 |
mainLinkColor: { |
| 2176 |
selector: "a:link", |
| 2177 |
style: "color", |
| 2178 |
type: "color" |
| 2179 |
}, |
| 2180 |
mainLinkHover: { |
| 2181 |
selector: "a:hover, a.plain:hover", |
| 2182 |
style: "color", |
| 2183 |
type: "color" |
| 2184 |
}, |
| 2185 |
mainLinkActive: { |
| 2186 |
selector: "a:active, a:focus, a.plain:active, a.plain:focus", |
| 2187 |
style: "color", |
| 2188 |
type: "color" |
| 2189 |
}, |
| 2190 |
|
| 2191 |
cmdFont: { |
| 2192 |
selector: ".cmdline, .cmdlineOld", |
| 2193 |
style: "fontFamily", |
| 2194 |
type: "font", |
| 2195 |
parent: "mainFont" |
| 2196 |
}, |
| 2197 |
cmdFontSize: { |
| 2198 |
selector: ".cmdline, .cmdlineOld", |
| 2199 |
style: "fontSize", |
| 2200 |
type: "fontsize", |
| 2201 |
parent: "mainFontSize" |
| 2202 |
}, |
| 2203 |
cmdColor: { |
| 2204 |
selector: ".cmdline, .cmdlineOld", |
| 2205 |
style: "color", |
| 2206 |
type: "color", |
| 2207 |
parent: "mainColor" |
| 2208 |
}, |
| 2209 |
cmdBold: { |
| 2210 |
selector: ".cmdline, .cmdlineOld", |
| 2211 |
style: "fontWeight", |
| 2212 |
checkbox: ["normal", "bold"] |
| 2213 |
}, |
| 2214 |
cmdItalic: { |
| 2215 |
selector: ".cmdline, .cmdlineOld", |
| 2216 |
style: "fontStyle", |
| 2217 |
checkbox: ["normal", "italic"] |
| 2218 |
}, |
| 2219 |
|
| 2220 |
statusFont: { |
| 2221 |
selector: "body.statusline", |
| 2222 |
style: "fontFamily", |
| 2223 |
type: "font", |
| 2224 |
parent: "mainFont" |
| 2225 |
}, |
| 2226 |
statusFontSize: { |
| 2227 |
selector: "body.statusline", |
| 2228 |
style: "fontSize", |
| 2229 |
type: "fontsize", |
| 2230 |
parent: "mainFontSize" |
| 2231 |
}, |
| 2232 |
statusColor: { |
| 2233 |
selector: "body.statusline", |
| 2234 |
style: "color", |
| 2235 |
type: "color" |
| 2236 |
}, |
| 2237 |
statusBkg: { |
| 2238 |
selector: "body.statusline", |
| 2239 |
style: "backgroundColor", |
| 2240 |
type: "color" |
| 2241 |
}, |
| 2242 |
|
| 2243 |
statusLinkColor: { |
| 2244 |
selector: "body.statusline a:link", |
| 2245 |
style: "color", |
| 2246 |
type: "color" |
| 2247 |
}, |
| 2248 |
statusLinkHover: { |
| 2249 |
selector: "body.statusline a:hover, body.statusline a.plain:hover", |
| 2250 |
style: "color", |
| 2251 |
type: "color" |
| 2252 |
}, |
| 2253 |
statusLinkActive: { |
| 2254 |
selector: "body.statusline a:active," |
| 2255 |
+ "body.statusline a:focus," |
| 2256 |
+ "body.statusline a.plain:active," |
| 2257 |
+ "body.statusline a.plain:focus", |
| 2258 |
style: "color", |
| 2259 |
type: "color" |
| 2260 |
}, |
| 2261 |
|
| 2262 |
serifFont: { |
| 2263 |
selector: ".serifFont", |
| 2264 |
style: "fontFamily", |
| 2265 |
type: "font" |
| 2266 |
}, |
| 2267 |
serifFontSize: { |
| 2268 |
selector: ".serifFont", |
| 2269 |
style: "fontSize", |
| 2270 |
type: "fontsize", |
| 2271 |
parent: "mainFontSize" |
| 2272 |
}, |
| 2273 |
|
| 2274 |
sansFont: { |
| 2275 |
selector: ".sansFont", |
| 2276 |
style: "fontFamily", |
| 2277 |
type: "font" |
| 2278 |
}, |
| 2279 |
sansFontSize: { |
| 2280 |
selector: ".sansFont", |
| 2281 |
style: "fontSize", |
| 2282 |
type: "fontsize", |
| 2283 |
parent: "mainFontSize" |
| 2284 |
}, |
| 2285 |
|
| 2286 |
scriptFont: { |
| 2287 |
selector: ".scriptFont", |
| 2288 |
style: "fontFamily", |
| 2289 |
type: "font" |
| 2290 |
}, |
| 2291 |
scriptFontSize: { |
| 2292 |
selector: ".scriptFont", |
| 2293 |
style: "fontSize", |
| 2294 |
type: "fontsize", |
| 2295 |
parent: "mainFontSize" |
| 2296 |
}, |
| 2297 |
|
| 2298 |
ttFont: { |
| 2299 |
selector: ".ttFont,tt", |
| 2300 |
style: "fontFamily", |
| 2301 |
type: "font" |
| 2302 |
}, |
| 2303 |
ttFontSize: { |
| 2304 |
selector: ".ttFont", |
| 2305 |
style: "fontSize", |
| 2306 |
type: "fontsize", |
| 2307 |
parent: "mainFontSize" |
| 2308 |
} |
| 2309 |
}; |
| 2310 |
|
| 2311 |
|
| 2312 |
function initDefProfile() |
| 2313 |
{ |
| 2314 |
|
| 2315 |
if (!(curPrefProfile in prefProfiles)) |
| 2316 |
{ |
| 2317 |
|
| 2318 |
var pro = { profileName: "Default" }; |
| 2319 |
prefsMapper.forEach(function(m, id) { pro[id] = null; }); |
| 2320 |
|
| 2321 |
|
| 2322 |
curPrefProfile = nextPrefProfile++; |
| 2323 |
prefProfiles[curPrefProfile] = pro; |
| 2324 |
} |
| 2325 |
} |
| 2326 |
|
| 2327 |
|
| 2328 |
function initPrefsDialog(dlg) |
| 2329 |
{ |
| 2330 |
|
| 2331 |
initDefProfile(); |
| 2332 |
|
| 2333 |
|
| 2334 |
|
| 2335 |
|
| 2336 |
dlgProfiles = { }; |
| 2337 |
prefProfiles.forEach(function(pro, id) { |
| 2338 |
dlgProfiles[id] = pro.copy(false); |
| 2339 |
}); |
| 2340 |
|
| 2341 |
|
| 2342 |
dlgCurProfile = curPrefProfile; |
| 2343 |
|
| 2344 |
|
| 2345 |
var proNames = []; |
| 2346 |
dlgProfiles.forEach(function(pro, id) { |
| 2347 |
var name = pro.profileName || "Untitled"; |
| 2348 |
proNames.push({ id: id, name: name, sortName: name.toLowerCase() }); |
| 2349 |
}); |
| 2350 |
|
| 2351 |
|
| 2352 |
proNames.sort(function(a, b) { |
| 2353 |
return a.sortName.localeCompare(b.sortName); |
| 2354 |
}); |
| 2355 |
|
| 2356 |
|
| 2357 |
var sel = $(dlg, "curProfile"); |
| 2358 |
var idx = 0; |
| 2359 |
proNames.forEach(function(pro) { |
| 2360 |
var o = new Option(pro.name, pro.id); |
| 2361 |
try { sel.add(o); } catch (e) { sel.add(o, null); } |
| 2362 |
}); |
| 2363 |
|
| 2364 |
|
| 2365 |
setSelectByValue(sel, dlgCurProfile); |
| 2366 |
|
| 2367 |
|
| 2368 |
prefsToDlg(dlg, dlgProfiles[dlgCurProfile], true); |
| 2369 |
|
| 2370 |
|
| 2371 |
breadthSearch(dlg, function(ele) { |
| 2372 |
|
| 2373 |
|
| 2374 |
if (prefsMapper[ele.id]) |
| 2375 |
ele.onchange = function(ev) { onPrefItemChange(ev, dlg, ele); }; |
| 2376 |
|
| 2377 |
|
| 2378 |
return false; |
| 2379 |
}); |
| 2380 |
} |
| 2381 |
|
| 2382 |
|
| 2383 |
var dlgProfiles = null; |
| 2384 |
var dlgCurProfile = null; |
| 2385 |
|
| 2386 |
|
| 2387 |
|
| 2388 |
function xmlToPrefs(prefs) |
| 2389 |
{ |
| 2390 |
|
| 2391 |
var newPrefs = { }; |
| 2392 |
|
| 2393 |
|
| 2394 |
if (xmlHasChild(prefs, "profile")) |
| 2395 |
{ |
| 2396 |
var pros = prefs.getElementsByTagName("profile"); |
| 2397 |
for (var i = 0 ; i < pros.length ; ++i) |
| 2398 |
{ |
| 2399 |
|
| 2400 |
|
| 2401 |
var pro = pros[i]; |
| 2402 |
var tab = { }; |
| 2403 |
var pid = xmlChildText(pro, "id"); |
| 2404 |
newPrefs[pid] = tab; |
| 2405 |
|
| 2406 |
|
| 2407 |
var pidn = parseInt(pid); |
| 2408 |
if (pidn && pidn >= nextPrefProfile) |
| 2409 |
nextPrefProfile = pidn + 1; |
| 2410 |
|
| 2411 |
|
| 2412 |
var items = pro.getElementsByTagName("item"); |
| 2413 |
for (var j = 0 ; items && j < items.length ; ++j) |
| 2414 |
{ |
| 2415 |
|
| 2416 |
var item = items[j]; |
| 2417 |
var id = xmlChildText(item, "id"); |
| 2418 |
var val = xmlChildText(item, "value"); |
| 2419 |
|
| 2420 |
|
| 2421 |
if (val == "") |
| 2422 |
val = null; |
| 2423 |
|
| 2424 |
|
| 2425 |
tab[id] = val; |
| 2426 |
} |
| 2427 |
|
| 2428 |
|
| 2429 |
if (!("profileName" in tab)) |
| 2430 |
tab.profileName = "Untitled"; |
| 2431 |
} |
| 2432 |
} |
| 2433 |
|
| 2434 |
|
| 2435 |
var newCur = null; |
| 2436 |
if (xmlHasChild(prefs, "currentProfile")) |
| 2437 |
newCur = xmlChildText(prefs, "currentProfile"); |
| 2438 |
|
| 2439 |
|
| 2440 |
|
| 2441 |
if (newPrefs.propCount() > 0 && newCur && newCur in newPrefs) |
| 2442 |
{ |
| 2443 |
|
| 2444 |
prefProfiles = newPrefs; |
| 2445 |
curPrefProfile = newCur; |
| 2446 |
|
| 2447 |
|
| 2448 |
prefsToCSS(); |
| 2449 |
} |
| 2450 |
} |
| 2451 |
|
| 2452 |
|
| 2453 |
function prefsToCSS(prefs, win) |
| 2454 |
{ |
| 2455 |
|
| 2456 |
initDefProfile(); |
| 2457 |
|
| 2458 |
|
| 2459 |
if (!prefs) |
| 2460 |
prefs = prefProfiles[curPrefProfile]; |
| 2461 |
|
| 2462 |
|
| 2463 |
if (!win) |
| 2464 |
win = window; |
| 2465 |
|
| 2466 |
|
| 2467 |
|
| 2468 |
|
| 2469 |
var tab = { }; |
| 2470 |
prefsMapper.forEach(function(m, id) |
| 2471 |
{ |
| 2472 |
|
| 2473 |
var sels = m.selector.toUpperCase(); |
| 2474 |
|
| 2475 |
|
| 2476 |
sels.split(",").forEach(function(sel) |
| 2477 |
{ |
| 2478 |
|
| 2479 |
|
| 2480 |
sel = sel.trim(); |
| 2481 |
var e; |
| 2482 |
if (sel in tab) |
| 2483 |
e = tab[sel]; |
| 2484 |
else |
| 2485 |
tab[sel] = e = []; |
| 2486 |
|
| 2487 |
|
| 2488 |
e.push([m.style, getPrefVal(prefs, id)]); |
| 2489 |
}); |
| 2490 |
}); |
| 2491 |
|
| 2492 |
|
| 2493 |
win.applyCSS(tab); |
| 2494 |
|
| 2495 |
|
| 2496 |
calcLayout(); |
| 2497 |
} |
| 2498 |
|
| 2499 |
|
| 2500 |
function prefsToDlg(dlg, prefs, init) |
| 2501 |
{ |
| 2502 |
|
| 2503 |
breadthSearch(dlg, function(ele) |
| 2504 |
{ |
| 2505 |
|
| 2506 |
if (ele.id && prefsMapper[ele.id]) |
| 2507 |
prefToControl(ele, prefs, init); |
| 2508 |
|
| 2509 |
|
| 2510 |
return false; |
| 2511 |
}); |
| 2512 |
} |
| 2513 |
|
| 2514 |
|
| 2515 |
|
| 2516 |
function prefToControl(ele, prefs, init) |
| 2517 |
{ |
| 2518 |
|
| 2519 |
var id = ele.id, m = prefsMapper[id]; |
| 2520 |
|
| 2521 |
|
| 2522 |
var val = prefs[id]; |
| 2523 |
var defVal = getPrefVal(prefs, id); |
| 2524 |
if (val == undefined) |
| 2525 |
val = null; |
| 2526 |
|
| 2527 |
|
| 2528 |
var isDef = (val == null); |
| 2529 |
if (isDef) |
| 2530 |
val = defVal; |
| 2531 |
|
| 2532 |
|
| 2533 |
switch (m.type) |
| 2534 |
{ |
| 2535 |
case "color": |
| 2536 |
|
| 2537 |
if (init |
| 2538 |
|| ele.useDefaultColor != isDef |
| 2539 |
|| ele.style.backgroundColor != val) |
| 2540 |
setColorButton(ele, val, isDef); |
| 2541 |
break; |
| 2542 |
|
| 2543 |
case "font": |
| 2544 |
case "fontsize": |
| 2545 |
|
| 2546 |
if (isDef) |
| 2547 |
val = "*" + val; |
| 2548 |
|
| 2549 |
|
| 2550 |
if (init || ele.value != val) |
| 2551 |
ele.value = val; |
| 2552 |
break; |
| 2553 |
|
| 2554 |
default: |
| 2555 |
if (m.checkbox) |
| 2556 |
{ |
| 2557 |
|
| 2558 |
ele.checked = (val == m.checkbox[1]); |
| 2559 |
} |
| 2560 |
else if (ele.type == "select-one") |
| 2561 |
{ |
| 2562 |
|
| 2563 |
var opts = ele.options; |
| 2564 |
for (var i = 0 ; i < opts.length ; ++i) |
| 2565 |
{ |
| 2566 |
|
| 2567 |
if (opts[i].value == val) |
| 2568 |
{ |
| 2569 |
ele.selectedIndex = i; |
| 2570 |
break; |
| 2571 |
} |
| 2572 |
} |
| 2573 |
} |
| 2574 |
else |
| 2575 |
{ |
| 2576 |
|
| 2577 |
if (isDef) |
| 2578 |
val = "*" + val; |
| 2579 |
|
| 2580 |
|
| 2581 |
if (init || ele.value != val) |
| 2582 |
ele.value = val; |
| 2583 |
} |
| 2584 |
break; |
| 2585 |
} |
| 2586 |
} |
| 2587 |
|
| 2588 |
function setColorButton(ele, color, isDef) |
| 2589 |
{ |
| 2590 |
ele.useDefaultColor = isDef; |
| 2591 |
if (color) |
| 2592 |
{ |
| 2593 |
ele.style.backgroundColor = color; |
| 2594 |
ele.style.color = contrastColor(color); |
| 2595 |
} |
| 2596 |
ele.innerHTML = (isDef ? "*" : ""); |
| 2597 |
} |
| 2598 |
|
| 2599 |
|
| 2600 |
|
| 2601 |
|
| 2602 |
function contrastColor(color) |
| 2603 |
{ |
| 2604 |
|
| 2605 |
color = parseColor(color); |
| 2606 |
|
| 2607 |
|
| 2608 |
var r = 255 - ((color >> 16) & 0xff); |
| 2609 |
var g = 255 - ((color >> 8) & 0xff); |
| 2610 |
var b = 255 - (color & 0xff); |
| 2611 |
|
| 2612 |
|
| 2613 |
|
| 2614 |
|
| 2615 |
if (r >= 0x70 && r <= 0x90 |
| 2616 |
&& g >= 0x70 && g <= 0x90 |
| 2617 |
&& b >= 0x70 && b <= 0x90) |
| 2618 |
r = g = b = 0; |
| 2619 |
|
| 2620 |
|
| 2621 |
return unparseCColor(r, g, b); |
| 2622 |
} |
| 2623 |
|
| 2624 |
|
| 2625 |
|
| 2626 |
function dlgToPrefs(dlg, prefs) |
| 2627 |
{ |
| 2628 |
|
| 2629 |
|
| 2630 |
|
| 2631 |
|
| 2632 |
|
| 2633 |
|
| 2634 |
|
| 2635 |
breadthSearch(dlg, function(ele) |
| 2636 |
{ |
| 2637 |
|
| 2638 |
if (prefsMapper[ele.id]) |
| 2639 |
controlToPref(ele, prefs); |
| 2640 |
|
| 2641 |
|
| 2642 |
return false; |
| 2643 |
}); |
| 2644 |
} |
| 2645 |
|
| 2646 |
|
| 2647 |
function controlToPref(ele, prefs) |
| 2648 |
{ |
| 2649 |
|
| 2650 |
var id = ele.id; |
| 2651 |
var m = prefsMapper[ele.id]; |
| 2652 |
|
| 2653 |
|
| 2654 |
var val; |
| 2655 |
switch (m.type) |
| 2656 |
{ |
| 2657 |
case "color": |
| 2658 |
val = ele.useDefaultColor ? null : ele.style.backgroundColor; |
| 2659 |
break; |
| 2660 |
|
| 2661 |
case "font": |
| 2662 |
case "fontsize": |
| 2663 |
|
| 2664 |
val = ele.value; |
| 2665 |
if (val.charAt(0) == '*') |
| 2666 |
val = null; |
| 2667 |
break; |
| 2668 |
|
| 2669 |
default: |
| 2670 |
if (m.checkbox) |
| 2671 |
val = m.checkbox[ele.checked ? 1 : 0]; |
| 2672 |
else |
| 2673 |
val = ele.value; |
| 2674 |
break; |
| 2675 |
} |
| 2676 |
|
| 2677 |
|
| 2678 |
prefs[id] = val; |
| 2679 |
} |
| 2680 |
|
| 2681 |
function getPrefVal(prefs, id) |
| 2682 |
{ |
| 2683 |
|
| 2684 |
for (var i = 0 ; i < 2 ; ++i) |
| 2685 |
{ |
| 2686 |
|
| 2687 |
var s = [prefs, defaultPrefs][i]; |
| 2688 |
|
| 2689 |
|
| 2690 |
for (var cid = id ; cid ; ) |
| 2691 |
{ |
| 2692 |
|
| 2693 |
var m = prefsMapper[cid]; |
| 2694 |
|
| 2695 |
|
| 2696 |
var val = s[cid]; |
| 2697 |
if (val != null && val != undefined) |
| 2698 |
return val; |
| 2699 |
|
| 2700 |
|
| 2701 |
cid = m ? m.parent : null; |
| 2702 |
} |
| 2703 |
} |
| 2704 |
|
| 2705 |
|
| 2706 |
return null; |
| 2707 |
} |
| 2708 |
|
| 2709 |
function onPrefItemChange(ev, dlg, ele) |
| 2710 |
{ |
| 2711 |
|
| 2712 |
var profile = dlgProfiles[dlgCurProfile]; |
| 2713 |
|
| 2714 |
|
| 2715 |
controlToPref(ele, profile); |
| 2716 |
|
| 2717 |
|
| 2718 |
prefsToDlg(dlg, profile, false); |
| 2719 |
} |
| 2720 |
|
| 2721 |
function newPrefProfile() |
| 2722 |
{ |
| 2723 |
|
| 2724 |
|
| 2725 |
|
| 2726 |
var n = null; |
| 2727 |
dlgProfiles.forEach(function (pro) { |
| 2728 |
if (pro.profileName.match(/^\s*profile\s+(\d+)\s*$/i)) |
| 2729 |
{ |
| 2730 |
var m = parseInt(RegExp.$1); |
| 2731 |
if (n == null || m > n) |
| 2732 |
n = m; |
| 2733 |
} |
| 2734 |
}); |
| 2735 |
|
| 2736 |
|
| 2737 |
if (n == null) |
| 2738 |
n = dlgProfiles.propCount(); |
| 2739 |
|
| 2740 |
|
| 2741 |
var initName = "Profile " + (n+1); |
| 2742 |
|
| 2743 |
|
| 2744 |
var prefsDlg = dialogStack.top().ele; |
| 2745 |
|
| 2746 |
|
| 2747 |
createOrRenamePrefProfile("Create Profile", initName, function(newName) |
| 2748 |
{ |
| 2749 |
|
| 2750 |
var newPro = dlgProfiles[dlgCurProfile].copy(false); |
| 2751 |
|
| 2752 |
|
| 2753 |
newPro.profileName = newName; |
| 2754 |
|
| 2755 |
|
| 2756 |
dlgProfiles.forEach(function(id) { |
| 2757 |
id = parseInt(id); |
| 2758 |
if (nextPrefProfile <= id) |
| 2759 |
nextPrefProfile = id + 1; |
| 2760 |
}); |
| 2761 |
|
| 2762 |
|
| 2763 |
var newID = (nextPrefProfile++).toString(); |
| 2764 |
dlgProfiles[newID] = newPro; |
| 2765 |
|
| 2766 |
|
| 2767 |
var sel = $(prefsDlg, "curProfile"); |
| 2768 |
addSelectOptionSort(sel, newName, newID); |
| 2769 |
|
| 2770 |
|
| 2771 |
dlgCurProfile = newID; |
| 2772 |
setSelectByValue(sel, newID); |
| 2773 |
}); |
| 2774 |
} |
| 2775 |
|
| 2776 |
function renamePrefProfile() |
| 2777 |
{ |
| 2778 |
|
| 2779 |
var prefsDlg = dialogStack.top().ele; |
| 2780 |
|
| 2781 |
|
| 2782 |
createOrRenamePrefProfile( |
| 2783 |
"Rename Profile", dlgProfiles[dlgCurProfile].profileName, |
| 2784 |
function(newName) { |
| 2785 |
if (newName != dlgCurProfile) |
| 2786 |
{ |
| 2787 |
|
| 2788 |
var pro = dlgProfiles[dlgCurProfile]; |
| 2789 |
pro.profileName = newName; |
| 2790 |
|
| 2791 |
|
| 2792 |
var sel = $(prefsDlg, "curProfile"); |
| 2793 |
var opt = sel.options[sel.selectedIndex]; |
| 2794 |
opt.text = newName; |
| 2795 |
} |
| 2796 |
}); |
| 2797 |
} |
| 2798 |
|
| 2799 |
function createOrRenamePrefProfile(title, initName, setName) |
| 2800 |
{ |
| 2801 |
|
| 2802 |
showDialog({ |
| 2803 |
id: 'profileName', |
| 2804 |
title: title, |
| 2805 |
contents: "Profile name:<br>" |
| 2806 |
+ "<input type=\"text\" size=\"50\" value=\"" |
| 2807 |
+ initName.htmlify() + "\">", |
| 2808 |
buttons: [{ name: "OK", isDefault: true, save: true }, |
| 2809 |
{ name: "Cancel", isCancel: true }], |
| 2810 |
dimensions: { width: "70ex" }, |
| 2811 |
|
| 2812 |
|
| 2813 |
dismiss: function(dlg, btn) { |
| 2814 |
if (btn && btn.save) |
| 2815 |
{ |
| 2816 |
|
| 2817 |
var newName = $(dlg, "<INPUT>").value.trim(); |
| 2818 |
|
| 2819 |
|
| 2820 |
var err = null; |
| 2821 |
if (newName.match(/^\s+$/)) |
| 2822 |
err = "Please enter a name for the new profile."; |
| 2823 |
else if (newName != initName |
| 2824 |
&& dlgProfiles.propWhich(function(ele, prop) { |
| 2825 |
return prop.trim().toLowerCase() == newName.toLowerCase(); |
| 2826 |
})) |
| 2827 |
err = "There's already a profile with this name. " |
| 2828 |
+ "Please choose a different name."; |
| 2829 |
|
| 2830 |
|
| 2831 |
if (err) |
| 2832 |
{ |
| 2833 |
showDialog({ title: "Profile Name", contents: err }); |
| 2834 |
return false; |
| 2835 |
} |
| 2836 |
|
| 2837 |
|
| 2838 |
setName(newName); |
| 2839 |
} |
| 2840 |
|
| 2841 |
|
| 2842 |
return true; |
| 2843 |
} |
| 2844 |
}); |
| 2845 |
} |
| 2846 |
|
| 2847 |
function delPrefProfile() |
| 2848 |
{ |
| 2849 |
|
| 2850 |
var prefsDlg = dialogStack.top().ele; |
| 2851 |
|
| 2852 |
|
| 2853 |
if (dlgProfiles.propCount() == 1) |
| 2854 |
{ |
| 2855 |
$alert("This is the only profile. If you wish to delete this " |
| 2856 |
+ "profile, please create a replacement first.", |
| 2857 |
"Error"); |
| 2858 |
return; |
| 2859 |
} |
| 2860 |
|
| 2861 |
|
| 2862 |
$confirm("Do you really want to delete the profile \"" |
| 2863 |
+ dlgProfiles[dlgCurProfile].profileName + "\"?", |
| 2864 |
function(del) { |
| 2865 |
|
| 2866 |
if (del) |
| 2867 |
{ |
| 2868 |
|
| 2869 |
var sel = $(prefsDlg, "curProfile"); |
| 2870 |
var idx = sel.selectedIndex; |
| 2871 |
sel.remove(idx); |
| 2872 |
|
| 2873 |
|
| 2874 |
delete dlgProfiles[dlgCurProfile]; |
| 2875 |
|
| 2876 |
|
| 2877 |
dlgCurProfile = dlgProfiles.propWhich( |
| 2878 |
function() { return true; }); |
| 2879 |
|
| 2880 |
|
| 2881 |
setSelectByValue(sel, dlgCurProfile); |
| 2882 |
|
| 2883 |
|
| 2884 |
prefsToDlg(prefsDlg, dlgProfiles[dlgCurProfile], true); |
| 2885 |
} |
| 2886 |
}, "Delete Profile"); |
| 2887 |
} |
| 2888 |
|
| 2889 |
function resetPrefProfile() |
| 2890 |
{ |
| 2891 |
|
| 2892 |
var prefsDlg = dialogStack.top().ele; |
| 2893 |
|
| 2894 |
|
| 2895 |
$confirm("This will discard all of your custom settings for this " |
| 2896 |
+ "profile and restore its to the story's default " |
| 2897 |
+ "settings. Are you sure you want to do proceed?", |
| 2898 |
function(reset) { |
| 2899 |
if (reset) |
| 2900 |
{ |
| 2901 |
|
| 2902 |
var pro = dlgProfiles[dlgCurProfile]; |
| 2903 |
|
| 2904 |
|
| 2905 |
prefsMapper.forEach(function(m, id) { pro[id] = null; }); |
| 2906 |
|
| 2907 |
|
| 2908 |
prefsToDlg(prefsDlg, dlgProfiles[dlgCurProfile], true); |
| 2909 |
} |
| 2910 |
}, "Reset Profile to Defaults"); |
| 2911 |
} |
| 2912 |
|
| 2913 |
function onClosePrefsDialog(dlg, btn) |
| 2914 |
{ |
| 2915 |
|
| 2916 |
if (btn && btn.save) |
| 2917 |
{ |
| 2918 |
|
| 2919 |
dlgToPrefs(dlg, dlgProfiles[dlgCurProfile]); |
| 2920 |
|
| 2921 |
|
| 2922 |
prefProfiles = dlgProfiles; |
| 2923 |
curPrefProfile = dlgCurProfile; |
| 2924 |
|
| 2925 |
|
| 2926 |
prefsToCSS(); |
| 2927 |
|
| 2928 |
|
| 2929 |
var post = []; |
| 2930 |
post.push("current-profile=" + curPrefProfile); |
| 2931 |
prefProfiles.forEach(function(pro, proID) |
| 2932 |
{ |
| 2933 |
pro.forEach(function(val, id) { |
| 2934 |
post.push(proID + "." + id + "=" + (val ? val : "")); |
| 2935 |
}); |
| 2936 |
}); |
| 2937 |
|
| 2938 |
|
| 2939 |
post = post.join("\r\n"); |
| 2940 |
|
| 2941 |
|
| 2942 |
var f = function(req, resp) { |
| 2943 |
if (xmlHasChild(resp, "error")) |
| 2944 |
logError("An error occurred saving your preference changes.", |
| 2945 |
xmlChildText("error"), null); |
| 2946 |
}; |
| 2947 |
serverRequest("/webui/setPrefs", ServerRequest.Command, |
| 2948 |
f, post, "text/plain"); |
| 2949 |
} |
| 2950 |
|
| 2951 |
|
| 2952 |
return true; |
| 2953 |
} |
| 2954 |
|
| 2955 |
function onChangeProfile(ev, sel) |
| 2956 |
{ |
| 2957 |
|
| 2958 |
dlgCurProfile = sel.value; |
| 2959 |
|
| 2960 |
|
| 2961 |
prefsToDlg(dialogStack.top().ele, dlgProfiles[dlgCurProfile], true); |
| 2962 |
} |
| 2963 |
|
| 2964 |
|
| 2965 |
|
| 2966 |
|
| 2967 |
|
| 2968 |
|
| 2969 |
function showFileDialog(desc) |
| 2970 |
{ |
| 2971 |
|
| 2972 |
var prompt = xmlChildText(desc, "prompt"); |
| 2973 |
var dlgType = xmlChildText(desc, "dialogType"); |
| 2974 |
var fileType = xmlChildText(desc, "fileType"); |
| 2975 |
var url = xmlChildText(desc, "url"); |
| 2976 |
|
| 2977 |
|
| 2978 |
showDialog({ |
| 2979 |
id: "inputFile", |
| 2980 |
title: prompt, |
| 2981 |
contents: $("fileDialog"), |
| 2982 |
init: initFileDialog, |
| 2983 |
fillWidth: true, |
| 2984 |
url: url, |
| 2985 |
buttons: [], |
| 2986 |
dismiss: function(dlg, btn) { |
| 2987 |
|
| 2988 |
serverRequest("/webui/inputFileDismissed"); |
| 2989 |
return true; |
| 2990 |
} |
| 2991 |
}); |
| 2992 |
} |
| 2993 |
|
| 2994 |
function initFileDialog(dlg, params) |
| 2995 |
{ |
| 2996 |
var fr = $(dlg, "<IFRAME>"); |
| 2997 |
var frWin = fr.contentWindow || fr.contentDocument.window; |
| 2998 |
frWin.location = params.url; |
| 2999 |
} |
| 3000 |
|
| 3001 |
|
| 3002 |
|
| 3003 |
|
| 3004 |
|
| 3005 |
|
| 3006 |
function showInputDialog(desc) |
| 3007 |
{ |
| 3008 |
|
| 3009 |
var iconID = parseInt(xmlChildText(desc, "icon")); |
| 3010 |
var prompt = xmlChildText(desc, "prompt").htmlify().replace(/\n/g, '<br>'); |
| 3011 |
var title = xmlChildText(desc, "title").htmlify(); |
| 3012 |
var defbtn = parseInt(xmlChildText(desc, "defaultButton")); |
| 3013 |
var cxlbtn = parseInt(xmlChildText(desc, "cancelButton")); |
| 3014 |
var buttons = xpath(desc, "buttons/button[*]#text").map(function(name, i) { |
| 3015 |
var key = (name.match(/&(.)/) ? RegExp.$1 : null); |
| 3016 |
name = name.htmlify().replace(/&(.)/, "<B>$1</B>"); |
| 3017 |
var idx = i + 1; |
| 3018 |
return { |
| 3019 |
name: name, |
| 3020 |
key: key, |
| 3021 |
isDefault: idx == defbtn, |
| 3022 |
isCancel: idx == cxlbtn, |
| 3023 |
buttonIndex: idx |
| 3024 |
}; |
| 3025 |
}); |
| 3026 |
|
| 3027 |
|
| 3028 |
var icons = [null, "dlgIconWarning", "dlgIconInfo", |
| 3029 |
"dlgIconQuestion", "dlgIconError"]; |
| 3030 |
var icon = ""; |
| 3031 |
if (iconID >= 0 && iconID < icons.length) |
| 3032 |
icon = icons[iconID]; |
| 3033 |
|
| 3034 |
|
| 3035 |
var img = (icon |
| 3036 |
? "<img src=\"/webuires/" + icon |
| 3037 |
+ ".gif\" class=\"inputDialogIcon\">" |
| 3038 |
: ""); |
| 3039 |
|
| 3040 |
|
| 3041 |
var cont = "<table class=\"inputDialogTab\">" |
| 3042 |
+ "<tr>" |
| 3043 |
+ "<td>" + img + "</td>" |
| 3044 |
+ "<td class=\"inputDialogPrompt\">" + prompt + "</td>" |
| 3045 |
+ "</tr>" |
| 3046 |
+ "</table>"; |
| 3047 |
|
| 3048 |
|
| 3049 |
showDialog({ |
| 3050 |
id: "inputDialog", |
| 3051 |
title: title, |
| 3052 |
contents: "<div class=\"inputDialog\">" + cont + "</div>", |
| 3053 |
buttons: buttons, |
| 3054 |
dismiss: function(dlg, btn) { |
| 3055 |
var idx = btn.buttonIndex || cxlbtn; |
| 3056 |
serverRequest("/webui/inputDialog?button=" + idx); |
| 3057 |
return true; |
| 3058 |
}, |
| 3059 |
fillWidth: true |
| 3060 |
}); |
| 3061 |
} |
| 3062 |
|
| 3063 |
|
| 3064 |
|
| 3065 |
|
| 3066 |
|
| 3067 |
|
| 3068 |
|
| 3069 |
|
| 3070 |
|
| 3071 |
|
| 3072 |
|
| 3073 |
|
| 3074 |
|
| 3075 |
|
| 3076 |
function showUploadDialog(desc) |
| 3077 |
{ |
| 3078 |
|
| 3079 |
var prompt = xmlChildText(desc, "prompt"); |
| 3080 |
|
| 3081 |
|
| 3082 |
var init = function(dlg, params) |
| 3083 |
{ |
| 3084 |
var doc = getIFrameDoc($(dlg, "<IFRAME>")); |
| 3085 |
doc.open("text/html"); |
| 3086 |
doc.write( |
| 3087 |
"<html><head><title>File Upload</title>" |
| 3088 |
+ "<link rel=\"stylesheet\" href=\"/webuires/tads.css\">" |
| 3089 |
+ "<link rel=\"stylesheet\" href=\"/webuires/main.css\">" |
| 3090 |
+ "</head>" |
| 3091 |
+ "<body>" |
| 3092 |
+ "<div class=\"dialogWrapper\"><div class=\"dialogContent\">" |
| 3093 |
+ "<form method=\"post\" name=\"uploadDialog\" " |
| 3094 |
+ "enctype=\"multipart/form-data\" " |
| 3095 |
+ "action=\"/webui/uploadFileDialog\" " |
| 3096 |
+ "style=\"padding-top: 2em;\">" |
| 3097 |
+ "Please select a file:" |
| 3098 |
+ "<div style='margin: 1em;'>" |
| 3099 |
+ "<input type=\"file\" size=\"50\" name=\"file\">" |
| 3100 |
+ "</div>" |
| 3101 |
+ "</form>" |
| 3102 |
+ "</div></div>" |
| 3103 |
+ "</body>" |
| 3104 |
+ "</html>"); |
| 3105 |
doc.close(); |
| 3106 |
}; |
| 3107 |
|
| 3108 |
|
| 3109 |
var submit = function() |
| 3110 |
{ |
| 3111 |
var doc = getIFrameDoc($(dialogStack.top().ele, "<IFRAME>")); |
| 3112 |
var form = $(doc.body, "<FORM>"); |
| 3113 |
form.submit(); |
| 3114 |
}; |
| 3115 |
|
| 3116 |
|
| 3117 |
showDialog({ |
| 3118 |
id: "uploadFile", |
| 3119 |
init: init, |
| 3120 |
fillWidth: true, |
| 3121 |
title: prompt, |
| 3122 |
contents: $("uploadDialog"), |
| 3123 |
buttons: [ |
| 3124 |
{ name: "OK", isDefault: true, onclick: submit }, |
| 3125 |
{ name: "Cancel", isCancel: true } |
| 3126 |
], |
| 3127 |
dismiss: function(dlg, btn) { |
| 3128 |
serverRequest("/webui/inputFileDismissed"); |
| 3129 |
return true; |
| 3130 |
} |
| 3131 |
}); |
| 3132 |
} |
| 3133 |
|
| 3134 |
|
| 3135 |
|
| 3136 |
|
| 3137 |
|
| 3138 |
|
| 3139 |
|
| 3140 |
|
| 3141 |
|
| 3142 |
|
| 3143 |
|
| 3144 |
|
| 3145 |
|
| 3146 |
|
| 3147 |
function addDownloadFrame(fname) |
| 3148 |
{ |
| 3149 |
|
| 3150 |
removeDownloadFrame(fname); |
| 3151 |
|
| 3152 |
|
| 3153 |
var fr = document.createElement("IFRAME"); |
| 3154 |
fr.className = "downloadFile"; |
| 3155 |
|
| 3156 |
|
| 3157 |
fr.src = fname; |
| 3158 |
|
| 3159 |
|
| 3160 |
document.body.appendChild(fr); |
| 3161 |
} |
| 3162 |
|
| 3163 |
|
| 3164 |
|
| 3165 |
|
| 3166 |
|
| 3167 |
function removeDownloadFrame(fname) |
| 3168 |
{ |
| 3169 |
|
| 3170 |
for (var ele = document.body.firstChild ; ele ; ele = nxt) |
| 3171 |
{ |
| 3172 |
|
| 3173 |
var nxt = ele.nextSibling; |
| 3174 |
|
| 3175 |
|
| 3176 |
if (ele.nodeName == "IFRAME" && ele.src == fname) |
| 3177 |
document.body.removeChild(ele); |
| 3178 |
} |
| 3179 |
} |
| 3180 |
|
| 3181 |
|
| 3182 |
|
| 3183 |
|
| 3184 |
|
| 3185 |
|
| 3186 |
|
| 3187 |
|
| 3188 |
var menuSysLinkCount = 0, menuSysTopicCount = 0, menuSysLastTopic = 0; |
| 3189 |
function showMenuSys(r) |
| 3190 |
{ |
| 3191 |
|
| 3192 |
var title = xmlChildText(r, "title"); |
| 3193 |
|
| 3194 |
|
| 3195 |
var buttons = []; |
| 3196 |
|
| 3197 |
|
| 3198 |
var s = "<div class=\"menuSys\">"; |
| 3199 |
|
| 3200 |
|
| 3201 |
var initFocus = null; |
| 3202 |
|
| 3203 |
|
| 3204 |
var prev = function() { serverRequest("/webui/menusys?prev"); }; |
| 3205 |
var up = function() { menuSysArrow(-1); }; |
| 3206 |
var down = function() { menuSysArrow(1); }; |
| 3207 |
var sel = null; |
| 3208 |
|
| 3209 |
|
| 3210 |
if (xmlHasChild(r, "close")) |
| 3211 |
{ |
| 3212 |
|
| 3213 |
dismissDialogById("menuSys"); |
| 3214 |
return; |
| 3215 |
} |
| 3216 |
else if (xmlHasChild(r, "menuItem")) |
| 3217 |
{ |
| 3218 |
|
| 3219 |
var contents = xmlChild(r, "menuItem"); |
| 3220 |
for (var i = 0 ; i < contents.length ; ++i) |
| 3221 |
{ |
| 3222 |
var item = xmlNodeText(contents[i]); |
| 3223 |
var idx = i + 1; |
| 3224 |
s += "<div class=\"menuSysItem\">" |
| 3225 |
+ "<a href=\"#\" id=\"menuSysLink" + idx |
| 3226 |
+ "\" onclick=\"javascript:menuSysSel(" + idx |
| 3227 |
+ ");return false;\">" |
| 3228 |
+ item + "</a></div>"; |
| 3229 |
} |
| 3230 |
|
| 3231 |
|
| 3232 |
sel = function() { |
| 3233 |
var ae = document.activeElement; |
| 3234 |
if (ae && ae.id.search(/^menuSysLink(\d+)$/) == 0) |
| 3235 |
menuSysSel(parseInt(RegExp.$1)); |
| 3236 |
}; |
| 3237 |
|
| 3238 |
|
| 3239 |
|
| 3240 |
if (xmlHasChild(r, "fromChild")) |
| 3241 |
initFocus = "menuSysLink" + parseInt(xmlChildText(r, "fromChild")); |
| 3242 |
|
| 3243 |
|
| 3244 |
menuSysLinkCount = contents.length; |
| 3245 |
|
| 3246 |
|
| 3247 |
buttons.push({ onclick: up, key: "Up" }); |
| 3248 |
buttons.push({ onclick: up, key: "U+0050" }); |
| 3249 |
buttons.push({ onclick: down, key: "Down" }); |
| 3250 |
buttons.push({ onclick: down, key: "U+004E" }); |
| 3251 |
} |
| 3252 |
else if (xmlHasChild(r, "topicItem")) |
| 3253 |
{ |
| 3254 |
|
| 3255 |
|
| 3256 |
|
| 3257 |
|
| 3258 |
|
| 3259 |
s += "<div id=\"menuSysTopicList\">"; |
| 3260 |
var contents = xmlChild(r, "topicItem"); |
| 3261 |
menuSysTopicCount = parseInt(xmlChildText(r, "numItems")); |
| 3262 |
menuSysLastTopic = contents.length; |
| 3263 |
for (var i = 0 ; i < contents.length ; ++i) |
| 3264 |
{ |
| 3265 |
var idx = i + 1; |
| 3266 |
var item = xmlNodeText(contents[i]); |
| 3267 |
s += "<div class=\"menuSysItem\" id=\"menuSysTopic" + idx + "\">" |
| 3268 |
+ item |
| 3269 |
+ " [" + idx + "/" + menuSysTopicCount + "]" |
| 3270 |
+ "</div>"; |
| 3271 |
} |
| 3272 |
|
| 3273 |
|
| 3274 |
s += "</div>"; |
| 3275 |
|
| 3276 |
|
| 3277 |
s += "<div class=\"menuSysTopicFooter\">"; |
| 3278 |
|
| 3279 |
|
| 3280 |
if (menuSysLastTopic < menuSysTopicCount) |
| 3281 |
s += "<span id=\"menuSysNextButton\">(Press Space or " |
| 3282 |
+ "<a href=\"#\" onclick=\"javascript:menuSysNextTopic();" |
| 3283 |
+ "return false;\">click here</a> to see the next item)" |
| 3284 |
+ "</span>"; |
| 3285 |
|
| 3286 |
|
| 3287 |
s += "<span id=\"menuSysTheEnd\"" |
| 3288 |
+ (menuSysLastTopic < menuSysTopicCount |
| 3289 |
? " style=\"display:none;\"" : "") |
| 3290 |
+ ">[The End]</span>"; |
| 3291 |
|
| 3292 |
|
| 3293 |
sel = menuSysNextTopic; |
| 3294 |
|
| 3295 |
|
| 3296 |
buttons.push({ onclick: menuSysNextTopic, key: "U+0020" }); |
| 3297 |
buttons.push({ onclick: menuSysNextTopic, key: "Enter" }); |
| 3298 |
buttons.push({ onclick: menuSysNextTopic, key: "Down" }); |
| 3299 |
} |
| 3300 |
else if (xmlHasChild(r, "longTopic")) |
| 3301 |
{ |
| 3302 |
|
| 3303 |
var winrc = getWindowRect(); |
| 3304 |
var maxht = winrc.height * 0.75; |
| 3305 |
|
| 3306 |
|
| 3307 |
s += "<div class=\"menuSysLongTopic\" style=\"max-height:" |
| 3308 |
+ maxht + "px;\">" |
| 3309 |
+ xmlChildText(r, "longTopic") |
| 3310 |
+ "</div>"; |
| 3311 |
|
| 3312 |
|
| 3313 |
if (xmlHasChild(r, "nextChapter") || xmlHasChild(r, "prevChapter")) |
| 3314 |
{ |
| 3315 |
s += "<div class=\"menuSysChapterButtons\">"; |
| 3316 |
|
| 3317 |
if (xmlHasChild(r, "prevChapter")) |
| 3318 |
{ |
| 3319 |
s += "<a href=\"#\" onclick=\"javascript:menuSysGoChapter(" |
| 3320 |
+ "'prev');return false;\">< Previous</a>"; |
| 3321 |
|
| 3322 |
up = function() { menuSysGoChapter('prev'); }; |
| 3323 |
buttons.push({ onclick: up, key: "Left" }); |
| 3324 |
buttons.push({ onclick: up, key: "U+0008" }); |
| 3325 |
} |
| 3326 |
|
| 3327 |
if (xmlHasChild(r, "nextChapter")) |
| 3328 |
{ |
| 3329 |
s += "<a href=\"#\" onclick=\"javascript:menuSysGoChapter(" |
| 3330 |
+ "'next');return false;\">Next: " |
| 3331 |
+ xmlChildText(r, "nextChapter") |
| 3332 |
+ " ></a>"; |
| 3333 |
|
| 3334 |
sel = down = function() { menuSysGoChapter('next'); }; |
| 3335 |
buttons.push({ onclick: down, key: "Right" }); |
| 3336 |
buttons.push({ onclick: down, key: "U+0020" }); |
| 3337 |
} |
| 3338 |
|
| 3339 |
s += "</div>"; |
| 3340 |
} |
| 3341 |
} |
| 3342 |
|
| 3343 |
|
| 3344 |
s += "</div>"; |
| 3345 |
|
| 3346 |
|
| 3347 |
if (!xmlHasChild(r, "isTop")) |
| 3348 |
{ |
| 3349 |
|
| 3350 |
buttons.push({ name: "Return", onclick: prev }); |
| 3351 |
|
| 3352 |
|
| 3353 |
|
| 3354 |
|
| 3355 |
buttons.push({ onclick: prev, key: "U+0008" }); |
| 3356 |
buttons.push({ onclick: prev, key: "Left" }); |
| 3357 |
} |
| 3358 |
|
| 3359 |
|
| 3360 |
buttons.push({ name: "Close", isCancel: true }); |
| 3361 |
|
| 3362 |
|
| 3363 |
var keylists = xmlChild(r, "keylist"); |
| 3364 |
if (keylists) |
| 3365 |
{ |
| 3366 |
|
| 3367 |
|
| 3368 |
var keyfuncs = [ |
| 3369 |
{ isCancel: true, onclick: null }, |
| 3370 |
{ isCancel: false, onclick: prev }, |
| 3371 |
{ isCancel: false, onclick: up }, |
| 3372 |
{ isCancel: false, onclick: down }, |
| 3373 |
{ isCancel: false, onclick: sel } |
| 3374 |
]; |
| 3375 |
|
| 3376 |
|
| 3377 |
for (var i = 0 ; i < keylists.length ; ++i) |
| 3378 |
{ |
| 3379 |
var kf = keyfuncs[i]; |
| 3380 |
var kl = xmlChild(keylists[i], "key"); |
| 3381 |
for (var j = 0 ; j < kl.length ; ++j) |
| 3382 |
{ |
| 3383 |
|
| 3384 |
var k = xmlNodeText(kl[j]); |
| 3385 |
|
| 3386 |
|
| 3387 |
|
| 3388 |
if (k.search(/^\[(.*)\]$/) == 0) |
| 3389 |
{ |
| 3390 |
|
| 3391 |
k = DOM3toTADSKey.propWhich( |
| 3392 |
function(val) { return val == k; }); |
| 3393 |
} |
| 3394 |
else |
| 3395 |
{ |
| 3396 |
|
| 3397 |
k = k.toUpperCase(); |
| 3398 |
} |
| 3399 |
|
| 3400 |
|
| 3401 |
|
| 3402 |
|
| 3403 |
if (k && (kf.onclick || kf.isCancel)) |
| 3404 |
{ |
| 3405 |
buttons.unshift( |
| 3406 |
{ onclick: kf.onclick, |
| 3407 |
isCancel: kf.isCancel, |
| 3408 |
key: k }); |
| 3409 |
} |
| 3410 |
} |
| 3411 |
} |
| 3412 |
} |
| 3413 |
|
| 3414 |
|
| 3415 |
|
| 3416 |
|
| 3417 |
|
| 3418 |
|
| 3419 |
dismissDialogById("menuSys", { isCancel: true, isNewDlg: true }); |
| 3420 |
|
| 3421 |
|
| 3422 |
showDialog({ |
| 3423 |
id: "menuSys", |
| 3424 |
fullWidth: true, |
| 3425 |
title: title, |
| 3426 |
initFocus: initFocus, |
| 3427 |
contents: s, |
| 3428 |
buttons: buttons, |
| 3429 |
dimensions: { width: "90%" }, |
| 3430 |
dismiss: function(dlg, btn) { |
| 3431 |
if (!btn.isNewDlg) |
| 3432 |
serverRequest("/webui/menusys?close"); |
| 3433 |
return true; |
| 3434 |
} |
| 3435 |
}); |
| 3436 |
} |
| 3437 |
|
| 3438 |
function menuSysGoChapter(dir) |
| 3439 |
{ |
| 3440 |
serverRequest("/webui/menusys?chapter=" + dir); |
| 3441 |
} |
| 3442 |
|
| 3443 |
|
| 3444 |
|
| 3445 |
|
| 3446 |
|
| 3447 |
function menuSysArrow(dir) |
| 3448 |
{ |
| 3449 |
|
| 3450 |
var ele = document.activeElement; |
| 3451 |
|
| 3452 |
|
| 3453 |
if (ele == null || !ele.id || ele.id.search(/^menuSysLink(\d+)$/) < 0) |
| 3454 |
{ |
| 3455 |
|
| 3456 |
ele = (dir > 0 ? 1 : menuSysLinkCount); |
| 3457 |
} |
| 3458 |
else |
| 3459 |
{ |
| 3460 |
|
| 3461 |
ele = parseInt(RegExp.$1) + dir; |
| 3462 |
} |
| 3463 |
|
| 3464 |
|
| 3465 |
if (ele < 1) |
| 3466 |
ele = menuSysLinkCount; |
| 3467 |
else if (ele > menuSysLinkCount) |
| 3468 |
ele = 1; |
| 3469 |
|
| 3470 |
|
| 3471 |
ele = $("menuSysLink" + ele); |
| 3472 |
if (ele) |
| 3473 |
ele.focus(); |
| 3474 |
} |
| 3475 |
|
| 3476 |
|
| 3477 |
|
| 3478 |
|
| 3479 |
function menuSysNextTopic() |
| 3480 |
{ |
| 3481 |
|
| 3482 |
if (menuSysLastTopic >= menuSysTopicCount) |
| 3483 |
return; |
| 3484 |
|
| 3485 |
|
| 3486 |
serverRequest("/webui/menusys?nextTopic", ServerRequest.Command, |
| 3487 |
function(req, resp) |
| 3488 |
{ |
| 3489 |
|
| 3490 |
var txt = xmlChildText(resp, "topicItem"); |
| 3491 |
if (txt) |
| 3492 |
{ |
| 3493 |
|
| 3494 |
menuSysLastTopic++; |
| 3495 |
|
| 3496 |
|
| 3497 |
var ele = document.createElement("DIV"); |
| 3498 |
ele.className = "menuSysItem"; |
| 3499 |
ele.id = "menuSysTopic" + menuSysLastTopic; |
| 3500 |
ele.innerHTML = txt |
| 3501 |
+ " [" + menuSysLastTopic |
| 3502 |
+ "/" + menuSysTopicCount + "]"; |
| 3503 |
|
| 3504 |
|
| 3505 |
$("menuSysTopicList").appendChild(ele); |
| 3506 |
|
| 3507 |
|
| 3508 |
|
| 3509 |
if (menuSysLastTopic >= menuSysTopicCount) |
| 3510 |
{ |
| 3511 |
$("menuSysNextButton").style.display = "none"; |
| 3512 |
$("menuSysTheEnd").style.display = "inline"; |
| 3513 |
} |
| 3514 |
} |
| 3515 |
}); |
| 3516 |
} |
| 3517 |
|
| 3518 |
|
| 3519 |
|
| 3520 |
|
| 3521 |
|
| 3522 |
|
| 3523 |
function menuSysSel(idx) |
| 3524 |
{ |
| 3525 |
serverRequest("/webui/menusys?select=" + idx); |
| 3526 |
} |
| 3527 |
|
| 3528 |
|
| 3529 |
|
| 3530 |
|
| 3531 |
|
| 3532 |
|
| 3533 |
function showPageMenu(ev, arrow) |
| 3534 |
{ |
| 3535 |
|
| 3536 |
ev = getEvent(ev); |
| 3537 |
|
| 3538 |
|
| 3539 |
var menu = $("pageMenuDiv"); |
| 3540 |
|
| 3541 |
|
| 3542 |
closePopup(menu); |
| 3543 |
|
| 3544 |
|
| 3545 |
var sh = document.createElement("DIV"); |
| 3546 |
sh.className = "menuShadow"; |
| 3547 |
document.body.appendChild(sh); |
| 3548 |
var closer = function() { |
| 3549 |
document.body.removeChild(sh); |
| 3550 |
}; |
| 3551 |
|
| 3552 |
|
| 3553 |
menu.style.display = "block"; |
| 3554 |
openPopup(ev, menu, closer, null, arrow); |
| 3555 |
|
| 3556 |
|
| 3557 |
var arc = getObjectRect(arrow); |
| 3558 |
var mrc = getObjectRect(menu); |
| 3559 |
mrc.x = arc.x + arc.width - mrc.width; |
| 3560 |
mrc.y = arc.y + arc.height; |
| 3561 |
moveObject(menu, mrc.x, mrc.y); |
| 3562 |
|
| 3563 |
|
| 3564 |
sh.style.width = mrc.width + "px"; |
| 3565 |
sh.style.height = mrc.height + "px"; |
| 3566 |
moveObject(sh, mrc.x + 3, mrc.y + 3); |
| 3567 |
} |
| 3568 |
|
| 3569 |
function pageMenuClick(item) |
| 3570 |
{ |
| 3571 |
closePopup($("pageMenuDiv")); |
| 3572 |
if (item == 'prefs') |
| 3573 |
{ |
| 3574 |
showPrefsDialog(); |
| 3575 |
} |
| 3576 |
else if (item == 'errlog') |
| 3577 |
{ |
| 3578 |
showErrorLog(); |
| 3579 |
} |
| 3580 |
} |
| 3581 |
|
| 3582 |
|
| 3583 |
|
| 3584 |
|
| 3585 |
|
| 3586 |
var screenName = "Host"; |
| 3587 |
function setScreenName(name) |
| 3588 |
{ |
| 3589 |
serverRequest("/webui/setScreenName?name=" + encodeURIComponent(name)); |
| 3590 |
screenName = name; |
| 3591 |
} |
| 3592 |
|