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 ...
随机推荐
- .Net多线程编程—System.Threading.Tasks.Parallel
System.Threading.Tasks.Parallel类提供了Parallel.Invoke,Parallel.For,Parallel.ForEach这三个静态方法. 1 Parallel. ...
- 工厂方法模式——创建型模式02
1. 简单工厂模式 在介绍工厂方法模式之前,先介绍一下简单工厂模式.虽然简单工厂模式不属于GoF 23种设计模式,但通常将它作为学习其他工厂模式的入门,并且在实际开发中使用的也较为频繁. (1 ...
- 展望未来:使用 PostCSS 和 cssnext 书写 CSS
原文链接:A look into writing future CSS with PostCSS and cssnext 译者:nzbin 像twitter,google,bbc使用的一样,我打算看一 ...
- [.NET] 打造一个很简单的文档转换器 - 使用组件 Spire.Office
打造一个很简单的文档转换器 - 使用组件 Spire.Office [博主]反骨仔 [原文]http://www.cnblogs.com/liqingwen/p/6024827.html 序 之前,& ...
- 【NLP】干货!Python NLTK结合stanford NLP工具包进行文本处理
干货!详述Python NLTK下如何使用stanford NLP工具包 作者:白宁超 2016年11月6日19:28:43 摘要:NLTK是由宾夕法尼亚大学计算机和信息科学使用python语言实现的 ...
- Python(九)Tornado web 框架
一.简介 Tornado 是 FriendFeed 使用的可扩展的非阻塞式 web 服务器及其相关工具的开源版本.这个 Web 框架看起来有些像web.py 或者 Google 的 webapp,不过 ...
- const let,console.log('a',a)跟console.log('a'+a)的区别
const 创建一个只读的常量 let块级作用域 const let重复赋值都会报错 console.log('a',a) a console.log('a'+a) a2 逗号的值会有空格:用加号的值 ...
- ESLint的使用笔记
原文地址:https://csspod.com/getting-started-with-eslint/?utm_source=tuicool&utm_medium=referral 在团队协 ...
- 使用rowid抽取数据方法以及大数据量游标卡住的应对
平时工作的时候,经常会遇到这种事情,从一个大表A中,抽取字段a在一个相对较小B的表的数据,比如,从一个详单表中,抽取几万个用户号码的话单出来.这种时候,一般来说, 做关联查询: create tabl ...
- SharePoint 2013管理中心里【管理服务器上的服务】不见了
打开管理中心,准备配置Managed Metadata Service,发现"管理服务器上的服务"不见了 那我自己拼url直接访问:http://xxxx/_admin/Serve ...