1. //browseFile(fieldToStoreURL){
  2. //getFullPath(filePathURL){
  3. //getSimpleFileName() {
  4. //fixUpPath(docURL,siteURL,savedPath)
  5. //fileIsCurrentlyOpen(absoluteFileURL);
  6.  
  7. //Invokes dialog to allow user to select filename. Puts value in text input.
  8. // The optional flag stripParameters will remove anything after a question
  9. // mark if it is set to true
  10.  
  11. function browseFile(fieldToStoreURL, stripParameters) {
  12. var fileName = "";
  13. fileName = browseForFileURL(); //returns a local filename
  14. if (stripParameters) {
  15. var index = fileName.indexOf("?");
  16. if (index != -1) {
  17. fileName = fileName.substring(0,index);
  18. }
  19. }
  20. if (fileName) fieldToStoreURL.value = fileName;
  21. }
  22.  
  23. //function: getFullPath
  24. //description: converts relative paths into full paths that start with
  25. //file:///
  26. //Why this is important: A user is prompted for a location to save
  27. //a file. Dreamweaver generates a path that is relative to the currently
  28. //opened document. If a developer tries to use this URL in DWfile, it will
  29. //not work because dreamweaver assumes the path to be relative to the
  30. //extension file. However, full paths will work
  31. //Note that this function sometimes returns a full path that is indirect:
  32. //For instance: file:///C|/MyWebSite/Hobbies/Cooking/.../Hobbies/Images/cake.gif
  33. //However, the user never sees this file path.
  34. //
  35. //Arguments:
  36. //filePathURL - doc-relative,site-relative, or absolute file path
  37.  
  38. function getFullPath(filePathURL){
  39. var retVal = (filePathURL)?filePathURL:'';
  40. var docURL;
  41. var dotDotSlash;
  42. var inMiddle;
  43.  
  44. if (retVal != ''){
  45. //if the document path is relative, for example,My Docs/My Schedule.htm
  46. //create an absolute path.
  47. if ( filePathURL.indexOf("file://")!=0 ){
  48.  
  49. //if doc relative...
  50. if ( filePathURL.charAt(0)!="/" ){
  51. docURL = dreamweaver.getDocumentDOM('document').URL;
  52. dotDotSlash = filePathURL.indexOf('../');
  53. while (dotDotSlash == 0){
  54. docURL = docURL.substring(0,docURL.lastIndexOf("/"));
  55. filePathURL = filePathURL.substring(3);
  56. dotDotSlash = filePathURL.indexOf('../');
  57. }
  58. retVal = docURL.substring(0,docURL.lastIndexOf("/")+1) + filePathURL;
  59. //else path is site relative...
  60. } else {
  61. retVal = dreamweaver.getSiteRoot() + filePathURL.substring(1);
  62. }
  63. }
  64. }
  65. return retVal;
  66. }
  67.  
  68. //Returns the simple file name for the current document
  69.  
  70. function getSimpleFileName() {
  71. var filePath = dreamweaver.getDocumentPath("document"); //get full path of file
  72. var lastSlash = filePath.lastIndexOf("/");
  73. if (lastSlash != -1) filePath = filePath.substring(lastSlash+1);
  74. return filePath;
  75. }
  76.  
  77. // fixUpPath()
  78. // Given the location of the current document, the site root,
  79. // and the path to a file or folder (expressed as a file:// URL),
  80. // returns one of the following:
  81. // the file:// URL passed in, if the document has not been saved
  82. // the file:// URL passed in, if the document is not in the current site
  83. // a document-relative path, if the document has been saved in the current site
  84. function fixUpPath(docURL,siteURL,savedPath){
  85. var retVal = "";
  86. if (docURL == "" || (docURL != "" && savedPath.indexOf(dw.getSiteRoot()) == -1)){
  87. retVal = savedPath;
  88. }else{
  89. docURL = docURL.substring(0,docURL.lastIndexOf('/')+1);
  90. var endStr = (docURL.length > savedPath.length)?savedPath.length:docURL.length;
  91. var commonStr = "";
  92. for (var i=0; i < endStr; i++){
  93. if (docURL.charAt(i) == savedPath.charAt(i)){
  94. commonStr += docURL.charAt(i);
  95. }else{
  96. break;
  97. }
  98. }
  99.  
  100. var whatsLeft = docURL.substring(commonStr.length);
  101. var slashPos = whatsLeft.indexOf('/');
  102. var slashCount = 0;
  103. var dotDotSlash = "";
  104.  
  105. while (slashPos != -1){
  106. slashCount++;
  107. slashPos = whatsLeft.indexOf('/',slashPos+1);
  108. }
  109.  
  110. for (var j=1; j <= slashCount; j++){
  111. dotDotSlash += '../';
  112. }
  113.  
  114. retVal = dotDotSlash + savedPath.substring(commonStr.length);
  115. }
  116. return retVal;
  117. }
  118.  
  119. // function: fileIsCurrentlyOpen
  120. // description: given a file path, determines if the file is currently open
  121. // argument: absoluteFilePath -- an absolute file path
  122. function fileIsCurrentlyOpen(absoluteFilePath) {
  123. var fileObj = dw.getDocumentDOM(absoluteFilePath);
  124. var openFilesArr = dw.getDocumentList();
  125. var fileIsOpen = false, nOpenFiles,i;
  126.  
  127. // openFilesArr is an array of currently open document objects
  128. if (openFilesArr.length && openFilesArr.length > 0) {
  129. nOpenFiles = openFilesArr.length;
  130. for (i=0;i<nOpenFiles;i++) {
  131. if (fileObj == openFilesArr[i]) {
  132. fileIsOpen = true;
  133. break;
  134. }
  135. }
  136.  
  137. }
  138. return fileIsOpen;
  139. }

