home *** CD-ROM | disk | FTP | other *** search
/ Chip 2003 October / Chip Ekim 2003.iso / prog / code / contr / setup.exe / Disk1 / data1.cab / Configuration_En / Menus / MM / Design Notes Launch Sel.js < prev    next >
Encoding:
JavaScript  |  2003-07-18  |  2.6 KB  |  74 lines

  1. // Copyright 2000, 2001, 2002, 2003 Macromedia, Inc. All rights reserved.
  2.  
  3. //Launches Design Notes iff selection is IMG, EMBED, OBJECT, APPLET, or INPUT/IMAGE
  4.  
  5. //******************* GLOBALS **********************
  6.  
  7. var CMD_TO_LAUNCH = "Design Notes.htm";
  8.  
  9. //***************** API  ******************
  10.  
  11. function canAcceptCommand() {
  12.   var src = getSrcAttrib();
  13.   return (src != null && src.length > 0);
  14. }
  15.  
  16. //***************** LOCAL FUNCTIONS  ******************
  17.  
  18. function initializeUI() {
  19.   var filePath="", src="", metafile, qMark, fObj;
  20.  
  21.   src = getSrcAttrib();
  22.   qMark = src.lastIndexOf("?");
  23.   if (qMark != -1) src = src.substring(0,qMark); //if url has ?, trim it off
  24.   if (src) {
  25.     fObj = new File(src);
  26.     filePath = fObj.getAbsolutePath(); //resolve the local path of the selection
  27.     if (filePath && fObj.exists()) {  
  28.       metafile = (MMNotes.open(filePath));        //open, or create metafile
  29.       if (metafile) {                            //if okay to open
  30.         MMNotes.close(metafile);                  //close it
  31.         MMNotes.FileInfo_filePath = filePath;     //store the filePath as a global
  32.         dw.popupCommand(CMD_TO_LAUNCH); //launch the command
  33.       } else {
  34.         alert(MSG_MetaDisabled);
  35.       }
  36.     } else {
  37.       alert(MSG_FileNotFound+filePath);
  38.  } }
  39. }
  40.  
  41. function getSrcAttrib() {
  42.   var i, offsets, selNode, tagName, src="", node;
  43.   var dom  = dw.getDocumentDOM();
  44.   
  45.   selNode = dom.getSelectedNode();
  46.   if (selNode.nodeType == Node.ELEMENT_NODE) {
  47.     tagName = selNode.tagName;
  48.     if (tagName == "IMG" || tagName == "EMBED") { //has SRC attribute
  49.       src = selNode.getAttribute("SRC");
  50.  
  51.     } else if (tagName == "OBJECT") {             //search OBJECT params for src
  52.       for (i=0; !src && i<selNode.childNodes.length; i++) {
  53.         node = selNode.childNodes[i];
  54.         if (node.nodeType == Node.ELEMENT_NODE) { 
  55.           if (node.tagName == "PARAM" && (""+node.getAttribute("NAME")).toUpperCase() == "SRC") {
  56.             src = node.getAttribute("VALUE");
  57.           } else if (node.tagName == "EMBED") { //for ActiveX controls
  58.             src = node.getAttribute("SRC");
  59.           }
  60.         }
  61.       }
  62.  
  63.     } else if (tagName == "INPUT" && selNode.getAttribute("SRC")) { //works for input/image
  64.       src = selNode.getAttribute("SRC");
  65.  
  66.     } else if (tagName == "APPLET" && selNode.getAttribute("CODE")) { //works for applets
  67.       src = selNode.getAttribute("CODE");
  68.   } } 
  69.   if (!src) src="";
  70.   if (1 < src.length && src.length <= 4 && src.charAt(0)==".") src = "";  //if .xyz, consider it to be empty
  71.  
  72.   return unescape(src);
  73. }
  74.