123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732 |
- function CScriptLoader(sWebContentRoot)
- {
-
- this.m_oFiles = {};
-
- this.m_aScripts = [];
-
- this.m_aDocumentWriters = [];
- this.m_ajaxWarnings = [];
- this.m_bIgnoreAjaxWarnings = false;
-
- this.m_bHandleStylesheetLimit = false;
-
-
- this.m_iInterval = 20;
-
- this.m_reFindCssPath = new RegExp('<link[^>]*href="([^"]*)"', "i");
-
- this.m_reFindInlineStyle = /<style\b(\s|.)*?<\/style>/gi;
-
- this.m_reHasCss = /<link .*?>/gi;
-
- this.m_reIsCss = /\.css$/i;
-
- this.m_reIsJavascript = /\.js$/i;
-
- this.m_reIsPromptingLocaleJavascript = /prompting.res.[promptingStrings|promptLocale].*\.js$/i;
-
- this.m_reScriptTagClose = /\s*<\/script>.*?$/i;
-
- this.m_reScriptTagOpen = /^.*?<script[^>]*>\s*/i;
-
- this.m_reStyleTagClose = /(-|>|\s)*<\/style>\s*$/gi;
-
- this.m_reStyleTagOpen = /^\s*<style[^>]*>(\s|<|!|-)*/gi;
-
- this.m_reEscapedCharacters = /\\[\\"']/g;
-
- this.m_reStringLiterals = /("|')[\s\S]*?\1/g;
-
- this.m_sWebContentRoot = sWebContentRoot;
-
- this.m_bHasCompletedExecution = false;
-
- this.m_aScriptLoadQueue = [];
-
- this.m_bBlockScriptLoading = false;
-
-
- this.m_bUseScriptBlocking = false;
-
-
- this.m_bBlockPromptingLocaleScripts = false;
-
-
- this.m_aBlockedPromptingLocaleFileQueue = [];
- }
- CScriptLoader.prototype.hasCompletedExecution = function()
- {
- return this.m_bHasCompletedExecution;
- };
- CScriptLoader.prototype.setHandlerStylesheetLimit = function(handleLimit) {
- this.m_bHandleStylesheetLimit = handleLimit;
- };
- CScriptLoader.prototype.executeScripts = function(callback, sNamespaceId)
- {
- if (this.isReadyToExecute())
- {
- for (var idxScript = 0; idxScript < this.m_aScripts.length; idxScript++)
- {
- if (this.m_aScripts[idxScript])
- {
- var oScript = document.createElement('script');
- oScript.setAttribute("language", "javascript");
- oScript.setAttribute("type", "text/javascript");
- this.addNamespaceAttribute(oScript, sNamespaceId);
- oScript.text = this.m_aScripts[idxScript];
- document.getElementsByTagName("head").item(0).appendChild(oScript);
- }
- }
- this.m_aScripts = [];
- for(var idx = 0; idx < this.m_aDocumentWriters.length; ++idx)
- {
- var documentWriter = this.m_aDocumentWriters[idx];
- documentWriter.execute();
- }
- this.m_aDocumentWriters = [];
- if (!this.m_aScripts.length && !this.m_aDocumentWriters.length)
- {
- if (typeof callback == "function") {
- callback();
- }
- this.m_bHasCompletedExecution = true;
- }
- else
- {
- setTimeout(function(){window.gScriptLoader.executeScripts(callback, sNamespaceId);}, this.m_iInterval);
- }
- }
- else
- {
- setTimeout(function(){window.gScriptLoader.executeScripts(callback, sNamespaceId);}, this.m_iInterval);
- }
- };
- CScriptLoader.prototype.isReadyToExecute = function()
- {
- for (var idxFile in this.m_oFiles)
- {
- if (this.m_oFiles[idxFile] != "complete")
- {
- return false;
- }
- }
- if (this.m_aScriptLoadQueue.length > 0) {
- return false;
- }
- return true;
- };
- CScriptLoader.prototype.loadCSS = function(sHTML, oReportDiv, bUseNamespacedGRS, sNamespaceId)
- {
- var aM = sHTML.match(this.m_reHasCss);
- if (aM)
- {
- for (var i = 0; i < aM.length; i++)
- {
- if (aM[i].match(this.m_reFindCssPath))
- {
- var linkRef = RegExp.$1;
- if(linkRef.indexOf("GlobalReportStyles") != -1)
- {
- this.validateGlobalReportStyles(linkRef);
- if (bUseNamespacedGRS)
- {
-
-
- if (linkRef.indexOf("GlobalReportStyles.css") != -1) {
- linkRef = linkRef.replace("GlobalReportStyles.css", "GlobalReportStyles_10.css");
- }
- var sClassPrefix = this.getGlobalReportStylesClassPrefix(linkRef);
- linkRef = linkRef.replace(".css", "_NS.css");
- if (oReportDiv) {
- oReportDiv.className = "buxReport " + sClassPrefix;
- }
- }
- }
- this.loadObject(linkRef, sNamespaceId);
- }
-
- sHTML = sHTML.replace(aM[i], "");
- }
- }
- return sHTML;
- };
- CScriptLoader.prototype.getGlobalReportStylesClassPrefix = function(globalReportStyleLinkRef)
- {
- var sClassPrefix = null;
- if (globalReportStyleLinkRef.indexOf("GlobalReportStyles_11.4.css") != -1)
- {
- sClassPrefix = "v114";
- }
- if (globalReportStyleLinkRef.indexOf("GlobalReportStyles_11.css") != -1)
- {
- sClassPrefix = "v11";
- }
- if (globalReportStyleLinkRef.indexOf("GlobalReportStyles_10.css") != -1)
- {
- sClassPrefix = "v10";
- }
- else if (globalReportStyleLinkRef.indexOf("GlobalReportStyles_1.css") != -1)
- {
- sClassPrefix = "v1";
- }
- else if (globalReportStyleLinkRef.indexOf("GlobalReportStyles_none.css") != -1)
- {
- sClassPrefix = "vnone";
- }
- else if (globalReportStyleLinkRef.indexOf("GlobalReportStyles.css") != -1)
- {
- sClassPrefix = "v8";
- }
- return sClassPrefix;
- };
- CScriptLoader.prototype.validateGlobalReportStyles = function(globalReportStyleLinkRef)
- {
- var linkNodes = document.getElementsByTagName("link");
- for(var i = 0; i < linkNodes.length; ++i)
- {
- var linkNode = linkNodes[i];
- if(linkNode.getAttribute("href").indexOf("GlobalReportStyles") != -1)
- {
- if(linkNode.getAttribute("href").toLowerCase() != globalReportStyleLinkRef.toLowerCase())
- {
-
- var existingGRSRef = globalReportStyleLinkRef.split("/");
- var newGRSRef = linkNode.getAttribute("href").split("/");
- if(existingGRSRef[existingGRSRef.length -1] != newGRSRef[newGRSRef.length-1])
- {
- this.m_ajaxWarnings.push("Ajax response contains different versions of the GlobalReportStyles.css.");
- }
- }
- break;
- }
- }
- };
- CScriptLoader.prototype.loadFile = function(sURL_param, sContent_param, sType_param)
- {
- var sURL = "";
- if (sURL_param) {
- sURL = sURL_param;
- }
- var sContent = null;
- if (typeof sContent_param == "string") {
- sContent = sContent_param;
- }
- var sType = "POST";
- if (sType_param == "GET") {
- sType = "GET";
- }
- var oHTTPRequest = null;
- if (typeof ActiveXObject != "undefined")
- {
- oHTTPRequest = new ActiveXObject("Msxml2.XMLHTTP");
- }
- else
- {
- oHTTPRequest = new XMLHttpRequest();
- }
- oHTTPRequest.open(sType, sURL, false);
- oHTTPRequest.send(sContent);
- return oHTTPRequest.responseText;
- };
- function CScriptLoader_onReadyStateChange() {
- if (typeof this.readyState == "undefined") {
-
- this.readyState = "complete";
- }
- if (this.readyState == "loaded" || this.readyState == "complete") {
- var path = this.sFilePath;
-
- if (!path && this.getAttribute) {
- path = this.getAttribute("href");
- }
- window.gScriptLoader.setFileState(path, "complete");
- window.gScriptLoader.m_bBlockScriptLoading = false;
-
-
-
- if (this.sFilePath && window.gScriptLoader.m_bBlockPromptingLocaleScripts &&
- this.sFilePath.match(window.gScriptLoader.m_reIsPromptingLocaleJavascript)) {
- window.gScriptLoader.m_bBlockPromptingLocaleScripts = false;
- if (window.gScriptLoader.m_aBlockedPromptingLocaleFileQueue.length > 0) {
- var sQueueObject = window.gScriptLoader.m_aBlockedPromptingLocaleFileQueue.shift();
- window.gScriptLoader.loadObject(sQueueObject.sName, sQueueObject.sNamespaceId);
- }
- }
-
- if (window.gScriptLoader.m_aScriptLoadQueue.length > 0) {
- window.gScriptLoader.loadObject();
- }
- }
- }
- CScriptLoader.prototype.moveLinks = function(node) {
- if (!node) {
- return;
- }
-
- var sName = node.getAttribute("href");
-
- if (!sName || this.m_oFiles[sName]) {
- return;
- }
-
- this.m_oFiles[sName] = "complete";
-
- document.getElementsByTagName("head").item(0).appendChild(node);
- };
- CScriptLoader.prototype.loadObject = function(sName, sNamespaceId) {
- var oFile = null;
- if (typeof sName === "undefined") {
- if (this.m_aScriptLoadQueue.length > 0) {
- var sQueueObject = this.m_aScriptLoadQueue.shift();
- sName = sQueueObject.name;
- sNamespaceId = sQueueObject.namespaceId;
- } else {
- return;
- }
- }
- if (this.m_oFiles[sName]) {
- return;
- }
- if (this.m_bBlockScriptLoading) {
- this.m_aScriptLoadQueue.push({
- "name": sName,
- "namespaceId": sNamespaceId
- });
- } else {
- if (sName.match(this.m_reIsCss))
- {
-
- oFile = document.createElement('link');
- oFile.setAttribute("rel", "stylesheet");
- oFile.setAttribute("type", "text/css");
- oFile.setAttribute("href", sName);
-
-
- if (window.isIE && window.isIE()) {
- oFile.onreadystatechange = CScriptLoader_onReadyStateChange;
- oFile.onload = CScriptLoader_onReadyStateChange;
- oFile.onerror = CScriptLoader_onReadyStateChange;
- this.m_oFiles[sName] = "new";
- }
- else {
- this.m_oFiles[sName] = "complete";
- }
- }
- else if (sName.match(this.m_reIsJavascript))
- {
-
- if (sName.match(this.m_reIsPromptingLocaleJavascript)) {
-
- if (this.m_bBlockPromptingLocaleScripts) {
- this.m_aBlockedPromptingLocaleFileQueue.push ({
- 'sName' : sName,
- 'sNamespaceId' : sNamespaceId
- });
- return;
- }
- this.m_bBlockPromptingLocaleScripts = true;
- }
-
- this.m_bBlockScriptLoading = this.m_bUseScriptBlocking;
- oFile = document.createElement('script');
- oFile.setAttribute("language", "javascript");
- oFile.setAttribute("type", "text/javascript");
- oFile.setAttribute("src", sName);
- oFile.sFilePath = sName;
- oFile.onreadystatechange = CScriptLoader_onReadyStateChange;
- oFile.onload = CScriptLoader_onReadyStateChange;
- oFile.onerror = CScriptLoader_onReadyStateChange;
- this.addNamespaceAttribute(oFile, sNamespaceId);
- this.m_oFiles[sName] = "new";
- }
- if (oFile)
- {
- document.getElementsByTagName("head").item(0).appendChild(oFile);
- }
- }
- };
- CScriptLoader.prototype.loadScriptsFromDOM = function(domElement, sNamespaceId, bProcessDocumentWrite)
- {
- if (!domElement)
- {
- return;
- }
- var scriptElements = domElement.getElementsByTagName("script");
- while(scriptElements.length > 0)
- {
- var scriptElement = scriptElements[0];
- if (scriptElement.getAttribute("src") != null && scriptElement.getAttribute("src").length > 0)
- {
- this.loadObject(scriptElement.getAttribute("src"), sNamespaceId);
- }
- else
- {
- var sScript = scriptElement.innerHTML;
- var hasDocumentWrite = false;
- if(sScript.indexOf("document.write")!= -1) {
-
-
-
-
-
-
-
-
-
-
- var stripQuotes = sScript.replace(this.m_reEscapedCharacters, "").replace(this.m_reStringLiterals, "");
- hasDocumentWrite = (stripQuotes.indexOf("document.write") != -1);
- }
- if(hasDocumentWrite) {
- if (bProcessDocumentWrite) {
- var sId = "CVScriptFromDOMPlaceHolder" + scriptElements.length + sNamespaceId;
- var spanElement = scriptElement.ownerDocument.createElement("span");
- spanElement.setAttribute("id", sId);
- scriptElement.parentNode.insertBefore(spanElement, scriptElement);
- this.m_aDocumentWriters.push(new CDocumentWriter(sId, sScript));
- }
- } else if (sScript.length > 0) {
- this.m_aScripts.push(sScript);
- }
- }
- scriptElement.parentNode.removeChild(scriptElement);
- }
- };
- CScriptLoader.prototype.loadStyles = function(domElement, sNamespaceId)
- {
- if (!domElement || !domElement.parentNode)
- {
- return;
- }
- var styleElements = domElement.parentNode.getElementsByTagName("style");
- while(styleElements.length > 0) {
- var styleElement = styleElements[0];
- if (sNamespaceId) {
- this.addNamespaceAttribute(styleElement, sNamespaceId);
- }
-
- if (window.isIE && window.isIE() && window.getNavVer() < 10) {
-
-
- if ((document.getElementsByTagName("style").length + document.getElementsByTagName("link").length) >= 30) {
- if (this.m_bHandleStylesheetLimit) {
-
-
- if( typeof window.gaRV_INSTANCES != "undefined") {
- for (var i=0; i < window.gaRV_INSTANCES.length; i++) {
- window.gaRV_INSTANCES[i].cleanupStyles();
- }
- }
- }
-
-
- if ((document.getElementsByTagName("style").length + document.getElementsByTagName("link").length) >= 30) {
- if (typeof console != "undefined" && console && console.log) {
- console.log("Stylesheet limit reached.");
- }
-
- this.m_ajaxWarnings.push("Stylesheet limit reached.");
- return;
- }
- }
- }
- document.getElementsByTagName("head").item(0).appendChild(styleElement);
- }
- };
- CScriptLoader.prototype.loadAll = function(oReportDiv, callback, sNamespaceId, bProcessDocumentWrite)
- {
- this.m_bScriptLoaderCalled = true;
-
- this.m_bHasCompletedExecution = false;
- this.loadScriptsFromDOM(oReportDiv, sNamespaceId, bProcessDocumentWrite);
- if(this.containsAjaxWarnings())
- {
- return false;
- }
-
-
-
- this.loadStyles(oReportDiv, sNamespaceId);
- if(this.containsAjaxWarnings())
- {
- return false;
- }
- this.executeScripts(callback, sNamespaceId);
- return true;
- };
- CScriptLoader.prototype.setFileState = function(sFile, sState)
- {
- this.m_oFiles[sFile] = sState;
- };
- CScriptLoader.prototype.containsAjaxWarnings = function(){
- if (this.m_bIgnoreAjaxWarnings) {
- return false;
- }
- else {
- return (this.m_ajaxWarnings.length > 0);
- }
- };
- CScriptLoader.prototype.addNamespaceAttribute = function(oItem, sNamespaceId)
- {
- if (typeof sNamespaceId === "string") {
- oItem.setAttribute("namespaceId", sNamespaceId);
- }
- };
- if (typeof window.gScriptLoader == "undefined")
- {
- window.gScriptLoader = new CScriptLoader();
- }
|