overlib_crossframe.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. //\/////
  2. //\ overLIB Crossframe Support Plugin
  3. //\ This file requires overLIB 4.10 or later.
  4. //\
  5. //\ overLIB 4.05 - You may not remove or change this notice.
  6. //\ Copyright Erik Bosrup 1998-2004. All rights reserved.
  7. //\ Contributors are listed on the homepage.
  8. //\ See http://www.bosrup.com/web/overlib/ for details.
  9. // $Revision: 1.8 $ $Date: 2004/11/25 21:27:19 $
  10. //\/////
  11. //\mini
  12. ////////
  13. // PRE-INIT
  14. // Ignore these lines, configuration is below.
  15. ////////
  16. if (typeof olInfo == 'undefined' || typeof olInfo.meets == 'undefined' || !olInfo.meets(4.10)) alert('overLIB 4.10 or later is required for the Cross Frame Support Plugin.');
  17. else {
  18. registerCommands('frame');
  19. ////////
  20. // PLUGIN FUNCTIONS
  21. ///////
  22. // Parses FRAME command
  23. function parseFrameExtras(pf,i,ar) {
  24. var k = i,v;
  25. if (k < ar.length) {
  26. if (ar[k] == FRAME) { v = ar[++k]; if(pf == 'ol_') ol_frame = v; else opt_FRAME(v); return k; }
  27. }
  28. return -1;
  29. }
  30. ////////
  31. // SUPPORT FUNCTIONS
  32. ////////
  33. // Defines which frame we should point to.
  34. function opt_FRAME(frm) {
  35. o3_frame = frm;
  36. over = createDivContainer('overDiv');
  37. return 0;
  38. }
  39. // Get frame depth of nested frames
  40. function frmDepth(thisFrame,ofrm) {
  41. var retVal = '';
  42. for (var i = 0; i<thisFrame.length; i++) {
  43. if (thisFrame[i].length > 0) {
  44. retVal = frmDepth(thisFrame[i],ofrm);
  45. if (retVal == '') continue;
  46. } else if (thisFrame[i] != ofrm) continue;
  47. retVal = '[' + i + ']' + retVal;
  48. break;
  49. }
  50. return retVal;
  51. }
  52. // Gets frame reference value relative to top frame
  53. function getFrmRef(srcFrm,tgetFrm) {
  54. var rtnVal = ''
  55. if (tgetFrm != srcFrm) {
  56. var tFrm = frmDepth(top.frames,tgetFrm)
  57. var sFrm = frmDepth(top.frames,srcFrm)
  58. if (sFrm.length == tFrm.length) {
  59. l = tFrm.lastIndexOf('[')
  60. if (l) {
  61. while ( sFrm.substring(0,l) != tFrm.substring(0,l) )
  62. l = tFrm.lastIndexOf('[',l-1)
  63. tFrm = tFrm.substr(l)
  64. sFrm = sFrm.substr(l)
  65. }
  66. }
  67. var cnt = 0, p = '',str = tFrm
  68. while ((k = str.lastIndexOf('[')) != -1) {
  69. cnt++
  70. str = str.substring(0,k)
  71. }
  72. for (var i = 0; i<cnt; i++) p = p + 'parent.'
  73. rtnVal = p + 'frames' + sFrm + '.'
  74. }
  75. return rtnVal
  76. }
  77. function chkForFrmRef() {
  78. if(o3_frame != ol_frame) fnRef = getFrmRef(ol_frame,o3_frame)
  79. return true;
  80. }
  81. ////////
  82. // PLUGIN REGISTRATIONS
  83. ////////
  84. registerCmdLineFunction(parseFrameExtras);
  85. registerPostParseFunction(chkForFrmRef);
  86. }