原址:http://www.delphipraxis.net/332540-post7.html

Dreamweaver 扩展开发:文档路径等信息的处理的更多相关文章

  1. 如何用代码读取Office Online Server2016的文档的备注信息

    前言 在一个项目上客户要求读取office online server 2016的对文档的备注信息,如下图: 以前思路老纠结在OOS这个在线上,总有以为这个信息存储在某个列表中,其实错了,这个备注信息 ...

  2. Java读取“桌面”、“我的文档”路径的方法

    读取“桌面”的方法: javax.swing.filechooser.FileSystemView fsv = javax.swing.filechooser.FileSystemView.getFi ...

  3. 笔记:XML-解析文档-XPath 定位信息

    如果需要定位某个XML文档中的一段特定信息,那么通过遍历DOM 树的众多节点来进行行查找显得有些麻烦,XPath语言使得访问树节点变得很容易,例如,下面的XML文档结构: <?xml versi ...

  4. web开发--文档下载

    GOOGLE在线文档下载地址分享(GOOGLE的文档地址暂不能用了,会放在其它位置..) GOOGLE的在线文档功能好象挂掉了...等找个其它存放的位置把这些文档再上传上去... 存在GOOGLE里面 ...

  5. 进阶开发——文档,缓存,ip限速

    一.文档自动化管理 1.django rest framework提供了一个接口: 可以将代码中注释转换为文档中内容(list,create等),以及help_text等等,且会生成JavaScrip ...

  6. [extjs] extjs 5.1 API 开发 文档

    官方博客发布了这个新版本说明,英文文章请戳下面 http://www.sencha.com/blog/announcing-sencha-ext-js-5.1/ 翻译版本请戳下面: http://ex ...

  7. 1.selenium实战之从txt文档读取配置信息并执行登录

    前置条件: 1.本机已搭建ECShop3.0网站 2.在脚本目录创建了user.txt文本如下: 目的:实现从txt中读取配置文件信息,本实战中,包含url地址.用户名.密码,然后进行ESChop的登 ...

  8. Dreamweaver 扩展开发:C-level extensibility and the JavaScript interpreter

    The C code in your library must interact with the Dreamweaver JavaScript interpreter at the followin ...

  9. Dreamweaver 扩展开发: Calling a C++ function from JavaScript

    After you understand how C-level extensibility works in Dreamweaver and its dependency on certain da ...

随机推荐

  1. .Net多线程编程—System.Threading.Tasks.Parallel

    System.Threading.Tasks.Parallel类提供了Parallel.Invoke,Parallel.For,Parallel.ForEach这三个静态方法. 1 Parallel. ...

  2. 工厂方法模式——创建型模式02

    1. 简单工厂模式     在介绍工厂方法模式之前,先介绍一下简单工厂模式.虽然简单工厂模式不属于GoF 23种设计模式,但通常将它作为学习其他工厂模式的入门,并且在实际开发中使用的也较为频繁. (1 ...

  3. 展望未来:使用 PostCSS 和 cssnext 书写 CSS

    原文链接:A look into writing future CSS with PostCSS and cssnext 译者:nzbin 像twitter,google,bbc使用的一样,我打算看一 ...

  4. [.NET] 打造一个很简单的文档转换器 - 使用组件 Spire.Office

    打造一个很简单的文档转换器 - 使用组件 Spire.Office [博主]反骨仔 [原文]http://www.cnblogs.com/liqingwen/p/6024827.html 序 之前,& ...

  5. 【NLP】干货!Python NLTK结合stanford NLP工具包进行文本处理

    干货!详述Python NLTK下如何使用stanford NLP工具包 作者:白宁超 2016年11月6日19:28:43 摘要:NLTK是由宾夕法尼亚大学计算机和信息科学使用python语言实现的 ...

  6. Python(九)Tornado web 框架

    一.简介 Tornado 是 FriendFeed 使用的可扩展的非阻塞式 web 服务器及其相关工具的开源版本.这个 Web 框架看起来有些像web.py 或者 Google 的 webapp,不过 ...

  7. const let,console.log('a',a)跟console.log('a'+a)的区别

    const 创建一个只读的常量 let块级作用域 const let重复赋值都会报错 console.log('a',a) a console.log('a'+a) a2 逗号的值会有空格:用加号的值 ...

  8. ESLint的使用笔记

    原文地址:https://csspod.com/getting-started-with-eslint/?utm_source=tuicool&utm_medium=referral 在团队协 ...

  9. 使用rowid抽取数据方法以及大数据量游标卡住的应对

    平时工作的时候,经常会遇到这种事情,从一个大表A中,抽取字段a在一个相对较小B的表的数据,比如,从一个详单表中,抽取几万个用户号码的话单出来.这种时候,一般来说, 做关联查询: create tabl ...

  10. SharePoint 2013管理中心里【管理服务器上的服务】不见了

    打开管理中心,准备配置Managed Metadata Service,发现"管理服务器上的服务"不见了 那我自己拼url直接访问:http://xxxx/_admin/Serve ...