Dreamweaver extension development: process document paths and other information

Source: Internet
Author: User
Tags dreamweaver
// BrowseFile (fieldToStoreURL) {// getFullPath (filePathURL) {// getSimpleFileName () {// fixUpPath (docURL, siteURL, savedPath) // fileIsCurrentlyOpen (absoluteFileURL ); // Invokes dialog to allow user to select filename. puts value in text input. // The optional flag stripParameters will remove anything after a question // mark if it is set to truefunction browseFile (fieldToStoreURL, stripParameters) {var fileNam E = ""; fileName = browseForFileURL (); // returns a local filename if (stripParameters) {var index = fileName. indexOf ("? "); If (index! =-1) {fileName = fileName. substring (0, index) ;}} if (fileName) fieldToStoreURL. value = fileName;} // function: getFullPath // description: converts relative paths into full paths that start with // file: // Why this is important: A user is prompted for a location to save // a file. dreamweaver generates a path that is relative to the currently // opened document. if a developer tries to use this URL in D Wfile, it will // not work because dreamweaver assumes the path to be relative to the // extension file. however, full paths will work // Note that this function sometimes returns a full path that is indirect: // For instance: file: /// C |/MyWebSite/Hobbies/Cooking /... /Hobbies/Images/cake.gif // However, the user never sees this file path. /// Arguments: // filePathURL-doc-relative, site-relative, or absolute File pathfunction getFullPath (filePathURL) {var retVal = (filePathURL )? FilePathURL: ''; var docURL; var dotDotSlash; var inMiddle; if (retVal! = '') {// If the document path is relative, for example, My Docs/My Schedule.htm // create an absolute path. if (filePathURL. indexOf ("file ://")! = 0) {// if doc relative... if (filePathURL. charAt (0 )! = "/") {DocURL = dreamweaver. getDocumentDOM ('document '). URL; dotDotSlash = filePathURL. indexOf ('.. /'); while (dotDotSlash = 0) {docURL = docURL. substring (0, docURL. lastIndexOf ("/"); filePathURL = filePathURL. substring (3); dotDotSlash = filePathURL. indexOf ('.. /');} retVal = docURL. substring (0, docURL. lastIndexOf ("/") + 1) + filePathURL; // else path is site relative ...} else {retVal = dreamweaver. ge TSiteRoot () + filePathURL. substring (1) ;}}return retVal;} // Returns the simple file name for the current documentfunction getSimpleFileName () {var filePath = dreamweaver. getDocumentPath ("document"); // get full path of file var lastSlash = filePath. lastIndexOf ("/"); if (lastSlash! =-1) filePath = filePath. substring (lastSlash + 1); return filePath;} // fixUpPath () // Given the location of the current document, the site root, // and the path to a file or folder (expressed as a file: // URL), // returns one of the following: // the file: // URL passed in, if the document has not been saved // the file: // URL passed in, if the document is not in the current site // a document-relative p Ath, if the document has been saved in the current sitefunction fixUpPath (docURL, siteURL, savedPath) {var retVal = ""; if (docURL = "" | (docURL! = "" & SavedPath. indexOf (dw. getSiteRoot () =-1) {retVal = savedPath;} else {docURL = docURL. substring (0, docURL. lastIndexOf ('/') + 1); var endStr = (docURL. length> savedPath. length )? SavedPath. length: docURL. length; var commonStr = ""; for (var I = 0; I <endStr; I ++) {if (docURL. charAt (I) = savedPath. charAt (I) {commonStr + = docURL. charAt (I);} else {break;} var whatsLeft = docURL. substring (commonStr. length); var slashPos = whatsLeft. indexOf ('/'); var slashCount = 0; var dotDotSlash = ""; while (slashPos! =-1) {slashCount ++; slashPos = whatsLeft. indexOf ('/', slashPos + 1);} for (var j = 1; j <= slashCount; j ++) {dotDotSlash + = '.. /';} retVal = dotDotSlash + savedPath. substring (commonStr. length);} return retVal;} // function: fileIsCurrentlyOpen // description: given a file path, determines if the file is currently open // argument: absoluteFilePath -- an absolute file pathfunction fileIsCurrentlyOpen (absoluteFilePath) {var fileObj = dw. getDocumentDOM (absoluteFilePath); var openFilesArr = dw. getDocumentList (); var fileIsOpen = false, nOpenFiles, I; // openFilesArr is an array of currently open document objects if (openFilesArr. length & openFilesArr. length> 0) {nOpenFiles = openFilesArr. length; for (I = 0; I <nOpenFiles; I ++) {if (fileObj = openFilesArr [I]) {fileIsOpen = true; break ;}}} return fileIsOpen ;}

Site: http://www.delphipraxis.net/332540-post7.html

Dreamweaver extension development: process document paths and other information

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.