overlib_setonoff.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. //\/////
  2. //\ overLIB Set On/Off Plugin
  3. //\ This file requires overLIB 4.10 or later.
  4. //\
  5. //\ overLIB 4.10 - You may not remove or change this notice.
  6. //\ Copyright Erik Bosrup 1998-2003. All rights reserved.
  7. //\ Contributors are listed on the homepage.
  8. //\ See http://www.bosrup.com/web/overlib/ for details.
  9. // $Revision: 1.3 $ $Date: 2004/11/25 21:27:19 $
  10. //
  11. //\/////
  12. //\mini
  13. ////////
  14. // PRE-INIT
  15. // Ignore these lines, configuration is below.
  16. ////////
  17. if (typeof olInfo == 'undefined' || typeof olInfo.meets == 'undefined' || !olInfo.meets(4.10)) alert('overLIB 4.10 or later is required for the Set On/Off Plugin.');
  18. else {
  19. registerCommands('seton, setoff');
  20. var olSetType;
  21. // END OF CONFIGURATION
  22. // Don't change anything below this line, all configuration is above.
  23. ////////
  24. // PLUGIN FUNCTIONS
  25. ////////
  26. // Set runtime variables
  27. function setOnOffVariables() {
  28. olSetType = 0;
  29. }
  30. // Parses Set On/Off Parameters
  31. function parseOnOffExtras(pf, i, ar) {
  32. var k = i, v;
  33. if (k < ar.length) {
  34. if (ar[k] == SETON||ar[k] == SETOFF) { olSetType = 1; k = opt_MULTICOMMANDS(++k, ar); return k; }
  35. }
  36. return -1;
  37. }
  38. ///////
  39. // HELPER FUNCTIONS
  40. ///////
  41. // searches arg list for COMMAND;
  42. function hasCommand(istrt, args, COMMAND) {
  43. for (var i = istrt; i < args.length; i++) {
  44. if (typeof args[i] == 'number' && args[i] == COMMAND) return i;
  45. }
  46. return -1;
  47. }
  48. // scans for toggle like commands to be forced ON/OFF
  49. function scanCommandSet(pf, args) {
  50. var k = -1, j, je;
  51. if (olSetType) {
  52. // search for SETON command
  53. while ((k = hasCommand(++k, args, SETON)) < args.length && k > -1) {
  54. je = opt_MULTICOMMANDS(k + 1, args);
  55. for (j = k + 1; j < (k + je); j++) setNoParamCommand(1, pf, args[j]);
  56. k += (je - 1);
  57. }
  58. // search for SETOFF command
  59. k = -1;
  60. while ((k = hasCommand(++k, args, SETOFF)) < args.length && k > -1) {
  61. je = opt_MULTICOMMANDS(k + 1, args);
  62. for (j = k + 1; j < (k + je); j++) setNoParamCommand(0, pf, args[j]);
  63. k += (je - 1);
  64. }
  65. }
  66. return true;
  67. }
  68. var olRe;
  69. // set command according to whichType (0 or 1)
  70. function setNoParamCommand(whichType, pf, COMMAND) {
  71. var v = pms[COMMAND - 1 - pmStart];
  72. if(pmt && !olRe) olRe = eval('/' + pmt.split(',').join('|') + '/');
  73. if (pf != 'ol_' && /capturefirst/.test(v)) return; // no o3_capturefirst variable
  74. if (pf != 'ol_' && /wrap/.test(v) && eval(pf + 'wrap') && (whichType == 0)) {
  75. nbspCleanup(); // undo wrap effects since checked after all parsing
  76. o3_width = ol_width;
  77. }
  78. if (olRe.test(v)) eval(pf + v + '=' + ((whichType && COMMAND == AUTOSTATUSCAP) ? whichType++ : whichType));
  79. }
  80. function opt_MULTICOMMANDS(i, ar) {
  81. var k = i;
  82. while (k < ar.length && typeof ar[k] == 'number' && ar[k] > pmStart) {k++; if (ar[k - 1] == 'SETON'||ar[k - 1] == 'SETOFF') break;}
  83. k -= (k < ar.length ? 2 : 1);
  84. return k;
  85. }
  86. ////////
  87. // PLUGIN REGISTRATIONS
  88. ////////
  89. registerRunTimeFunction(setOnOffVariables);
  90. registerCmdLineFunction(parseOnOffExtras);
  91. registerPostParseFunction(scanCommandSet);
  92. }