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 true
function browseFile(fieldToStoreURL, stripParameters) {
var fileName = "";
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 DWfile, 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 path
function 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.getSiteRoot() + filePathURL.substring(1);
}
}
}
return retVal;
}
//Returns the simple file name for the current document
function 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 path, if the document has been saved in the current site
function 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 path
function 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;
}
原址:http://www.delphipraxis.net/332540-post7.html
Dreamweaver 扩展开发:文档路径等信息的处理的更多相关文章
- 如何用代码读取Office Online Server2016的文档的备注信息
前言 在一个项目上客户要求读取office online server 2016的对文档的备注信息,如下图: 以前思路老纠结在OOS这个在线上,总有以为这个信息存储在某个列表中,其实错了,这个备注信息 ...
- Java读取“桌面”、“我的文档”路径的方法
读取“桌面”的方法: javax.swing.filechooser.FileSystemView fsv = javax.swing.filechooser.FileSystemView.getFi ...
- 笔记:XML-解析文档-XPath 定位信息
如果需要定位某个XML文档中的一段特定信息,那么通过遍历DOM 树的众多节点来进行行查找显得有些麻烦,XPath语言使得访问树节点变得很容易,例如,下面的XML文档结构: <?xml versi ...
- web开发--文档下载
GOOGLE在线文档下载地址分享(GOOGLE的文档地址暂不能用了,会放在其它位置..) GOOGLE的在线文档功能好象挂掉了...等找个其它存放的位置把这些文档再上传上去... 存在GOOGLE里面 ...
- 进阶开发——文档,缓存,ip限速
一.文档自动化管理 1.django rest framework提供了一个接口: 可以将代码中注释转换为文档中内容(list,create等),以及help_text等等,且会生成JavaScrip ...
- [extjs] extjs 5.1 API 开发 文档
官方博客发布了这个新版本说明,英文文章请戳下面 http://www.sencha.com/blog/announcing-sencha-ext-js-5.1/ 翻译版本请戳下面: http://ex ...
- 1.selenium实战之从txt文档读取配置信息并执行登录
前置条件: 1.本机已搭建ECShop3.0网站 2.在脚本目录创建了user.txt文本如下: 目的:实现从txt中读取配置文件信息,本实战中,包含url地址.用户名.密码,然后进行ESChop的登 ...
- Dreamweaver 扩展开发:C-level extensibility and the JavaScript interpreter
The C code in your library must interact with the Dreamweaver JavaScript interpreter at the followin ...
- Dreamweaver 扩展开发: Calling a C++ function from JavaScript
After you understand how C-level extensibility works in Dreamweaver and its dependency on certain da ...
随机推荐
- 简谈百度坐标反转至WGS84的三种思路
文章版权由作者李晓晖和博客园共有,若转载请于明显处标明出处:http://www.cnblogs.com/naaoveGIS/ 1.背景 基于百度地图进行数据展示是目前项目中常见场景,但是因为百度地图 ...
- 散列表(hash table)——算法导论(13)
1. 引言 许多应用都需要动态集合结构,它至少需要支持Insert,search和delete字典操作.散列表(hash table)是实现字典操作的一种有效的数据结构. 2. 直接寻址表 在介绍散列 ...
- Emoji选项列表
一.需要的前提文件 从网上下载Emoji的表情包,当然是png的图片,因为WPF不支持彩色的Emoji,所以,做列表的时候,需要用图片. 随着压缩包一起的还有一个Emoji.xml文件,文件的层级结构 ...
- Yeoman 官网教学案例:使用 Yeoman 构建 WebApp
STEP 1:设置开发环境 与yeoman的所有交互都是通过命令行.Mac系统使用terminal.app,Linux系统使用shell,windows系统可以使用cmder/PowerShell/c ...
- 关于 devbridge-autocomplete 插件多选操作的实现方法
目前据我所知最好用的 autocomplete 插件就是 jquery-ui 的 autocomplete 以及 devbridge 的 autocomplete 插件. 我最终选择了 devbrid ...
- MVC常遇见的几个场景代码分享
本次主要分享几个场景的处理代码,有更好处理方式多多交流,相互促进进步:代码由来主要是这几天使用前端Ace框架做后台管理系统,这Ace是H5框架里面的控件效果挺多的,做兼容也很好,有点遗憾是控件效果基本 ...
- UWP开发必备:常用数据列表控件汇总比较
今天是想通过实例将UWP开发常用的数据列表做汇总比较,作为以后项目开发参考.UWP开发必备知识点总结请参照[UWP开发必备以及常用知识点总结]. 本次主要讨论以下控件: GridView:用于显示数据 ...
- 设置tomcat远程debug
查看端口占用情况命令: netstat -tunlp |grep 8000 tomcat 启动远程debug: startup.sh 中的最后一行 exec "$PRGDIR"/& ...
- C#~异步编程再续~await与async引起的w3wp.exe崩溃-问题友好的解决
返回目录 关于死锁的原因 理解该死锁的原因在于理解await 处理contexts的方式,默认的,当一个未完成的Task 被await的时候,当前的上下文将在该Task完成的时候重新获得并继续执行剩余 ...
- autocomplete的使用
autocomplete使用分为本地调用方法和读取远程读取数据源的方法 (1)本地调用方法 <script src="Scripts/jquery-1.4.1.min.js" ...