home *** CD-ROM | disk | FTP | other *** search
- //=========================================================================================================
- //
- // Copyright 2002, 2003 Macromedia, Inc. All rights reserved.
- //
- // Feature: Contributor Flash Editing
- // Author: JDH
- // Module: EditFlash.js
- // Purpose: Flash editing dialog.
- // Updates:
- // 7/30/02 - Started file control
- //
- //=========================================================================================================
-
- var helpDoc = MM.HELP_objFlash;
-
- function receiveArguments()
- {
- }
-
- function canAcceptCommand()
- {
- if ( dw.getDocumentDOM().getCCSharedSetting_TextOnlyInNonTemplates() )
- return false;
- return true;
- }
-
- function commandButtons()
- {
- /*return new Array(MM.BTN_OK, "run()",
- MM.BTN_Cancel, "window.close()",
- MM.BTN_Help, "displayHelp()" );
-
- */
-
- return new Array( "PutButtonsOnBottom", "OkButton", MM.BTN_OK, "run()",
- "PutButtonOnLeft", MM.BTN_Help, "displayHelp()",
- "CancelButton", MM.BTN_Cancel, "window.close()");
-
-
- }
-
- var fileWidth;
- var fileHeight;
- var origWidth;
- var origHeight;
- var aspectRatio;
-
- function initializeUI()
- {
- var play = "";
- var loop = "";
- var src = "";
-
- // Look for the loop and play params attached to the flash
- // movie
-
- selectedNode = dw.getDocumentDOM().getSelectedNode();
- selectedNode.outerHTML = selectedNode.outerHTML;
-
- if ( selectedNode.childNodes )
- {
- for ( var index = 0; index < selectedNode.childNodes.length; index++ )
- {
- var node = selectedNode.childNodes[ index ];
- if ( node.tagName == "PARAM" )
- {
- var nodeName = node.getAttribute( "name" );
- nodeName = nodeName.toLowerCase();
- if ( nodeName == "loop" )
- loop = node.getAttribute( "value" );
- if ( nodeName == "play" )
- play = node.getAttribute( "value" );
- if ( nodeName == "movie" )
- src = node.getAttribute( "value" );
-
- }
- }
- }
-
- // Set the check boxes
-
- if ( !play || play.toLowerCase() != "false" )
- document.theForm.play.checked = true;
-
- if ( !loop || loop.toLowerCase() != "false" )
- document.theForm.loop.checked = true;
-
- // set the movie title
- if ( src )
- {
- // before we do anything else, remove any query string
- var index = src.lastIndexOf("?");
- if( index != -1 )
- src = src.substr( 0, index );
-
- var filePath = unescape( src );
- index = filePath.lastIndexOf("/");
- if( index != -1 )
- filePath = filePath.substr( index+1, filePath.length );
-
- document.fileName.innerHTML = filePath;
-
- var movieURL = dwscripts.getAbsoluteURL(unescape(src));
- if (movieURL != null)
- {
- var moviePath = dwscripts.localURLToFilePath(movieURL);
-
- if (moviePath != null)
- {
- var widthHeight = dw.extractWidthAndHeightFromSWF(moviePath);
- if (widthHeight != null)
- {
- fileWidth = widthHeight[0];
- fileHeight = widthHeight[1];
- }
- }
- }
- }
-
- origWidth = selectedNode.getAttribute("width");
- origHeight = selectedNode.getAttribute("height");
-
- if (fileWidth == null || fileHeight == null)
- document.theForm.resetsize.disabled=true;
- else
- {
- document.theForm.resetsize.disabled=false;
- if (origWidth == null)
- origWidth = fileWidth;
- if (origHeight == null)
- origHeight = fileHeight;
- }
-
- if (origWidth == null || origHeight == null)
- {
- document.theForm.width.disabled="true";
- document.theForm.widthselector.disabled="true";
- document.theForm.height.disabled="true";
- document.theForm.heightselector.disabled="true";
- document.theForm.constraint.disabled="true";
- document.theForm.resetsize.disabled="true";
- }
- else
- {
- document.theForm.width.value = origWidth;
- document.theForm.height.value = origHeight;
- }
-
- aspectRatio = fileWidth / fileHeight;
- }
-
- function widthInPixels()
- {
- var width = document.theForm.width.value;
- if (document.theForm.widthselector.selectedIndex == 1)
- width = Math.round((width / 100) * fileWidth);
- return width
- }
-
- function setWidthInPixels(width)
- {
- if (document.theForm.widthselector.selectedIndex == 1)
- document.theForm.width.value = Math.round(100 * width / fileWidth);
- else
- document.theForm.width.value = width;
- }
-
- function heightInPixels()
- {
- var height = document.theForm.height.value;
- if (document.theForm.heightselector.selectedIndex == 1)
- height = Math.round((height / 100) * fileHeight);
- return height
- }
-
- function setHeightInPixels(height)
- {
- if (document.theForm.heightselector.selectedIndex == 1)
- document.theForm.height.value = Math.round(100 * height / fileHeight);
- else
- document.theForm.height.value = height;
- }
-
- function widthSet()
- {
- if (document.theForm.constraint.checked)
- {
- var width = widthInPixels();
- var height = Math.round(width / aspectRatio);
-
- setHeightInPixels(height);
- }
- }
-
- function heightSet()
- {
- if (document.theForm.constraint.checked)
- {
- var height = heightInPixels();
- var width = Math.round(height * aspectRatio);
-
- setWidthInPixels(width);
- }
- }
-
- function widthSelectorChange()
- {
- if (document.theForm.widthselector.selectedIndex == 1)
- document.theForm.width.value =
- Math.round(100 * document.theForm.width.value / fileWidth);
- else
- document.theForm.width.value =
- Math.round(fileWidth * document.theForm.width.value / 100);
- }
-
- function heightSelectorChange()
- {
- if (document.theForm.heightselector.selectedIndex == 1)
- document.theForm.height.value =
- Math.round(100 * document.theForm.height.value / fileHeight);
- else
- document.theForm.height.value =
- Math.round(fileHeight * document.theForm.height.value / 100);
- }
-
- function resetSize()
- {
- setWidthInPixels(fileWidth);
- setHeightInPixels(fileHeight);
- }
-
-
- function run()
- {
- // Set that we have not found the param tags
-
- var playObj = null;
- var loopObj = null;
- var embedObj = null;
- var src;
-
- // Look for the param tags as well as the embed tags,
- // when you find them, alter them to the new values
-
- selectedNode = dw.getDocumentDOM().getSelectedNode();
- selectedNode.outerHTML = selectedNode.outerHTML;
-
- if ( selectedNode.childNodes )
- {
- for ( var index = 0; index < selectedNode.childNodes.length; index++ )
- {
- var node = selectedNode.childNodes[ index ];
- if ( node.tagName == "PARAM" )
- {
- var nodeName = node.getAttribute( "name" );
- nodeName = nodeName.toLowerCase();
- if ( nodeName == "loop" )
- loopObj = node;
- if ( nodeName == "play" )
- playObj = node;
- if ( nodeName == "movie" )
- src = node.getAttribute( "value" );
- }
- if ( node.tagName == "EMBED" )
- embedObj = node;
- }
- }
-
- // Get the values of the check boxes
-
- var play = "false";
- if ( document.theForm.play.checked )
- play = "true";
-
- var loop = "false";
- if ( document.theForm.loop.checked )
- loop = "true";
-
- // If we haven't found the param tags then we need to add them
- if ( embedObj )
- {
- embedObj.setAttribute( "play", play );
- embedObj.setAttribute( "loop", loop );
- }
-
- if ( loopObj )
- loopObj.setAttribute( "value", loop );
- if ( playObj )
- playObj.setAttribute( "value", play );
-
- if ( loopObj == null )
- selectedNode.innerHTML = "<param name=\"loop\" value=\"" + loop + "\">\n" + selectedNode.innerHTML;
- if ( playObj == null )
- selectedNode.innerHTML = "<param name=\"play\" value=\"" + play + "\">\n" + selectedNode.innerHTML;
-
- var newWidth = widthInPixels();
- var newHeight = heightInPixels();
-
- if (newWidth != origWidth || newHeight != origHeight)
- {
- selectedNode.setAttribute("width", newWidth);
- selectedNode.setAttribute("height", newHeight);
- }
-
- window.close();
- }
-