home *** CD-ROM | disk | FTP | other *** search
/ internet.au CDrom 42 / NETCD42.iso / web / w95 / dream2.exe / data1.cab / Program_Files / Configuration / Behaviors / Actions / Check Plugin.js < prev    next >
Encoding:
JavaScript  |  1998-11-30  |  5.4 KB  |  173 lines

  1. // Copyright 1998 Macromedia, Inc. All rights reserved.
  2.  
  3. //****************** Globals *******************
  4.  
  5. function initGlobals() {
  6.   PLUGIN_NAMES = new Array("Shockwave Flash","Shockwave for Director","LiveAudio",
  7.                            "Netscape Media Player","QuickTime Plug-In");
  8. }
  9.  
  10. var PLUGIN_NAMES;
  11.  
  12.  
  13. //******************* BEHAVIOR FUNCTION **********************
  14.  
  15. //Sends the browser to one URL if the plugin exists, otherwise
  16. //sends the browser to an alternate URL.
  17. //The function accepts the following arguments:
  18. //  plugin  - the *exact* name of the plugin as registered (ex: Shockwave Flash 2.0)
  19. //  theURL  - optional URL, often a filename, URL encoded. (ex: file.htm, http://www.x.com/y.htm)
  20. //  altURL  - required URL, often a filename, URL encoded. (ex: file.htm, http://www.x.com/y.htm)
  21. //  IEGoesToURL - boolean. If true, Internet Explorer always goes to theURL. If false, altURL.
  22. //
  23. //Checks if the plugins array exists and the plugin is found, *or*
  24. //if flag is set, and MSIE browser for Win95/NT (ActiveX ok), then goes to theURL if nonempty.
  25. //else goes to altURL. Goes to a URL by setting the window.location property.
  26.  
  27. function MM_checkPlugin(plugin, theURL, altURL, IEGoesToURL) { //v2.0
  28.   if ((navigator.plugins && navigator.plugins[plugin]) || //if NS, or
  29.       (IEGoesToURL &&  //if flag set, and MSIE browser for Win95/NT (ActiveX)
  30.        navigator.appName.indexOf('Microsoft') != -1 &&
  31.        navigator.appVersion.indexOf('Mac') == -1 &&
  32.        navigator.appVersion.indexOf('3.1') == -1)) {
  33.     if (theURL.length>2) window.location = theURL;
  34.   } else {
  35.     if (altURL.length>2) window.location = altURL;
  36.   }
  37.   document.MM_returnValue = false;
  38. }
  39.  
  40.  
  41. //******************* API **********************
  42.  
  43.  
  44. //Can be used with any tag and any event
  45.  
  46. function canAcceptBehavior(){
  47.   return true;
  48. }
  49.  
  50.  
  51.  
  52. //Returns a Javascript function to be inserted in HTML head with script tags.
  53.  
  54. function behaviorFunction() {
  55.   return "MM_checkPlugin";
  56. }
  57.  
  58.  
  59.  
  60. //Returns fn call to insert in HTML tag <TAG... onEvent='thisFn(arg)'>
  61. //Calls escQuotes to find embedded quotes and precede them with \
  62. //Calls escape to encode URLs
  63.  
  64. function applyBehavior() {
  65.   var pluginName, theURL, altURL, IEGoesToURL, theMenu;
  66.  
  67.   if (document.theForm.theRadio[0].checked) { //get URL from textfield or menu
  68.     pluginName = document.theForm.menu.options[document.theForm.menu.selectedIndex].text;
  69.   } else {
  70.     pluginName = escQuotes(document.theForm.pluginName.value);
  71.   }
  72.  
  73.   theURL = escape(document.theForm.theURL.value);  //URL encode
  74.   altURL = escape(document.theForm.altURL.value);  //URL encode
  75.   IEGoesToURL = document.theForm.IEGoesToURL.checked;
  76.   if (pluginName && altURL) {
  77.     return "MM_checkPlugin('"+pluginName+"','"+theURL+"','"+altURL+"',"+IEGoesToURL+")";
  78.   } else {
  79.     return MSG_NoPluginOrURL;
  80.   }
  81. }
  82.  
  83.  
  84.  
  85. //Returns a dummy function call to inform Dreamweaver the type of certain behavior
  86. //call arguments. This information is used by DW to fixup behavior args when the
  87. //document is moved or changed.
  88. //
  89. //It is passed an actual function call string generated by applyBehavior(), which
  90. //may have a variable list of arguments, and this should return a matching mask.
  91. //
  92. //The return values are:
  93. //  URL     : argument could be a file path, which DW will update during Save As...
  94. //  NS4.0ref: arg is an object ref that may be changed by Convert Tables to Layers
  95. //  IE4.0ref: arg is an object ref that may be changed by Convert Tables to Layers
  96. //  other...: argument is ignored
  97.  
  98. function identifyBehaviorArguments(fnCallStr) {
  99.   var argArray;
  100.  
  101.   argArray = extractArgs(fnCallStr);
  102.   if (argArray.length == 5) {
  103.     return "other,URL,URL,other";
  104.   } else {
  105.     return "";
  106.   }
  107. }
  108.  
  109.  
  110.  
  111. //Passed the function call above, takes prior arguments and reloads the UI.
  112. //Removes any escape characters "\"
  113.  
  114. function inspectBehavior(argStr){
  115.   var i, plugIn, inMenu;
  116.   var argArray = extractArgs(argStr);
  117.  
  118.   if (argArray.length == 5) {
  119.  
  120.     plugIn = unescQuotes(argArray[1]);
  121.     document.theForm.theURL.value = unescape(argArray[2]);  //URL decode
  122.     document.theForm.altURL.value = unescape(argArray[3]);  //URL decode
  123.     document.theForm.IEGoesToURL.checked = eval(argArray[4]);
  124.  
  125.     inMenu = false;
  126.     for (i=0; i<document.theForm.menu.options.length; i++) { //check if exists in menu
  127.       if (document.theForm.menu.options[i].text == plugIn) {
  128.         document.theForm.menu.selectedIndex = i;
  129.         inMenu = true;
  130.         break;
  131.       }
  132.     }
  133.     if (!inMenu) {
  134.       document.theForm.pluginName.value = plugIn;
  135.       setRadio(1); //set radio
  136.     }
  137.   }
  138. }
  139.  
  140.  
  141.  
  142. //**************** LOCAL FUNCTIONS ****************
  143.  
  144.  
  145. //Loads a preset list of some plugin names.
  146.  
  147. function initializeUI() {
  148.   initGlobals();
  149.   for (i=0; i<PLUGIN_NAMES.length; i++)
  150.     document.theForm.menu.options[i] = new Option(PLUGIN_NAMES[i]);
  151.  
  152.   document.theForm.theURL.focus(); //set focus on textbox
  153.   document.theForm.theURL.select(); //set insertion point into textbox
  154. }
  155.  
  156.  
  157.  
  158. //Passed a number, selects that radio.
  159.  
  160. function setRadio(num) {
  161.   document.theForm.theRadio[0].checked = (num==0)?true:false;
  162.   document.theForm.theRadio[1].checked = (num==1)?true:false;
  163. }
  164.  
  165.  
  166.  
  167. //**************** GENERIC FUNCTIONS ****************
  168.  
  169. //function extractArgs(upStr){
  170. //function escQuotes(theStr){
  171. //function unescQuotes(theStr){
  172. //function browseFile(fieldToStoreURL){
  173.