home *** CD-ROM | disk | FTP | other *** search
/ PC User 2003 December / Australian PC User - December 2003 (CD2).iso / software / apps / files / dwmx2k4.exe / Disk1 / data1.cab / Configuration_En / Objects / PHP / PHPPageEncoding.js < prev    next >
Encoding:
JavaScript  |  2003-09-05  |  1.7 KB  |  56 lines

  1. // Copyright 1999, 2000, 2001, 2002, 2003 Macromedia, Inc. All rights reserved.
  2.  
  3. //---------------     API FUNCTIONS    ---------------
  4.  
  5. function isDOMRequired() {
  6.     return false;
  7. }
  8.  
  9.  
  10. function objectTag() {
  11.   var dom = dw.getDocumentDOM();
  12.   var encoding = "";
  13.   if( dom )
  14.         encoding = dom.getCharSet();
  15.   var encodingStr = "mb_http_input(\"" + encoding + "\");\nmb_http_output(\"" + encoding + "\");"; 
  16.   
  17.   //for text view, just drop the code at the IP, assume the coder is putting it in the correct place
  18.   if( dw.getFocus() == 'textView' )
  19.   {
  20.       return encodingStr;
  21.   }
  22.   else if (dom)
  23.   {
  24.     
  25.     if (encoding)
  26.     {
  27.       var docStr = dom.documentElement.outerHTML;
  28.       var selectionStart = 0;
  29.       var selectionEnd = 0;
  30.       var newDocStr = "";
  31.  
  32.       //first try to see if this tag is already here and up to date
  33.       if( -1 < docStr.search( /mb_http_input\(["'][\w-]*["']\)/i)  ||  -1 < docStr.search( /mb_http_output\(["'][\w-]*["']\)/i ) )
  34.       {
  35.             dom.serverModel.updatePageDirective(dom);
  36.             docStr = dom.documentElement.outerHTML;
  37.             selectionStart = docStr.search( /mb_http_input\(["'][\w-]*["']\)/i );
  38.             if( 0 > selectionStart )
  39.                 selectionStart = docStr.search( /mb_http_output\(["'][\w-]*["']\)/i );
  40.             selectionEnd = docStr.indexOf( ")", selectionStart ) +1;
  41.       }
  42.       else
  43.       {  
  44.           //add this to the top of the page
  45.           newDocStr =  "<?php\n" + encodingStr + "\n?>\n" + docStr;
  46.           selectionStart = 6;
  47.           selectionEnd = encodingStr.length;
  48.           dom.documentElement.outerHTML = newDocStr;
  49.       
  50.          //put the focus to the code view, so the user know we did something
  51.         dom.source.setSelection(selectionStart, selectionEnd);
  52.       }
  53.     }
  54.   }
  55. }
  56.