Undocumented Dreamweaver: Finding Out what Document Type you are dealing with.
Posted Tuesday, September 07, 2004 5:19:12 AM by Paul R. Boon
The majority of extensions deal with manipulating a document in someway. Knowing what the type of document the user is currently editing becomes a small but important part of writing these type of extensions.
Now whilst this might seem an easy thing to work out, after all you simply look at the files extension and you can tell if its a CSS document, an html document or a PHP document etc.
Well this may be true, but what if the document has not been saved?
What document type does Dreamweaver think it is, and how do we find this out? Ah, i hear people saying, the simple answer is to get the user to save the document first, then we can check the file extension after the save has happened.
Yes, this is a solution, but it is not how i like to do things. Personally i only want the user to get involved when there is a real need for the user to make a decision. If the code can be written to handle a situation without the need for user input, then that's preferable.
So how can we determine the document type without checking the file extension, we simply use an undocumented static property of the Document Object called documentType.
Example of use:
var dom = dw.getDocumentDOM();
var thisDocType = dom.documentType;
So in the above example the thisDocType variable holds the value of the static property, and the values of the property match the id attribute of the matching document type defined in Dreamweaver's MMDocumentTypes.xml file, located in the Configuration/DocumentTypes folder.
Note: This also works on unsaved documents.
Example of the types of values stored for the corresponding document type.
| Documents of Type | documentType Property Value |
| HTML | HTML |
| JavaScript | JavaScript |
| ASP JavaScript | ASP-JS |
| ASP VBScript | ASP-VB |
| ColdFusion | ColdFusion |
| ColdFusion CFC | CFC |
| JSP | JSP |
| ASP.NET VB | ASP.NET_VB |
| ASP.NET C# | ASP.NET_CSharp |
| PHP MySQL | PHP_MySQL |
| CSS | CSS |
| XML | XML |
| ActionScript | Actionscript |
Note: for a full list see the MMDocumentTypes.xml file located in DW Install Path configuration/DocumentTypes folder.
Category tags: Dreamweaver, Extensibility
Posted by Paul R. Boon
Add comment |
View comments (0) |
Permalink
|
Trackbacks (0)
|
Digg This
See Community MX content by Paul R. Boon


Blog RSS feed













