common.js 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133
  1. /*
  2. *+------------------------------------------------------------------------+
  3. *| Licensed Materials - Property of IBM
  4. *| IBM Cognos Products: Viewer
  5. *| (C) Copyright IBM Corp. 2001, 2018
  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. cvLoadDialog = function(oCognosViewerObject, aFormFields, width, height, sIframeTitle, bSendExtraFormFields)
  13. {
  14. bSendExtraFormFields = (( bSendExtraFormFields === undefined ) ? true : bSendExtraFormFields );
  15. var formWarpRequest = document.getElementById("formWarpRequest" + oCognosViewerObject.getId());
  16. if(formWarpRequest && oCognosViewerObject)
  17. {
  18. oCognosViewerObject.getWorkingDialog().hide();
  19. var target = "";
  20. var sPath = "";
  21. var modalDialog = null;
  22. if (oCognosViewerObject.isAccessibleMode())
  23. {
  24. target = "winNAT_" + ( new Date() ).getTime();
  25. sPath = oCognosViewerObject.getWebContentRoot() + "/" + "rv/blankNewWin.html?cv.id=" + this.getCVId();
  26. }
  27. else
  28. {
  29. var parent = document.body;
  30. modalDialog = new CModal("", "", parent, null, null, height, width, true, true, false, true, oCognosViewerObject.getWebContentRoot());
  31. if (typeof sIframeTitle == "string")
  32. {
  33. document.getElementById(CMODAL_CONTENT_ID).setAttribute("title", sIframeTitle);
  34. }
  35. document.getElementById(CMODAL_BACK_IFRAME_ID).setAttribute("title", RV_RES.IDS_JS_MODAL_BACK_IFRAME);
  36. target = CMODAL_CONTENT_ID;
  37. }
  38. var dialogForm = document.createElement("FORM");
  39. dialogForm.method = "POST";
  40. dialogForm.action = oCognosViewerObject.getGateway();
  41. dialogForm.target = target;
  42. dialogForm.style.margin = "0px";
  43. document.body.appendChild(dialogForm);
  44. for(var formFieldName in aFormFields)
  45. {
  46. dialogForm.appendChild(createHiddenFormField(formFieldName, aFormFields[formFieldName]));
  47. }
  48. if (bSendExtraFormFields)
  49. {
  50. dialogForm.appendChild(createHiddenFormField("cv.id", oCognosViewerObject.getId()));
  51. dialogForm.appendChild(createHiddenFormField("b_action", "xts.run"));
  52. dialogForm.appendChild(createHiddenFormField("ui.action", formWarpRequest["ui.action"].value));
  53. dialogForm.appendChild(createHiddenFormField("ui.object", formWarpRequest["ui.object"].value));
  54. if(typeof oCognosViewerObject.rvMainWnd != "undefined")
  55. {
  56. dialogForm.appendChild(createHiddenFormField("run.outputFormat", oCognosViewerObject.rvMainWnd.getCurrentFormat()));
  57. }
  58. if(typeof formWarpRequest["run.outputLocale"] != "undefined")
  59. {
  60. dialogForm.appendChild(createHiddenFormField("run.outputLocale", formWarpRequest["run.outputLocale"].value));
  61. }
  62. if(typeof dialogForm["backURL"] == "undefined" && typeof dialogForm["ui.backURL"] == "undefined" && typeof formWarpRequest["ui.backURL"] != "undefined")
  63. {
  64. dialogForm.appendChild(createHiddenFormField("ui.backURL", formWarpRequest["ui.backURL"].value));
  65. }
  66. if(typeof oCognosViewerObject != "undefined" && typeof oCognosViewerObject.getConversation != "undefined" && typeof oCognosViewerObject.getTracking != "undefined")
  67. {
  68. dialogForm.appendChild(createHiddenFormField("ui.conversation", oCognosViewerObject.getConversation()));
  69. dialogForm.appendChild(createHiddenFormField("m_tracking", oCognosViewerObject.getTracking()));
  70. if(oCognosViewerObject.envParams["ui.name"] != "undefined")
  71. {
  72. dialogForm.appendChild(createHiddenFormField("ui.name", oCognosViewerObject.envParams["ui.name"]));
  73. }
  74. }
  75. }
  76. // Remove onBeforeUnLoad for this submission but set it back after.
  77. var oldUnload = window.onbeforeunload;
  78. window.onbeforeunload = null;
  79. if (oCognosViewerObject.isAccessibleMode())
  80. {
  81. window.open(sPath, target, "rv");
  82. dialogForm.submit();
  83. }
  84. else
  85. {
  86. // Submit the form
  87. dialogForm.submit();
  88. modalDialog.show();
  89. }
  90. window.onbeforeunload = oldUnload;
  91. document.body.removeChild(dialogForm);
  92. oCognosViewerObject.modalShown = true;
  93. }
  94. };
  95. function createHiddenFormField(name, value)
  96. {
  97. var formField = document.createElement("input");
  98. formField.setAttribute("type", "hidden");
  99. formField.setAttribute("name", name);
  100. formField.setAttribute("id", name);
  101. formField.setAttribute("value", value);
  102. return(formField);
  103. }
  104. function isAuthenticationFault(soapFaultDocument)
  105. {
  106. if(soapFaultDocument != null) {
  107. var camElement = XMLHelper_FindChildByTagName(soapFaultDocument, "CAM", true);
  108. return (camElement != null && XMLHelper_FindChildByTagName(camElement, "promptInfo", true) != null);
  109. }
  110. }
  111. /*
  112. * Checks the response for an authentication fault. If it finds one it will launch the log on dialog
  113. * Returns true if an authentication fault was detected
  114. */
  115. function processAuthenticationFault(soapFaultDocument, cognosViewerID)
  116. {
  117. if (isAuthenticationFault( soapFaultDocument) )
  118. {
  119. launchLogOnDialog(cognosViewerID, soapFaultDocument );
  120. return true;
  121. }
  122. return false;
  123. }
  124. function isObjectEmpty(object) {
  125. for(var property in object) {
  126. if(object.hasOwnProperty(property))
  127. return false;
  128. }
  129. return true;
  130. }
  131. /*
  132. * Calls close.xts which end up showing the log on dialog
  133. */
  134. function launchLogOnDialog(cvID, response)
  135. {
  136. try
  137. {
  138. var oCV = getCognosViewerObjectRef(cvID);
  139. var params = {
  140. "b_action":"xts.run",
  141. "m":"portal/close.xts",
  142. "h_CAM_action" : "logonAs"};
  143. if (response != null)
  144. {
  145. var namespaceNodes = XMLHelper_FindChildrenByTagName(response, "namespace", true);
  146. if (namespaceNodes != null)
  147. {
  148. for(var index = 0; index < namespaceNodes.length; ++index)
  149. {
  150. var namespaceNode = namespaceNodes[index];
  151. if (namespaceNode != null)
  152. {
  153. var namespaceNameNode = XMLHelper_FindChildByTagName(namespaceNode, "name", false);
  154. var namespaceValueNode = XMLHelper_FindChildByTagName(namespaceNode, "value", false);
  155. if (namespaceNameNode != null && namespaceValueNode != null)
  156. {
  157. var namespaceName = XMLHelper_GetText(namespaceNameNode);
  158. var namespaceValue = XMLHelper_GetText(namespaceValueNode);
  159. if (namespaceName != null && namespaceName.length > 0)
  160. {
  161. params[namespaceName] = namespaceValue;
  162. }
  163. }
  164. }
  165. }
  166. }
  167. }
  168. cvLoadDialog(oCV, params, 540, 460, null, false);
  169. }
  170. catch(exception)
  171. {
  172. }
  173. }
  174. /*
  175. * Goes through the array of cognos viewer objects to find the one that's waiting on a fault
  176. */
  177. function getCVWaitingOnFault()
  178. {
  179. // need to find our oCV object
  180. var oCV = null;
  181. for (var iIndex=0; iIndex < window.gaRV_INSTANCES.length; iIndex++)
  182. {
  183. // if the oCV object has a retryRequest then it must be the one that triggered the log on
  184. if (window.gaRV_INSTANCES[iIndex].getRetryDispatcherEntry() != null)
  185. {
  186. oCV = window.gaRV_INSTANCES[iIndex];
  187. break;
  188. }
  189. }
  190. return oCV;
  191. }
  192. /*
  193. * Callback used from the logon dialog
  194. */
  195. function ccModalCallBack(command, data)
  196. {
  197. var oCV = getCVWaitingOnFault();
  198. destroyCModal();
  199. if (typeof HiddenIframeDispatcherEntry == "function" && HiddenIframeDispatcherEntry.hideIframe) {
  200. var oCV = window.gaRV_INSTANCES[0];
  201. if (oCV) {
  202. HiddenIframeDispatcherEntry.hideIframe(oCV.getId())
  203. }
  204. }
  205. if (oCV != null)
  206. {
  207. if (typeof command != "undefined" && command == "ok")
  208. {
  209. var retryEntry = oCV.getRetryDispatcherEntry();
  210. if (retryEntry) {
  211. retryEntry.retryRequest();
  212. }
  213. if (oCV.getRV() != null) {
  214. oCV.getRV().updateUserName();
  215. }
  216. }
  217. else
  218. {
  219. oCV.rvMainWnd.hideOpenMenus();
  220. }
  221. }
  222. }
  223. /*
  224. * Callback when the user hits the cancel button in a fault dialog
  225. */
  226. function closeErrorPage()
  227. {
  228. var oCV = getCVWaitingOnFault();
  229. destroyCModal();
  230. if (oCV != null) {
  231. oCV.setRetryDispatcherEntry(null);
  232. oCV.rvMainWnd.hideOpenMenus();
  233. }
  234. }
  235. function getCrossBrowserNode(evt, checkExplicitOriginalTarget) {
  236. var node = null;
  237. if (checkExplicitOriginalTarget && evt.explicitOriginalTarget) {
  238. node = evt.explicitOriginalTarget;
  239. }
  240. else if (evt.originalTarget) {
  241. node = evt.originalTarget;
  242. }
  243. else if (evt.target) {
  244. node = evt.target;
  245. }
  246. else if (evt.srcElement) {
  247. node = evt.srcElement;
  248. }
  249. try {
  250. if ( node && node.nodeType == 3) { // needed for safari
  251. node = node.parentNode;
  252. }
  253. }
  254. catch (ex) {
  255. // sometimes node may not be an HTML element (like a XUL element) and accessing nodeType will generate an error.
  256. }
  257. return node;
  258. }
  259. function getNodeFromEvent(evt, bReturnImageNode)
  260. {
  261. var node = getCrossBrowserNode(evt, true);
  262. if (node && node.getAttribute && node.getAttribute("name") == "primarySelectionDiv") {
  263. node = node.parentNode.firstChild;
  264. }
  265. if (node && node.getAttribute && node.getAttribute("flashChartContainer") == "true") {
  266. node = node.firstChild;
  267. }
  268. // if the event was from the chart container, go find the image tag within the span.
  269. if (node && node.getAttribute && node.getAttribute("chartContainer") == "true" && node.childNodes) {
  270. for (var i=0; i < node.childNodes.length; i ++) {
  271. if (node.childNodes[i].nodeName.toLowerCase() == "img") {
  272. node = node.childNodes[i];
  273. break;
  274. }
  275. }
  276. }
  277. // if the event was from an image which isn't a chart, get the parent
  278. else if (!bReturnImageNode && node && node.nodeName && node.nodeName.toLowerCase() == "img" && node.getAttribute("rsvpChart") != "true")
  279. {
  280. node = node.parentNode;
  281. }
  282. return node;
  283. }
  284. function getCtxNodeFromEvent(evt)
  285. {
  286. try
  287. {
  288. var node = getCrossBrowserNode(evt);
  289. var sNAME = node.nodeName.toUpperCase();
  290. if((sNAME == "SPAN" || sNAME == 'AREA' || sNAME == 'IMG') && node.getAttribute("ctx") != null)
  291. {
  292. return node;
  293. }
  294. else if (sNAME == "SPAN" && (node.parentNode.getAttribute("ctx") != null))
  295. {
  296. return node.parentNode;
  297. }
  298. }
  299. catch(exception){}
  300. return null;
  301. }
  302. function getDocumentFromEvent(evt)
  303. {
  304. var node = getCrossBrowserNode(evt, true);
  305. var nodeDocument = node.document ? node.document : node.ownerDocument;
  306. return nodeDocument;
  307. }
  308. function stopEventBubble(evt)
  309. {
  310. evt.returnValue = false;
  311. evt.cancelBubble = true;
  312. if(typeof evt.stopPropagation != "undefined")
  313. {
  314. evt.stopPropagation();
  315. }
  316. if(typeof evt.preventDefault != "undefined")
  317. {
  318. evt.preventDefault();
  319. }
  320. return false;
  321. }
  322. function setNodeFocus(evt)
  323. {
  324. //get the event in a cross-browser fashion
  325. evt = (evt) ? evt : ((event) ? event : null);
  326. // set the focus to child span
  327. var srcNode = getNodeFromEvent(evt);
  328. if (srcNode && srcNode.nodeName) {
  329. var nodeName = srcNode.nodeName.toLowerCase();
  330. // We only want to set focus to a textItem that's inside a list or crosstab
  331. if ((nodeName == "td" || nodeName == "span") && srcNode.childNodes && srcNode.childNodes.length > 0 && srcNode.childNodes[0].className == "textItem")
  332. {
  333. try {
  334. srcNode.childNodes[0].focus();
  335. }
  336. catch(e) {
  337. if (typeof console !== "undefined" && console.log) {
  338. console.log("CCognosViewer: Could not set focus to node. setNodeFocus method common.js");
  339. }
  340. }
  341. }
  342. }
  343. }
  344. function html_encode(str)
  345. {
  346. return str.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
  347. }
  348. function replaceNewLine(myString) {
  349. var regX = /\r\n|\r|\n/g;
  350. var replaceString = '<br/>';
  351. return myString.replace(regX, replaceString);
  352. }
  353. //take an input string and convert it into
  354. //xml friendly entity references
  355. function xml_encode(sInputString)
  356. {
  357. var sOutputString = "" + sInputString;
  358. if ((sOutputString == '0') || ((sInputString != null) && (sInputString != false)))
  359. {
  360. //&amp;
  361. sOutputString = sOutputString.replace(/&/g, "&amp;");
  362. //&lt;
  363. sOutputString = sOutputString.replace(/</g, "&lt;");
  364. //&gt;
  365. sOutputString = sOutputString.replace(/>/g, "&gt;");
  366. //&quot;
  367. sOutputString = sOutputString.replace(/"/g, "&quot;");
  368. //&apos;
  369. sOutputString = sOutputString.replace(/'/g, "&apos;");
  370. }
  371. else if (sInputString == null)
  372. {
  373. //return empty string if the value is null or false
  374. sOutputString = "";
  375. }
  376. return sOutputString;
  377. }
  378. //take an xml friendly string and convert it into
  379. //a js friendly string
  380. function xml_decodeParser(sAll, sGroup1)
  381. {
  382. var sRetval = sAll;
  383. switch(sGroup1)
  384. {
  385. case 'amp': sRetval = '&'; break;
  386. case 'lt': sRetval = '<'; break;
  387. case 'gt': sRetval = '>'; break;
  388. case 'quot': sRetval = '"'; break;
  389. case 'apos': sRetval = "'"; break;
  390. }
  391. return sRetval;
  392. }
  393. function xml_decode(sInputString)
  394. {
  395. var sOutputString = "" + sInputString;
  396. if ((sOutputString == '0') || ((sInputString != null) && (sInputString != false)))
  397. {
  398. sOutputString = sOutputString.replace(/&(amp|lt|gt|quot|apos);/g, xml_decodeParser);
  399. }
  400. else if (sInputString == null)
  401. {
  402. //return empty string if the value is null or false
  403. sOutputString = "";
  404. }
  405. return sOutputString;
  406. }
  407. //Take a string and convert it into a string that is good to use as attribute value in an xpath.
  408. //E.g to construct a xpath to get child elements that have name attribute:
  409. //var xpath = "//[@name=" + xpath_attr_encode(nameValue) + "]";
  410. function xpath_attr_encode(sInputString)
  411. {
  412. var sQuotedString = null;
  413. if (sInputString.indexOf("'") >= 0 && sInputString.indexOf('"') >= 0) {
  414. var aInputs = sInputString.split('"');
  415. sQuotedString = "concat(";
  416. for (var i = 0; i < aInputs.length; ++i) {
  417. if (i > 0) {
  418. sQuotedString += ",";
  419. }
  420. if (aInputs[i].length > 0) {
  421. sQuotedString += ('"' + aInputs[i] + '"');
  422. } else {
  423. sQuotedString += '\'"\'';
  424. }
  425. }
  426. sQuotedString += ")";
  427. } else if (sInputString.indexOf("'") >= 0) {
  428. sQuotedString = '"' + sInputString + '"';
  429. } else {
  430. sQuotedString = "'" + sInputString + "'";
  431. }
  432. return sQuotedString;
  433. }
  434. function getCognosViewerObjectString(sId)
  435. {
  436. return "oCV" + sId;
  437. }
  438. function getCognosViewerObjectRefAsString(sId)
  439. {
  440. return "window." + getCognosViewerObjectString(sId);
  441. }
  442. function getCognosViewerObjectRef(sId)
  443. {
  444. return window[getCognosViewerObjectString(sId)];
  445. }
  446. function getCognosViewerSCObjectString(sId)
  447. {
  448. return "oCVSC" + sId;
  449. }
  450. function getCognosViewerSCObjectRefAsString(sId)
  451. {
  452. return "window." + getCognosViewerSCObjectString(sId);
  453. }
  454. function getCognosViewerSCObjectRef(sId)
  455. {
  456. return window[getCognosViewerSCObjectString(sId)];
  457. }
  458. function cleanupGlobalObjects(sId) {
  459. cleanupVariable( getCognosViewerObjectString(sId) );
  460. cleanupVariable( getCognosViewerSCObjectString(sId) );
  461. }
  462. function cleanupVariable( sVariableName ) {
  463. if( typeof window[sVariableName] != "undefined" && window[sVariableName] ) {
  464. if (isIE()){
  465. //It seems like IE does not like "delete window[sVariableName];"
  466. //it throws an exception and complains that
  467. // "Object doesn't support this action"
  468. //However, using eval seems to work
  469. eval( "delete " + sVariableName );
  470. } else {
  471. delete window[sVariableName];
  472. }
  473. }
  474. }
  475. function loadClass(sClass)
  476. {
  477. try
  478. {
  479. var object = eval("new " + sClass + "();");
  480. return object;
  481. }
  482. catch(e)
  483. {
  484. return null;
  485. }
  486. }
  487. function getElementsByClassName(oElm, strTagName, strClassName)
  488. {
  489. var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
  490. var arrReturnElements = [];
  491. var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
  492. var eleLen = arrElements.length;
  493. for(var i=0; i<eleLen; i++)
  494. {
  495. var oElement = arrElements[i];
  496. if(oRegExp.test(oElement.className))
  497. {
  498. arrReturnElements.push(oElement);
  499. }
  500. }
  501. return arrReturnElements;
  502. }
  503. function getImmediateLayoutContainerId(node)
  504. {
  505. var currentNode = node;
  506. while (currentNode != null)
  507. {
  508. if (currentNode.getAttribute && currentNode.getAttribute("lid") != null)
  509. {
  510. return currentNode.getAttribute("lid");
  511. }
  512. currentNode = currentNode.parentNode;
  513. }
  514. return null;
  515. }
  516. function getChildElementsByAttribute(oElm, aTagNames, strAttributeName, strAttributeValue)
  517. {
  518. return getDescendantElementsByAttribute(oElm, aTagNames, strAttributeName, strAttributeValue, true);
  519. }
  520. function getElementsByAttribute(oElm, aTagNames, strAttributeName, strAttributeValue, maxSize, expAttributeValue) {
  521. return getDescendantElementsByAttribute(oElm, aTagNames, strAttributeName, strAttributeValue, false, maxSize, expAttributeValue);
  522. }
  523. function getDescendantElementsByAttribute(oElm, aTagNames, strAttributeName, strAttributeValue, childOnly, maxSize, expAttributeValue) {
  524. var arrReturnElements = [];
  525. var oAttributeValue = null;
  526. if( typeof expAttributeValue === "undefined")
  527. {
  528. oAttributeValue = (typeof strAttributeValue != "undefined") ? new RegExp("(^|\\s)" + strAttributeValue + "(\\s|$)", "i"): null;
  529. }
  530. else
  531. {
  532. oAttributeValue = expAttributeValue;
  533. }
  534. if (typeof aTagNames == "string")
  535. {
  536. aTagNames = [aTagNames];
  537. }
  538. var tagLen = (oElm ? aTagNames.length : 0);
  539. for (var tagName=0; tagName < tagLen; tagName++)
  540. {
  541. var arrElements = null;
  542. if (childOnly)
  543. {
  544. if (aTagNames[tagName] == "*" && oElm.all)
  545. {
  546. arrElements = oElm.childNodes;
  547. }
  548. else
  549. {
  550. arrElements = [];
  551. var childNodes = oElm.childNodes;
  552. for (var i = 0; i < childNodes.length; ++i)
  553. {
  554. if (childNodes[i].nodeName.toLowerCase() == aTagNames[tagName].toLowerCase())
  555. {
  556. arrElements.push(childNodes[i]);
  557. }
  558. }
  559. }
  560. }
  561. else
  562. {
  563. arrElements = (aTagNames[tagName] == "*" && oElm.all) ? oElm.all : oElm.getElementsByTagName(aTagNames[tagName]);
  564. }
  565. var eleLen = arrElements.length;
  566. for (var idx = 0; idx < eleLen; idx++) {
  567. var oCurrent = arrElements[idx];
  568. var oAttribute = oCurrent.getAttribute && oCurrent.getAttribute(strAttributeName);
  569. if (oAttribute !== null) {
  570. var oAttributeString = null;
  571. if (typeof oAttribute === "number") {
  572. oAttributeString = String(oAttribute);
  573. } else if (typeof oAttribute === "string" && oAttribute.length > 0) {
  574. oAttributeString = oAttribute;
  575. }
  576. if(oAttributeString !== null) {
  577. if (typeof strAttributeValue == "undefined" || (oAttributeValue && oAttributeValue.test(oAttributeString))) {
  578. arrReturnElements.push(oCurrent);
  579. if (maxSize != -1 && arrReturnElements.length > maxSize) {
  580. return [];
  581. }
  582. else if (maxSize == 1 && arrReturnElements.length == 1) {
  583. return arrReturnElements;
  584. }
  585. }
  586. }
  587. }
  588. }
  589. }
  590. return arrReturnElements;
  591. }
  592. function savedOutputDoneLoading(cvId, count) {
  593. var oCV = window["oCV" + cvId];
  594. var oWidget = (oCV && oCV.getViewerWidget ? oCV.getViewerWidget() : null);
  595. var savedOutput = (oWidget ? oWidget.getSavedOutput() : null);
  596. if ( savedOutput ) {
  597. savedOutput.outputDoneLoading();
  598. } else if (count < 5) {
  599. // if we can't find the viewer object after a few tries, give up so we don't go into an endless loop.
  600. // Something bad must of happened since the iframe is done loading and we can't find the
  601. // correct viewer object to show the saved output
  602. count++;
  603. var _tryAgain = function() {
  604. savedOutputDoneLoading(cvId, count);
  605. };
  606. setTimeout(_tryAgain, 100);
  607. }
  608. }
  609. /*
  610. * Copied from V5HTML.xsl, so any fixes here must also be done there.
  611. */
  612. function getNavVer()
  613. {
  614. var temp;
  615. if (isIE()){
  616. return getIEVersion();
  617. } else {
  618. temp = navigator.userAgent.split('\/');
  619. return parseFloat(temp[temp.length - 1]);
  620. }
  621. }
  622. function isSafari()
  623. {
  624. // Chrome navigator.userAgent
  625. // "mozilla/5.0 (macintosh; intel mac os x 10_14_0) applewebkit/537.36 (khtml, like gecko) chrome/69.0.3497.100 safari/537.36"
  626. // Safari navigator.userAgent
  627. // "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.0 Safari/605.1.15" = $2
  628. // if the navigator.userAgent contains safari, but not chrome...then the browser safari
  629. return (navigator.userAgent.toLowerCase().indexOf('safari') != -1 && navigator.userAgent.toLowerCase().indexOf('chrome') == -1);
  630. }
  631. /*
  632. * Copied from V5HTML.xsl, so any fixes here must also be done there.
  633. */
  634. function isIE()
  635. {
  636. return (navigator.userAgent.indexOf('MSIE') != -1 || navigator.userAgent.indexOf('Trident') != -1);
  637. }
  638. function getIEVersion()
  639. {
  640. var regExMatch = navigator.userAgent.match(/(?:MSIE |Trident\/.*; rv:)(\d+)/);
  641. return regExMatch ? parseFloat(regExMatch[1]) : null;
  642. }
  643. /**
  644. * Return true iff Firefox is the current browser.
  645. * Note that this works only for released versions of Firefox.
  646. */
  647. /*
  648. * There is no analogous function in V5HTML.xsl, this is based on
  649. * information from:
  650. * http://www.quirksmode.org/js/detect.html
  651. */
  652. function isFF()
  653. {
  654. return (navigator.userAgent.indexOf('Firefox') != -1);
  655. }
  656. function isIOS()
  657. {
  658. return navigator.userAgent.indexOf('iPad') != -1 || navigator.userAgent.indexOf('iPhone') != -1;
  659. }
  660. /*
  661. * Copied from V5HTML.xsl, so any fixes here must also be done there.
  662. */
  663. function displayChart(imageName, imgSrc, useScale, isImage)
  664. {
  665. if (imgSrc.length > 1){
  666. document.images[imageName].src = imgSrc;
  667. }
  668. }
  669. function isFlashChartNode(evt)
  670. {
  671. var node = getNodeFromEvent(evt);
  672. if(node != null && typeof node.getAttribute == "function")
  673. {
  674. return node.getAttribute("flashChart") != null;
  675. }
  676. return false;
  677. }
  678. //TODO - this isn't really a common method, so it should be moved to a BUX specific area
  679. function onFlashChartRightClick(evt)
  680. {
  681. if (evt && evt.button && evt.button != 0 && isFlashChartNode(evt))
  682. {
  683. return onViewerChartFocus(evt);
  684. }
  685. }
  686. function onViewerChartFocus(evt)
  687. {
  688. if (evt.stopPropagation) {evt.stopPropagation();}
  689. if (evt.preventDefault) {evt.preventDefault();}
  690. if (evt.preventCapture) {evt.preventCapture();}
  691. if (evt.preventBubble) {evt.preventBubble();}
  692. var node = getNodeFromEvent(evt);
  693. var viewerId = node.getAttribute("viewerId");
  694. // possible that the viewer is on the parent, try there
  695. if (!viewerId) {
  696. viewerId = node.parentNode.getAttribute("viewerId");
  697. }
  698. if (!viewerId) {
  699. return;
  700. }
  701. var oCV = window["oCV" + viewerId];
  702. var selectionAction = oCV.getAction("Selection");
  703. selectionAction.pageClicked(evt);
  704. return stopEventBubble(evt);
  705. }
  706. function clientToScreenCoords(domObject, offsetParent)
  707. {
  708. var current = domObject;
  709. var coords = { topCoord:0, leftCoord:0 };
  710. while(current != null && current != offsetParent)
  711. {
  712. coords.topCoord += current.offsetTop; coords.leftCoord += current.offsetLeft;
  713. current = current.offsetParent;
  714. }
  715. return coords;
  716. }
  717. function getCurrentPosistionString(oCV, current, count)
  718. {
  719. var positionString = RV_RES.IDS_JS_INFOBAR_ITEM_COUNT;
  720. var reParam0 = /\{0\}/;
  721. var reParam1 = /\{1\}/;
  722. positionString = positionString.replace(reParam0, current);
  723. positionString = " " + positionString.replace(reParam1, count) + " ";
  724. return positionString;
  725. }
  726. function applyJSONProperties(obj, properties) {
  727. for(property in properties) {
  728. if(typeof properties[property] == "object" && !(properties[property] instanceof Array)) {
  729. if(typeof obj[property] == "undefined") {
  730. obj[property] = {};
  731. }
  732. applyJSONProperties(obj[property], properties[property]);
  733. } else {
  734. obj[property] = properties[property];
  735. }
  736. }
  737. };
  738. /*
  739. * Class for containing common static functions
  740. */
  741. function CViewerCommon()
  742. {
  743. }
  744. CViewerCommon.openNewWindowOrTab = function( sURL, sWindowName )
  745. {
  746. //Leave the third parameter unspecified so that the browser's settings to open in tab/window will take effect.
  747. return window.open( sURL, sWindowName );
  748. };
  749. CViewerCommon.toJSON = function(obj) {
  750. var type = typeof (obj);
  751. if (type != "object" || type === null) {
  752. if (type === "string") {
  753. obj = '"'+obj+'"';
  754. }
  755. return String(obj);
  756. }
  757. else {
  758. var prototype;
  759. var prop;
  760. var json = [];
  761. var isArray = (obj && obj.constructor == Array);
  762. for (prototype in obj) {
  763. prop = obj[prototype];
  764. type = typeof(prop);
  765. if (type === "string") {
  766. prop = '"'+prop+'"';
  767. }
  768. else if (type == "object" && prop !== null) {
  769. prop = CViewerCommon.toJSON(prop);
  770. }
  771. json.push((isArray ? "" : '"' + prototype + '":') + String(prop));
  772. }
  773. return (isArray ? "[" : "{") + String(json) + (isArray ? "]" : "}");
  774. }
  775. };
  776. /*
  777. * Will resize all the pinned containers in the stand alone Viewer.
  778. */
  779. function resizePinnedContainers() {
  780. var oCV = window.gaRV_INSTANCES[0];
  781. if (oCV && !oCV.m_viewerFragment) {
  782. var oPinFreezeManager = oCV.getPinFreezeManager();
  783. if (oPinFreezeManager && oPinFreezeManager.hasFrozenContainers()) {
  784. var oRVContent = document.getElementById("RVContent" + oCV.getId());
  785. var mainViewerTable = document.getElementById("mainViewerTable" + oCV.getId());
  786. var pageWidth = oRVContent.clientWidth;
  787. var pageHeight = mainViewerTable.clientHeight;
  788. oPinFreezeManager.resize(pageWidth, pageHeight);
  789. // force IE to repaint the div or the the RVContent div won't resize
  790. if (isIE()) {
  791. oCV.repaintDiv(oRVContent);
  792. }
  793. }
  794. }
  795. }
  796. function setWindowHref(url) {
  797. var oldUnload=window.onbeforeunload;
  798. window.onbeforeunload=null;
  799. window.location.href = url;
  800. window.onbeforeunload=oldUnload;
  801. }
  802. /**
  803. * Replaces parameter place holders in the specified msg with the specified args.
  804. * args can be a string or any array, otherwise, it is treated as string.
  805. * for example, getMessage("param0 {0}", 'zero") will return "param0 zero".
  806. */
  807. CViewerCommon.getMessage = function(msg, args)
  808. {
  809. if (typeof args == "undefined")
  810. {
  811. return msg;
  812. }
  813. else if (typeof args == "string")
  814. {
  815. msg = msg.replace("{0}", args);
  816. }
  817. else if (args.length)
  818. {
  819. for (var i = 0; i < args.length; ++i)
  820. {
  821. msg = msg.replace("{" + i + "}", args[i]);
  822. }
  823. }
  824. else
  825. {
  826. msg = msg.replace("{0}", args);
  827. }
  828. return msg;
  829. };
  830. function getViewerDirection() {
  831. if(window.gaRV_INSTANCES && window.gaRV_INSTANCES.length) {
  832. return gaRV_INSTANCES[0].getDirection();
  833. }
  834. return "ltr";
  835. }
  836. function isViewerBidiEnabled() {
  837. if(window.gaRV_INSTANCES && window.gaRV_INSTANCES.length) {
  838. var bidiEnabled = gaRV_INSTANCES[0].isBidiEnabled();
  839. if(bidiEnabled){
  840. return true;
  841. }
  842. }
  843. return false;
  844. }
  845. function getViewerBaseTextDirection() {
  846. if(window.gaRV_INSTANCES && window.gaRV_INSTANCES.length) {
  847. return gaRV_INSTANCES[0].getBaseTextDirection();
  848. }
  849. return "";
  850. }
  851. /**
  852. * Enforces current BTD on input string, by inserting unicode Bidi directional
  853. * marks before (LRE/RLE) and after (PDF).
  854. *
  855. * @param {string} sText, input string
  856. * @return {string} input string forced to current BTD
  857. */
  858. function enforceTextDir(sText) {
  859. if(isViewerBidiEnabled() && sText){
  860. var sDir = getViewerBaseTextDirection();
  861. var bidiUtils = BidiUtils.getInstance();
  862. if(sDir == 'auto') {
  863. sDir = bidiUtils.resolveStrBtd(sText);
  864. }
  865. var strongSeparator = (!dojo._isBodyLtr()) ? bidiUtils.RLM : bidiUtils.LRM;
  866. return strongSeparator + ((sDir==="rtl") ? bidiUtils.RLE : bidiUtils.LRE) + sText + bidiUtils.PDF + strongSeparator;
  867. }
  868. return sText;
  869. };
  870. /**
  871. * returns the direction in use on the given element (ltr or rtl)
  872. */
  873. function getElementDirection(element) {
  874. var dir = null;
  875. if(element.currentStyle) { //IE
  876. dir = element.currentStyle.direction;
  877. } else if(window.getComputedStyle) { //FF
  878. var style = window.getComputedStyle(element,null);
  879. if(style) {
  880. dir = style.getPropertyValue("direction");
  881. }
  882. }
  883. if(dir) {
  884. dir = dir.toLowerCase();
  885. }
  886. return dir;
  887. }
  888. /**
  889. * Returns the amount an element have been scrolled to the left.
  890. * This function is necessary due to a Firefox behaviour, where in
  891. * RTL mode, the scrollLeft actually returns the amount scrolled
  892. * to the right, and the value is negative. In some places, this
  893. * is documented as an feature, in others, as a bug. See:
  894. * https://bugzilla.mozilla.org/show_bug.cgi?id=383026
  895. * https://developer.mozilla.org/en/DOM/element.scrollLeft
  896. * IE on the other hand always returns the distance scrolled from
  897. * the left, with a positive value, regardless of direction.
  898. */
  899. function getScrollLeft(element) {
  900. if(getElementDirection(element) === "rtl" && isFF()) {
  901. // scrollLeft + offsetWidth + scrollRight = scrollWidth,
  902. // where scrollRight = -element.scrollLeft
  903. return element.scrollWidth - element.offsetWidth + element.scrollLeft;
  904. }
  905. return element.scrollLeft;
  906. }
  907. /**
  908. * Modifies the scroll position of the element such that it is
  909. * scrollLeft pixels from the left, regardless of the browser or
  910. * direction. (See comment on getScrollLeft for more details)
  911. */
  912. function setScrollLeft(element, scrollLeft) {
  913. if(getElementDirection(element) === "rtl" && isFF()) {
  914. // scrollLeft + offsetWidth + scrollRight = scrollWidth,
  915. // where scrollRight = -element.scrollLeft
  916. element.scrollLeft = element.offsetWidth + scrollLeft - element.scrollWidth;
  917. } else {
  918. element.scrollLeft = scrollLeft;
  919. }
  920. }
  921. /**
  922. * Modifies the scroll position of the element such that it is
  923. * scrollRight pixels from the right, regardless of the browser
  924. * or direction. (See comment on getScrollLeft for more details)
  925. */
  926. function setScrollRight(element, scrollRight) {
  927. if(getElementDirection(element) === "rtl" && isFF()) {
  928. //Take advantage of Firefox behaviour - less arithmetic
  929. element.scrollLeft = -scrollRight;
  930. } else {
  931. element.scrollLeft = element.scrollWidth - element.offsetWidth - scrollRight;
  932. }
  933. }
  934. /**
  935. * return the inherited padding and border rectangle properties in an
  936. * object (marginLeft/Right/Top/Bottom, borderLeftWidth/Right/Top/Bottom,
  937. * paddingLeft/Right/Top/Bottom).
  938. * Set the parameter toInt to true to strip out the "px" unit and make into
  939. * an int.
  940. */
  941. function getBoxInfo(el, toInt) {
  942. //Set all styles as a static member of the function
  943. if(!getBoxInfo.aStyles) {
  944. getBoxInfo.aStyles = [
  945. {name: "marginLeft", ie: "marginLeft", ff: "margin-left"},
  946. {name: "marginRight", ie: "marginRight", ff: "margin-right"},
  947. {name: "marginTop", ie: "marginTop", ff: "margin-top"},
  948. {name: "marginBottom", ie: "marginBottom", ff: "margin-bottom"},
  949. {name: "borderLeftWidth", ie: "borderLeftWidth", ff: "border-left-width"},
  950. {name: "borderRightWidth", ie: "borderRightWidth", ff: "border-right-width"},
  951. {name: "borderTopWidth", ie: "borderTopWidth", ff: "border-top-width"},
  952. {name: "borderBottomWidth", ie: "borderBottomWidth", ff: "border-bottom-width"},
  953. {name: "paddingLeft", ie: "paddingLeft", ff: "padding-left"},
  954. {name: "paddingRight", ie: "paddingRight", ff: "padding-right"},
  955. {name: "paddingTop", ie: "paddingTop", ff: "padding-top"},
  956. {name: "paddingBottom", ie: "paddingBottom", ff: "padding-bottom"}
  957. ];
  958. }
  959. var oSizing = {};
  960. var oStyle = null;
  961. if (el.currentStyle) { //IE
  962. oStyle = el.currentStyle;
  963. } else if (window.getComputedStyle) { //Firefox
  964. oStyle = window.getComputedStyle(el,null);
  965. }
  966. if(!oStyle) {
  967. return null;
  968. }
  969. for (i in getBoxInfo.aStyles) {
  970. var style = getBoxInfo.aStyles[i];
  971. var size = null;
  972. if(oStyle.getPropertyValue) {
  973. size = oStyle.getPropertyValue(style.ff);
  974. } else {
  975. size = oStyle[style.ie];
  976. }
  977. if(size && toInt) {
  978. size = Number(size.replace('px',''));
  979. }
  980. oSizing[style.name] = size;
  981. }
  982. return oSizing;
  983. }