/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
- function getBrowserId()
- {
- if (top.name == null || top.name == "")
- {
- top.name = (new Date()).getTime();
- }
- return top.name;
- }
- function addBrowserIdToURL(strUrl)
- {
- if (strUrl.indexOf("__dmfClientId") == -1)
- {
- strUrl += ((strUrl.indexOf("?") == -1) ? "?" : "&");
- strUrl += "__dmfClientId=" + getBrowserId();
- }
- return strUrl;
- }
- var topLevelWnd = null;
- function getTopLevelWnd()
- {
- if (topLevelWnd == null)
- {
- topLevelWnd = this;
- while (topLevelWnd.parent != topLevelWnd && isDispatchableWindow(topLevelWnd.parent))
- {
- topLevelWnd = topLevelWnd.parent;
- }
- }
- return topLevelWnd;
- }
- getTopLevelWnd._scope = window;
- function getAbsoluteFramePath(frameName)
- {
- var absolutePath = null;
- var framePath = getRelativeFramePath(getTopLevelWnd(), frameName);
- if (framePath != null)
- {
- absolutePath = "getTopLevelWnd()." + framePath;
- }
- return absolutePath;
- }
- function getRelativeFramePath(containerFrame, frameName)
- {
- var framePath = null;
- for (var iChildFrame = 0; iChildFrame < containerFrame.frames.length; iChildFrame++)
- {
- var objChildFrame = containerFrame.frames[iChildFrame];
- if (isAccessibleWindow(objChildFrame) && objChildFrame.name == frameName)
- {
- framePath = "frames[" + iChildFrame + "]";
- break;
- }
- }
- if (framePath == null)
- {
- for (var iChildFrame = 0; iChildFrame < containerFrame.frames.length; iChildFrame++)
- {
- var childFramePath = getRelativeFramePath(containerFrame.frames[iChildFrame], frameName);
- if (childFramePath != null)
- {
- framePath = "frames[" + iChildFrame + "]." + childFramePath;
- break;
- }
- }
- }
- return framePath;
- }
- function getFrameNamePath(wnd)
- {
- // recurively build parent's frame path
- if (wnd == getTopLevelWnd())
- {
- return "";
- }
- var parent = wnd.parent;
- if (parent != null)
- {
- for (var i = 0; i < parent.frames.length; i++)
- {
- var frameWnd = parent.frames[i];
- if (frameWnd == wnd)
- {
- var parentFrameNamePath = getFrameNamePath(parent);
- if (parentFrameNamePath != null)
- {
- return parentFrameNamePath + '/' + frameWnd.name;
- }
- }
- }
- }
- return null;
- }
- function isValidFrameNamePath(frameNamePath)
- {
- return _isValidFrameNamePath(getTopLevelWnd(), frameNamePath.substring(1));
- }
- function _isValidFrameNamePath(wnd, frameNamePath)
- {
- var slash = frameNamePath.indexOf("/");
- if (slash != -1)
- {
- var frameName = frameNamePath.substring(0, slash);
- for (var i = 0; i < wnd.frames.length; i++)
- {
- if (wnd.frames[i].name == frameName)
- {
- return _isValidFrameNamePath(wnd.frames[i], frameNamePath.substring(slash+1))
- }
- }
- return false;
- }
- else
- {
- return true;
- }
- }
- function walkDownFrameSet(strFramePath)
- {
- var strResult = strFramePath;
- if ((strResult != null) && (typeof strResult != "undefined"))
- {
- var oFrame = eval(strResult);
- while (oFrame && oFrame.isNest && oFrame.isNest._scope == oFrame)
- {
- strResult += ".frames[0]";
- oFrame = eval(strResult);
- }
- }
- return strResult;
- }
- function isDispatchableWindow(wnd)
- {
- var bIsDispatchable = false;
- if (isAccessibleWindow(wnd))
- {
- if (typeof(wnd.getTopLevelWnd) != "undefined" && wnd.getTopLevelWnd._scope == wnd)
- {
- bIsDispatchable = true;
- }
- }
- return bIsDispatchable;
- }
- function isAccessibleWindow(wnd)
- {
- var bIsAccessible = false;
- try
- {
- if ("x" + wnd.location + "x" != "xx")
- {
- if (typeof(wnd.document) == "object")
- {
- bIsAccessible = true;
- }
- }
- }
- catch(e)
- {
- // If we hit errors here, we can only assume it's because of something very
- // Whatever the reason, if we can't get to something as basic as wnd.document and
- // wnd.location, WDK can't do anything with the wnd anyway. Hence return false.
- bIsAccessible = false;
- }
- return bIsAccessible;
- }
- function isWindowInitialised(wnd)
- {
- var bWindowInitialised = false;
- if (isDispatchableWindow(wnd) == true)
- {
- bWindowInitialised = _isWindowInitialised(wnd);
- }
- return bWindowInitialised;
- }
- function _isWindowInitialised(wnd)
- {
- var bWindowInitialised = false;
- if (typeof(wnd.g_bWindowInitialised) != "undefined")
- {
- bWindowInitialised = wnd.g_bWindowInitialised;
- }
- else
- {
- bWindowInitialised = true;
- }
- if ( bWindowInitialised == true && g_clientInfo.isBrowser(ClientInfo.SAFARI) )
- {
- bWindowInitialised = (wnd.document.readyState == 'complete');
- }
- return bWindowInitialised;
- }
- function isValidWindow(path)
- {
- var bValid = true;
- var wnd = eval(path);
- if ( wnd && isAccessibleWindow(wnd) )
- {
- if ( isDispatchableWindow(wnd) )
- {
- bValid = _isWindowInitialised(wnd);
- }
- else
- {
- // Currently due to the frame javascript scope bug with Safari there's no way to differentiate this case
- bValid = true;
- }
- }
- else
- {
- bValid = false;
- }
- return bValid;
- }
- function allWindowsInitialised(wnd)
- {
- var initialised = true;
- var currentWindowInitialised = isWindowInitialised(wnd);
- if ( currentWindowInitialised == true )
- {
- if (wnd.frames.length > 0)
- {
- for (var j=0; j < wnd.frames.length; j++)
- {
- initialised = allWindowsInitialised(wnd.frames[j]);
- if ( initialised == false )
- {
- break;
- }
- }
- }
- }
- else
- {
- initialised = false;
- }
- return initialised;
- }
- function createTestHook(contextPath)
- {
- var element = window.document.createElement("IMG");
- element.id = "wdk_window_initialised";
- element.src = contextPath + "/wdk/modalFade.gif";
- with (element.style)
- {
- top = 1;
- left = 1;
- width = 1;
- height = 1;
- alt = "";
- overflow = "hidden";
- position = "absolute";
- visibility = "visible";
- }
- window.document.body.appendChild(element);
- }
- function setFocusOnFrame(strFrameName)
- {
- var strFramePath = getAbsoluteFramePath(strFrameName);
- var frameWindow = eval(getAbsoluteFramePath(strFrameName));
- frameWindow.focus();
- }
- function getAbsoluteLeft(objectId)
- {
- var o = document.getElementById(objectId)
- oLeft = o.offsetLeft
- while(o.offsetParent!=null)
- {
- oParent = o.offsetParent
- oLeft += oParent.offsetLeft
- o = oParent
- }
- return oLeft
- }
- function getAbsoluteTop(objectId)
- {
- var o = document.getElementById(objectId)
- oTop = o.offsetTop
- while(o.offsetParent!=null)
- {
- oParent = o.offsetParent
- oTop += oParent.offsetTop
- o = oParent
- }
- return oTop
- }
- function getAbsoluteRight(objectId)
- {
- return getAbsoluteLeft(objectId) + document.getElementById(objectId).offsetWidth;
- }
- function getAbsoluteBottom(objectId)
- {
- return getAbsoluteTop(objectId) + document.getElementById(objectId).offsetHeight;
- }
- function ClientInfo() {
- this.m_browserInfo = new Array();
- this.m_platformInfo = new Array();
- this.m_browserVersion = "";
- this.m_browserVersionMajor = "";
- this.m_browserVersionMinor = "";
- this.m_initialized = false;
- this.init();
- };
- ClientInfo.prototype.isBrowser = function(oBrowser)
- {
- return (typeof this.m_browserInfo[oBrowser.getId()] != 'undefined');
- };
- ClientInfo.prototype.isPlatform = function(oPlatform)
- {
- return (typeof this.m_platformInfo[oPlatform.getId()] != 'undefined');
- };
- ClientInfo.prototype.getBrowserVersion = function()
- {
- return this.m_browserVersion;
- };
- ClientInfo.prototype.getBrowserVersionMajor = function()
- {
- return this.m_browserVersionMajor;
- };
- ClientInfo.prototype.getBrowserVersionMinor = function()
- {
- return this.m_browserVersionMinor;
- };
- ClientInfo.prototype.isBrowserVersionSupported = function(strSupportedList)
- {
- var bIsSupported = false;
- if (strSupportedList)
- {
- var verarr = strSupportedList.split(",");
- var majorMinor = this.getBrowserVersionMajor() + "." + this.getBrowserVersionMinor().split(".")[0];
- for (i=0; i<verarr.length; i++)
- {
- if (verarr[i].indexOf(majorMinor, 0) != -1)
- {
- bIsSupported = true;
- break;
- }
- }
- if (!bIsSupported)
- {
- bIsSupported = (strSupportedList.indexOf(this.getBrowserVersion()) != -1);
- }
- }
- return bIsSupported;
- };
- ClientInfo.prototype.isJavaEnabled = function()
- {
- return navigator.javaEnabled();
- };
- ClientInfo.prototype.toString = function()
- {
- var buf = "Browsers=[";
- var browsers = "";
- for (var i in this.m_browserInfo)
- {
- if (browsers != "") browsers += ",";
- browsers += this.m_browserInfo[i].getId();
- }
- buf += browsers + "];";
- buf += "Platforms=[";
- var platforms = "";
- for (var j in this.m_platformInfo)
- {
- if (platforms != "") platforms += ",";
- platforms += this.m_platformInfo[j].getId();
- }
- buf += platforms + "];";
- buf += "BrowserVersions(Full,Maj,Min)=" + this.m_browserVersion + "," + this.m_browserVersionMajor + "," + this.m_browserVersionMinor +";";
- buf += "Initialized=" + this.m_initialized;
- return buf;
- };
- function Platform(strId) {
- this.strId = strId;
- };
- Platform.prototype.getId = function() {
- return this.strId;
- };
- function Browser(strId) {
- this.strId = strId;
- };
- Browser.prototype.getId = function() {
- return this.strId;
- };
- ClientInfo.MOZILLA = new Browser("MOZILLA");
- ClientInfo.MSIE = new Browser("MSIE");
- ClientInfo.NETSCAPE = new Browser("NETSCAPE");
- ClientInfo.SAFARI = new Browser("SAFARI");
- ClientInfo.FIREFOX = new Browser("FIREFOX");
- ClientInfo.MACOS = new Platform("MACOS");
- ClientInfo.MACOS_9 = new Platform("MACOS_9");
- ClientInfo.MACOS_X = new Platform("MACOS_X");
- ClientInfo.SUNOS = new Platform("SUNOS");
- ClientInfo.LINUX = new Platform("LINUX");
- ClientInfo.UNIX = new Platform("UNIX");
- ClientInfo.WIN2K = new Platform("WIN2K");
- ClientInfo.WINNT = new Platform("WINNT");
- ClientInfo.WINXP = new Platform("WINXP");
- ClientInfo.WIN = new Platform("WIN");
- ClientInfo.UNKNOWN_BROWSER = new Browser("UNKNOWN_BROWSER");
- ClientInfo.UNKNOWN_PLATFORM = new Platform("UNKNOWN_PLATFORM");
- ClientInfo.prototype.isInitialized = function()
- {
- return this.m_initialized;
- };
- ClientInfo.prototype.init = function()
- {
- if (this.isInitialized() == false)
- {
- var userAgent = navigator.userAgent.toLowerCase();
- var is_ie = ((userAgent.indexOf("msie") != -1) && (userAgent.indexOf("opera") == -1));
- var is_safari = ((userAgent.indexOf("safari") != -1));
- if (is_ie)
- {
- this.setClientBrowser(ClientInfo.MSIE);
- }
- else if (is_safari)
- {
- this.setClientBrowser(ClientInfo.SAFARI);
- }
- else
- {
- var is_moz = ((userAgent.indexOf("mozilla") != -1) && (userAgent.indexOf("spoofer") == -1)
- && (userAgent.indexOf("compatible") == -1) && (userAgent.indexOf("opera") == -1)
- && (userAgent.indexOf("webtv") == -1) && (userAgent.indexOf("hotjava") == -1));
- var is_netscape = is_moz && (userAgent.indexOf("netscape") != -1);
- if (is_moz)
- {
- this.setClientBrowser(ClientInfo.MOZILLA);
- if (userAgent.indexOf("firefox") != -1)
- {
- this.setClientBrowser(ClientInfo.FIREFOX);
- }
- }
- if (is_netscape)
- {
- this.setClientBrowser(ClientInfo.NETSCAPE);
- }
- }
- if ((this.isClientBrowserKnown()) == false)
- {
- this.setClientBrowser(ClientInfo.UNKNOWN_BROWSER);
- }
- var is_win = ((userAgent.indexOf("windows") != -1) || (userAgent.indexOf("16bit") != -1));
- var is_mac = (userAgent.indexOf("mac") != -1);
- var is_maxosx = (is_mac && userAgent.indexOf("mac os x") != -1);
- var is_linux = (userAgent.indexOf("linux") != -1);
- var is_sunos = (userAgent.indexOf("sunos") != -1);
- var is_unix = !is_win &&
- (is_maxosx || is_linux || is_sunos
- || (userAgent.indexOf("x11") != -1)
- || (userAgent.indexOf("irix") != -1)
- || (userAgent.indexOf("hp-ux") != -1)
- || ((userAgent.indexOf("sco") != -1) || (userAgent.indexOf("unix_sv") != -1))
- || (userAgent.indexOf("unix_system_v") != -1)
- || (userAgent.indexOf("ncr") != -1)
- || (userAgent.indexOf("reliantunix") != -1)
- || ((userAgent.indexOf("dec") != -1) || (userAgent.indexOf("osf1") != -1) ||
- (userAgent.indexOf("dec_alpha") != -1) || (userAgent.indexOf("alphaserver") != -1) ||
- (userAgent.indexOf("ultrix") != -1) || (userAgent.indexOf("alphastation") != -1))
- || (userAgent.indexOf("sinix") != -1)
- || (userAgent.indexOf("aix") != -1)
- || (userAgent.indexOf("inux") != -1)
- || (userAgent.indexOf("bsd") != -1)
- || (userAgent.indexOf("freebsd") != -1));
- if (is_win)
- {
- this.setClientPlatform(ClientInfo.WIN);
- if (is_win && ((userAgent.indexOf("windows nt 5.1") != -1)))
- {
- this.setClientPlatform(ClientInfo.WINXP);
- }
- else if (is_win && ((userAgent.indexOf("windows nt 5.0") != -1)))
- {
- this.setClientPlatform(ClientInfo.WIN2K);
- }
- else if (is_win && ((userAgent.indexOf("windows nt 4.0") != -1)))
- {
- this.setClientPlatform(ClientInfo.WINNT);
- }
- }
- else if (is_mac)
- {
- this.setClientPlatform(ClientInfo.MACOS);
- if (is_maxosx)
- {
- this.setClientPlatform(ClientInfo.MACOS_X);
- }
- else
- {
- var is_macos9 = (is_mac && !is_maxosx);
- if (is_macos9)
- {
- this.setClientPlatform(ClientInfo.MACOS_9);
- }
- }
- }
- else if (is_linux)
- {
- this.setClientPlatform(ClientInfo.LINUX);
- }
- if (is_unix)
- {
- this.setClientPlatform(ClientInfo.UNIX);
- }
- if ((this.isClientPlatformKnown()) == false)
- {
- this.setClientPlatform(ClientInfo.UNKNOWN_PLATFORM);
- }
- this.initBrowserVersion(userAgent);
- this.m_initialized = true;
- }
- };
- ClientInfo.prototype.initBrowserVersion = function(userAgent)
- {
- var recognizedAgent = false;
- if (userAgent)
- {
- var startIndex = -1;
- var endIndex = -1;
- if (this.isBrowser(ClientInfo.NETSCAPE) || this.isBrowser(ClientInfo.FIREFOX))
- {
- startIndex = userAgent.lastIndexOf("/");
- if (startIndex != -1)
- {
- startIndex = startIndex + 1;
- endIndex = userAgent.indexOf(" ", startIndex);
- if (endIndex == -1)
- {
- endIndex = userAgent.length;
- }
- }
- }
- else if (this.isBrowser(ClientInfo.MSIE))
- {
- startIndex = userAgent.indexOf("msie ");
- if (startIndex != -1)
- {
- startIndex = startIndex + 5;
- endIndex = userAgent.indexOf(";", startIndex);
- }
- }
- else if (this.isBrowser(ClientInfo.MOZILLA))
- {
- startIndex = userAgent.indexOf("rv:");
- if (startIndex != -1)
- {
- startIndex = startIndex + 3;
- endIndex = userAgent.indexOf(")", startIndex);
- }
- }
- else if (this.isBrowser(ClientInfo.SAFARI))
- {
- startIndex = userAgent.lastIndexOf("/");
- if (startIndex != -1)
- {
- startIndex = startIndex + 1;
- endIndex = userAgent.length;
- }
- }
- if (startIndex != -1 && endIndex != -1 && startIndex < endIndex)
- {
- recognizedAgent = true;
- this.m_browserVersion = userAgent.substring( startIndex, endIndex );
- var decimalIndex = this.m_browserVersion.indexOf(".");
- if (decimalIndex != -1)
- {
- this.m_browserVersionMajor = this.m_browserVersion.substring(0, decimalIndex);
- this.m_browserVersionMinor = this.m_browserVersion.substring(decimalIndex+1);
- }
- else
- {
- this.m_browserVersionMajor = this.m_browserVersion;
- this.m_browserVersionMinor = "";
- }
- }
- }
- if (recognizedAgent == false)
- {
- this.m_browserVersion = "";
- this.m_browserVersionMinor = "";
- this.m_browserVersionMajor = "";
- }
- };
- ClientInfo.prototype.setClientBrowser = function(oBrowser)
- {
- this.m_browserInfo[oBrowser.getId()] = oBrowser;
- };
- ClientInfo.prototype.setClientPlatform = function(oPlatform)
- {
- this.m_platformInfo[oPlatform.getId()] = oPlatform;
- };
- ClientInfo.prototype.isClientBrowserKnown = function()
- {
- return (this.getLength(this.m_browserInfo) > 0);
- };
- ClientInfo.prototype.isClientPlatformKnown = function()
- {
- return (this.getLength(this.m_platformInfo) > 0);
- };
- ClientInfo.prototype.getLength = function(assocArray)
- {
- var i = 0;
- for (var p in assocArray)
- {
- i++;
- }
- return i;
- };
- var g_clientInfo = new ClientInfo();