Creating the JavaScript file that implements the Data Sources API functions
After you have defined the name of the data source, the name of the supporting script files, and the code for the working Adobe Dreamweaver document, you need to specify the JavaScript functions for Adobe Dreamweaver to provide the user with the ability to add, insert, and delete the necessary code into a document.
Based on the construction of the Cookie Variable data source, you can implement the MyXML data source, as shown in the following example. (The MyDatasource_Variable command used in the addDynamicSource() function is defined in Creating the supporting command files for user input.)
To create the JavaScript file:
- Create a new blank file.
- Enter the following:
//************** GLOBALS VARS *****************var MyDatasource_FILENAME = "REQ_D.gif";var DATASOURCELEAF_FILENAME = "DSL_D.gif";//****************** API **********************function addDynamicSource(){ MM.retVal = ""; MM.MyDatasourceContents = ""; dw.popupCommand("MyDatasource_Variable"); if (MM.retVal == "OK") { var theResponse = MM.MyDatasourceContents; if (theResponse.length) { var siteURL = dw.getSiteRoot(); if (siteURL.length) { dwscripts.addListValueToNote(siteURL, "MyDatasource", theResponse); } else { alert(MM.MSG_DefineSite); } } else { alert(MM.MSG_DefineMyDatasource); } }}function findDynamicSources(){ var retList = new Array(); var siteURL = dw.getSiteRoot() if (siteURL.length) { var bindingsArray = dwscripts.getListValuesFromNote(siteURL, "MyDatasource"); if (bindingsArray.length > 0) { // Here you create an instance of the DataSource class as defined in the
// DataSourceClass.js file to store the return values. retList.push(new DataSource("MyDatasource", MyDatasource_FILENAME, false, "MyDatasource.htm")) } } return retList;}function generateDynamicSourceBindings(sourceName){ var retVal = new Array(); var siteURL = dw.getSiteRoot(); // For localized object name... if (sourceName != "MyDatasource") { sourceName = "MyDatasource"; } if (siteURL.length) { var bindingsArray = dwscripts.getListValuesFromNote(siteURL, sourceName); retVal = getDataSourceBindingList(bindingsArray, DATASOURCELEAF_FILENAME, true, "MyDatasource.htm"); } return retVal;}function generateDynamicDataRef(sourceName, bindingName, dropObject){ var paramObj = new Object(); paramObj.bindingName = bindingName; var retStr = extPart.getInsertString("", "MyDatasource_DataRef", paramObj); // We need to strip the cfoutput tags if we are inserting into a CFOUTPUT tag // or binding to the attributes of a ColdFusion tag. So, we use the
// dwscripts.canStripCfOutputTags() function from dwscriptsServer.js if (dwscripts.canStripCfOutputTags(dropObject, true)) { retStr = dwscripts.stripCFOutputTags(retStr, true); } return retStr;}function inspectDynamicDataRef(expression){ var retArray = new Array(); if(expression.length) { var params = extPart.findInString("MyDatasource_DataRef", expression); if (params) { retArray[0] = params.sourceName; retArray[1] = params.bindingName; } } return retArray;}function deleteDynamicSource(sourceName, bindingName){ var siteURL = dw.getSiteRoot(); if (siteURL.length) { //For localized object name if (sourceName != "MyDatasource") { sourceName = "MyDatasource"; } dwscripts.deleteListValueFromNote(siteURL, sourceName, bindingName); }} - Save this file MyDatasource.js in the Configuration/DataSources/ColdFusion.