1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 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 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 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 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675
|
/*
* $Id$
*
* This file is part of the OpenLink Software Ajax Toolkit (OAT) project.
*
* Copyright (C) 2005-2012 OpenLink Software
*
* See LICENSE file for details.
*/
var OAT = {
base: "",
/**
* Initialize OAT
*/
init: function() {
OAT.Event.attach(window, "load", this._onload); /* listen for window.onload */
var nodes = document.getElementsByTagName("script"); /* locate self */
for (var i=0;i<nodes.length;i++) {
var s = nodes[i];
var re = s.src.match(/^(.*)(oat|loader)\.js$/);
if (re) {
this.base = re[1];
this._initialLoad(); /* load initial features */
return;
}
}
throw new Error("OAT cannot find itself");
},
_loaded: false,
_winloaded: false,
/**
* Is everything ready to call window.init ?
*/
_checkInit: function() {
if (!this._loaded || !this._winloaded) { return; }
if (typeof(window.init) == "function") { window.init(); }
},
/**
* window.onload happened
*/
_onload: function() {
OAT._winloaded = true;
OAT._checkInit();
},
/**
* All initial features are loaded
*/
_initialLoaded: function() {
OAT._loaded = true;
OAT.MSG.send(OAT, "OAT_LOADED", null);
OAT.MSG.send(OAT, "OAT_LOAD", null); // XXX: Backward-compat hack
OAT._checkInit();
},
/**
* Load features initialy specified in window.featureList
*/
_initialLoad: function() {
if (window.featureList && window.featureList.length) {
this.Loader.load(window.featureList, this._initialLoaded);
} else {
this._initialLoaded();
}
}
};
/**
* @namespace
*/
OAT.Preferences = {
showAjax: 1, /* show Ajax window even if not explicitly requested by application? */
useCursors: 1, /* scrollable cursors */
windowTypeOverride: 0, /* do not guess window type */
xsltPath: "/DAV/JS/xslt/",
imagePath: "/DAV/JS/images/",
stylePath: "/DAV/JS/styles/",
endpointXmla: "/XMLA",
version: "2.9.3",
build: "$Date: 2011/11/17 16:38:25 $",
httpError: 1, /* show http errors */
allowDefaultResize: 1,
allowDefaultDrag: 1
}
OAT.Debug = {
levels: {
WARNING: 1,
ERROR: 2,
CRITICAL: 3 },
level_msg: ["OAT Warning",
"OAT Error",
"OAT Critical"],
log: function (lvl,msg) {
if (!!window.console && OAT.Preferences.debug) {
window.console.log (OAT.Debug.level_msg[lvl] + ': ' + msg);
}
},
reportObsolete: function (where) {
OAT.Debug.log (OAT.Debug.levels.WARNING,'Obsolete call: ' + where)
OAT.MSG.send (OAT,'OBSOLETE_CALL',where);
}
};
OAT.ApiKeys = {
services: {
gmapapi: {
/* key domain : key */
}
},
addKey:function(svc,url,key) {
if (svc in this.services) {
this.services[svc][url] = key;
} else {
var entry = {};
entry[url] = key;
this.services[svc] = entry;
}
},
getKey:function(svc) {
var services = OAT.ApiKeys.services;
var href = window.location.href;
if (!svc in services) { return false; }
for (var url in services[svc]) {
var key = services[svc][url];
if(href.match(url)) { return key; }
}
return false;
}
}
/**
* provides a shortcut for getElementById
* @param something dom node, string id, or array of nodes/id's
* @returns single or array of matching dom nodes
*/
function $(something) {
if (typeof(something) == "string") {
var elm = document.getElementById(something);
} else {
var elm = something;
}
if (something instanceof Array) {
var elm = [];
for (var i=0;i<something.length;i++) { elm.push($(something[i])); }
}
if (!elm) return false;
return elm;
}
/**
* Returns list of elements belonging to given class.
* Optional root tag whose children will be searched (document by
* default) and tag type (all tags by default) can be specified.
* Prior to 2.8, this function was identical to $v(), please update
* your code to reflect this change and use $v() where appropriate.
* @param {string} className name of the class to match
* @param {node} root optional root element
* @param {string} tag optional elements of this tag only will be matched
* @returns {array} of matching elements
* @since 2.8
*/
function $$(className, root, tag) {
var e = $(root) || document;
var tag = tag || "*";
var elms = e.getElementsByTagName(tag);
var matches = [];
if (OAT.Dom.isClass(e,className)) { matches.push(e); }
for(var i=0;i<elms.length;i++) {
if(OAT.Dom.isClass(elms[i],className)) { matches.push(elms[i]); }
}
return matches;
}
/**
* returns a value of the element. equivalent to $().value
* @param string id or node
* @returns node value, or false if no such element exists or has
* no value property
*/
function $v(something) {
var e = $(something);
if (!e) return false;
if (!("value" in e)) return false;
return e.value;
}
/**
* check if obj is an array
* @param obj (suspected) array obj
* @returns true if obj is an array
*/
function isArray(array) { return !!(array && array.constructor == Array); }
/**
* backward compatibility function,
* see https://developer.mozilla.org/en/New_in_JavaScript_1.6
* for details
*/
if (!Array.prototype.indexOf) {
Array.prototype.indexOf = function(item, from) {
var len = this.length;
var i = from || 0;
if (i < 0) { i += len; }
for (;i<len;i++) {
if (i in this && this[i] === item) { return i; }
}
return -1;
}
}
if (!Array.indexOf) {
Array.indexOf = function(obj, item, from) { return Array.prototype.indexOf.call(obj, item, from); }
}
/**
* backward compatibility function,
* see https://developer.mozilla.org/en/New_in_JavaScript_1.6
* For details
*/
if (!Array.prototype.lastIndexOf) {
Array.prototype.lastIndexOf = function(item, from) {
var len = this.length;
var i = from || len-1;
if (i < 0) { i += len; }
for (;i>-1;i--) {
if (i in this && this[i] === item) { return i; }
}
return -1;
}
}
if (!Array.lastIndexOf) {
Array.lastIndexOf = function(obj, item, from) { return Array.prototype.lastIndexOf.call(obj, item, from); }
}
/**
* backward compatibility function,
* see https://developer.mozilla.org/en/New_in_JavaScript_1.6
* for details
*/
if (!Array.prototype.forEach) {
Array.prototype.forEach = function(cb, _this) {
var len = this.length;
for (var i=0;i<len;i++) {
if (i in this) { cb.call(_this, this[i], i, this); }
}
}
}
if (!Array.forEach) {
Array.forEach = function(obj, cb, _this) { Array.prototype.forEach.call(obj, cb, _this); }
}
/**
* backward compatibility function,
* see https://developer.mozilla.org/en/New_in_JavaScript_1.6
* for details
*/
if (!Array.prototype.every) {
Array.prototype.every = function(cb, _this) {
var len = this.length;
for (var i=0;i<len;i++) {
if (i in this && !cb.call(_this, this[i], i, this)) { return false; }
}
return true;
}
}
if (!Array.every) {
Array.every = function(obj, cb, _this) { return Array.prototype.every.call(obj, cb, _this); }
}
/**
* backward compatibility function,
* see https://developer.mozilla.org/en/New_in_JavaScript_1.6
* for details
*/
if (!Array.prototype.some) {
Array.prototype.some = function(cb, _this) {
var len = this.length;
for (var i=0;i<len;i++) {
if (i in this && cb.call(_this, this[i], i, this)) { return true; }
}
return false;
}
}
if (!Array.some) {
Array.some = function(obj, cb, _this) { return Array.prototype.some.call(obj, cb, _this); }
}
/**
* backward compatibility function,
* see https://developer.mozilla.org/en/New_in_JavaScript_1.6
* for details
*/
if (!Array.prototype.map) {
Array.prototype.map = function(cb, _this) {
var len = this.length;
var res = new Array(len);
for (var i=0;i<len;i++) {
if (i in this) { res[i] = cb.call(_this, this[i], i, this); }
}
return res;
}
}
if (!Array.map) {
Array.map = function(obj, cb, _this) { return Array.prototype.map.call(obj, cb, _this); }
}
/**
* backward compatibility function,
* see https://developer.mozilla.org/en/New_in_JavaScript_1.6
* for details
*/
if (!Array.prototype.filter) {
Array.prototype.filter = function(cb, _this) {
var len = this.length;
var res = [];
for (var i=0;i<len;i++) {
if (i in this) {
var val = this[i];
if (cb.call(_this, val, i, this)) { res.push(val); }
}
}
return res;
}
}
if (!Array.filter) {
Array.filter = function(obj, cb, _this) { return Array.prototype.filter.call(obj, cb, _this); }
}
/**
* find a string in array of strings
* @param {str} string to find
* @returns {integer} index of array containing first matching elem or -1 if none found
*/
Array.prototype.find = function(str) {
for (var i=0;i<this.length;i++) if (this[i] == str) { return i; }
return -1;
}
/**
* copy an array
* @returns {array} copy of this
*/
Array.prototype.copy = function() {
var a = [];
for (var i=0;i<this.length;i++) { a.push(this[i]); }
return a;
}
/**
* appends elements to this array
* @param {array} arr object or array to append
*/
Array.prototype.append = function(arr) {
var a = arr;
if (!(arr instanceof Array)) { a = [arr]; }
for (var i=0;i<a.length;i++) { this.push(a[i]); }
}
/**
* removes whitespace from start and end of the string
* @returns {string} trimmed string
*/
String.prototype.trim = function() {
return this.match(/^\s*([\s\S]*?)\s*$/)[1];
}
/**
* returns a string repeated n-times
* @param {integer} times number of repetitions
* @returns repeated string, or empty string if times is zero
*/
String.prototype.repeat = function(times) {
var ret = '';
for (var i=0;i<times;i++) { ret += this; }
return ret;
}
/**
* pads string with zeros (from left) to specified length
* @param length final string length
* @returns padded string
*/
String.prototype.leadingZero = function(length) {
var l = (length ? length : 2);
var tmp = this;
while (tmp.length < l) { tmp = "0"+tmp; }
return tmp.toString();
}
/**
* returns string truncated to maxlength or 20 if not specified
* @returns {string} truncated string
* @param {integer} maxlen maximum length of new string
*/
String.prototype.truncate = function(maxlen) {
var str = this.trim();
if (!maxlen || maxlen < 2)
maxlen = 20;
if (str.length <= maxlen)
return this;
var half = Math.floor(maxlen / 2);
return str.substr(0, half) + "..." + str.substr(length-half); /* IE does not support negative numbers in substr */
}
/**
* returns number represented as file size in human readable form
* (B,kB,MB,GB,TB)
* @returns {string} size
*/
Number.prototype.toSize = function() {
var post = ["B","kB","MB","GB","TB"];
var stepSize = 1024;
var result = this;
for (var i=0;i<post.length;i++) {
if (result >= stepSize && i+1 < post.length) {
result = result / stepSize;
} else { return Math.round(result) + " " + post[i]; }
}
return this;
}
/**
* adds suport for date formatting
* @param {string} formatStr
* d day of month, zero padded
* g hours, 12 hour cycle
* G hours, 24 hour cycle
* h hours, 12 hour cycle, zero padded
* H hours, 24 hour cycle, zero padded
* i minutes, zero padded
* j day of month
* m month (01 = Jan, 02 = Feb..), zero padded
* n month (1 = Jan, 2 = Feb)
* s seconds, zero padded
* U seconds since Unix Epoch
* w day of the week (0 Sunday, 6 Saturday)
* Y full year, e.g. 2008
* x milliseconds, zero padded
* @returns {string} formated date
*/
Date.prototype.format = function(formatStr) {
var result = formatStr;
result = result.replace(/d/,this.getDate().toString().leadingZero(2));
result = result.replace(/g/,parseInt(this.getHours()) % 12);
result = result.replace(/G/,this.getHours());
result = result.replace(/h/,(parseInt(this.getHours()) % 12).toString().leadingZero(2));
result = result.replace(/H/,this.getHours().toString().leadingZero(2));
result = result.replace(/i/,this.getMinutes().toString().leadingZero(2));
result = result.replace(/j/,this.getDate());
result = result.replace(/m/,(this.getMonth()+1).toString().leadingZero(2));
result = result.replace(/n/,this.getMonth()+1);
result = result.replace(/s/,this.getSeconds().toString().leadingZero(2));
result = result.replace(/U/,this.getTime());
result = result.replace(/w/,this.getDay());
result = result.replace(/Y/,this.getFullYear());
result = result.replace(/x/,this.getMilliseconds().toString().leadingZero(3));
return result;
}
/**
* returns date as string in human-readable format j.n.Y H:i:s
* @returns {string} formated date
*/
Date.prototype.toHumanString = function() {
return this.format("j.n.Y H:i:s");
}
/**
* @namespace DOM common functions
*/
OAT.Dom = {
/**
* creates arbitrary element with specified DOM/style attributes and class
* @param {string} tagName tag name of the element
* @param {object} obj key:value pairs to be set as properties of node or node.style
* @param {className} backwards compatibility classname shortcut..
* @returns {object} new element
*/
create:function(tagName,obj,className) {
var elm = document.createElement(tagName);
if (!obj) { return elm; }
for (p in obj) {
var value = obj[p];
if (p == "class") { p = "className"; }
if (p in elm) { elm[p] = value; }
}
if (className) elm["className"] = className;
OAT.Style.set(elm,obj);
return elm;
},
/**
* creates element in specified namespace
* @param {string} ns element namespace
* @param {string} tagName element tag name
* @returns {node} new element
*/
createNS:function(ns,tagName) {
if (document.createElementNS) {
var elm = document.createElementNS(ns,tagName);
} else {
var elm = document.createElement(tagName);
elm.setAttribute("xmlns",ns);
}
return elm;
},
/**
* creates text element
* @param {string} text text node content
* @returns {node} new text element
*/
text:function(text) {
return document.createTextNode(text);
},
/**
* creates image element
* @param {string} src image source url
* @param {string} srcBlank
* @param {integer} w image width
* @param {integer} h image height
* @returns {node} new image node
*/
image:function(src,srcBlank,w,h) {
var o = {};
if (w) { o["width"] = w; }
if (h) { o["height"] = h; }
var elm = OAT.Dom.create("img",o);
OAT.Dom.imageSrc(elm,src,srcBlank);
return elm;
},
imageSrc:function(element,src,srcBlank) {
var elm = $(element);
var png = !!src.toLowerCase().match(/png$/);
if (png && OAT.Browser.isIE6) {
if (!srcBlank) { srcBlank = OAT.Preferences.imagePath+'Blank.gif'; }
elm.src = srcBlank;
elm.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+src+"', sizingMethod='image')";
} else {
elm.src = src;
}
},
/**
* creates option element and optionally attach it to parent select
* @param {string} name name attribute value
* @param {string} value value of the option
* @param {node} parent parent (select) node
* @returns {node} new option node
*/
option:function(name,value,parent) {
var opt = OAT.Dom.create("option");
opt.innerHTML = name;
opt.value = value;
if (parent) { $(parent).appendChild(opt); }
return opt;
},
append:function() {
for (var i=0;i<arguments.length;i++) {
var arr = arguments[i];
if (!(arr instanceof Array)) { continue; }
if (arr.length < 2) { continue; }
var parent = $(arr[0]);
for (var j=1;j<arr.length;j++) {
var children = arr[j];
if (!(children instanceof Array)) { children = [children]; }
for (var k=0;k<children.length;k++) {
var child = children[k];
parent.appendChild($(child));
}
}
}
},
/**
* hides one or more elements
* @param {node} element single element or array of elements. function also
* accepts variable number of arguments
*/
hide:function(element) {
if (arguments.length > 1) {
for (var i=0;i<arguments.length;i++) { OAT.Dom.hide(arguments[i]); }
return;
}
if (element instanceof Array) {
for (var i=0;i<element.length;i++) { OAT.Dom.hide(element[i]); }
return;
}
var elm = $(element);
if (!elm) { return; }
/* ie input hack */
var inputs_ = elm.getElementsByTagName("input");
var inputs = [];
for (var i=0;i<inputs_.length;i++) { inputs.push(inputs_[i]); }
if (elm.tagName.toLowerCase() == "input") { inputs.push(elm); }
for (var i=0;i<inputs.length;i++) {
var inp = inputs[i];
if (inp.type == "radio" || inp.type == "checkbox") {
if (!inp.__checked) { inp.__checked = (inp.checked ? "1" : "0"); }
}
}
/* */
elm.style.display = "none";
},
/**
* shows one or more hidden elements
* @param {node} element single element or array of elements. function also
* accepts variable number of arguments
*/
show:function(element) {
if (arguments.length > 1) {
for (var i=0;i<arguments.length;i++) { OAT.Dom.show(arguments[i]); }
return;
}
if (element instanceof Array) {
for (var i=0;i<element.length;i++) { OAT.Dom.show(element[i]); }
return;
}
var elm = $(element);
if (!elm) { return; }
elm.style.display = "";
/* ie input hack */
var inputs_ = elm.getElementsByTagName("input");
var inputs = [];
for (var i=0;i<inputs_.length;i++) { inputs.push(inputs_[i]); }
if (elm.tagName.toLowerCase() == "input") { inputs.push(elm); }
for (var i=0;i<inputs.length;i++) {
var inp = inputs[i];
if (inp.type == "radio" || inp.type == "checkbox") {
if (inp["__checked"] && inp.__checked === "1") { inp.checked = true; }
if (inp["__checked"] && inp.__checked === "0") { inp.checked = false; }
inp.__checked = false;
}
}
/* */
},
/**
* removes all children of an element
* @param {node} element to be cleared
*/
clear:function(element) {
var elm = $(element);
while (elm.firstChild) { elm.removeChild(elm.firstChild); }
},
/**
* removes an element
* @param {node} element element to be removed
*/
unlink:function(element) {
var elm = $(element);
if (!elm) { return; } /* invalid element */
if (!elm.parentNode) { return; } /* no parent */
if (elm.parentNode.nodeType != 1) { return; } /* parent is document fragment */
elm.parentNode.removeChild(elm);
},
/**
* centers an element along x and/or y axis according to reference
* @param {node} element element to be centered
* @param {integer} x true/false center along x axis
* @param {integer} y true/false center along y axis
* @param {node} reference reference element for centering (default is offsetParent)
*/
center:function(element,x,y,reference) {
var elm = $(element);
var p = elm.offsetParent;
if (reference) { p = reference; }
if (!p) { return; }
var par_dims = (p == document.body || p.tagName.toLowerCase() == "html" ? OAT.Dom.getViewport() : OAT.Dom.getWH(p));
var dims = OAT.Dom.getWH(elm);
var new_x = Math.round(par_dims[0]/2 - dims[0]/2);
var new_y = Math.round(par_dims[1]/2 - dims[1]/2);
if (new_y < 0) { new_y = 30; }
var s = OAT.Dom.getScroll();
if (p == document.body || p.tagName.toLowerCase() == "html") {
new_x += s[0];
new_y += s[1];
}
if (x) { elm.style.left = new_x + "px"; }
if (y) { elm.style.top = new_y + "px"; }
},
/**
* checks if child is in the subtree of parent
* @param {node} child
* @param {node} parent
* @returns true if parent matches, false if not or node is in detached subtree
*/
isChild:function(child, parent) {
var c_elm = $(child);
var p_elm = $(parent);
/* walk up from the child. if we find parent element, return true */
var node = c_elm.parentNode;
do {
if (!node) { return false; }
if (node == p_elm) { return true; }
node = node.parentNode;
} while (node != document.body && node != document);
return false;
},
/**
* returns color string as RGB triple. string starting with # is
* treated like hexadecimal color representation
* @param {string} str string that specifies the color
* @returns {array} [r,g,b] triple in 0..255 range
*/
color:function(str) {
var hex2dec = function(hex) { return parseInt(hex,16); }
/* returns [col1,col2,col3] in decimal */
if (str.match(/#/)) {
/* hex */
if (str.length == 4) {
var tmpstr = "#"+str.charAt(1)+str.charAt(1)+str.charAt(2)+str.charAt(2)+str.charAt(3)+str.charAt(3);
} else {
var tmpstr = str;
}
var tmp = tmpstr.match(/#(..)(..)(..)/);
return [hex2dec(tmp[1]),hex2dec(tmp[2]),hex2dec(tmp[3])];
} else {
/* decimal */
var tmp = str.match(/\(([^,]*),([^,]*),([^\)]*)/);
return [parseInt(tmp[1]),parseInt(tmp[2]),parseInt(tmp[3])];
}
},
/**
* checks whether an element belongs to a given class
* @param {node} something element to check
* @param {string} className name of the class
* @returns {boolean} true or false
*/
isClass:function(something,className) {
var elm = $(something);
if (!elm) { return false; }
if (className == "*") { return true; }
if (className == "") { return false; }
if (!elm.className || typeof(elm.className) != "string") { return false; }
var arr = elm.className.split(" ");
var index = arr.indexOf(className);
return (index != -1);
},
/**
* adds className to object's class attribute
* @param {node} something element to alter
* @param {string} className name of the class
*/
addClass:function(something,className) {
var elm = $(something);
if (!elm) { return; }
if (OAT.Dom.isClass(elm,className)) { return; }
var arr = elm.className.split(" ");
arr.push(className);
if (arr[0] == "") { arr.splice(0,1); }
elm.className = arr.join(" ");
},
/**
* removes className from object's class attribute
* @param {node} something element to alter
* @param {string} className name of the class
*/
removeClass:function(something,className) {
var elm = $(something);
if (!elm) { return; }
if (!OAT.Dom.isClass(elm,className)) { return; } /* cannot remove non-existing class */
if (className == "*") { elm.className = ""; } /* should not occur */
var arr = elm.className.split(" ");
var index = arr.indexOf(className);
if (index == -1) { return; } /* should NOT occur! */
arr.splice(index,1);
elm.className = arr.join(" ");
},
getViewport:function() {
if (OAT.Browser.isWebKit) {
return [window.innerWidth,window.innerHeight];
}
if (OAT.Browser.isOpera || document.compatMode == "BackCompat") {
return [document.body.clientWidth,document.body.clientHeight];
} else {
return [document.documentElement.clientWidth,document.documentElement.clientHeight];
}
},
position:function(something) {
var elm = $(something);
var parent = elm.offsetParent;
if (elm == document.body || elm == document || !parent) { return OAT.Dom.getLT(elm); }
var parent_coords = OAT.Dom.position(parent);
var c = OAT.Dom.getLT(elm);
/*
var x = elm.offsetLeft - elm.scrollLeft + parent_coords[0];
var y = elm.offsetTop - elm.scrollTop + parent_coords[1];
*/
/*
this is interesting:
Opera with no scrolling reports scrollLeft/Top equal to offsetLeft/Top for <input> elements
*/
var x = c[0];
var y = c[1];
if (!OAT.Browser.isOpera || elm.scrollTop != elm.offsetTop || elm.scrollLeft != elm.offsetLeft) {
x -= elm.scrollLeft;
y -= elm.scrollTop;
}
if (OAT.Browser.isWebKit && parent == document.body && OAT.Style.get(elm,"position") == "absolute") {
return [x,y];
}
x += parent_coords[0];
y += parent_coords[1];
return [x,y];
},
/**
* returns coordinate of top left corner of an element
* @param {node} element
* @returns {array} [x,y] coordinates in pixels
*/
getLT:function(something) {
var elm = $(something);
var curr_x,curr_y;
if (elm.style.left && elm.style.position != "relative") {
curr_x = parseInt(elm.style.left);
} else {
curr_x = elm.offsetLeft;
}
if (elm.style.top && elm.style.position != "relative") {
curr_y = parseInt(elm.style.top);
} else {
curr_y = elm.offsetTop;
}
return [curr_x,curr_y];
},
/**
* returns width and height of an element
* @param {node} element
* @returns {array} [width,height]
*/
getWH:function(something) {
var elm = $(something);
return [elm.offsetWidth, elm.offsetHeight];
},
/**
* moves element by specified amount
* @param {node} element element to be moved
* @param {integer} dx x-axis displacement
* @param {integer} dy y-axis displacement
*/
moveBy:function(element,dx,dy) {
var curr_x,curr_y;
var elm = $(element);
/*
If the element is not anchored to left top corner, strange things will happen during resizing;
therefore, we need to make sure it is anchored properly.
*/
if (OAT.Style.get(elm,"position") == "absolute") {
if (!elm.style.left) {
elm.style.left = elm.offsetLeft + "px";
elm.style.right = "";
}
if (!elm.style.top) {
elm.style.top = elm.offsetTop + "px";
elm.style.bottom = "";
}
}
var tmp = OAT.Dom.getLT(elm);
curr_x = tmp[0];
curr_y = tmp[1];
var x = curr_x + dx;
var y = curr_y + dy;
elm.style.left = x + "px";
elm.style.top = y + "px";
},
/**
* resizes given element by specified amount
* @param {node} element to be resized
* @param {integer} x-axis size change
* @param {integer} y-axis size change
*/
resizeBy:function(element,dx,dy) {
var curr_w, curr_h;
var elm = $(element);
/*
If the element is not anchored to left top corner, strange things will happen during resizing;
therefore, we need to make sure it is anchored properly.
*/
if (OAT.Style.get(elm,"position") == "absolute" && dx) {
if (!elm.style.left) {
elm.style.left = elm.offsetLeft + "px";
elm.style.right = "";
}
if (!elm.style.top && dy) {
elm.style.top = elm.offsetTop + "px";
elm.style.bottom = "";
}
}
var tmp = OAT.Dom.getWH(elm);
var w = (elm.style.width && elm.style.width != "auto" ? parseInt(elm.style.width) : tmp[0]);
var h = (elm.style.height && elm.style.height != "auto" ? parseInt(elm.style.height) : tmp[1]);
w += dx;
h += dy;
if (dx) { elm.style.width = w + "px"; }
if (dy) { elm.style.height = h + "px"; }
},
removeSelection:function() {
var selObj = false;
if (document.getSelection && !OAT.Browser.isGecko) { selObj = document.getSelection(); }
if (window.getSelection) { selObj = window.getSelection(); }
if (document.selection) { selObj = document.selection; }
if (selObj) {
if (selObj.empty) { selObj.empty(); }
if (selObj.removeAllRanges) { selObj.removeAllRanges(); }
}
},
getScroll:function() {
if (OAT.Browser.isWebKit || (OAT.Browser.isIE && document.compatMode == "BackCompat")) {
var l = document.body.scrollLeft;
var t = document.body.scrollTop;
} else {
var l = Math.max(document.documentElement.scrollLeft,document.body.scrollLeft);
var t = Math.max(document.documentElement.scrollTop,document.body.scrollTop);
}
return [l,t];
},
getFreeSpace:function(x,y) {
var scroll = OAT.Dom.getScroll();
var port = OAT.Dom.getViewport();
var spaceLeft = x - scroll[0];
var spaceRight = port[0] - x + scroll[0];
var spaceTop = y - scroll[1];
var spaceBottom = port[1] - y + scroll[1];
var left = (spaceLeft > spaceRight);
var top = (spaceTop > spaceBottom);
return [left,top];
},
toSafeXML:function(str) {
if (!str || (typeof(str) != "string")) { return str; }
return str.replace(/&/g,"&").replace(/>/g,">").replace(/</g,"<");
},
fromSafeXML:function(str) {
if (!str || (typeof(str) != "string")) { return str; }
return str.replace(/&/g,"&").replace(/>/g,">").replace(/</g,"<");
},
uriParams:function() {
var result = {};
var s = location.search;
if (s.length > 1) { s = s.substring(1); }
if (!s) { return result; }
var parts = s.split("&");
for (var i=0; i < parts.length; i++) {
var part = parts[i];
if (!part) { continue; }
var index = part.indexOf("=");
if (index == -1) { result[decodeURIComponent(part)] = ""; continue; } /* not a pair */
var key = part.substring(0,index);
var val = part.substring(index+1);
key = decodeURIComponent(key);
val = decodeURIComponent(val.replace(/\+/g, " "));
var r = false;
if ((r = key.match(/(.*)\[\]$/))) {
key = r[1];
if (key in result) {
result[key].push(val);
} else {
result[key] = [val];
}
} else {
result[key] = val;
}
}
return result;
},
changeHref:function(elm,newHref) {
/* opera cannot do this with elements not being part of the page :/ */
var ok = false;
var e = $(elm);
var node = e;
while (node.parentNode) {
node = node.parentNode;
if (node == document.body) { ok = true; }
}
if (ok) {
e.href = newHref;
} else if (e.parentNode) {
var oldParent = e.parentNode;
var next = e.nextSibling;
document.body.appendChild(e);
e.href = newHref;
OAT.Dom.unlink(e);
oldParent.insertBefore(e,next);
} else {
document.body.appendChild(e);
e.href = newHref;
OAT.Dom.unlink(e);
}
},
/**
* sets position to relative if it isn't absolute
* @param {node} elm element
*/
makePosition:function(elm) {
var e = $(elm);
if (OAT.Style.get(e,"position") != "absolute") {
e.style.position = "relative";
}
}
}
/**
* @namespace Style helper
*/
OAT.Style = {
/**
* appends new stylesheet file to document
* @param {string} file filename of the stylesheet
* @param {integer} force force reloading even if stylesheet file already included
*/
include:function(file,force) {
if (!file) return;
if (!file.match(/:\/\//)) { file = OAT.Preferences.stylePath + file; }
if (!force) { /* prevent loading when already loaded */
var styles = document.getElementsByTagName('link');
var host = location.protocol + '//' + location.host;
for (var i=0;i<styles.length;i++)
if (file == styles[i].getAttribute('href') || host+file==styles[i].getAttribute('href'))
return;
}
var elm = OAT.Dom.create("link");
elm.rel = "stylesheet";
elm.rev = "stylesheet";
elm.type = "text/css";
elm.href = file;
document.getElementsByTagName("head")[0].appendChild(elm);
},
/**
* returns value of specified element style property
* @param {node} elm element
* @param {string} property property name
* @returns {string} property value
*/
get:function(elm,property) {
var element = $(elm);
if (document.defaultView && document.defaultView.getComputedStyle) {
var cs = document.defaultView.getComputedStyle(element,'');
if (!cs) { return true; }
return cs[property];
} else {
try {
var out = element.currentStyle[property];
} catch (e) {
var out = element.getExpression(property);
}
return out;
}
},
/**
* sets css style attributes
* @param {node} something element
* @param {object} obj object with key:value property pairs
*/
set:function(something, obj) {
var elm = $(something);
if (!elm) { return ; }
for (var p in obj) {
var val = obj[p];
if (p == "float") {
p = (OAT.Browser.isIE ? "styleFloat" : "cssFloat");
}
if (p == "opacity") {
val = Math.max(val,0);
if (OAT.Browser.isIE) {
p = "filter";
val = "alpha(opacity="+Math.round(100*val)+")";
elm.style.zoom = 1;
}
}
if (p in elm.style) { elm.style[p] = val; }
}
},
/**
* Backwards compat -
* @param {element} something element
* @param {opacity} opacity value
*/
opacity:function(element,opacity) {
var o = Math.max(opacity,0);
var elm = $(element);
if (OAT.Browser.isIE) {
elm.style.filter = "alpha(opacity="+Math.round(o*100)+")";
} else {
elm.style.opacity = o;
}
}
}
/**
* @namespace browser helper
*/
OAT.Browser = {
isKonqueror:!!navigator.userAgent.match(/konqueror/i),
isKHTML:!!navigator.userAgent.match(/khtml/i),
isIE: !!navigator.userAgent.match(/msie/i),
isIE6:!!navigator.userAgent.match(/msie 6/i),
isIE7:!!navigator.userAgent.match(/msie 7/i),
isIE8:!!navigator.userAgent.match(/msie 8/i),
isIE9:!!navigator.userAgent.match(/msie 9/i),
/* !isIE && !isIE7 */
isGecko:(!navigator.userAgent.match(/khtml/i) && !!navigator.userAgent.match(/Gecko/i)),
isOpera:!!navigator.userAgent.match(/Opera/),
isWebKit:!!navigator.userAgent.match(/AppleWebKit/),
/* OS detection */
isMac:!!navigator.platform.toString().match(/mac/i),
isLinux:!!navigator.platform.toString().match(/linux/i),
isWindows:!!navigator.userAgent.match(/windows/i),
/* mozilla chrome */
isChrome:function() {
try {
if (Components.classes)
return true;
else
return false;
} catch(e) {
return false;
}
},
isIphone:!!navigator.platform.toString().match(/iphone/i),
isIpod:!!navigator.platform.toString().match(/ipod/i),
isSymbian:!!navigator.platform.toString().match(/symbian/i),
isS60:!!navigator.platform.toString().match(/series60/i),
isAndroid:!!navigator.userAgent.match(/android/i),
isScreenOnly:(!!navigator.platform.toString().match(/iphone/i) ||
!!navigator.platform.toString().match(/symbian/i) ||
!!navigator.platform.toString().match(/ipod/i) ||
!!navigator.userAgent.match(/android/i)),
hasXmlParser: ((!!document.implementation &&
!!document.implementation.createDocument) ||
(!!document.getImplementation &&
!!document.getImplementation().createDocument)),
hasSVG:(!!document.implementation &&
document.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#BasicStructure", "1.1")),
hasHtml5Storage: function () {
try {
return 'localStorage' in window && window['localStorage'] !== null;
}
catch (e) {
return false;
}
}
}
/**
* @namespace Event helper
*/
OAT.Event = {
/**
* attaches event to a given element, optionally with a callback
* and/or scope from which the callback will be executed
* @param {node} elm attach the event to this element
* @param {event} event event to be attached
* @param {function} callback callback to execute when event fires up
* @param {object} scope scope object
*/
attach:function(elm,event,callback,scope) {
var element = $(elm);
var cb = callback;
if (scope) { cb = function() { return callback.call(scope,arguments); } }
if (element.addEventListener) { /* gecko */
element.addEventListener(event,cb,false);
} else if (element.attachEvent) { /* ie */
element.attachEvent("on"+event,cb);
} else { /* ??? */
element["on"+event] = cb;
}
},
/**
* detaches an event from given element
* @param {node} elm detach event from this element
* @param {object} event event to be detached
* @param {function} callback event callback
*/
detach:function(elm,event,callback) {
var element = $(elm);
if (element.removeEventListener) { /* gecko */
element.removeEventListener(event,callback,false);
} else if (element.detachEvent) { /* ie */
element.detachEvent("on"+event,callback);
} else { /* ??? */
element["on"+event] = false;
}
},
/**
* returns event source element
* @returns {node} event source
*/
source:function(event) {
return (event.target ? event.target : event.srcElement);
},
/**
* cancels event propagation up the event tree
*/
cancel:function(event) {
event.cancelBubble = true;
if (event.stopPropagation) { event.stopPropagation(); }
},
/**
* returns position of the event
* @returns {array} [x,y]
*/
position:function(event) {
var scroll = OAT.Dom.getScroll();
return [event.clientX+scroll[0],event.clientY+scroll[1]];
},
/**
* prevents default browser action for given event
*/
prevent:function(event) {
if (event.preventDefault) { event.preventDefault(); }
event.returnValue = false;
}
}
/**
* @namespace Messages
*/
OAT.MSG = {
DEBUG:"DEBUG",
OAT_DEBUG:"OAT_DEBUG",
OAT_LOAD:"OAT_LOAD",
ANIMATION_STOP:"ANIMATION_STOP",
TREE_EXPAND:"TREE_EXPAND",
TREE_COLLAPSE:"TREE_COLLAPSE",
DS_RECORD_PREADVANCE:"DS_RECORD_PREADVANCE",
DS_RECORD_ADVANCE:"DS_RECORD_ADVANCE",
DS_PAGE_PREADVANCE:"DS_PAGE_PREADVANCE",
DS_PAGE_ADVANCE:"DS_PAGE_ADVANCE",
AJAX_START:"AJAX_START",
AJAX_ERROR:"AJAX_ERROR",
AJAX_TIMEOUT:"AJAX_TIMEOUT",
GD_START:"GD_START",
GD_ABORT:"GD_ABORT",
GD_END:"GD_END",
DOCK_DRAG:"DOCK_DRAG",
DOCK_REMOVE:"DOCK_REMOVE",
SLB_OPENED:"SLB_OPENED",
SLB_CLOSED:"SLB_CLOSED",
GRID_CELLCLICK:"GRID_CELLCLICK",
GRID_ROWCLICK:"GRID_ROWCLICK",
API_LOADING:"API_LOADING",
API_LOADED:"API_LOADED",
STORE_LOADING:"STORE_LOADING",
STORE_LOADED:"STORE_LOADED",
STORE_LOAD_FAILED:"STORE_LOAD_FAILED",
STORE_ENABLED:"STORE_ENABLED",
STORE_DISABLED:"STORE_DISABLED",
STORE_CLEARED:"STORE_CLEARED",
STORE_REMOVED:"STORE_REMOVED",
RDFMINI_VIEW_CHANGED:"RDFMINI_VIEW_CHANGED",
registry:[],
/**
* adds new listener to registry
* @param {string || object} sender listen to messages from this sender, "*" for everyone
* @param {string} msg listen to this message, "*" for any
* @param {function} callback callback to execute upon message retrieval
*/
attach:function(sender, msg, callback) {
if (!sender) { return; }
if (!callback || typeof callback == "undefined") {
throw (new Error ("OAT.MSG.attach requires callback function."));
}
OAT.MSG.registry.push([sender, msg, callback]);
},
/**
* removes listener from registry
* @param {string || object} sender message's sender or "*"
* @param {string} msg message
* @param {function} callback callback to execute upon message retrieval
*/
detach:function(sender, msg, callback) {
if (!sender) { return; }
var index = -1;
for (var i=0;i<OAT.MSG.registry.length;i++) {
var rec = OAT.MSG.registry[i];
if (rec[0] == sender && rec[1] == msg && rec[2] == callback) { index = i; }
}
if (index != -1) { OAT.MSG.registry.splice(index,1); }
},
/**
* dispatches new message
* @param {object} sender message sender
* @param {message code} msg message string or numeric code
* @param {event} event message event
*/
send:function(sender, msg, event) {
for (var i=0;i<OAT.MSG.registry.length;i++) {
var record = OAT.MSG.registry[i];
var senderOK = (sender == record[0] || record[0] == "*");
if (!senderOK) { continue; }
var msgOK = (msg == record[1] || record[1] == "*");
if (msgOK) { record[2](sender, msg, event); }
} /* for all listeners */
} /* send message */
}
/**
* @namespace Loading
* @message LOADER_LOADING
* @message LOADER_LOADED
*/
OAT.Loader = {
_loaded: [], /* already loaded modules */
_callbacks: {}, /* array of callbacks for each module */
_cacheBuster: false,
/**
* Module finished loading, execute all its callbacks
* @param {string} name
*/
_finished: function(name) {
this._loaded.push(name);
var arr = this._callbacks[name];
for (var i=0;i<arr.length;i++) { arr[i](); }
delete this._callbacks[name];
},
/**
* Create script file name
* @param {string} name Module name
*/
_createPath: function(name) {
var url = "";
if (name.match(/:\/\//)) { /* strings with "://" are considered absolute */
url = name;
} else {
url = OAT.base+name+".js";
}
if (this._cacheBuster) {
url += (url.indexOf("?") == -1 ? "?" : "&") + Math.random();
}
return url;
},
/**
* Creates script node and adds event listener
* @param {string} name Module name
*/
_createNode: function(name) {
var script = document.createElement("script");
script.type = "text/javascript";
var loader = this;
if (script.addEventListener) {
script.addEventListener("load", function() { loader._finished(name); } ,false);
script.addEventListener("error", function() { loader._finished(name); } ,false);
} else {
script.attachEvent("onreadystatechange", function() {
if (script.readyState == 'loaded' || script.readyState == 'complete') {
loader._finished(name);
}
});
}
script.src = this._createPath(name);
document.getElementsByTagName("head")[0].appendChild(script);
},
/**
* Load all dependencies for "name", then execute callback
* @param {string} name Module name
* @param {function} callback To be executed
*/
_loadDependencies: function(name, callback) {
if (name in this._depends) {
this.load(this._depends[name], callback);
} else {
if (callback) { callback(); }
}
},
/**
* Loads one module, then execute callback
* @param {string} name Module name
* @param {function} callback To be executed
*/
_loadOne: function(name, callback) { /* load one module */
if (this.isLoaded(name)) {
if (callback) { callback(); }
return;
}
var loader = this;
var after = function() { /* to be executed when dependencies are met */
var arr = []; /* list of load callbacks */
if (name in loader._callbacks) {
arr = loader._callbacks[name];
} else {
loader._callbacks[name] = arr;
}
if (arr.length) { /* someone else already waits */
arr.push(callback); /* add ourself to queue */
} else { /* we are first */
arr.push(callback);
loader._createNode(name);
}
}
this._loadDependencies(name, after);
},
/**
* Loads all modules, then execute callback
* @param {string[]} modules Module names
* @param {function} callback To be executed
* @param {function[]} [dependencies] Explicit dependencies
*/
load: function(modules, callback, dependencies) {
if (dependencies) {
var thisf = arguments.callee; /* this function */
var thiso = this; /* this object */
thisf.call(thiso, dependencies, function() {
thisf.call(thiso, modules, callback);
});
}
var m = modules;
if (!(m instanceof Array)) { m = [m]; }
OAT.MSG.send(this, "LOADER_LOADING", m);
var count = m.length;
var done = function() { /* after each module loads */
count--;
if (!count) {
OAT.MSG.send(this, "LOADER_LOADED", m);
if (callback) { callback(); }
}
}
if (count) {
for (var i=0;i<m.length;i++) {
this._loadOne(m[i], done);
}
} else {
OAT.MSG.send(this, "LOADER_LOADED", m);
if (callback) { callback(); }
}
},
/**
* Tests whether the module in question is already loaded
* @param {string} module
* @returns {bool}
*/
isLoaded: function(module) {
for (var i=0;i<this._loaded.length;i++) { /* already loaded */
if (this._loaded[i] == module) { return true; }
}
return false;
},
_depends: {
ajax:["crypto","xml"],
anchor:"win",
calendar:["drag","notify"],
color:"drag",
combobox:"instant",
combobutton:"instant",
combolist:"instant",
connection:"crypto",
datasource:["jsobj","json","xml","connection","dstransport","ajax"],
dav:["grid","tree","toolbar","ajax","xml","dialog","resize","drag"],
dereference:"ajax",
dialog:["win","dimmer"],
dock:["animation","ghostdrag","resize"],
form:["ajax","dialog","datasource","formobject","crypto"],
formobject:["drag","resize","datasource","tab","win"],
fresnel:"xml",
ghostdrag:"animation",
graph:"canvas",
graphsidebar:"tree",
graphsvg:["svg","graphsidebar","rdf","dereference"],
grid:["instant","anchor"],
linechart:"svg",
menu:"animation",
notify:"animation",
panelbar:"animation",
piechart:"svg",
pivot:["ghostdrag","statistics","instant","barchart"],
quickedit:"instant",
rdf:"xml",
rdfmini:["rdfstore","rdftabs","notify"],
rdfstore:["rdf","dereference","n3"],
rssreader:"xml",
schema:["xml"],
simplefx:"animation",
slidebar:"animation",
soap:"ajax",
sparkline:"linechart",
svgsparql:"geometry",
timeline:["slider","tlscale","resize"],
tree:"ghostdrag",
win:["drag","layers"],
ws:["xml","soap","ajax","schema","connection"],
xml:["xpath"],
xmla:["soap","xml","connection"]
},
featureLoaded: function (s) {
return (true);
}
}
OAT.init();
|