Location: PHPKode > scripts > Prioritexter > Javascript.php
<?php
class Javascript {

  function initialize() {
    Javascript::browserDetect();
    Javascript::showFunctions();
  }

  function encapsulate($script) {
    return "<script>$script</script>";
  }

  function browserDetect() {
  ?>
    <script language="JavaScript">
    
         dom = document.getElementById;
         ie  = document.all;
         ie4 = ie && !dom;
         ie5 = dom && ie;
         ns4 = document.layers;
         ns6 = dom && !ie; 
    
         if (ie5 || ns6)
           new_browser = true;
         else
           new_browser = false;
    
    
         // works; os holds the os.
         var detect = navigator.userAgent.toLowerCase();
         if (detect.indexOf('mac')+1) os = "mac";
         if (detect.indexOf('win')+1) os = "win";
         if ((detect.indexOf('linux')+1) || 
    	 (detect.indexOf('linux')+1)) os = "unix";
    </script>
    
    <?
      }
    
      function showFunctions() {
      ?>
    <script language="JavaScript">
    
    function menuHilite(index, mode) {
    
      if (document.getElementById("menu_selector_" + index)) {
        document.getElementById("menu_selector_" + index).className=("menu_selector_"+mode);
        for(var i=0; i<<?= sizeof($menu_items) ?>; i++) {
          if (index != i) {
            document.getElementById('menu_selector_' + i).className='menu_selector_off';
          }
        }
      }
    
      if (document.getElementById("menu_border_" + index)) {
        document.getElementById("menu_border_" + index).className=("menu_border_"+mode);
        for(var i=0; i<<?= sizeof($menu_borders) ?>; i++) {
          if (index != i) {
            document.getElementById('menu_border_' + i).className='menu_border_off';
          }
        }
      }
    }
    
    function toggleExpand(index) {
        var el = document.getElementById('submenu_' + index);
    
        if((el.style.display != "block") && (new_browser)){ 
          el.style.display = "block";
        }else{
          el.style.display = "none";
        }
        // get rid of that annoying boundary created when you click moust over
        // a link... whose idea was that!?
        var menu_el = document.getElementById('menu_item_' + index);
        menu_el.blur();
    }
    
    function getById(theId) {
      if (document.all)
        return ("document.all." + theId);
      else if (document.getElementById)  
        return ("document.getElementById('" + theId + "')");
    }
    
    function blink(numBlinkers, numBlinksEach) {
      var html="";
    
        for (i=0; i<numBlinkers; i++) {
        var blinkId = "blinker_" + i;
        // get ready to switch the visibility... note: at first visibility == ""
        if (!eval(getById(blinkId) + ".style.visibility == 'hidden'")) {
          html = getById(blinkId) + ".style.visibility = 'hidden';";
        }
        else {
          html = getById(blinkId) + ".style.visibility = 'visible';";
        }
        
        // make it visible or invisible!
        eval(html);
        }
    
      // keep calling blink() hile decrememting counter of number of times to blink
      // Stop at 0 blinks left; then make sure it's visible!
      if (numBlinksEach>0) 
        window.setTimeout( "blink("+ numBlinkers + "," + (numBlinksEach-1) +")", 500 );
      else 
        eval(getById(blinkId) + ".style.visibility = 'visible';");
    }
    
     function refuseVal(str_1, str_2) {
      if (str_1 == str_2) {
        alert("Sorry, you must enter a new value before you can continue.");
        return false;
      } else
        return true;
     }
     
     function erase(obj) {
       obj.value = "";
     } 
    
    </script>
    
    <?
  }

  function stringForBrowser($new_ver, $old_ver) {
    // (probably unnescessary line)
    $new_ver = Text::cleanStr($new_ver);
    $old_ver = Text::cleanStr($old_ver);
    $s_out = "<script language=\"Javascript\">"
       . "if (new_browser) {"
       . " document.write('". $new_ver ."');"
       . "} else {"
       . " document.write('". $old_ver ."');"
       . "}"
       . "</script>";
    return $s_out;
  }

  // display the javascript function "textToHtml" (happens, for convenience,
  // to have same name as this PHP function), which accepts a form text
  // element (textarea), and replaces its text using a series of reg exp's.
  // basically, it's all about quietly getting pasted in text, with
  // visual (but not html) line breaks, to show up as desired
  // in html. hard part is not fucking up perfectly fine html and such
  // that already exists... (see \\r\\n{2,}<p> and \\r\\n{2,}<br>
  // replacements, which detect many lines leading up to a <p>
  // or whatever and protect it from being interpreted as desired
  // whitespace)
  // also, note that a newline is \r and then \n . pain in the ass...
  // i need to double-escape those values (like \\r ) because the
  // javascript is INSIDE php string, so php lets \\ be treated like \
  // and javascript sees plain old \r as two characters.
  function textToHtml() {
    $s = "function textToHtml(element) {"
       .  "var re = new RegExp('\\r\\n ', 'gi');"
       .  "element.value = element.value.replace(re, '\\n\\n<p>');"
       .  "var re = new RegExp('\\r\\n{2,}<p>', 'gi');"
       .  "element.value = element.value.replace(re, '\\n<p>');"
       .  "var re = new RegExp('\\r\\n{2,}<br>', 'gi');"
       .  "element.value = element.value.replace(re, '\\n<br>');"
       .  "var re = new RegExp('\\r\\n\\r\\n\\r\\n', 'gi');"
       .  "element.value = element.value.replace(re, '\\n<p>&nbsp;<br>');"
       .  "var re = new RegExp('\\r\\n\\r\\n', 'gi');"
       .  "element.value = element.value.replace(re, '\\n\\n<p>');"
       . "}";

    return $s;
  }

