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 ...
随机推荐
- 前端css兼容性与易混淆的点
一.常用的骨灰级清除浮动 .clearfix:after { content: "."; display: block; height:; clear: both; visibil ...
- Elasticsearch 5.0 中term 查询和match 查询的认识
Elasticsearch 5.0 关于term query和match query的认识 一.基本情况 前言:term query和match query牵扯的东西比较多,例如分词器.mapping ...
- MVVM模式解析和在WPF中的实现(五)View和ViewModel的通信
MVVM模式解析和在WPF中的实现(五) View和ViewModel的通信 系列目录: MVVM模式解析和在WPF中的实现(一)MVVM模式简介 MVVM模式解析和在WPF中的实现(二)数据绑定 M ...
- C语言 · 整数平均值
编写函数,求包含n个元素的整数数组中元素的平均值.要求在函数内部使用指针操纵数组元素,其中n个整数从键盘输入,输出为其平均值. 样例输入: (输入格式说明:5为输入数据的个数,3 4 0 0 2 是以 ...
- Xamarin+Prism开发详解二:Xaml文件如何简单绑定Resources资源文件内容
我们知道在UWP里面有Resources文件xxx.resx,在Android里面有String.Xml文件等.那跨平台如何统一这些类别不一的资源文件以及Xaml设计文件如何绑定这些资源?应用支持多国 ...
- iOS controller解耦探究实现——第一次写博客
大学时曾经做过android的开发,目前的工作是iOS的开发.之前自己记录东西都是通过自己比较喜欢的笔记类的应用记录下了.直到前段时一个哥们拉着我注册了一个博客.现在终于想明白了,博客这个东西受众会稍 ...
- VSCode调试go语言出现:exec: "gcc": executable file not found in %PATH%
1.问题描述 由于安装VS15 Preview 5,搞的系统由重新安装一次:在用vscdoe编译go语言时,出现以下问题: # odbcexec: "gcc": executabl ...
- 值得注意的ibatis动态sql语法格式
一.Ibatis常用动态sql语法,简单粗暴用一例子 <select id="iBatisSelectList" parameterClass="java.util ...
- 高性能 TCP/UDP/HTTP 通信框架 HP-Socket v4.1.1
HP-Socket 是一套通用的高性能 TCP/UDP/HTTP 通信框架,包含服务端组件.客户端组件和 Agent 组件,广泛适用于各种不同应用场景的 TCP/UDP/HTTP 通信系统,提供 C/ ...
- hibernate-mapping-3.0.dtd;hibernate-configuration-3.0.dtd;hibernate.properties所在路径
hibernate-mapping-3.0.dtd 所在路径:hibernate-release-5.2.5.Final\project\hibernate-core\src\main\resourc ...