PageRenderTime 125ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/epa-cms3/dist/wdk/include/locate.js

https://bitbucket.org/bdiperna/cms
JavaScript | 607 lines | 602 code | 0 blank | 5 comment | 210 complexity | 2de504f27238619a8b956630408f4324 MD5 | raw file
  1. function getBrowserId()
  2. {
  3. if (top.name == null || top.name == "")
  4. {
  5. top.name = (new Date()).getTime();
  6. }
  7. return top.name;
  8. }
  9. function addBrowserIdToURL(strUrl)
  10. {
  11. if (strUrl.indexOf("__dmfClientId") == -1)
  12. {
  13. strUrl += ((strUrl.indexOf("?") == -1) ? "?" : "&");
  14. strUrl += "__dmfClientId=" + getBrowserId();
  15. }
  16. return strUrl;
  17. }
  18. var topLevelWnd = null;
  19. function getTopLevelWnd()
  20. {
  21. if (topLevelWnd == null)
  22. {
  23. topLevelWnd = this;
  24. while (topLevelWnd.parent != topLevelWnd && isDispatchableWindow(topLevelWnd.parent))
  25. {
  26. topLevelWnd = topLevelWnd.parent;
  27. }
  28. }
  29. return topLevelWnd;
  30. }
  31. getTopLevelWnd._scope = window;
  32. function getAbsoluteFramePath(frameName)
  33. {
  34. var absolutePath = null;
  35. var framePath = getRelativeFramePath(getTopLevelWnd(), frameName);
  36. if (framePath != null)
  37. {
  38. absolutePath = "getTopLevelWnd()." + framePath;
  39. }
  40. return absolutePath;
  41. }
  42. function getRelativeFramePath(containerFrame, frameName)
  43. {
  44. var framePath = null;
  45. for (var iChildFrame = 0; iChildFrame < containerFrame.frames.length; iChildFrame++)
  46. {
  47. var objChildFrame = containerFrame.frames[iChildFrame];
  48. if (isAccessibleWindow(objChildFrame) && objChildFrame.name == frameName)
  49. {
  50. framePath = "frames[" + iChildFrame + "]";
  51. break;
  52. }
  53. }
  54. if (framePath == null)
  55. {
  56. for (var iChildFrame = 0; iChildFrame < containerFrame.frames.length; iChildFrame++)
  57. {
  58. var childFramePath = getRelativeFramePath(containerFrame.frames[iChildFrame], frameName);
  59. if (childFramePath != null)
  60. {
  61. framePath = "frames[" + iChildFrame + "]." + childFramePath;
  62. break;
  63. }
  64. }
  65. }
  66. return framePath;
  67. }
  68. function getFrameNamePath(wnd)
  69. {
  70. // recurively build parent's frame path
  71. if (wnd == getTopLevelWnd())
  72. {
  73. return "";
  74. }
  75. var parent = wnd.parent;
  76. if (parent != null)
  77. {
  78. for (var i = 0; i < parent.frames.length; i++)
  79. {
  80. var frameWnd = parent.frames[i];
  81. if (frameWnd == wnd)
  82. {
  83. var parentFrameNamePath = getFrameNamePath(parent);
  84. if (parentFrameNamePath != null)
  85. {
  86. return parentFrameNamePath + '/' + frameWnd.name;
  87. }
  88. }
  89. }
  90. }
  91. return null;
  92. }
  93. function isValidFrameNamePath(frameNamePath)
  94. {
  95. return _isValidFrameNamePath(getTopLevelWnd(), frameNamePath.substring(1));
  96. }
  97. function _isValidFrameNamePath(wnd, frameNamePath)
  98. {
  99. var slash = frameNamePath.indexOf("/");
  100. if (slash != -1)
  101. {
  102. var frameName = frameNamePath.substring(0, slash);
  103. for (var i = 0; i < wnd.frames.length; i++)
  104. {
  105. if (wnd.frames[i].name == frameName)
  106. {
  107. return _isValidFrameNamePath(wnd.frames[i], frameNamePath.substring(slash+1))
  108. }
  109. }
  110. return false;
  111. }
  112. else
  113. {
  114. return true;
  115. }
  116. }
  117. function walkDownFrameSet(strFramePath)
  118. {
  119. var strResult = strFramePath;
  120. if ((strResult != null) && (typeof strResult != "undefined"))
  121. {
  122. var oFrame = eval(strResult);
  123. while (oFrame && oFrame.isNest && oFrame.isNest._scope == oFrame)
  124. {
  125. strResult += ".frames[0]";
  126. oFrame = eval(strResult);
  127. }
  128. }
  129. return strResult;
  130. }
  131. function isDispatchableWindow(wnd)
  132. {
  133. var bIsDispatchable = false;
  134. if (isAccessibleWindow(wnd))
  135. {
  136. if (typeof(wnd.getTopLevelWnd) != "undefined" && wnd.getTopLevelWnd._scope == wnd)
  137. {
  138. bIsDispatchable = true;
  139. }
  140. }
  141. return bIsDispatchable;
  142. }
  143. function isAccessibleWindow(wnd)
  144. {
  145. var bIsAccessible = false;
  146. try
  147. {
  148. if ("x" + wnd.location + "x" != "xx")
  149. {
  150. if (typeof(wnd.document) == "object")
  151. {
  152. bIsAccessible = true;
  153. }
  154. }
  155. }
  156. catch(e)
  157. {
  158. // If we hit errors here, we can only assume it's because of something very
  159. // Whatever the reason, if we can't get to something as basic as wnd.document and
  160. // wnd.location, WDK can't do anything with the wnd anyway. Hence return false.
  161. bIsAccessible = false;
  162. }
  163. return bIsAccessible;
  164. }
  165. function isWindowInitialised(wnd)
  166. {
  167. var bWindowInitialised = false;
  168. if (isDispatchableWindow(wnd) == true)
  169. {
  170. bWindowInitialised = _isWindowInitialised(wnd);
  171. }
  172. return bWindowInitialised;
  173. }
  174. function _isWindowInitialised(wnd)
  175. {
  176. var bWindowInitialised = false;
  177. if (typeof(wnd.g_bWindowInitialised) != "undefined")
  178. {
  179. bWindowInitialised = wnd.g_bWindowInitialised;
  180. }
  181. else
  182. {
  183. bWindowInitialised = true;
  184. }
  185. if ( bWindowInitialised == true && g_clientInfo.isBrowser(ClientInfo.SAFARI) )
  186. {
  187. bWindowInitialised = (wnd.document.readyState == 'complete');
  188. }
  189. return bWindowInitialised;
  190. }
  191. function isValidWindow(path)
  192. {
  193. var bValid = true;
  194. var wnd = eval(path);
  195. if ( wnd && isAccessibleWindow(wnd) )
  196. {
  197. if ( isDispatchableWindow(wnd) )
  198. {
  199. bValid = _isWindowInitialised(wnd);
  200. }
  201. else
  202. {
  203. // Currently due to the frame javascript scope bug with Safari there's no way to differentiate this case
  204. bValid = true;
  205. }
  206. }
  207. else
  208. {
  209. bValid = false;
  210. }
  211. return bValid;
  212. }
  213. function allWindowsInitialised(wnd)
  214. {
  215. var initialised = true;
  216. var currentWindowInitialised = isWindowInitialised(wnd);
  217. if ( currentWindowInitialised == true )
  218. {
  219. if (wnd.frames.length > 0)
  220. {
  221. for (var j=0; j < wnd.frames.length; j++)
  222. {
  223. initialised = allWindowsInitialised(wnd.frames[j]);
  224. if ( initialised == false )
  225. {
  226. break;
  227. }
  228. }
  229. }
  230. }
  231. else
  232. {
  233. initialised = false;
  234. }
  235. return initialised;
  236. }
  237. function createTestHook(contextPath)
  238. {
  239. var element = window.document.createElement("IMG");
  240. element.id = "wdk_window_initialised";
  241. element.src = contextPath + "/wdk/modalFade.gif";
  242. with (element.style)
  243. {
  244. top = 1;
  245. left = 1;
  246. width = 1;
  247. height = 1;
  248. alt = "";
  249. overflow = "hidden";
  250. position = "absolute";
  251. visibility = "visible";
  252. }
  253. window.document.body.appendChild(element);
  254. }
  255. function setFocusOnFrame(strFrameName)
  256. {
  257. var strFramePath = getAbsoluteFramePath(strFrameName);
  258. var frameWindow = eval(getAbsoluteFramePath(strFrameName));
  259. frameWindow.focus();
  260. }
  261. function getAbsoluteLeft(objectId)
  262. {
  263. var o = document.getElementById(objectId)
  264. oLeft = o.offsetLeft
  265. while(o.offsetParent!=null)
  266. {
  267. oParent = o.offsetParent
  268. oLeft += oParent.offsetLeft
  269. o = oParent
  270. }
  271. return oLeft
  272. }
  273. function getAbsoluteTop(objectId)
  274. {
  275. var o = document.getElementById(objectId)
  276. oTop = o.offsetTop
  277. while(o.offsetParent!=null)
  278. {
  279. oParent = o.offsetParent
  280. oTop += oParent.offsetTop
  281. o = oParent
  282. }
  283. return oTop
  284. }
  285. function getAbsoluteRight(objectId)
  286. {
  287. return getAbsoluteLeft(objectId) + document.getElementById(objectId).offsetWidth;
  288. }
  289. function getAbsoluteBottom(objectId)
  290. {
  291. return getAbsoluteTop(objectId) + document.getElementById(objectId).offsetHeight;
  292. }
  293. function ClientInfo() {
  294. this.m_browserInfo = new Array();
  295. this.m_platformInfo = new Array();
  296. this.m_browserVersion = "";
  297. this.m_browserVersionMajor = "";
  298. this.m_browserVersionMinor = "";
  299. this.m_initialized = false;
  300. this.init();
  301. };
  302. ClientInfo.prototype.isBrowser = function(oBrowser)
  303. {
  304. return (typeof this.m_browserInfo[oBrowser.getId()] != 'undefined');
  305. };
  306. ClientInfo.prototype.isPlatform = function(oPlatform)
  307. {
  308. return (typeof this.m_platformInfo[oPlatform.getId()] != 'undefined');
  309. };
  310. ClientInfo.prototype.getBrowserVersion = function()
  311. {
  312. return this.m_browserVersion;
  313. };
  314. ClientInfo.prototype.getBrowserVersionMajor = function()
  315. {
  316. return this.m_browserVersionMajor;
  317. };
  318. ClientInfo.prototype.getBrowserVersionMinor = function()
  319. {
  320. return this.m_browserVersionMinor;
  321. };
  322. ClientInfo.prototype.isBrowserVersionSupported = function(strSupportedList)
  323. {
  324. var bIsSupported = false;
  325. if (strSupportedList)
  326. {
  327. var verarr = strSupportedList.split(",");
  328. var majorMinor = this.getBrowserVersionMajor() + "." + this.getBrowserVersionMinor().split(".")[0];
  329. for (i=0; i<verarr.length; i++)
  330. {
  331. if (verarr[i].indexOf(majorMinor, 0) != -1)
  332. {
  333. bIsSupported = true;
  334. break;
  335. }
  336. }
  337. if (!bIsSupported)
  338. {
  339. bIsSupported = (strSupportedList.indexOf(this.getBrowserVersion()) != -1);
  340. }
  341. }
  342. return bIsSupported;
  343. };
  344. ClientInfo.prototype.isJavaEnabled = function()
  345. {
  346. return navigator.javaEnabled();
  347. };
  348. ClientInfo.prototype.toString = function()
  349. {
  350. var buf = "Browsers=[";
  351. var browsers = "";
  352. for (var i in this.m_browserInfo)
  353. {
  354. if (browsers != "") browsers += ",";
  355. browsers += this.m_browserInfo[i].getId();
  356. }
  357. buf += browsers + "];";
  358. buf += "Platforms=[";
  359. var platforms = "";
  360. for (var j in this.m_platformInfo)
  361. {
  362. if (platforms != "") platforms += ",";
  363. platforms += this.m_platformInfo[j].getId();
  364. }
  365. buf += platforms + "];";
  366. buf += "BrowserVersions(Full,Maj,Min)=" + this.m_browserVersion + "," + this.m_browserVersionMajor + "," + this.m_browserVersionMinor +";";
  367. buf += "Initialized=" + this.m_initialized;
  368. return buf;
  369. };
  370. function Platform(strId) {
  371. this.strId = strId;
  372. };
  373. Platform.prototype.getId = function() {
  374. return this.strId;
  375. };
  376. function Browser(strId) {
  377. this.strId = strId;
  378. };
  379. Browser.prototype.getId = function() {
  380. return this.strId;
  381. };
  382. ClientInfo.MOZILLA = new Browser("MOZILLA");
  383. ClientInfo.MSIE = new Browser("MSIE");
  384. ClientInfo.NETSCAPE = new Browser("NETSCAPE");
  385. ClientInfo.SAFARI = new Browser("SAFARI");
  386. ClientInfo.FIREFOX = new Browser("FIREFOX");
  387. ClientInfo.MACOS = new Platform("MACOS");
  388. ClientInfo.MACOS_9 = new Platform("MACOS_9");
  389. ClientInfo.MACOS_X = new Platform("MACOS_X");
  390. ClientInfo.SUNOS = new Platform("SUNOS");
  391. ClientInfo.LINUX = new Platform("LINUX");
  392. ClientInfo.UNIX = new Platform("UNIX");
  393. ClientInfo.WIN2K = new Platform("WIN2K");
  394. ClientInfo.WINNT = new Platform("WINNT");
  395. ClientInfo.WINXP = new Platform("WINXP");
  396. ClientInfo.WIN = new Platform("WIN");
  397. ClientInfo.UNKNOWN_BROWSER = new Browser("UNKNOWN_BROWSER");
  398. ClientInfo.UNKNOWN_PLATFORM = new Platform("UNKNOWN_PLATFORM");
  399. ClientInfo.prototype.isInitialized = function()
  400. {
  401. return this.m_initialized;
  402. };
  403. ClientInfo.prototype.init = function()
  404. {
  405. if (this.isInitialized() == false)
  406. {
  407. var userAgent = navigator.userAgent.toLowerCase();
  408. var is_ie = ((userAgent.indexOf("msie") != -1) && (userAgent.indexOf("opera") == -1));
  409. var is_safari = ((userAgent.indexOf("safari") != -1));
  410. if (is_ie)
  411. {
  412. this.setClientBrowser(ClientInfo.MSIE);
  413. }
  414. else if (is_safari)
  415. {
  416. this.setClientBrowser(ClientInfo.SAFARI);
  417. }
  418. else
  419. {
  420. var is_moz = ((userAgent.indexOf("mozilla") != -1) && (userAgent.indexOf("spoofer") == -1)
  421. && (userAgent.indexOf("compatible") == -1) && (userAgent.indexOf("opera") == -1)
  422. && (userAgent.indexOf("webtv") == -1) && (userAgent.indexOf("hotjava") == -1));
  423. var is_netscape = is_moz && (userAgent.indexOf("netscape") != -1);
  424. if (is_moz)
  425. {
  426. this.setClientBrowser(ClientInfo.MOZILLA);
  427. if (userAgent.indexOf("firefox") != -1)
  428. {
  429. this.setClientBrowser(ClientInfo.FIREFOX);
  430. }
  431. }
  432. if (is_netscape)
  433. {
  434. this.setClientBrowser(ClientInfo.NETSCAPE);
  435. }
  436. }
  437. if ((this.isClientBrowserKnown()) == false)
  438. {
  439. this.setClientBrowser(ClientInfo.UNKNOWN_BROWSER);
  440. }
  441. var is_win = ((userAgent.indexOf("windows") != -1) || (userAgent.indexOf("16bit") != -1));
  442. var is_mac = (userAgent.indexOf("mac") != -1);
  443. var is_maxosx = (is_mac && userAgent.indexOf("mac os x") != -1);
  444. var is_linux = (userAgent.indexOf("linux") != -1);
  445. var is_sunos = (userAgent.indexOf("sunos") != -1);
  446. var is_unix = !is_win &&
  447. (is_maxosx || is_linux || is_sunos
  448. || (userAgent.indexOf("x11") != -1)
  449. || (userAgent.indexOf("irix") != -1)
  450. || (userAgent.indexOf("hp-ux") != -1)
  451. || ((userAgent.indexOf("sco") != -1) || (userAgent.indexOf("unix_sv") != -1))
  452. || (userAgent.indexOf("unix_system_v") != -1)
  453. || (userAgent.indexOf("ncr") != -1)
  454. || (userAgent.indexOf("reliantunix") != -1)
  455. || ((userAgent.indexOf("dec") != -1) || (userAgent.indexOf("osf1") != -1) ||
  456. (userAgent.indexOf("dec_alpha") != -1) || (userAgent.indexOf("alphaserver") != -1) ||
  457. (userAgent.indexOf("ultrix") != -1) || (userAgent.indexOf("alphastation") != -1))
  458. || (userAgent.indexOf("sinix") != -1)
  459. || (userAgent.indexOf("aix") != -1)
  460. || (userAgent.indexOf("inux") != -1)
  461. || (userAgent.indexOf("bsd") != -1)
  462. || (userAgent.indexOf("freebsd") != -1));
  463. if (is_win)
  464. {
  465. this.setClientPlatform(ClientInfo.WIN);
  466. if (is_win && ((userAgent.indexOf("windows nt 5.1") != -1)))
  467. {
  468. this.setClientPlatform(ClientInfo.WINXP);
  469. }
  470. else if (is_win && ((userAgent.indexOf("windows nt 5.0") != -1)))
  471. {
  472. this.setClientPlatform(ClientInfo.WIN2K);
  473. }
  474. else if (is_win && ((userAgent.indexOf("windows nt 4.0") != -1)))
  475. {
  476. this.setClientPlatform(ClientInfo.WINNT);
  477. }
  478. }
  479. else if (is_mac)
  480. {
  481. this.setClientPlatform(ClientInfo.MACOS);
  482. if (is_maxosx)
  483. {
  484. this.setClientPlatform(ClientInfo.MACOS_X);
  485. }
  486. else
  487. {
  488. var is_macos9 = (is_mac && !is_maxosx);
  489. if (is_macos9)
  490. {
  491. this.setClientPlatform(ClientInfo.MACOS_9);
  492. }
  493. }
  494. }
  495. else if (is_linux)
  496. {
  497. this.setClientPlatform(ClientInfo.LINUX);
  498. }
  499. if (is_unix)
  500. {
  501. this.setClientPlatform(ClientInfo.UNIX);
  502. }
  503. if ((this.isClientPlatformKnown()) == false)
  504. {
  505. this.setClientPlatform(ClientInfo.UNKNOWN_PLATFORM);
  506. }
  507. this.initBrowserVersion(userAgent);
  508. this.m_initialized = true;
  509. }
  510. };
  511. ClientInfo.prototype.initBrowserVersion = function(userAgent)
  512. {
  513. var recognizedAgent = false;
  514. if (userAgent)
  515. {
  516. var startIndex = -1;
  517. var endIndex = -1;
  518. if (this.isBrowser(ClientInfo.NETSCAPE) || this.isBrowser(ClientInfo.FIREFOX))
  519. {
  520. startIndex = userAgent.lastIndexOf("/");
  521. if (startIndex != -1)
  522. {
  523. startIndex = startIndex + 1;
  524. endIndex = userAgent.indexOf(" ", startIndex);
  525. if (endIndex == -1)
  526. {
  527. endIndex = userAgent.length;
  528. }
  529. }
  530. }
  531. else if (this.isBrowser(ClientInfo.MSIE))
  532. {
  533. startIndex = userAgent.indexOf("msie ");
  534. if (startIndex != -1)
  535. {
  536. startIndex = startIndex + 5;
  537. endIndex = userAgent.indexOf(";", startIndex);
  538. }
  539. }
  540. else if (this.isBrowser(ClientInfo.MOZILLA))
  541. {
  542. startIndex = userAgent.indexOf("rv:");
  543. if (startIndex != -1)
  544. {
  545. startIndex = startIndex + 3;
  546. endIndex = userAgent.indexOf(")", startIndex);
  547. }
  548. }
  549. else if (this.isBrowser(ClientInfo.SAFARI))
  550. {
  551. startIndex = userAgent.lastIndexOf("/");
  552. if (startIndex != -1)
  553. {
  554. startIndex = startIndex + 1;
  555. endIndex = userAgent.length;
  556. }
  557. }
  558. if (startIndex != -1 && endIndex != -1 && startIndex < endIndex)
  559. {
  560. recognizedAgent = true;
  561. this.m_browserVersion = userAgent.substring( startIndex, endIndex );
  562. var decimalIndex = this.m_browserVersion.indexOf(".");
  563. if (decimalIndex != -1)
  564. {
  565. this.m_browserVersionMajor = this.m_browserVersion.substring(0, decimalIndex);
  566. this.m_browserVersionMinor = this.m_browserVersion.substring(decimalIndex+1);
  567. }
  568. else
  569. {
  570. this.m_browserVersionMajor = this.m_browserVersion;
  571. this.m_browserVersionMinor = "";
  572. }
  573. }
  574. }
  575. if (recognizedAgent == false)
  576. {
  577. this.m_browserVersion = "";
  578. this.m_browserVersionMinor = "";
  579. this.m_browserVersionMajor = "";
  580. }
  581. };
  582. ClientInfo.prototype.setClientBrowser = function(oBrowser)
  583. {
  584. this.m_browserInfo[oBrowser.getId()] = oBrowser;
  585. };
  586. ClientInfo.prototype.setClientPlatform = function(oPlatform)
  587. {
  588. this.m_platformInfo[oPlatform.getId()] = oPlatform;
  589. };
  590. ClientInfo.prototype.isClientBrowserKnown = function()
  591. {
  592. return (this.getLength(this.m_browserInfo) > 0);
  593. };
  594. ClientInfo.prototype.isClientPlatformKnown = function()
  595. {
  596. return (this.getLength(this.m_platformInfo) > 0);
  597. };
  598. ClientInfo.prototype.getLength = function(assocArray)
  599. {
  600. var i = 0;
  601. for (var p in assocArray)
  602. {
  603. i++;
  604. }
  605. return i;
  606. };
  607. var g_clientInfo = new ClientInfo();