   function disableMoveButtons() {
    $s = "function disableMoveButtons(selected_value,"
       .      "first_value, last_value, button_elements) {"
       . "if (first_value==selected_value)"
       .   "button_elements[0].disabled=true;"
       . "else button_elements[0].disabled=false;"
       . "if (last_value==selected_value)"
       .   "button_elements[1].disabled=true;"
       . "else button_elements[1].disabled=false;"
       . "}";

    return $s;
  }

   function redirect($href) {
     $s = "location.href=\"$href\";";
     return $s;
   }

   function wysiwygFunctions() {
     $s ="  var viewMode = 1; // WYSIWYG"
	. ""
	. "  function Init()"
	. "  {"
	. "    iView.document.designMode = 'On';"
	. "  }"
	. "  "
	. "  function selOn(ctrl)"
	. "  {"
	. "	ctrl.style.borderColor = '#000000';"
	. "	ctrl.style.backgroundColor = '#B5BED6';"
	. "	ctrl.style.cursor = 'hand';	"
	. "  }"
	. "  "
	. "  function selOff(ctrl)"
	. "  {"
	. "	ctrl.style.borderColor = '#D6D3CE';  "
	. "	ctrl.style.backgroundColor = '#D6D3CE';"
	. "  }"
	. "  "
	. "  function selDown(ctrl)"
	. "  {"
	. "	ctrl.style.backgroundColor = '#8492B5';"
	. "  }"
	. "  "
	. "  function selUp(ctrl)"
	. "  {"
	. "    ctrl.style.backgroundColor = '#B5BED6';"
	. "  }"
	. "    "
	. "  function doBold()"
	. "  {"
	. "	iView.document.execCommand('bold', false, null);"
	. "  }"
	. ""
	. "  function doItalic()"
	. "  {"
	. "	iView.document.execCommand('italic', false, null);"
	. "  }"
	. ""
	. "  function doUnderline()"
	. "  {"
	. "	iView.document.execCommand('underline', false, null);"
	. "  }"
	. "  "
	. "  function doLeft()"
	. "  {"
	. "    iView.document.execCommand('justifyleft', false, null);"
	. "  }"
	. ""
	. "  function doCenter()"
	. "  {"
	. "    iView.document.execCommand('justifycenter', false, null);"
	. "  }"
	. ""
	. "  function doRight()"
	. "  {"
	. "    iView.document.execCommand('justifyright', false, null);"
	. "  }"
	. ""
	. "  function doOrdList()"
	. "  {"
	. "    iView.document.execCommand('insertorderedlist', false, null);"
	. "  }"
	. ""
	. "  function doBulList()"
	. "  {"
	. "    iView.document.execCommand('insertunorderedlist', false, null);"
	. "  }"
	. "  "
	. "  function doForeCol()"
	. "  {"
	. "    var fCol = prompt('Enter foreground color', '');"
	. "    "
	. "    if(fCol != null)"
	. "      iView.document.execCommand('forecolor', false, fCol);"
	. "  }"
	. ""
	. "  function doBackCol()"
	. "  {"
	. "    var bCol = prompt('Enter background color', '');"
	. "    "
	. "    if(bCol != null)"
	. "      iView.document.execCommand('backcolor', false, bCol);"
	. "  }"
	. ""
	. "  function doLink()"
	. "  {"
	. "    iView.document.execCommand('createlink');"
	. "  }"
	. "  "
	. "  function doImage()"
	. "  {"
	. "    var imgSrc = prompt('Enter image location', '');"
	. "    "
	. "    if(imgSrc != null)    "
	. "     iView.document.execCommand('insertimage', false, imgSrc);"
	. "  }"
	. "  "
	. "  function doRule()"
	. "  {"
	. "  iView.document.execCommand('inserthorizontalrule', false, null);"
	. "  }"
	. "  "
	. "  function doFont(fName)"
	. "  {"
	. "    if(fName != '')"
	. "      iView.document.execCommand('fontname', false, fName);"
	. "  }"
	. "  "
	. "  function doSize(fSize)"
	. "  {"
	. "    if(fSize != '')"
	. "      iView.document.execCommand('fontsize', false, fSize);"
	. "  }"
	. "  "
	. "  function doHead(hType)"
	. "  {"
	. "    if(hType != '')"
	. "    {"
	. "      iView.document.execCommand('formatblock', false, hType);  "
	. "      doFont(selFont.options[selFont.selectedIndex].value);"
	. "    }"
	. "  }"
	. "  "
	. "  function doToggleView()"
	. "  {  "
	. "    if(viewMode == 1)"
	. "    {"
	. "      iHTML = iView.document.body.innerHTML;"
	. "      iView.document.body.innerText = iHTML;"
	. "      "
	. "      // Hide all controls"
	. "      tblCtrls.style.display = 'none';"
	. "      selFont.style.display = 'none';"
	. "      selSize.style.display = 'none';"
	. "      selHeading.style.display = 'none';"
	. "      iView.focus();"
	. "      "
	. "      viewMode = 2; // Code"
	. "    }"
	. "    else"
	. "    {"
	. "      iText = iView.document.body.innerText;"
	. "      iView.document.body.innerHTML = iText;"
	. "      "
	. "      // Show all controls"
	. "      tblCtrls.style.display = 'block';"
	. "      selFont.style.display = 'inline';"
	. "      selSize.style.display = 'inline';"
	. "      selHeading.style.display = 'inline';"
	. "      iView.focus();"
	. "      "
	. "      viewMode = 1; // WYSIWYG"
	. "    }"
	. "  }";


   }

}
Return current item: Prioritexter