CCognosViewerUtilities.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732
  1. /*
  2. *+------------------------------------------------------------------------+
  3. *| Licensed Materials - Property of IBM
  4. *| IBM Cognos Products: Viewer
  5. *| (C) Copyright IBM Corp. 2001, 2020
  6. *|
  7. *| US Government Users Restricted Rights - Use, duplication or
  8. *| disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  9. *|
  10. *+------------------------------------------------------------------------+
  11. */
  12. /**
  13. Loads dynamically CSS and JavaScript files and execute inline scripts found in HTML code in the response outputs.
  14. @constructor
  15. */
  16. function CScriptLoader(sWebContentRoot)
  17. {
  18. /**
  19. Array of files to load.
  20. @type array
  21. @private
  22. */
  23. this.m_oFiles = {};
  24. /**
  25. Array of inline script to execute.
  26. @type array
  27. @private
  28. */
  29. this.m_aScripts = [];
  30. /**
  31. Array of document.writes/document.writeln to execute.
  32. @type array
  33. @private
  34. */
  35. this.m_aDocumentWriters = [];
  36. this.m_ajaxWarnings = [];
  37. this.m_bIgnoreAjaxWarnings = false;
  38. this.m_bHandleStylesheetLimit = false;
  39. /**
  40. Length of the interval (in Milliseconds) to check if files are done loading and that we can execute the inline scripts.
  41. @type integer
  42. @private
  43. */
  44. this.m_iInterval = 20;
  45. /**
  46. Regular expression to retrieve CSS file paths.
  47. @type RegularExpression
  48. @private
  49. */
  50. this.m_reFindCssPath = new RegExp('<link[^>]*href="([^"]*)"', "i");
  51. /**
  52. Regular expression to retrieve CSS inline code.
  53. @type RegularExpression
  54. @private
  55. */
  56. this.m_reFindInlineStyle = /<style\b(\s|.)*?<\/style>/gi;
  57. /**
  58. Regular expression to test if a CSS (&lt;link&gt; tag) is present.
  59. @type RegularExpression
  60. @private
  61. */
  62. this.m_reHasCss = /<link .*?>/gi;
  63. /**
  64. Regular expression to test if a file name has a CSS extension.
  65. @type RegularExpression
  66. @private
  67. */
  68. this.m_reIsCss = /\.css$/i;
  69. /**
  70. Regular expression to test if a file name has a JS extension.
  71. @type RegularExpression
  72. @private
  73. */
  74. this.m_reIsJavascript = /\.js$/i;
  75. /**
  76. Regular expression to test if a file name is a Prompting Toolkit Locale JS file.
  77. If there are changes to Prmt localization file names this may have to be revisited.
  78. @type RegularExpression
  79. @private
  80. */
  81. this.m_reIsPromptingLocaleJavascript = /prompting.res.[promptingStrings|promptLocale].*\.js$/i;
  82. /**
  83. Regular expression to match closing &lt;script&gt; tags.
  84. @type RegularExpression
  85. @private
  86. */
  87. this.m_reScriptTagClose = /\s*<\/script>.*?$/i;
  88. /**
  89. Regular expression to match opening &lt;script&gt; tags.
  90. @type RegularExpression
  91. @private
  92. */
  93. this.m_reScriptTagOpen = /^.*?<script[^>]*>\s*/i;
  94. /**
  95. Regular expression to match closing &lt;style&gt; tags.
  96. @type RegularExpression
  97. @private
  98. */
  99. this.m_reStyleTagClose = /(-|>|\s)*<\/style>\s*$/gi;
  100. /**
  101. Regular expression to match opening &lt;style&gt; tags.
  102. @type RegularExpression
  103. @private
  104. */
  105. this.m_reStyleTagOpen = /^\s*<style[^>]*>(\s|<|!|-)*/gi;
  106. /**
  107. Regular expression to match any escaped backslashes,
  108. quotes or double quotes.
  109. @type RegularExpression
  110. @private
  111. */
  112. this.m_reEscapedCharacters = /\\[\\"']/g;
  113. /**
  114. Regular expression to match any strings, assuming no
  115. escaped characters.
  116. @type RegularExpression
  117. @private
  118. */
  119. this.m_reStringLiterals = /("|')[\s\S]*?\1/g;
  120. /**
  121. String that represents the web content root
  122. @type String
  123. @private
  124. */
  125. this.m_sWebContentRoot = sWebContentRoot;
  126. /**
  127. Flag to signal that loaded scripts have completed execution
  128. @type Boolean
  129. @private
  130. */
  131. this.m_bHasCompletedExecution = false;
  132. /**
  133. Array of scripts to be loaded (in order) by inserting them into the DOM
  134. @type Array
  135. @private
  136. */
  137. this.m_aScriptLoadQueue = [];
  138. /**
  139. Flag to signal that a script is currently being downloaded and executed. When set
  140. to true, other scripts will be placed in the queue until the script has been loaded.
  141. @type Boolean
  142. @private
  143. */
  144. this.m_bBlockScriptLoading = false;
  145. /**
  146. Flag to signal that script load order should be enforced. This is currently only necessary
  147. with Internet Exlporer. See: http://www.stevesouders.com/blog/2009/04/27/loading-scripts-without-blocking/.
  148. @type Boolean
  149. @private
  150. */
  151. // this flag is set to false to fix bugs: COGCQ00247831 and COGCQ00249348
  152. this.m_bUseScriptBlocking = false;
  153. /**
  154. Flag to signal that a Prompting Locale script is currently being downloaded and executed. When set
  155. to true, other Prompting Locale scripts will be placed in the queue.
  156. @type Boolean
  157. @private
  158. */
  159. this.m_bBlockPromptingLocaleScripts = false;
  160. /**
  161. Array of scripts to be loaded (in order - synchronously) by inserting them into the DOM
  162. @type Array
  163. @private
  164. */
  165. this.m_aBlockedPromptingLocaleFileQueue = [];
  166. }
  167. /**
  168. Return whether or not the loaded scripts have completed execution
  169. @public
  170. */
  171. CScriptLoader.prototype.hasCompletedExecution = function()
  172. {
  173. return this.m_bHasCompletedExecution;
  174. };
  175. CScriptLoader.prototype.setHandlerStylesheetLimit = function(handleLimit) {
  176. this.m_bHandleStylesheetLimit = handleLimit;
  177. };
  178. /**
  179. Helper function to execute all inline javascript from a page, after all javascript files were loading and processed.
  180. @private
  181. */
  182. CScriptLoader.prototype.executeScripts = function(callback, sNamespaceId)
  183. {
  184. if (this.isReadyToExecute())
  185. {
  186. for (var idxScript = 0; idxScript < this.m_aScripts.length; idxScript++)
  187. {
  188. if (this.m_aScripts[idxScript])
  189. {
  190. var oScript = document.createElement('script');
  191. oScript.setAttribute("language", "javascript");
  192. oScript.setAttribute("type", "text/javascript");
  193. this.addNamespaceAttribute(oScript, sNamespaceId);
  194. oScript.text = this.m_aScripts[idxScript];
  195. document.getElementsByTagName("head").item(0).appendChild(oScript);
  196. }
  197. }
  198. this.m_aScripts = [];
  199. for(var idx = 0; idx < this.m_aDocumentWriters.length; ++idx)
  200. {
  201. var documentWriter = this.m_aDocumentWriters[idx];
  202. documentWriter.execute();
  203. }
  204. this.m_aDocumentWriters = [];
  205. if (!this.m_aScripts.length && !this.m_aDocumentWriters.length)
  206. {
  207. if (typeof callback == "function") {
  208. callback();
  209. }
  210. this.m_bHasCompletedExecution = true;
  211. }
  212. else
  213. {
  214. setTimeout(function(){window.gScriptLoader.executeScripts(callback, sNamespaceId);}, this.m_iInterval);
  215. }
  216. }
  217. else
  218. {
  219. setTimeout(function(){window.gScriptLoader.executeScripts(callback, sNamespaceId);}, this.m_iInterval);
  220. }
  221. };
  222. /**
  223. Helper function.
  224. @type bool
  225. @private
  226. @return true if all files in {m_oFiles} are set to 'complete'. false otherwise.
  227. */
  228. CScriptLoader.prototype.isReadyToExecute = function()
  229. {
  230. for (var idxFile in this.m_oFiles)
  231. {
  232. if (this.m_oFiles[idxFile] != "complete")
  233. {
  234. return false;
  235. }
  236. }
  237. if (this.m_aScriptLoadQueue.length > 0) {
  238. return false;
  239. }
  240. return true;
  241. };
  242. /**
  243. Load and process a CSS file from HTML code [received from an ajax response].
  244. @private
  245. @param {string} sHTML HTML code with a &lt;link&gt; tag.
  246. @param {object} oReportDiv The report div.
  247. */
  248. CScriptLoader.prototype.loadCSS = function(sHTML, oReportDiv, bUseNamespacedGRS, sNamespaceId)
  249. {
  250. var aM = sHTML.match(this.m_reHasCss);
  251. if (aM)
  252. {
  253. for (var i = 0; i < aM.length; i++)
  254. {
  255. if (aM[i].match(this.m_reFindCssPath))
  256. {
  257. var linkRef = RegExp.$1;
  258. if(linkRef.indexOf("GlobalReportStyles") != -1)
  259. {
  260. this.validateGlobalReportStyles(linkRef);
  261. if (bUseNamespacedGRS)
  262. {
  263. // only time we're using the namespaced stylesheet is when we're in BUX,
  264. // so make sure we bring in the new styles
  265. if (linkRef.indexOf("GlobalReportStyles.css") != -1) {
  266. linkRef = linkRef.replace("GlobalReportStyles.css", "GlobalReportStyles_10.css");
  267. }
  268. var sClassPrefix = this.getGlobalReportStylesClassPrefix(linkRef);
  269. linkRef = linkRef.replace(".css", "_NS.css");
  270. if (oReportDiv) {
  271. oReportDiv.className = "buxReport " + sClassPrefix;
  272. }
  273. }
  274. }
  275. this.loadObject(linkRef, sNamespaceId);
  276. }
  277. // remove the link tag from the html block
  278. sHTML = sHTML.replace(aM[i], "");
  279. }
  280. }
  281. return sHTML;
  282. };
  283. /**
  284. * @private
  285. * @param (String)
  286. */
  287. CScriptLoader.prototype.getGlobalReportStylesClassPrefix = function(globalReportStyleLinkRef)
  288. {
  289. var sClassPrefix = null;
  290. if (globalReportStyleLinkRef.indexOf("GlobalReportStyles_11.4.css") != -1)
  291. {
  292. sClassPrefix = "v114";
  293. }
  294. if (globalReportStyleLinkRef.indexOf("GlobalReportStyles_11.css") != -1)
  295. {
  296. sClassPrefix = "v11";
  297. }
  298. if (globalReportStyleLinkRef.indexOf("GlobalReportStyles_10.css") != -1)
  299. {
  300. sClassPrefix = "v10";
  301. }
  302. else if (globalReportStyleLinkRef.indexOf("GlobalReportStyles_1.css") != -1)
  303. {
  304. sClassPrefix = "v1";
  305. }
  306. else if (globalReportStyleLinkRef.indexOf("GlobalReportStyles_none.css") != -1)
  307. {
  308. sClassPrefix = "vnone";
  309. }
  310. else if (globalReportStyleLinkRef.indexOf("GlobalReportStyles.css") != -1)
  311. {
  312. sClassPrefix = "v8";
  313. }
  314. return sClassPrefix;
  315. };
  316. /**
  317. * @private
  318. * @param (String)
  319. */
  320. CScriptLoader.prototype.validateGlobalReportStyles = function(globalReportStyleLinkRef)
  321. {
  322. var linkNodes = document.getElementsByTagName("link");
  323. for(var i = 0; i < linkNodes.length; ++i)
  324. {
  325. var linkNode = linkNodes[i];
  326. if(linkNode.getAttribute("href").indexOf("GlobalReportStyles") != -1)
  327. {
  328. if(linkNode.getAttribute("href").toLowerCase() != globalReportStyleLinkRef.toLowerCase())
  329. {
  330. //COGCQ00654064: only compares the file names
  331. var existingGRSRef = globalReportStyleLinkRef.split("/");
  332. var newGRSRef = linkNode.getAttribute("href").split("/");
  333. if(existingGRSRef[existingGRSRef.length -1] != newGRSRef[newGRSRef.length-1])
  334. {
  335. this.m_ajaxWarnings.push("Ajax response contains different versions of the GlobalReportStyles.css.");
  336. }
  337. }
  338. break;
  339. }
  340. }
  341. };
  342. /**
  343. Load a file synchronously and return the content.
  344. @param {string} sURL URL to fetch
  345. @param {string} sParams parameter string to add to the file
  346. @param {string} sType POST or GET
  347. @type string
  348. @return The content of the file
  349. @private
  350. */
  351. CScriptLoader.prototype.loadFile = function(sURL_param, sContent_param, sType_param)
  352. {
  353. var sURL = "";
  354. if (sURL_param) {
  355. sURL = sURL_param;
  356. }
  357. var sContent = null;
  358. if (typeof sContent_param == "string") {
  359. sContent = sContent_param;
  360. }
  361. var sType = "POST";
  362. if (sType_param == "GET") {
  363. sType = "GET";
  364. }
  365. var oHTTPRequest = null;
  366. if (typeof ActiveXObject != "undefined")
  367. {
  368. oHTTPRequest = new ActiveXObject("Msxml2.XMLHTTP");
  369. }
  370. else
  371. {
  372. oHTTPRequest = new XMLHttpRequest();
  373. }
  374. oHTTPRequest.open(sType, sURL, false);
  375. oHTTPRequest.send(sContent);
  376. return oHTTPRequest.responseText;
  377. };
  378. /**
  379. Helper Function. Event called when a file status is changed (ie. when it's done loading).
  380. @private
  381. */
  382. function CScriptLoader_onReadyStateChange() {
  383. if (typeof this.readyState == "undefined") {
  384. // Mozilla-based browser are using onload event, so we are here when the file is done loading.
  385. this.readyState = "complete";
  386. }
  387. if (this.readyState == "loaded" || this.readyState == "complete") {
  388. var path = this.sFilePath;
  389. // if we don't have path check for the href attribute - this is for CSS files.
  390. if (!path && this.getAttribute) {
  391. path = this.getAttribute("href");
  392. }
  393. window.gScriptLoader.setFileState(path, "complete");
  394. window.gScriptLoader.m_bBlockScriptLoading = false;
  395. // If we were loading a prompting locale file and the one that just finished is a prompting locale file, check to
  396. // see if we were blocking another one from loading and load it if we were.
  397. if (this.sFilePath && window.gScriptLoader.m_bBlockPromptingLocaleScripts &&
  398. this.sFilePath.match(window.gScriptLoader.m_reIsPromptingLocaleJavascript)) {
  399. window.gScriptLoader.m_bBlockPromptingLocaleScripts = false;
  400. if (window.gScriptLoader.m_aBlockedPromptingLocaleFileQueue.length > 0) {
  401. var sQueueObject = window.gScriptLoader.m_aBlockedPromptingLocaleFileQueue.shift();
  402. window.gScriptLoader.loadObject(sQueueObject.sName, sQueueObject.sNamespaceId);
  403. }
  404. }
  405. if (window.gScriptLoader.m_aScriptLoadQueue.length > 0) {
  406. window.gScriptLoader.loadObject();
  407. }
  408. }
  409. }
  410. /**
  411. * Used to move links from the body to the head
  412. */
  413. CScriptLoader.prototype.moveLinks = function(node) {
  414. if (!node) {
  415. return;
  416. }
  417. var sName = node.getAttribute("href");
  418. if (!sName || this.m_oFiles[sName]) {
  419. return;
  420. }
  421. this.m_oFiles[sName] = "complete";
  422. document.getElementsByTagName("head").item(0).appendChild(node);
  423. };
  424. /**
  425. Helper function to load and process file (CSS or Javascript) from HTML code received from an ajax response.
  426. @private
  427. @param {string} sName
  428. */
  429. CScriptLoader.prototype.loadObject = function(sName, sNamespaceId) {
  430. var oFile = null;
  431. if (typeof sName === "undefined") {
  432. if (this.m_aScriptLoadQueue.length > 0) {
  433. var sQueueObject = this.m_aScriptLoadQueue.shift();
  434. sName = sQueueObject.name;
  435. sNamespaceId = sQueueObject.namespaceId;
  436. } else {
  437. return;
  438. }
  439. }
  440. if (this.m_oFiles[sName]) {
  441. return;
  442. }
  443. if (this.m_bBlockScriptLoading) {
  444. this.m_aScriptLoadQueue.push({
  445. "name": sName,
  446. "namespaceId": sNamespaceId
  447. });
  448. } else {
  449. if (sName.match(this.m_reIsCss))
  450. {
  451. // Add a <link> tag in the document. This let the browser deals with the cache.
  452. oFile = document.createElement('link');
  453. oFile.setAttribute("rel", "stylesheet");
  454. oFile.setAttribute("type", "text/css");
  455. oFile.setAttribute("href", sName);
  456. // In IE the css files aren't always loaded before we insert the HTML. Wait for
  457. // the onreadystatechange event that lets us know the css file has been loaded.
  458. if (window.isIE && window.isIE()) {
  459. oFile.onreadystatechange = CScriptLoader_onReadyStateChange;
  460. oFile.onload = CScriptLoader_onReadyStateChange;
  461. oFile.onerror = CScriptLoader_onReadyStateChange;
  462. this.m_oFiles[sName] = "new";
  463. }
  464. else {
  465. this.m_oFiles[sName] = "complete";
  466. }
  467. }
  468. else if (sName.match(this.m_reIsJavascript))
  469. {
  470. // Need to handle prompt locale files differently. We need to make sure we're only loading one at a time.
  471. if (sName.match(this.m_reIsPromptingLocaleJavascript)) {
  472. // If we're already loading a prompt locale file, block this one for now.
  473. if (this.m_bBlockPromptingLocaleScripts) {
  474. this.m_aBlockedPromptingLocaleFileQueue.push ({
  475. 'sName' : sName,
  476. 'sNamespaceId' : sNamespaceId
  477. });
  478. return;
  479. }
  480. this.m_bBlockPromptingLocaleScripts = true;
  481. }
  482. this.m_bBlockScriptLoading = this.m_bUseScriptBlocking;
  483. oFile = document.createElement('script');
  484. oFile.setAttribute("language", "javascript");
  485. oFile.setAttribute("type", "text/javascript");
  486. oFile.setAttribute("src", sName);
  487. oFile.sFilePath = sName;
  488. oFile.onreadystatechange = CScriptLoader_onReadyStateChange;
  489. oFile.onload = CScriptLoader_onReadyStateChange;
  490. oFile.onerror = CScriptLoader_onReadyStateChange;
  491. this.addNamespaceAttribute(oFile, sNamespaceId);
  492. this.m_oFiles[sName] = "new";
  493. }
  494. if (oFile)
  495. {
  496. document.getElementsByTagName("head").item(0).appendChild(oFile);
  497. }
  498. }
  499. };
  500. /**
  501. * Finds script tags under a provided element, examines the scripts, makes any
  502. * necessary substitutions (e.g. _THIS_ is replaced with the namespace), sets
  503. * the scripts up for later execution, and removes the script tags from the
  504. * actual document body.
  505. */
  506. CScriptLoader.prototype.loadScriptsFromDOM = function(domElement, sNamespaceId, bProcessDocumentWrite)
  507. {
  508. if (!domElement)
  509. {
  510. return;
  511. }
  512. var scriptElements = domElement.getElementsByTagName("script");
  513. while(scriptElements.length > 0)
  514. {
  515. var scriptElement = scriptElements[0];
  516. if (scriptElement.getAttribute("src") != null && scriptElement.getAttribute("src").length > 0)
  517. {
  518. this.loadObject(scriptElement.getAttribute("src"), sNamespaceId);
  519. }
  520. else
  521. {
  522. var sScript = scriptElement.innerHTML;
  523. var hasDocumentWrite = false;
  524. if(sScript.indexOf("document.write")!= -1) {
  525. //document.write may be included in a string, not in the script itself,
  526. //particularly in the report description. The report description is
  527. //included in the same script tag as initialization code which must be
  528. //executed through m_aScripts, not m_aDocumentWriters, as the order
  529. //of code execution is relevant (the script node which contains the report
  530. //description is also the node which contains viewer initialization code,
  531. //and so this node must be loaded before all others). For this reason,
  532. //check that the document.write is indeed in the script by deleting
  533. //strings enclosed in quotes and checking for it after:
  534. //Remove \\s, \"s and 's, then "..."s and '...'s
  535. var stripQuotes = sScript.replace(this.m_reEscapedCharacters, "").replace(this.m_reStringLiterals, "");
  536. hasDocumentWrite = (stripQuotes.indexOf("document.write") != -1);
  537. }
  538. if(hasDocumentWrite) {
  539. if (bProcessDocumentWrite) {
  540. var sId = "CVScriptFromDOMPlaceHolder" + scriptElements.length + sNamespaceId;
  541. var spanElement = scriptElement.ownerDocument.createElement("span");
  542. spanElement.setAttribute("id", sId);
  543. scriptElement.parentNode.insertBefore(spanElement, scriptElement);
  544. this.m_aDocumentWriters.push(new CDocumentWriter(sId, sScript));
  545. }
  546. } else if (sScript.length > 0) {
  547. this.m_aScripts.push(sScript);
  548. }
  549. }
  550. scriptElement.parentNode.removeChild(scriptElement);
  551. }
  552. };
  553. /**
  554. Move the style elemnts from the HTML body to the head so they'll get evaluated
  555. @private
  556. @param {string} sHTML HTML code with a &lt;style&gt; tag.
  557. */
  558. CScriptLoader.prototype.loadStyles = function(domElement, sNamespaceId)
  559. {
  560. if (!domElement || !domElement.parentNode)
  561. {
  562. return;
  563. }
  564. var styleElements = domElement.parentNode.getElementsByTagName("style");
  565. while(styleElements.length > 0) {
  566. var styleElement = styleElements[0];
  567. if (sNamespaceId) {
  568. this.addNamespaceAttribute(styleElement, sNamespaceId);
  569. }
  570. if (window.isIE && window.isIE() && window.getNavVer() < 10) {
  571. // IE has a limit of 31 stylesheets. If ever we reach the limit, then re-submit the request in "page" mode.
  572. // fix for trakker 564899 and 615224
  573. if ((document.getElementsByTagName("style").length + document.getElementsByTagName("link").length) >= 30) {
  574. if (this.m_bHandleStylesheetLimit) {
  575. // Loops through all the Viewers and ask any that are currently hidden to remove their styles from the head
  576. if( typeof window.gaRV_INSTANCES != "undefined") {
  577. for (var i=0; i < window.gaRV_INSTANCES.length; i++) {
  578. window.gaRV_INSTANCES[i].cleanupStyles();
  579. }
  580. }
  581. }
  582. // Last try to see if there's now room for the style
  583. if ((document.getElementsByTagName("style").length + document.getElementsByTagName("link").length) >= 30) {
  584. if (typeof console != "undefined" && console && console.log) {
  585. console.log("Stylesheet limit reached.");
  586. }
  587. this.m_ajaxWarnings.push("Stylesheet limit reached.");
  588. return;
  589. }
  590. }
  591. }
  592. document.getElementsByTagName("head").item(0).appendChild(styleElement);
  593. }
  594. };
  595. CScriptLoader.prototype.loadAll = function(oReportDiv, callback, sNamespaceId, bProcessDocumentWrite)
  596. {
  597. this.m_bScriptLoaderCalled = true;
  598. this.m_bHasCompletedExecution = false;
  599. this.loadScriptsFromDOM(oReportDiv, sNamespaceId, bProcessDocumentWrite);
  600. if(this.containsAjaxWarnings())
  601. {
  602. return false;
  603. }
  604. // need to load the css and styles after we've replaced the innerHTML of the div
  605. // since IE would end up removing the styles from the head when the html in the div got replaces
  606. // bug 573581
  607. this.loadStyles(oReportDiv, sNamespaceId);
  608. if(this.containsAjaxWarnings())
  609. {
  610. return false;
  611. }
  612. this.executeScripts(callback, sNamespaceId);
  613. return true;
  614. };
  615. /**
  616. Setter for the loading state of a file.
  617. @private
  618. @param {string} sFile Path of the file to load.
  619. @param {string} sState State of the current file. Can be 'new' or 'complete'.
  620. */
  621. CScriptLoader.prototype.setFileState = function(sFile, sState)
  622. {
  623. this.m_oFiles[sFile] = sState;
  624. };
  625. CScriptLoader.prototype.containsAjaxWarnings = function(){
  626. if (this.m_bIgnoreAjaxWarnings) {
  627. return false;
  628. }
  629. else {
  630. return (this.m_ajaxWarnings.length > 0);
  631. }
  632. };
  633. CScriptLoader.prototype.addNamespaceAttribute = function(oItem, sNamespaceId)
  634. {
  635. if (typeof sNamespaceId === "string") {
  636. oItem.setAttribute("namespaceId", sNamespaceId);
  637. }
  638. };
  639. // Declare a global instance of CScriptLoader if none exists. We just need one instance per page.
  640. if (typeof window.gScriptLoader == "undefined")
  641. {
  642. window.gScriptLoader = new CScriptLoader();
  643. }