home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Practical Internet Web Designer 89
/
PIWD89.iso
/
pc
/
CONTENTS
/
DREAMWEAVER
/
UTILITIES
/
pawluk
/
FRAMEBUSTER
/
HP_INSERTCODE.JS
< prev
Wrap
Text File
|
2000-06-16
|
7KB
|
233 lines
// _insertCode.js
// Based on work by Andrew Wooldridge, Massimo Foti, Danny Goodman, others.
// Hal Pawluk 1999 hal@pawluk.com http://www.pawluk.com/public/
function openDocInsert(){
// insert in the currently open file
theLocalDom=dreamweaver.getDocumentDOM("document");
scriptinsert(theLocalDom,'openDoc');
window.close();
}
function closedDocInsert(theLocalDom){
// insert in a specific single closed file
scriptinsert(theLocalDom);
window.close();
}
function openDocRemove(){
// delete from the currently open file
theLocalDom=dreamweaver.getDocumentDOM("document");
scriptdelete(theLocalDom);
window.close();
}
function scriptinsert(thePageDom,target){ // --------------------
theHeadNode=thePageDom.getElementsByTagName("HEAD");
isThere=theHeadNode.item(0).innerHTML.indexOf(codeToCheck)!="-1";
if(isThere){ // if the function is here, alert only
if(target=='openDoc') // working on a single file
alert(activePage + ' - The script is already here');
}else{ //****
theHeadNode.item(0).innerHTML += "<script>" + Myscript + "</s"+"cript>";
} //****
} // end of scriptinsert function -----------------------
function scriptdelete(thePageDom){ // -----------------------------
theHeadNode = thePageDom.getElementsByTagName("HEAD");
isThere = theHeadNode.item(0).innerHTML.indexOf(codeToCheck) != -1;
if(isThere){ //If the code in inside the page
theScriptNodes=thePageDom.getElementsByTagName("SCRIPT");
// find the script with the code and remove it
for(i=0;i<theScriptNodes.length;i++){
if (theScriptNodes[i].innerHTML.indexOf(codeToCheck) != -1){
theHeadNode.item(0).innerHTML = subtractString(theHeadNode.item(0).innerHTML, theScriptNodes[i].outerHTML);
break;
}
}
}
} // end scriptdelete function --------------------------------
function allSiteInsert(){ // -----------------------------
// sitewide insert, not used by all extensions
checkForDWfile();
var theSiteRoot=dreamweaver.getSiteRoot();
if( !theSiteRoot )
alert("You need to define a site first");
else{
dirArray = new Array(); fileArray = new Array();
dirPointer = 0; filePointer = 0;
dirArray[0] = theSiteRoot;
// are there directories in the site?
haveDirectories = DWfile.listFolder(theSiteRoot + "*","directories");
if(haveDirectories != ""){
for(x=0; x<dirArray.length; x++){
dirArray = addToDirsArray(dirArray[x],dirArray);
fileArray = addToFilesArray(dirArray[x],fileArray,"*.ht*");
}
}else{
// are there suitable "*.ht*" files in the site?
haveFiles = DWfile.listFolder(theSiteRoot +"/*.ht*","files");
if(haveFiles != ""){
for(z=0; z<dirArray.length; z++){
fileArray = addToFilesArray(dirArray[z],fileArray,"*.ht*");
}
}
}
//Get all the files, do our job and save all
for(h=0; h<fileArray.length; h++){
tempDOM = dreamweaver.getDocumentDOM(fileArray[h]);
scriptinsert(tempDOM);
dreamweaver.saveDocument(tempDOM,fileArray[h]);
}
} // end else there is a site root
window.close();
} // end allSiteInsert function --------------------------------
function allSiteDelete(){ // -----------------------------------------
// sitewide delete, not used by all extensions
checkForDWfile();
var theSiteRoot=dreamweaver.getSiteRoot();
if( !theSiteRoot )
alert("You need to define a site first");
else{
dirArray = new Array(); fileArray = new Array();
dirPointer = 0; filePointer = 0;
dirArray[0] = theSiteRoot;
// are there directories in the site?
haveDirectories = DWfile.listFolder(theSiteRoot + "*","directories");
if(haveDirectories != ""){
for(x=0; x<dirArray.length; x++){
dirArray = addToDirsArray(dirArray[x],dirArray);
fileArray = addToFilesArray(dirArray[x],fileArray,"*.ht*");
}
}else{
// are there suitable "*.ht*" files in the site?
haveFiles = DWfile.listFolder(theSiteRoot +"/*.ht*","files");
if(haveFiles != ""){
for(z=0; z<dirArray.length; z++){
fileArray = addToFilesArray(dirArray[z],fileArray,"*.ht*");
}
}
}
// do our job and save all
for(h=0; h<fileArray.length; h++){
tempDOM = dreamweaver.getDocumentDOM(fileArray[h]);
scriptdelete(tempDOM);
dreamweaver.saveDocument(tempDOM,fileArray[h]);
}
} // end else there is a site root
window.close();
} // end allSiteDelete ---------------------------------
// -------------- Check for DWfile Functions ----------------------
function checkForDWfile(){
if(typeof(DWfile)=="undefined"){
message="Sorry, you need the DWfile library\r";
message+="You can download it from Macromedia's website";
alert(message);
dreamweaver.browseDocument("http://www.macromedia.com/support/dreamweaver/extend/dwfile/");
window.close();
return false;
}
else{
return nada="";
}
}
// ---------- Generic Site Functions by Andrew Wooldridge ---------
function addToDirsArray(startPath,oldDirArray){
tempDirArray=DWfile.listFolder(startPath+"*","directories");
for(k=0;k<tempDirArray.length;k++){
returnDirArray = oldDirArray;
returnDirArray[returnDirArray.length]=startPath+tempDirArray[k]+"/";
}
return returnDirArray;
}
function addToFilesArray(startPath,oldFileArray,fileMask){
tempFileArray=DWfile.listFolder(startPath + fileMask,"files");
returnFileArray = oldFileArray;
for(j=0;j<tempFileArray.length;j++){
returnFileArray[returnFileArray.length]=startPath+tempFileArray[j];
}
return returnFileArray;
}
// -------------- Generic String Functions by Danny Goodman ----------------------
// extract front part of string prior to searchString
function getFront(mainStr,searchStr){
foundOffset = mainStr.indexOf(searchStr);
if (foundOffset == -1)
return null;
else
return mainStr.substring(0,foundOffset);
}
// extract back end of string after searchString
function getEnd(mainStr,searchStr) {
foundOffset = mainStr.indexOf(searchStr);
if (foundOffset == -1)
return null;
else
return mainStr.substring(foundOffset+searchStr.length,mainStr.length);
}
// -------------- Hal Pawluk string functions ----------------------
function noSpaces(theString){
theEnd = theString.length;
for (i=0; i< theEnd; i++){
while ((theString.charAt(i)==" " || escape(theString.charAt(i))=="%0D") && i < theEnd){
theString = theString.substring(0,i) + theString.substring(i+1);
theEnd-- ;
}
}
return theString;
}
function subtractString(theString,theTakeaway){
theSplit = theString.indexOf(theTakeaway);
if (theSplit != -1);{
theLength = theTakeaway.length;
theString = theString.substring(0,theSplit) + theString.substring(theSplit+theLength);
}
return theString;
}
function insertInString(theString,theInsert,thePlace){
//to prepend use 'thePlace=0', to append use 'thePlace=theString.length'
if (thePlace<0 || thePlace>theString.length){
alert("Sorry, that's not in the string.");
return null;
}
else
return theString.substring(0,thePlace) + theInsert + theString.substring(thePlace);
}