aboutdialog.js 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. // Licensed Materials - Property of IBM
  2. //
  3. // IBM Cognos Products: ps
  4. //
  5. // (C) Copyright IBM Corp. 2005, 2013
  6. //
  7. // US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  8. // Copyright (C) 2008 Cognos Incorporated. All rights reserved.
  9. // Cognos and the Cognos logo are trademarks of Cognos Incorporated.
  10. function addEvent(obj, evType, fn) {
  11. if (obj.addEventListener) {
  12. obj.addEventListener(evType, fn, false);
  13. return true;
  14. } else if (obj.attachEvent) {
  15. var r = obj.attachEvent("on" + evType, fn);
  16. return r;
  17. } else {
  18. return false;
  19. }
  20. }
  21. function removeEvent(obj, type, fn) {
  22. if (obj.removeEventListener) {
  23. return obj.removeEventListener(type, fn, false);
  24. } else if (obj.detachEvent) {
  25. return obj.detachEvent('on' + type, fn);
  26. } else {
  27. return false;
  28. }
  29. }
  30. var aboutBox = null;
  31. function updateAboutBoxTitleAttribute(){
  32. try{
  33. if (aboutBox.currentMessageRequest.readyState == 4)
  34. {
  35. if (aboutBox.currentMessageRequest.status == 404){
  36. //in this case we failed to load the real message file....lets load the default
  37. aboutBox.messageLoadErrorCount++;
  38. if (aboutBox.messageLoadErrorCount < 2) {
  39. aboutBox.loadMessageFile(aboutBox.JSMessageFileDefault);
  40. }
  41. }
  42. if (aboutBox.currentMessageRequest.status >= 200 && aboutBox.currentMessageRequest.status < 300)
  43. {
  44. var messageFile = eval("(" + aboutBox.currentMessageRequest.responseText + ")");
  45. //Set the ALT text for the aboutbox image
  46. var text = messageFile.ABT.IDS_ABT_PRODUCT + "\n" + messageFile.ABT.IDS_ABT_VERSION + "\n" + messageFile.ABT.IDS_ABT_LEGAL;
  47. aboutBox.imageEl.alt = text;
  48. aboutBox.imageEl.title = text;
  49. text = messageFile.ABT.IDS_ABT_OK;
  50. if (typeof messageFile.ABT.IDS_ABT_OK === "undefined"){
  51. //if it can't find the ok string in the passed in message file then lets go with a hard coded ok....
  52. text = "OK";
  53. }
  54. aboutBox.okButtonText = text;
  55. }
  56. aboutBox.completeShow();
  57. }
  58. }
  59. catch (e){aboutBox.completeShow();}
  60. }
  61. function about_dialog(aboutImage, defaultImage, JSMessageFile, JSMessageFileDefault) {
  62. this.xmlHttpVersions = [
  63. "Msxml2.XMLHTTP.6.0",
  64. "Msxml2.XMLHTTP.3.0",
  65. "Msxml2.XMLHTTP",
  66. "Microsoft.XMLHTTP"
  67. ];
  68. this.xmlHttpDefault=this.findXMLHttpActiveXVersion();
  69. this.mainDiv = null;
  70. this.aboutImage = aboutImage;
  71. this.imageHeight = 452;
  72. this.imageWidth = 652;
  73. this.lockingFrame = null;
  74. this.defaultImage = defaultImage;
  75. this.JSMessageFile = JSMessageFile;
  76. this.JSMessageFileDefault = JSMessageFileDefault;
  77. aboutBox = this;
  78. this.currentMessageRequest = null;
  79. this.messageLoadErrorCount = 0;
  80. this.idToFocusOnClose = null;
  81. this.okButtonText = null;
  82. }
  83. about_dialog.prototype = {
  84. create: function() {
  85. this.errorCount = 0;
  86. this.mainDiv = document.createElement("div");
  87. this.mainDiv.tabIndex = "-1";
  88. this.mainDiv.style.width = this.imageWidth;
  89. this.mainDiv.style.position = "absolute";
  90. this.lockingFrame = document.createElement("div");
  91. this.lockingFrame.style.filter = "alpha(opacity=50)";
  92. this.lockingFrame.style.opacity = "0.5";
  93. this.lockingFrame.style.MozOpacity = "0.5";
  94. this.lockingFrame.style.height = "100%";
  95. this.lockingFrame.style.width = "100%";
  96. this.lockingFrame.style.position = "absolute";
  97. this.lockingFrame.style.left = "0px";
  98. this.lockingFrame.style.top = "0px";
  99. this.lockingFrame.style.backgroundColor = "rgb(221, 221, 221)";
  100. this.lockingFrame.style.zIndex = "100";
  101. this.mainDiv.style.zIndex = "200";
  102. this.hide();
  103. document.body.appendChild(this.mainDiv);
  104. document.body.appendChild(this.lockingFrame);
  105. this.imageEl = document.createElement("img");
  106. this.imageEl.tabIndex = "0";
  107. if (typeof this.defaultImage !== 'undefined'){
  108. this.imageEl.style.visibility = "hidden";
  109. addEvent(this.imageEl, "error", this.loadDefaultImage);
  110. addEvent(this.imageEl, "load", this.loadImageLoadComplete);
  111. }
  112. this.imageEl.src = this.aboutImage;
  113. this.mainDiv.appendChild(this.imageEl);
  114. addEvent(this.mainDiv, "click", this.aboutClicked);
  115. },
  116. loadMessageFile: function(messageFile){
  117. aboutBox.currentMessageRequest = aboutBox.getXMLHttpRequest();
  118. aboutBox.currentMessageRequest.open("GET",messageFile,true);
  119. aboutBox.currentMessageRequest.onreadystatechange = updateAboutBoxTitleAttribute;
  120. aboutBox.currentMessageRequest.send(null);
  121. },
  122. loadImageLoadComplete: function(){
  123. aboutBox.loadMessageFile(aboutBox.JSMessageFile);
  124. aboutBox.imageEl.style.visibility = "visible";
  125. },
  126. loadDefaultImage: function(){
  127. aboutBox.errorCount++;
  128. if (aboutBox.errorCount < 2){
  129. aboutBox.imageEl.src = aboutBox.defaultImage;
  130. }
  131. },
  132. createOKButton: function() {
  133. var aboutDivEl = document.createElement("div");
  134. aboutDivEl.style.border = "1px solid #999999";
  135. aboutDivEl.style.fontSize = "90%";
  136. aboutDivEl.style.fontWeight = "normal";
  137. aboutDivEl.style.padding = "2px 10px 3px";
  138. aboutDivEl.style.position = "absolute";
  139. this.mainDiv.appendChild(aboutDivEl);
  140. aboutDivEl.width = "55";
  141. var anc = document.createElement("a");
  142. anc.href = "javascript:if (aboutBox != null){aboutBox.aboutClicked();}";
  143. anc.onclick = function() {return false;};
  144. aboutDivEl.appendChild(anc);
  145. var ancText = this.okButtonText;
  146. if (ancText == null){
  147. ancText = "OK";
  148. }
  149. var textEl = document.createTextNode(ancText);
  150. anc.appendChild(textEl);
  151. anc.style.color = "#000000";
  152. anc.style.textDecoration = "none";
  153. anc.setAttribute("role", "button");
  154. this.okButton = anc;
  155. addEvent(anc, "keydown", this.aboutKeyDown);
  156. aboutDivEl.style.left = 20 + "px";
  157. aboutDivEl.style.bottom = "20px";
  158. },
  159. show: function() {
  160. if (this.mainDiv == null) {
  161. this.create();
  162. createOK = true;
  163. } else {
  164. this.completeShow();
  165. }
  166. },
  167. completeShow: function(){
  168. this.center();
  169. this.mainDiv.style.display = 'block';
  170. this.mainDiv.style.visibility = 'visible';
  171. this.lockingFrame.style.display = 'block';
  172. this.lockingFrame.style.visibility = 'visible';
  173. addEvent(document.body, "keydown", this.aboutKeyDown);
  174. this.createOKButton();
  175. this.mainDiv.focus();
  176. }
  177. ,
  178. center: function() {
  179. this.mainDiv.style.left = ((document.body.clientWidth - this.imageWidth) / 2) + document.body.scrollLeft + "px";
  180. this.mainDiv.style.top = ((this.getWindowHeight() - this.imageHeight) / 2) + document.body.scrollTop + "px";
  181. },
  182. getWindowHeight: function() {
  183. if( document.documentElement && document.documentElement.clientHeight ) {
  184. return document.documentElement.clientHeight;
  185. } else if( document.body && document.body.clientHeight ) {
  186. return document.body.clientHeight;
  187. } else if( typeof( window.innerHeight ) == 'number' ) {
  188. return window.innerHeight;
  189. }
  190. },
  191. aboutClicked: function(event) {
  192. if (event.stopPropagation) {
  193. event.stopPropagation();
  194. } else {
  195. event.cancelBubble = 'true';
  196. }
  197. if (aboutBox != null) {
  198. aboutBox.hide();
  199. aboutBox.destroyDialog();
  200. }
  201. },
  202. aboutKeyDown: function(event) {
  203. if (aboutBox == null) {
  204. return;
  205. }
  206. if (event.keyCode == 27 || event.keyCode == 32) {
  207. aboutBox.hide();
  208. aboutBox.destroyDialog();
  209. }
  210. },
  211. hide: function() {
  212. removeEvent(document.body, 'keydown', this.aboutKeyDown);
  213. aboutBox.mainDiv.style.display = 'none';
  214. this.mainDiv.style.visibility = 'hidden';
  215. this.lockingFrame.style.display = 'none';
  216. this.lockingFrame.style.visibility = 'hidden';
  217. if (this.idToFocusOnClose != null){
  218. var focEl = document.getElementById(this.idToFocusOnClose);
  219. if (focEl != null) {
  220. focEl.focus();
  221. }
  222. }
  223. },
  224. destroyDialog: function() {
  225. document.body.removeChild(this.mainDiv);
  226. document.body.removeChild(this.lockingFrame);
  227. this.mainDiv = null;
  228. this.lockingFrame = null;
  229. aboutBox = null;
  230. },
  231. findXMLHttpActiveXVersion: function(){
  232. if (window.ActiveXObject) {
  233. var i, l = this.xmlHttpVersions.length;
  234. for (i = 0; i < l; i++) {
  235. try {
  236. // Try and create the ActiveXObject for Internet Explorer, if it doesn't work, try again.
  237. var xmlhttp = new ActiveXObject(this.xmlHttpVersions[i]);
  238. if (xmlhttp)
  239. return this.xmlHttpVersions[i];
  240. } catch (e) {
  241. // this ActiveX is not there, continue with next one in list
  242. }
  243. }
  244. }
  245. return null;
  246. },
  247. getXMLHttpRequest:function(){
  248. if (this.xmlHttpDefault != null) {
  249. return new ActiveXObject(this.xmlHttpDefault);
  250. }
  251. // Well if there is no ActiveXObject available it must be firefox, opera, or something else
  252. if (typeof XMLHttpRequest != 'undefined') {
  253. try {
  254. return new XMLHttpRequest();
  255. } catch (e) {
  256. alert(e);
  257. }
  258. }
  259. throw "No XMLHttpRequest object is available";
  260. }
  261. };