espdefault.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*##############################################################################
  2. # Copyright (C) 2011 HPCC Systems.
  3. #
  4. # All rights reserved. This program is free software: you can redistribute it and/or modify
  5. # it under the terms of the GNU Affero General Public License as
  6. # published by the Free Software Foundation, either version 3 of the
  7. # License, or (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU Affero General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU Affero General Public License
  15. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. ############################################################################## */
  17. /*-----------------------------------------------------------------------
  18. Default ESP Script Functions
  19. **-----------------------------------------------------------------------*/
  20. /*-----------------------------------------------------------------------
  21. To be included in any ESP page that needs to prevent F5 from refreshing and
  22. resetting back to the home frameset.
  23. **-----------------------------------------------------------------------*/
  24. var isFF=/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent)?1:0;
  25. var isChrome=/Chrome[\/\s](\d+\.\d+)/.test(navigator.userAgent)?1:0;
  26. function nof5() {
  27. if (parent.window.frames && parent.window.frames[0]) {
  28. //parent.window.frames[0].focus();
  29. for (var i_tem = 0; i_tem < parent.window.frames.length; i_tem++) {
  30. if (parent.window.frames[i_tem] == window) {
  31. if (isFF)
  32. parent.window.frames[i_tem].onkeypress = new Function("e", "if(e.keyCode==116){parent.window.frames[" + i_tem + "].location.replace(parent.window.frames[" + i_tem + "].location);e.preventDefault();e.stopPropagation();}")
  33. else
  34. parent.window.frames[i_tem].document.onkeydown = new Function("var e=parent.window.frames[" + i_tem + "].event; if(e.keyCode==116){parent.window.frames[" + i_tem + "].location.replace(parent.window.frames[" + i_tem + "].location);e.keyCode=0;return false;};");
  35. }
  36. }
  37. }
  38. setF5ForFrames();
  39. }
  40. function getAFrame(name) {
  41. var aFrame = null;
  42. if (parent.window.frames && parent.window.frames[0]) {
  43. for (var i_tem = 0; i_tem < parent.window.frames.length; i_tem++) {
  44. if (parent.window.frames[i_tem].name == name)
  45. aFrame = parent.window.frames[i_tem];
  46. }
  47. }
  48. return aFrame;
  49. }
  50. function setF5ForFrames() {
  51. var headerFrame = getAFrame('header');
  52. if (headerFrame) {
  53. if (isFF)
  54. headerFrame.onkeypress = new Function("e", "if(e.keyCode==116){getAFrame('main').location.replace(getAFrame('main').location);e.preventDefault();e.stopPropagation();}")
  55. else
  56. headerFrame.document.onkeydown = new Function("var e=getAFrame('header').event; if(e.keyCode==116){getAFrame('main').location.replace(getAFrame('main').location);e.keyCode=0;return false;};");
  57. }
  58. var navFrame = getAFrame('nav');
  59. if (navFrame) {
  60. if (isFF)
  61. navFrame.onkeypress = new Function("e", "if(e.keyCode==116){getAFrame('main').location.replace(getAFrame('main').location);e.preventDefault();e.stopPropagation();}")
  62. else
  63. navFrame.document.onkeydown = new Function("var e=getAFrame('nav').event; if(e.keyCode==116){getAFrame('main').location.replace(getAFrame('main').location);e.keyCode=0;return false;};");
  64. }
  65. }
  66. function setReloadFunction(TargetFunction) {
  67. var LocalReloadFunction = (TargetFunction.indexOf('(') > -1 ? TargetFunction : TargetFunction + '()');
  68. if (parent.window.frames && parent.window.frames[0]) {
  69. //parent.window.frames[0].focus();
  70. for (var i_tem = 0; i_tem < parent.window.frames.length; i_tem++) {
  71. if (parent.window.frames[i_tem] == window) {
  72. if (isFF)
  73. parent.window.frames[i_tem].onkeypress = new Function("e", "if(e.keyCode==116){" + LocalReloadFunction + ";e.preventDefault();e.stopPropagation();}")
  74. else
  75. parent.window.frames[i_tem].document.onkeydown = new Function("var e=parent.window.frames[" + i_tem + "].event; if(e.keyCode==116){e.keyCode=0;" + LocalReloadFunction + ";return false;};");
  76. }
  77. }
  78. }
  79. }
  80. function go(url) {
  81. document.location.href = url;
  82. }