html
[ class tree: html ] [ index: html ] [ all elements ]

Source for file JavaScript.class.php

Documentation is available at JavaScript.class.php

  1. <?php
  2. /**
  3.  * For including this file you have to define the constant "CLASSPATH".
  4.  * Because every include in the framework depends on the CLASSPATH definition.
  5.  * The CLASSPATH means the relative path to the folder that contains the
  6.  * framework GilliGan.
  7.  *
  8.  * @package html
  9.  */
  10. if!defined"CLASSPATH" ) )
  11. {
  12.   echo "<h3>You have to define the constant CLASSPATH!</h3>\n";
  13.   echo "Example: define( 'CLASSPATH', '../path/to/classes/' );\n";
  14.   exit();
  15. }
  16.  
  17. /**
  18.  * Including a class to format plain text.
  19.  */
  20. require_onceCLASSPATH."core/PlainTextFormatter.class.php" );
  21.  
  22. /**
  23.  * Setting up javascripts.
  24.  *
  25.  * @version   0.2.81
  26.  * @package   html
  27.  * @author    Daniel Plücken <daniel@debakel.net>
  28.  * @license   http://www.gnu.org/copyleft/lesser.html
  29.  *             GNU Lesser General Public License
  30.  * @copyright Copyright (c) 2004 Daniel Plücken <daniel@debakel.net>
  31.  *
  32.  *  This library is free software; you can redistribute it and/or
  33.  *  modify it under the terms of the GNU Lesser General Public
  34.  *  License as published by the Free Software Foundation; either
  35.  *  version 2.1 of the License.
  36.  *
  37.  *  This library is distributed in the hope that it will be useful,
  38.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  39.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  40.  *  GNU Lesser General Public License for more details.
  41.  *
  42.  *  You should have received a copy of the GNU Lesser General
  43.  *  Public License along with this library; if not, write to the
  44.  *  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  45.  *  Boston, MA 02111-1307 USA
  46.  */
  47. class JavaScript
  48. {
  49.   /**
  50.    * The content of the javascript.
  51.    *
  52.    * @var    string  $body 
  53.    * @access private
  54.    */
  55.   var $body = "";
  56.  
  57.  
  58.  
  59.   /**
  60.    * Sets up a function to check if a given variable is empty. It has the same
  61.    * behavior like the function "empty" in php.
  62.    *
  63.    * @version 1.0
  64.    * @since   0.1.0
  65.    * @author  Daniel Plücken <daniel@debakel.net>
  66.    * @access  public
  67.    * @return  void 
  68.    */
  69.   function setEmpty()
  70.   {
  71.     static $alreadyIncluded false;
  72.  
  73.     if!$alreadyIncluded )
  74.     {
  75.       $out  "  function empty( value )\r\n";
  76.       $out .= "  {\r\n";
  77.       $out .= "    return ( value == \"\"\r\n";
  78.       $out .= "          || value == 0\r\n";
  79.       $out .= "          || value == undefined\r\n";
  80.       $out .= "          || value == \"0\" );\r\n";
  81.       $out .= "  }\r\n\r\n";
  82.  
  83.       $this->body .= $out;
  84.       $alreadyIncluded true;
  85.     }
  86.   }
  87.  
  88.  
  89.  
  90.   /**
  91.    * Sets up a function to encode a string to md5.
  92.    *
  93.    * @version   1.0
  94.    * @since     0.2.3
  95.    * @author    Henri Torgemane (Javasript)
  96.    * @author    Ralf Mieke <ralf@miekenet.de> (Javascript modifications)
  97.    * @author    Daniel Plücken <daniel@debakel.net>
  98.    * @copyright Copyright (c) 1996 Henri Torgemane
  99.    * @license   see output javascript.
  100.    *             Permission to use, copy, modify, and distribute this software
  101.    *             and its documentation for any purposes and without
  102.    *             fee is hereby granted provided that this copyright notice
  103.    *             appears in all copies.
  104.    *
  105.    *             Of course, this soft is provided \"as is\" without express or
  106.    *             implied warranty of any kind.
  107.    * @access    public
  108.    * @return    void 
  109.    */
  110.   function setMD5()
  111.   {
  112.     static $alreadyIncluded false;
  113.  
  114.     if!$alreadyIncluded )
  115.     {
  116.       $this->body .= JavaScript::getMD5();
  117.       $alreadyIncluded true;
  118.     }
  119.   }
  120.  
  121.  
  122.  
  123.   /**
  124.    * Returns a function to encode a string to md5.
  125.    *
  126.    * @version   1.0
  127.    * @since     0.2.3
  128.    * @author    Henri Torgemane (Javasript)
  129.    * @author    Ralf Mieke <ralf@miekenet.de> (Javascript modifications)
  130.    * @author    Daniel Plücken <daniel@debakel.net> (only include here)
  131.    * @copyright Copyright (c) 1996 Henri Torgemane
  132.    * @license   see output javascript:
  133.    *             Permission to use, copy, modify, and distribute this software
  134.    *             and its documentation for any purposes and without
  135.    *             fee is hereby granted provided that this copyright notice
  136.    *             appears in all copies.
  137.    *
  138.    *             Of course, this soft is provided \"as is\" without express or
  139.    *             implied warranty of any kind.
  140.    * @access    public
  141.    * @param     boolean $withJSdeclaration 
  142.    * @return    string 
  143.    */
  144.   function getMD5$withJSdeclaration false )
  145.   {
  146.     static $alreadyReturned false;
  147.  
  148.     $out "";
  149.     if !$alreadyReturned )
  150.     {
  151.       $out .= <<<JSCODE
  152.   /*
  153.    *  md5.js 1.0b 27/06/96
  154.    *
  155.    * Javascript implementation of the RSA Data Security, Inc. MD5
  156.    * Message-Digest Algorithm.
  157.    *
  158.    * Copyright (c) 1996 Henri Torgemane. All Rights Reserved.
  159.    *
  160.    * Permission to use, copy, modify, and distribute this software
  161.    * and its documentation for any purposes and without
  162.    * fee is hereby granted provided that this copyright notice
  163.    * appears in all copies.
  164.    *
  165.    * Of course, this soft is provided "as is" without express or implied
  166.    * warranty of any kind.
  167.    *
  168.    *
  169.    * Modified with german comments and some information about collisions.
  170.    * (Ralf Mieke, ralf@miekenet.de, http://mieke.home.pages.de)
  171.    */
  172.  
  173.  
  174.  
  175.   function array(n) {
  176.     for(i=0;i<n;i++) this[i]=0;
  177.     this.length=n;
  178.   }
  179.  
  180.  
  181.  
  182.   /* Einige grundlegenden Funktionen müssen wegen
  183.    * Javascript Fehlern umgeschrieben werden.
  184.    * Man versuche z.B. 0xffffffff >> 4 zu berechnen..
  185.    * Die nun verwendeten Funktionen sind zwar langsamer als die Originale,
  186.    * aber sie funktionieren.
  187.    */
  188.  
  189.   function integer(n) { return n%(0xffffffff+1); }
  190.  
  191.   function shr(a,b) {
  192.     a=integer(a);
  193.     b=integer(b);
  194.     if (a-0x80000000>=0) {
  195.       a=a%0x80000000;
  196.       a>>=b;
  197.       a+=0x40000000>>(b-1);
  198.     } else
  199.       a>>=b;
  200.     return a;
  201.   }
  202.  
  203.   function shl1(a) {
  204.     a=a%0x80000000;
  205.     if (a&0x40000000==0x40000000)
  206.     {
  207.       a-=0x40000000;
  208.       a*=2;
  209.       a+=0x80000000;
  210.     } else
  211.       a*=2;
  212.     return a;
  213.   }
  214.  
  215.   function shl(a,b) {
  216.     a=integer(a);
  217.     b=integer(b);
  218.     for (var i=0;i<b;i++) a=shl1(a);
  219.     return a;
  220.   }
  221.  
  222.   function and(a,b) {
  223.     a=integer(a);
  224.     b=integer(b);
  225.     var t1=(a-0x80000000);
  226.     var t2=(b-0x80000000);
  227.     if (t1>=0)
  228.       if (t2>=0)
  229.         return ((t1&t2)+0x80000000);
  230.       else
  231.         return (t1&b);
  232.     else
  233.       if (t2>=0)
  234.         return (a&t2);
  235.       else
  236.         return (a&b);
  237.   }
  238.  
  239.   function or(a,b) {
  240.     a=integer(a);
  241.     b=integer(b);
  242.     var t1=(a-0x80000000);
  243.     var t2=(b-0x80000000);
  244.     if (t1>=0)
  245.       if (t2>=0)
  246.         return ((t1|t2)+0x80000000);
  247.       else
  248.         return ((t1|b)+0x80000000);
  249.     else
  250.       if (t2>=0)
  251.         return ((a|t2)+0x80000000);
  252.       else
  253.         return (a|b);
  254.   }
  255.  
  256.   function xor(a,b) {
  257.     a=integer(a);
  258.     b=integer(b);
  259.     var t1=(a-0x80000000);
  260.     var t2=(b-0x80000000);
  261.     if (t1>=0)
  262.       if (t2>=0)
  263.         return (t1^t2);
  264.       else
  265.         return ((t1^b)+0x80000000);
  266.     else
  267.       if (t2>=0)
  268.         return ((a^t2)+0x80000000);
  269.       else
  270.         return (a^b);
  271.   }
  272.  
  273.   function not(a) {
  274.     a=integer(a);
  275.     return (0xffffffff-a);
  276.   }
  277.  
  278.   /* Beginn des Algorithmus */
  279.  
  280.       var state = new array(4);
  281.       var count = new array(2);
  282.           count[0] = 0;
  283.           count[1] = 0;
  284.       var buffer = new array(64);
  285.       var transformBuffer = new array(16);
  286.       var digestBits = new array(16);
  287.  
  288.       var S11 = 7;
  289.       var S12 = 12;
  290.       var S13 = 17;
  291.       var S14 = 22;
  292.       var S21 = 5;
  293.       var S22 = 9;
  294.       var S23 = 14;
  295.       var S24 = 20;
  296.       var S31 = 4;
  297.       var S32 = 11;
  298.       var S33 = 16;
  299.       var S34 = 23;
  300.       var S41 = 6;
  301.       var S42 = 10;
  302.       var S43 = 15;
  303.       var S44 = 21;
  304.  
  305.       function F(x,y,z) {
  306.           return or(and(x,y),and(not(x),z));
  307.       }
  308.  
  309.       function G(x,y,z) {
  310.           return or(and(x,z),and(y,not(z)));
  311.       }
  312.  
  313.       function H(x,y,z) {
  314.           return xor(xor(x,y),z);
  315.       }
  316.  
  317.       function I(x,y,z) {
  318.           return xor(y ,or(x , not(z)));
  319.       }
  320.  
  321.       function rotateLeft(a,n) {
  322.           return or(shl(a, n),(shr(a,(32 - n))));
  323.       }
  324.  
  325.       function FF(a,b,c,d,x,s,ac) {
  326.           a = a+F(b, c, d) + x + ac;
  327.           a = rotateLeft(a, s);
  328.           a = a+b;
  329.           return a;
  330.       }
  331.  
  332.       function GG(a,b,c,d,x,s,ac) {
  333.           a = a+G(b, c, d) +x + ac;
  334.           a = rotateLeft(a, s);
  335.           a = a+b;
  336.           return a;
  337.       }
  338.  
  339.       function HH(a,b,c,d,x,s,ac) {
  340.           a = a+H(b, c, d) + x + ac;
  341.           a = rotateLeft(a, s);
  342.           a = a+b;
  343.           return a;
  344.       }
  345.  
  346.       function II(a,b,c,d,x,s,ac) {
  347.           a = a+I(b, c, d) + x + ac;
  348.           a = rotateLeft(a, s);
  349.           a = a+b;
  350.           return a;
  351.       }
  352.  
  353.       function transform(buf,offset) {
  354.           var a=0, b=0, c=0, d=0;
  355.           var x = transformBuffer;
  356.  
  357.           a = state[0];
  358.           b = state[1];
  359.           c = state[2];
  360.           d = state[3];
  361.  
  362.           for (i = 0; i < 16; i++) {
  363.               x[i] = and(buf[i*4+offset],0xff);
  364.               for (j = 1; j < 4; j++) {
  365.                   x[i]+=shl(and(buf[i*4+j+offset] ,0xff), j * 8);
  366.               }
  367.           }
  368.  
  369.           /* Runde 1 */
  370.           a = FF ( a, b, c, d, x[ 0], S11, 0xd76aa478); /* 1 */
  371.           d = FF ( d, a, b, c, x[ 1], S12, 0xe8c7b756); /* 2 */
  372.           c = FF ( c, d, a, b, x[ 2], S13, 0x242070db); /* 3 */
  373.           b = FF ( b, c, d, a, x[ 3], S14, 0xc1bdceee); /* 4 */
  374.           a = FF ( a, b, c, d, x[ 4], S11, 0xf57c0faf); /* 5 */
  375.           d = FF ( d, a, b, c, x[ 5], S12, 0x4787c62a); /* 6 */
  376.           c = FF ( c, d, a, b, x[ 6], S13, 0xa8304613); /* 7 */
  377.           b = FF ( b, c, d, a, x[ 7], S14, 0xfd469501); /* 8 */
  378.           a = FF ( a, b, c, d, x[ 8], S11, 0x698098d8); /* 9 */
  379.           d = FF ( d, a, b, c, x[ 9], S12, 0x8b44f7af); /* 10 */
  380.           c = FF ( c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */
  381.           b = FF ( b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */
  382.           a = FF ( a, b, c, d, x[12], S11, 0x6b901122); /* 13 */
  383.           d = FF ( d, a, b, c, x[13], S12, 0xfd987193); /* 14 */
  384.           c = FF ( c, d, a, b, x[14], S13, 0xa679438e); /* 15 */
  385.           b = FF ( b, c, d, a, x[15], S14, 0x49b40821); /* 16 */
  386.  
  387.           /* Runde 2 */
  388.           a = GG ( a, b, c, d, x[ 1], S21, 0xf61e2562); /* 17 */
  389.           d = GG ( d, a, b, c, x[ 6], S22, 0xc040b340); /* 18 */
  390.           c = GG ( c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */
  391.           b = GG ( b, c, d, a, x[ 0], S24, 0xe9b6c7aa); /* 20 */
  392.           a = GG ( a, b, c, d, x[ 5], S21, 0xd62f105d); /* 21 */
  393.           d = GG ( d, a, b, c, x[10], S22,  0x2441453); /* 22 */
  394.           c = GG ( c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */
  395.           b = GG ( b, c, d, a, x[ 4], S24, 0xe7d3fbc8); /* 24 */
  396.           a = GG ( a, b, c, d, x[ 9], S21, 0x21e1cde6); /* 25 */
  397.           d = GG ( d, a, b, c, x[14], S22, 0xc33707d6); /* 26 */
  398.           c = GG ( c, d, a, b, x[ 3], S23, 0xf4d50d87); /* 27 */
  399.           b = GG ( b, c, d, a, x[ 8], S24, 0x455a14ed); /* 28 */
  400.           a = GG ( a, b, c, d, x[13], S21, 0xa9e3e905); /* 29 */
  401.           d = GG ( d, a, b, c, x[ 2], S22, 0xfcefa3f8); /* 30 */
  402.           c = GG ( c, d, a, b, x[ 7], S23, 0x676f02d9); /* 31 */
  403.           b = GG ( b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */
  404.  
  405.           /* Runde 3 */
  406.           a = HH ( a, b, c, d, x[ 5], S31, 0xfffa3942); /* 33 */
  407.           d = HH ( d, a, b, c, x[ 8], S32, 0x8771f681); /* 34 */
  408.           c = HH ( c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */
  409.           b = HH ( b, c, d, a, x[14], S34, 0xfde5380c); /* 36 */
  410.           a = HH ( a, b, c, d, x[ 1], S31, 0xa4beea44); /* 37 */
  411.           d = HH ( d, a, b, c, x[ 4], S32, 0x4bdecfa9); /* 38 */
  412.           c = HH ( c, d, a, b, x[ 7], S33, 0xf6bb4b60); /* 39 */
  413.           b = HH ( b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */
  414.           a = HH ( a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */
  415.           d = HH ( d, a, b, c, x[ 0], S32, 0xeaa127fa); /* 42 */
  416.           c = HH ( c, d, a, b, x[ 3], S33, 0xd4ef3085); /* 43 */
  417.           b = HH ( b, c, d, a, x[ 6], S34,  0x4881d05); /* 44 */
  418.           a = HH ( a, b, c, d, x[ 9], S31, 0xd9d4d039); /* 45 */
  419.           d = HH ( d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */
  420.           c = HH ( c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */
  421.           b = HH ( b, c, d, a, x[ 2], S34, 0xc4ac5665); /* 48 */
  422.  
  423.           /* Runde 4 */
  424.           a = II ( a, b, c, d, x[ 0], S41, 0xf4292244); /* 49 */
  425.           d = II ( d, a, b, c, x[ 7], S42, 0x432aff97); /* 50 */
  426.           c = II ( c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */
  427.           b = II ( b, c, d, a, x[ 5], S44, 0xfc93a039); /* 52 */
  428.           a = II ( a, b, c, d, x[12], S41, 0x655b59c3); /* 53 */
  429.           d = II ( d, a, b, c, x[ 3], S42, 0x8f0ccc92); /* 54 */
  430.           c = II ( c, d, a, b, x[10], S43, 0xffeff47d); /* 55 */
  431.           b = II ( b, c, d, a, x[ 1], S44, 0x85845dd1); /* 56 */
  432.           a = II ( a, b, c, d, x[ 8], S41, 0x6fa87e4f); /* 57 */
  433.           d = II ( d, a, b, c, x[15], S42, 0xfe2ce6e0); /* 58 */
  434.           c = II ( c, d, a, b, x[ 6], S43, 0xa3014314); /* 59 */
  435.           b = II ( b, c, d, a, x[13], S44, 0x4e0811a1); /* 60 */
  436.           a = II ( a, b, c, d, x[ 4], S41, 0xf7537e82); /* 61 */
  437.           d = II ( d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */
  438.           c = II ( c, d, a, b, x[ 2], S43, 0x2ad7d2bb); /* 63 */
  439.           b = II ( b, c, d, a, x[ 9], S44, 0xeb86d391); /* 64 */
  440.  
  441.           state[0] +=a;
  442.           state[1] +=b;
  443.           state[2] +=c;
  444.           state[3] +=d;
  445.  
  446.       }
  447.       /* Mit der Initialisierung von Dobbertin:
  448.          state[0] = 0x12ac2375;
  449.          state[1] = 0x3b341042;
  450.          state[2] = 0x5f62b97c;
  451.          state[3] = 0x4ba763ed;
  452.          gibt es eine Kollision:
  453.  
  454.          begin 644 Message1
  455.          M7MH=JO6_>MG!X?!51\$)W,CXV!A"=(!AR71,<X`Y-IIT9^Z&8L$2N'Y*Y:R.;
  456.          39GIK9>TF$W()/MEHR%C4:G1R:Q"=
  457.          `
  458.          end
  459.  
  460.          begin 644 Message2
  461.          M7MH=JO6_>MG!X?!51\$)W,CXV!A"=(!AR71,<X`Y-IIT9^Z&8L$2N'Y*Y:R.;
  462.          39GIK9>TF$W()/MEHREC4:G1R:Q"=
  463.          `
  464.          end
  465.       */
  466.       function init() {
  467.           count[0]=count[1] = 0;
  468.           state[0] = 0x67452301;
  469.           state[1] = 0xefcdab89;
  470.           state[2] = 0x98badcfe;
  471.           state[3] = 0x10325476;
  472.           for (i = 0; i < digestBits.length; i++)
  473.               digestBits[i] = 0;
  474.       }
  475.  
  476.       function update(b) {
  477.           var index,i;
  478.  
  479.           index = and(shr(count[0],3) , 0x3f);
  480.           if (count[0]<0xffffffff-7)
  481.             count[0] += 8;
  482.           else {
  483.             count[1]++;
  484.             count[0]-=0xffffffff+1;
  485.             count[0]+=8;
  486.           }
  487.           buffer[index] = and(b,0xff);
  488.           if (index  >= 63) {
  489.               transform(buffer, 0);
  490.           }
  491.       }
  492.  
  493.       function finish() {
  494.           var bits = new array(8);
  495.           var        padding;
  496.           var        i=0, index=0, padLen=0;
  497.  
  498.           for (i = 0; i < 4; i++) {
  499.               bits[i] = and(shr(count[0],(i * 8)), 0xff);
  500.           }
  501.           for (i = 0; i < 4; i++) {
  502.               bits[i+4]=and(shr(count[1],(i * 8)), 0xff);
  503.           }
  504.           index = and(shr(count[0], 3) ,0x3f);
  505.           padLen = (index < 56) ? (56 - index) : (120 - index);
  506.           padding = new array(64);
  507.           padding[0] = 0x80;
  508.           for (i=0;i<padLen;i++)
  509.             update(padding[i]);
  510.           for (i=0;i<8;i++)
  511.             update(bits[i]);
  512.  
  513.           for (i = 0; i < 4; i++) {
  514.               for (j = 0; j < 4; j++) {
  515.                   digestBits[i*4+j] = and(shr(state[i], (j * 8)) , 0xff);
  516.               }
  517.           }
  518.       }
  519.  
  520.   /* Ende des MD5 Algorithmus */
  521.  
  522.   function hexa(n) {
  523.    var hexa_h = "0123456789abcdef";
  524.    var hexa_c="";
  525.    var hexa_m=n;
  526.    for (hexa_i=0;hexa_i<8;hexa_i++) {
  527.      hexa_c=hexa_h.charAt(Math.abs(hexa_m)%16)+hexa_c;
  528.      hexa_m=Math.floor(hexa_m/16);
  529.    }
  530.    return hexa_c;
  531.   }
  532.  
  533.  
  534.   var ascii="01234567890123456789012345678901" +
  535.             " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ"+
  536.             "[\\\\]^_`abcdefghijklmnopqrstuvwxyz{|}~";
  537.  
  538.   function MD5(nachricht)
  539.   {
  540.    var l,s,k,ka,kb,kc,kd;
  541.  
  542.    init();
  543.    for (k=0;k<nachricht.length;k++) {
  544.      l=nachricht.charAt(k);
  545.      update(ascii.lastIndexOf(l));
  546.    }
  547.    finish();
  548.    ka=kb=kc=kd=0;
  549.    for (i=0;i<4;i++) ka+=shl(digestBits[15-i], (i*8));
  550.    for (i=4;i<8;i++) kb+=shl(digestBits[15-i], ((i-4)*8));
  551.    for (i=8;i<12;i++) kc+=shl(digestBits[15-i], ((i-8)*8));
  552.    for (i=12;i<16;i++) kd+=shl(digestBits[15-i], ((i-12)*8));
  553.    s=hexa(kd)+hexa(kc)+hexa(kb)+hexa(ka);
  554.    return s;
  555.   }
  556.  
  557. JSCODE;
  558.  
  559.       $alreadyReturned true;
  560.  
  561.       if$withJSdeclaration === true )
  562.       {
  563.         $js new JavaScript();
  564.         $js->add$out );
  565.  
  566.         $out $js->get();
  567.       }
  568.     // if ( !$alreadyReturned )
  569.  
  570.     return $out;
  571.   }
  572.  
  573.  
  574.  
  575.   /**
  576.    * Returns a function to inspect the type of a data.
  577.    *
  578.    * @version    1.0
  579.    * @since      0.2.8
  580.    * @see        http://javascript.crockford.com/remedial.html
  581.    * @param      boolean $withJSdeclaration 
  582.    * @access     public
  583.    * @return     string 
  584.    */
  585.   function getTypeOf$withJSdeclaration false )
  586.   {
  587.     static $alreadyReturned false;
  588.  
  589.     $out "";
  590.     if !$alreadyReturned )
  591.     {
  592.       $out .= <<<JSCRIPT
  593.     function typeOf(value) {
  594.         var s = typeof value;
  595.         if (s === 'object') {
  596.             if (value) {
  597.                 if (typeof value.length === 'number' &&
  598.                         !(value.propertyIsEnumerable('length')) &&
  599.                         typeof value.splice === 'function') {
  600.                     s = 'array';
  601.                 }
  602.             } else {
  603.                 s = 'null';
  604.             }
  605.         }
  606.         return s;
  607.     }
  608.  
  609.  
  610.     function isEmpty(o) {
  611.         var i, v;
  612.         if (typeOf(o) === 'object') {
  613.             for (i in o) {
  614.                 v = o[i];
  615.                 if (v !== undefined && typeOf(v) !== 'function') {
  616.                     return false;
  617.                 }
  618.             }
  619.         }
  620.         return true;
  621.     }
  622.  
  623.     String.prototype.entityify = function () {
  624.         return this.replace(/&/g, "&amp;").replace(/</g,        "&lt;").replace(/>/g, "&gt;");
  625.     };
  626.  
  627.     String.prototype.quote = function () {
  628.         var c, i, l = this.length, o = '"';
  629.         for (i = 0; i < l; i += 1) {
  630.             c = this.charAt(i);
  631.             if (c >= ' ') {
  632.                 if (c === '\\\\' || c === '"') {
  633.                     o += '\\\\';
  634.                 }
  635.                 o += c;
  636.             } else {
  637.                 switch (c) {
  638.                 case '\\b':
  639.                     o += '\\\\b';
  640.                     break;
  641.                 case '\\f':
  642.                     o += '\\\\f';
  643.                     break;
  644.                 case '\\n':
  645.                     o += '\\\\n';
  646.                     break;
  647.                 case '\\r':
  648.                     o += '\\\\r';
  649.                     break;
  650.                 case '\\t':
  651.                     o += '\\\\t';
  652.                     break;
  653.                 default:
  654.                     c = c.charCodeAt();
  655.                     o += '\\\\u00' + Math.floor(c / 16).toString(16) +
  656.                         (c % 16).toString(16);
  657.                 }
  658.             }
  659.         }
  660.         return o + '"';
  661.     };
  662.  
  663.     String.prototype.supplant = function (o) {
  664.         var i, j, s = this, v;
  665.         for (;;) {
  666.             i = s.lastIndexOf('{');
  667.             if (i < 0) {
  668.                 break;
  669.             }
  670.             j = s.indexOf('}', i);
  671.             if (i + 1 >= j) {
  672.                 break;
  673.             }
  674.             v = o[s.substring(i + 1, j)];
  675.             if (typeOf(v) !== 'string' && typeOf(v) !== 'number') {
  676.                 break;
  677.             }
  678.             s = s.substring(0, i) + v + s.substring(j + 1);
  679.         }
  680.         return s;
  681.     };
  682.  
  683.     String.prototype.trim = function () {
  684.         return this.replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1");
  685.     };
  686.  
  687. JSCRIPT;
  688.  
  689.        $alreadyReturned true;
  690.  
  691.        if $withJSdeclaration === true )
  692.        {
  693.           $js new JavaScript();
  694.           $js->add$out );
  695.  
  696.           $out $js->get();
  697.        }
  698.     }
  699.  
  700.     return $out;
  701.   }
  702.  
  703.  
  704.  
  705.  
  706.   /**
  707.    * Sets up a function to inspect the type of data.
  708.    *
  709.    * @version    1.0
  710.    * @since      0.2.8
  711.    * @see        http://javascript.crockford.com/remedial.html
  712.    * @access     public
  713.    * @return     void 
  714.    */
  715.   function setTypeOf()
  716.   {
  717.     static $alreadyIncluded false;
  718.  
  719.     if !$alreadyIncluded )
  720.     {
  721.       $this->body .= JavaScript::getTypeOf();
  722.       $alreadyIncluded true;
  723.     }
  724.   }
  725.  
  726.  
  727.  
  728.  
  729.  
  730.   /**
  731.    * Sets up a function to serialize arrays like in php.
  732.    *
  733.    * @version    1.0
  734.    * @since      0.2.2
  735.    * @deprecated Use the js library jslib/phpserializer.js
  736.    *                             and jslib/utf.js
  737.    * @author     Daniel Plücken <daniel@debakel.net>
  738.    * @access     public
  739.    * @return     void 
  740.    */
  741.   function setSerialize()
  742.   {
  743.     static $alreadyIncluded false;
  744.  
  745.     if !$alreadyIncluded )
  746.     {
  747.       $this->body .= JavaScript::getSerialize();
  748.       $alreadyIncluded true;
  749.     }
  750.   }
  751.  
  752.  
  753.  
  754.   /**
  755.    * Returns a function to serialize arrays like in php.
  756.    *
  757.    * @version    1.0
  758.    * @since      0.2.2
  759.    * @deprecated Use the js library jslib/phpserializer.js
  760.    *                             and jslib/utf.js
  761.    * @author     Daniel Plücken <daniel@debakel.net>
  762.    * @param      boolean $withJSdeclaration 
  763.    * @access     public
  764.    * @return     string 
  765.    */
  766.   function getSerialize$withJSdeclaration false )
  767.   {
  768.     static $alreadyReturned false;
  769.  
  770.     $out "";
  771.     if !$alreadyReturned )
  772.     {
  773.       $out .= JavaScript::getTypeOf();
  774.       $out .= <<<JSCRIPT
  775.  
  776.     function php_serialize( arr )
  777.     {
  778.         // inputarray
  779.         var ia = arr;
  780.         if ( typeof ia != 'object' )
  781.            return false;
  782.  
  783.         if ( typeOf( ia ) == 'array' )
  784.         {
  785.             var out = 'a:' + ia.length + ':{';
  786.             for ( var i = 0; i < ia.length; i++ )
  787.             {
  788.                 // only index based arrays at this moment!
  789.                 out += 'i:' + i + ';';
  790.  
  791.                 if ( typeof ia[i] === 'object' )
  792.                    out += '' + php_serialize( ia[i] );
  793.                 else
  794.                 if ( typeof ia[i] === 'string' )
  795.                    out += 's:' + ia[i].length + ':"' + ia[i] + '";';
  796.                 else
  797.                 if ( typeof ia[i] === 'number' )
  798.                    out += 'i:' + ia[i] + ';';
  799.             }
  800.             out += '}';
  801.         }
  802.         else
  803.         {
  804.             var out = '';
  805.             var cnt = 0;
  806.             for ( var pos in ia )
  807.             {
  808.                 out += 's:' + pos.length + ':"' + pos + '";';
  809.  
  810.                 if ( typeof ia[pos] == 'object' )
  811.                    out += '' + php_serialize( ia[pos] );
  812.                 else
  813.                 if ( typeof ia[pos] == 'string' )
  814.                    out += 's:' + ia[pos].length + ':"' + ia[pos] + '";';
  815.                 else
  816.                 if ( typeof ia[pos] == 'number' )
  817.                    out += 'i:' + ia[pos] + ';';
  818.  
  819.                 cnt++;
  820.             }
  821.             out = 'o:' + cnt + ':{' + out + '}';
  822.         }
  823.  
  824.         return out;
  825.     }
  826. JSCRIPT;
  827.  
  828.       $alreadyReturned true;
  829.  
  830.       if$withJSdeclaration === true )
  831.       {
  832.         $js new JavaScript();
  833.         $js->add$out );
  834.  
  835.         $out $js->get();
  836.       }
  837.     }
  838.  
  839.     return $out;
  840.   }
  841.  
  842.  
  843.  
  844.   /**
  845.    * Sets up a function to unserialize arrays like in php.
  846.    *
  847.    * @version    1.0
  848.    * @since      0.2.2
  849.    * @deprecated Use the js library jslib/phpserializer.js
  850.    *                             and jslib/utf.js
  851.    * @author     Daniel Plücken <daniel@debakel.net>
  852.    * @access     public
  853.    * @return     void 
  854.    */
  855.   function setUnserialize()
  856.   {
  857.     static $alreadyIncluded false;
  858.  
  859.     if!$alreadyIncluded )
  860.     {
  861.       $this->body .= JavaScript::getUnserialize();
  862.       $alreadyIncluded true;
  863.     }
  864.   }
  865.  
  866.  
  867.  
  868.   /**
  869.    * Returns a function to unserialize arrays like in php.
  870.    *
  871.    * @version    1.0
  872.    * @since      0.2.2
  873.    * @deprecated Use the js library jslib/phpserializer.js
  874.    *                             and jslib/utf.js
  875.    * @author     Daniel Plücken <daniel@debakel.net>
  876.    * @param      boolean $withJSdeclaration 
  877.    * @access     public
  878.    * @return     void 
  879.    */
  880.   function getUnserialize$withJSdeclaration false )
  881.   {
  882.     static $alreadyReturned false;
  883.  
  884.     $out "";
  885.     if!$alreadyReturned )
  886.     {
  887.       $out "  function php_unserialize( str )\r\n"
  888.             ."  {\r\n"
  889.             ."    arr = '';\r\n"
  890.             ."    for( i = 0; i < str.length; i++ )\r\n"
  891.             ."    {\r\n"
  892.             ."      depth = 0;\r\n"
  893.             ."      if( str.substr( i, 2 ) == 'a:' )\r\n"
  894.             ."      {\r\n"
  895.             ."        tmp = '';\r\n"
  896.             ."        while( t = str.substr( i+2, 1 ).match(/[0-9]/) )\r\n"
  897.             ."        {\r\n"
  898.             ."          tmp += t\r\n"
  899.             ."          i++;"
  900.             ."        }\r\n"
  901.             ."        // set pointer behind next \"\x7B\"\r\n"
  902.             ."        i += 4;\r\n\r\n"
  903.  
  904.             ."        if( depth == 0 )\r\n"
  905.             ."          arr = new Array( parseInt( tmp ) );\r\n"
  906.             ."        else\r\n"
  907.             ."          arr[arr.length] = unserialize( str );\r\n"
  908.             ."        depth++;\r\n"
  909.             ."      }\r\n\r\n"
  910.  
  911.             ."      key = '';\r\n"
  912.             ."      if( str.substr( i, 2 ) == 's:' )\r\n"
  913.             ."      {\r\n"
  914.             ."        while( t = str.substr( i+2, 1 ).match(/[0-9]/) )\r\n"
  915.             ."        {\r\n"
  916.             ."          tmp += t\r\n"
  917.             ."          i++;"
  918.             ."        }\r\n"
  919.             ."      }\r\n\r\n"
  920.  
  921.             ."      if( str.substr( i, 2 ) == 'i:' )\r\n"
  922.             ."      {\r\n"
  923.             ."      }\r\n\r\n"
  924.             ."    }\r\n"
  925.             ."  }\r\n";
  926.  
  927.       $alreadyReturned true;
  928.  
  929.       if$withJSdeclaration === true )
  930.       {
  931.         $js new JavaScript();
  932.         $js->add$out );
  933.  
  934.         $out $js->get();
  935.       }
  936.     }
  937.  
  938.     return $out;
  939.   }
  940.  
  941.  
  942.   /**
  943.    * Returns a function to proof whether the document is scrollable in
  944.    * vertically direction.
  945.    *
  946.    * @version    1.0
  947.    * @since      0.2.6
  948.    * @author     Daniel Plücken <daniel@debakel.net>
  949.    * @param      boolean $withJSdeclaration 
  950.    * @access     public
  951.    * @return     string 
  952.    */
  953.   function getBodyIsVerticallyScrollable$withJSdeclaration false )
  954.   {
  955.     static $alreadyReturned false;
  956.  
  957.     $out "";
  958.     if !$alreadyReturned )
  959.     {
  960.  
  961.        $out .= <<<JSCODE
  962.  
  963.   function bodyIsVerticallyScrollable()
  964.   {
  965.     window.scrollBy( 0, 1 );
  966.  
  967.     var bool_scrollable = false;
  968.     var pos_y = window.pageYOffset;
  969.     if ( pos_y == undefined )
  970.        pos_y = document.documentElement.scrollTop;
  971.  
  972.     if ( pos_y == undefined )
  973.        pos_y = document.body.scrollTop;
  974.  
  975.     window.scrollBy( 0, -1 );
  976.  
  977.     var pos_y_after_scrolling = window.pageYOffset;
  978.     if ( pos_y_after_scrolling  == undefined )
  979.        pos_y_after_scrolling = document.documentElement.scrollTop;
  980.  
  981.     if ( pos_y_after_scrolling  == undefined )
  982.        pos_y_after_scrolling = document.body.scrollTop;
  983.  
  984.  
  985.     if ( pos_y_after_scrolling != pos_y )
  986.        bool_scrollable = true;
  987.  
  988.     return bool_scrollable;
  989.   }
  990.  
  991. JSCODE;
  992.  
  993.        $alreadyReturned true;
  994.  
  995.        if $withJSdeclaration === true )
  996.        {
  997.           $js new JavaScript();
  998.           $js->add$out );
  999.  
  1000.           $out $js->get();
  1001.        }
  1002.     }
  1003.  
  1004.     return $out;
  1005.   }
  1006.  
  1007.  
  1008.  
  1009.   /**
  1010.    * Returns a function to proof whether the document is scrollable in
  1011.    * horizontally direction.
  1012.    *
  1013.    * @version    1.0
  1014.    * @since      0.2.6
  1015.    * @author     Daniel Plücken <daniel@debakel.net>
  1016.    * @param      boolean $withJSdeclaration 
  1017.    * @access     public
  1018.    * @return     string 
  1019.    */
  1020.   function getBodyIsHorizontallyScrollable$withJSdeclaration false )
  1021.   {
  1022.       static $alreadyReturned false;
  1023.  
  1024.       $out "";
  1025.       if !$alreadyReturned )
  1026.       {
  1027.  
  1028.           $out .= <<<JSCODE
  1029.  
  1030.   function bodyIsHorizontallyScrollable()
  1031.   {
  1032.     window.scrollBy( 1, 0 );
  1033.  
  1034.     var bool_scrollable = false;
  1035.     var pos_x = window.pageXOffset;
  1036.     if ( pos_x == undefined )
  1037.        pos_x = document.documentElement.scrollLeft;
  1038.  
  1039.     if ( pos_x == undefined )
  1040.        pos_x = document.body.scrollLeft;
  1041.  
  1042.     window.scrollBy( -1, 0 );
  1043.  
  1044.     var pos_x_after_scrolling = window.pageXOffset;
  1045.     if ( pos_x_after_scrolling  == undefined )
  1046.        pos_x_after_scrolling = document.documentElement.scrollLeft;
  1047.  
  1048.     if ( pos_x_after_scrolling  == undefined )
  1049.        pos_x_after_scrolling = document.body.scrollLeft;
  1050.  
  1051.  
  1052.     if ( pos_x_after_scrolling != pos_x )
  1053.        bool_scrollable = true;
  1054.  
  1055.     return bool_scrollable;
  1056.   }
  1057.  
  1058. JSCODE;
  1059.  
  1060.        $alreadyReturned true;
  1061.  
  1062.        if $withJSdeclaration === true )
  1063.        {
  1064.           $js new JavaScript();
  1065.           $js->add$out );
  1066.  
  1067.           $out $js->get();
  1068.        }
  1069.     }
  1070.  
  1071.     return $out;
  1072.   }
  1073.  
  1074.  
  1075.  
  1076.   /**
  1077.    * Returns a function to repeat a string given times.
  1078.    *
  1079.    * @version    1.0
  1080.    * @since      0.2.2
  1081.    * @author     Daniel Plücken <daniel@debakel.net>
  1082.    * @param      boolean $withJSdeclaration 
  1083.    * @access     public
  1084.    * @return     string 
  1085.    */
  1086.   function getStrRepeat$withJSdeclaration false )
  1087.   {
  1088.     static $alreadyReturned false;
  1089.  
  1090.     $out "";
  1091.     if !$alreadyReturned )
  1092.     {
  1093.  
  1094.        $out .= <<<JSCODE
  1095.   function str_repeat( str, times )
  1096.   {
  1097.     if ( times <= 0 )
  1098.        outputstr = '';
  1099.     else
  1100.     {
  1101.       outputstr = str;
  1102.       for ( var i = 1; i < times; i++ )
  1103.           outputstr += str;
  1104.     }
  1105.     return outputstr;
  1106.   }
  1107.  
  1108. JSCODE;
  1109.  
  1110.        $alreadyReturned true;
  1111.  
  1112.        if $withJSdeclaration === true )
  1113.        {
  1114.           $js new JavaScript();
  1115.           $js->add$out );
  1116.  
  1117.           $out $js->get();
  1118.        }
  1119.     }
  1120.  
  1121.     return $out;
  1122.   }
  1123.  
  1124.  
  1125.  
  1126.   /**
  1127.    * Sets up a function to repeat a given string given times. It has the same
  1128.    * behavior like the function "str_repeat" in php.
  1129.    *
  1130.    * @version 1.0
  1131.    * @since   0.1.5
  1132.    * @author  Daniel Plücken <daniel@debakel.net>
  1133.    * @access  public
  1134.    * @return  void 
  1135.    */
  1136.   function setStrRepeat()
  1137.   {
  1138.     static $alreadyIncluded false;
  1139.  
  1140.     if!$alreadyIncluded )
  1141.     {
  1142.       $this->body .= JavaScript::getStrRepeat();
  1143.       $alreadyIncluded true;
  1144.     }
  1145.   }
  1146.  
  1147.  
  1148.  
  1149.   /**
  1150.    * Returns a function to get the value of the inner window width.
  1151.    *
  1152.    * @version    1.0
  1153.    * @since      0.2.7
  1154.    * @author     Daniel Plücken <daniel@debakel.net>
  1155.    * @param      boolean $withJSdeclaration 
  1156.    * @access     public
  1157.    * @return     string 
  1158.    */
  1159.   function getGetInnerWindowWidth$withJSdeclaration false )
  1160.   {
  1161.     static $alreadyReturned false;
  1162.  
  1163.     $out "";
  1164.     if !$alreadyReturned )
  1165.     {
  1166.  
  1167.        $out .= <<<JSCODE
  1168.   function getInnerWindowWidth()
  1169.   {
  1170.     var window_width = 0;
  1171.     if ( typeof( window.innerWidth ) == 'number' )
  1172.        window_width = window.innerWidth;
  1173.     else
  1174.     if (
  1175.          document.documentElement
  1176.       && document.documentElement.clientWidth
  1177.        )
  1178.        window_width = document.documentElement.clientWidth;
  1179.     else
  1180.     if (
  1181.          document.body
  1182.       && document.body.clientWidth
  1183.        )
  1184.        window_width = document.body.clientWidth;
  1185.  
  1186.     return window_width;
  1187.   }
  1188.  
  1189. JSCODE;
  1190.  
  1191.        $alreadyReturned true;
  1192.  
  1193.        if $withJSdeclaration === true )
  1194.        {
  1195.           $js new JavaScript();
  1196.           $js->add$out );
  1197.  
  1198.           $out $js->get();
  1199.        }
  1200.     }
  1201.  
  1202.     return $out;
  1203.   }
  1204.  
  1205.  
  1206.  
  1207.   /**
  1208.    * Sets up a function to get the value of the inner window width.
  1209.    *
  1210.    * @version 1.0
  1211.    * @since   0.2.7
  1212.    * @author  Daniel Plücken <daniel@debakel.net>
  1213.    * @access  public
  1214.    * @return  void 
  1215.    */
  1216.   function setGetInnerWindowWidth()
  1217.   {
  1218.     static $alreadyIncluded false;
  1219.  
  1220.     if!$alreadyIncluded )
  1221.     {
  1222.       $this->body .= JavaScript::getGetInnerWindowWidth();
  1223.       $alreadyIncluded true;
  1224.     }
  1225.   }
  1226.  
  1227.  
  1228.  
  1229.   /**
  1230.    * Returns a function to get the value of the inner window height.
  1231.    *
  1232.    * @version    1.0
  1233.    * @since      0.2.6
  1234.    * @author     Daniel Plücken <daniel@debakel.net>
  1235.    * @param      boolean $withJSdeclaration 
  1236.    * @access     public
  1237.    * @return     string 
  1238.    */
  1239.   function getGetInnerWindowHeight$withJSdeclaration false )
  1240.   {
  1241.     static $alreadyReturned false;
  1242.  
  1243.     $out "";
  1244.     if !$alreadyReturned )
  1245.     {
  1246.  
  1247.        $out .= <<<JSCODE
  1248.   function getInnerWindowHeight()
  1249.   {
  1250.     var window_height = 0;
  1251.     if ( typeof( window.innerHeight ) == 'number' )
  1252.        window_height = window.innerHeight;
  1253.     else
  1254.     if (
  1255.          document.documentElement
  1256.       && document.documentElement.clientHeight
  1257.        )
  1258.        window_height = document.documentElement.clientHeight;
  1259.     else
  1260.     if (
  1261.          document.body
  1262.       && document.body.clientHeight
  1263.        )
  1264.        window_height = document.body.clientHeight;
  1265.  
  1266.     return window_height;
  1267.   }
  1268.  
  1269. JSCODE;
  1270.  
  1271.        $alreadyReturned true;
  1272.  
  1273.        if $withJSdeclaration === true )
  1274.        {
  1275.           $js new JavaScript();
  1276.           $js->add$out );
  1277.  
  1278.           $out $js->get();
  1279.        }
  1280.     }
  1281.  
  1282.     return $out;
  1283.   }
  1284.  
  1285.  
  1286.  
  1287.   /**
  1288.    * Sets up a function to get the value of the inner window height.
  1289.    *
  1290.    * @version 1.0
  1291.    * @since   0.2.6
  1292.    * @author  Daniel Plücken <daniel@debakel.net>
  1293.    * @access  public
  1294.    * @return  void 
  1295.    */
  1296.   function setGetInnerWindowHeight()
  1297.   {
  1298.     static $alreadyIncluded false;
  1299.  
  1300.     if!$alreadyIncluded )
  1301.     {
  1302.       $this->body .= JavaScript::getGetInnerWindowHeight();
  1303.       $alreadyIncluded true;
  1304.     }
  1305.   }
  1306.  
  1307.  
  1308.  
  1309.   /**
  1310.    * Sets up a function to fill a given string with zeros until it has the count
  1311.    * of given length.
  1312.    *
  1313.    * @version 1.0
  1314.    * @since   0.1.5
  1315.    * @author  Daniel Plücken <daniel@debakel.net>
  1316.    * @access  public
  1317.    * @return  void 
  1318.    */
  1319.   function setLeadingZeros()
  1320.   {
  1321.     static $alreadyIncluded false;
  1322.  
  1323.     if!$alreadyIncluded )
  1324.     {
  1325.       $this->setStrRepeat();
  1326.  
  1327.       $out  "  function leadingZeros( value, digits )\r\n";
  1328.       $out .= "  {\r\n";
  1329.       $out .= "    var string   = '' + value;\r\n";
  1330.       $out .= "    var reptimes = digits - string.length;\r\n\r\n";
  1331.       $out .= "    return str_repeat( '0', reptimes ) + string;\r\n";
  1332.       $out .= "  }\r\n\r\n";
  1333.  
  1334.       $this->body .= $out;
  1335.       $alreadyIncluded true;
  1336.     }
  1337.   }
  1338.  
  1339.  
  1340.  
  1341.   /**
  1342.    * Sets up a function to open a centred browser window.
  1343.    *
  1344.    * @version 1.1
  1345.    * @since   0.1.2
  1346.    * @author  Daniel Plücken <daniel@debakel.net>
  1347.    * @access  public
  1348.    * @return  void 
  1349.    */
  1350.   function setOpenCentredWindow()
  1351.   {
  1352.     static $alreadyIncluded false;
  1353.  
  1354.     if !$alreadyIncluded )
  1355.     {
  1356.       $out =
  1357. <<<JSCODE
  1358.     function openCentredWindow( theURL, winName, w, h, features )
  1359.     {
  1360.         var winl = ( screen.width - w ) / 2;
  1361.         var wint = ( screen.height - h ) / 2;
  1362.         tmp_obj = window.open( theURL, winName,
  1363.                                'height=' + h + ', '
  1364.                              + 'width=' + w + ', '
  1365.                              + 'top=' + wint + ', '
  1366.                              + 'left=' + winl + ', '
  1367.                              + features );
  1368.         eval( "window." + winName + " = tmp_obj;" );
  1369.     }
  1370.  
  1371. JSCODE;
  1372.  
  1373.       $this->body .= $out;
  1374.       $alreadyIncluded true;
  1375.     }
  1376.   }
  1377.  
  1378.  
  1379.  
  1380.   /**
  1381.    * Sets up a function to check if a given array contains the given value.
  1382.    * It has the same behavior like the function "in_array" in php.
  1383.    *
  1384.    * @version 1.0
  1385.    * @since   0.1.8
  1386.    * @author  Daniel Plücken <daniel@debakel.net>
  1387.    * @access  public
  1388.    * @return  void 
  1389.    */
  1390.   function setInArray()
  1391.   {
  1392.     static $alreadyIncluded false;
  1393.  
  1394.     if!$alreadyIncluded )
  1395.     {
  1396.       $this->body .= JavaScript::getInArray();
  1397.       $alreadyIncluded true;
  1398.     }
  1399.   }
  1400.  
  1401.  
  1402.   /**
  1403.    * Returns a function to check if a given array contains the given value.
  1404.    * It has the same behavior like the function "in_array" in php.
  1405.    *
  1406.    * @version 1.1
  1407.    * @since   0.2.1
  1408.    * @author  Daniel Plücken <daniel@debakel.net>
  1409.    * @param   boolean $withJSdeclaration 
  1410.    * @access  public
  1411.    * @return  string 
  1412.    */
  1413.   function getInArray$withJSdeclaration false )
  1414.   {
  1415.     static $alreadyReturned false;
  1416.  
  1417.     $out "";
  1418.     if!$alreadyReturned )
  1419.     {
  1420.       $out .= "  function in_array( val, arr )\r\n"
  1421.              ."  {\r\n"
  1422.              ."    for( i = 0; i < arr.length; i++ )\r\n"
  1423.              ."      if( val == arr[i] )\r\n"
  1424.              ."        return true;\r\n\r\n"
  1425.              ."    return false;\r\n"
  1426.              ."  }\r\n\r\n";
  1427.  
  1428.       $alreadyReturned true;
  1429.  
  1430.       if$withJSdeclaration )
  1431.       {
  1432.         $js new JavaScript();
  1433.         $js->add$out );
  1434.  
  1435.         $out $js->get();
  1436.       }
  1437.     }
  1438.  
  1439.     return $out;
  1440.   }
  1441.  
  1442.  
  1443.  
  1444.   /**
  1445.    * Sets up a function to check if a given HTML-element includes another
  1446.    * HTML-element.
  1447.    *
  1448.    * @version 1.0
  1449.    * @since   0.2.2
  1450.    * @author  Daniel Plücken <daniel@debakel.net>
  1451.    * @access  public
  1452.    * @return  void 
  1453.    */
  1454.   function setIsAncestorOf()
  1455.   {
  1456.     static $alreadyIncluded false;
  1457.  
  1458.     if!$alreadyIncluded )
  1459.     {
  1460.       $this->body .= JavaScript::getIsAncestorOf();
  1461.       $alreadyIncluded true;
  1462.     }
  1463.   }
  1464.  
  1465.  
  1466.  
  1467.   /**
  1468.    * Returns a function to check if a given HTML-element includes another
  1469.    * HTML-element.
  1470.    *
  1471.    * @version 1.1
  1472.    * @since   0.2.2
  1473.    * @author  Daniel Plücken <daniel@debakel.net>
  1474.    * @param   boolean $withJSdeclaration 
  1475.    * @access  public
  1476.    * @return  string 
  1477.    */
  1478.   function getIsAncestorOf$withJSdeclaration false )
  1479.   {
  1480.     static $alreadyReturned false;
  1481.  
  1482.     $out "";
  1483.     if!$alreadyReturned )
  1484.     {
  1485.       $out .= "  function isAncestorOf( "
  1486.                                       ."id_of_assumed_ancestor, "
  1487.                                       ."element_which_has_ancestor "
  1488.                                     .")\r\n"
  1489.              ."  {\r\n"
  1490.              ."    if( "
  1491.                      ."!document.getElementById( id_of_assumed_ancestor ) "
  1492.                   ."|| !element_which_has_ancestor.parentNode "
  1493.                    .")\r\n"
  1494.              ."      return false;\r\n"
  1495.              ."    else\r\n"
  1496.              ."    {\r\n"
  1497.              ."      par_el = element_which_has_ancestor.parentNode;\r\n"
  1498.              ."      do\r\n"
  1499.              ."      {\r\n"
  1500.              ."        try\r\n"
  1501.              ."        {\r\n"
  1502.              ."          if( "
  1503.                            ."par_el "
  1504.                         ."&& par_el.getAttribute( 'id' ) "
  1505.                         ."== id_of_assumed_ancestor "
  1506.                          .")\r\n"
  1507.              ."            return true;\r\n"
  1508.              ."        } catch( e ) {  }\r\n"
  1509.              ."      }\r\n"
  1510.              ."      while( par_el = par_el.parentNode );\r\n\r\n"
  1511.              ."      return false;\r\n"
  1512.              ."    }\r\n"
  1513.              ."  }\r\n\r\n";
  1514.  
  1515.       $alreadyReturned true;
  1516.  
  1517.       if$withJSdeclaration )
  1518.       {
  1519.         $js new JavaScript();
  1520.         $js->add$out );
  1521.  
  1522.         $out $js->get();
  1523.       }
  1524.     }
  1525.  
  1526.     return $out;
  1527.   }
  1528.  
  1529.  
  1530.  
  1531.   /**
  1532.    * Sets up a function to insert a record into an array only if the record
  1533.    * does not already exists in the array.
  1534.    *
  1535.    * @version 1.1
  1536.    * @since   0.1.7
  1537.    * @author  Daniel Plücken <daniel@debakel.net>
  1538.    * @access  public
  1539.    * @return  void 
  1540.    */
  1541.   function setArrayUniqueInsert()
  1542.   {
  1543.     static $alreadyIncluded false;
  1544.  
  1545.     if!$alreadyIncluded )
  1546.     {
  1547.       $this->setInArray();
  1548.       $out  "  function arrayUniqueInsert( arr, record )\r\n";
  1549.       $out .= "  {\r\n";
  1550.       $out .= "    if( !in_array( record, arr ) )\r\n";
  1551.       $out .= "      arr[arr.length] = record;\r\n\r\n";
  1552.       $out .= "    return arr;\r\n";
  1553.       $out .= "  }\r\n\r\n";
  1554.  
  1555.       $this->body .= $out;
  1556.       $alreadyIncluded true;
  1557.     }
  1558.   }
  1559.  
  1560.  
  1561.  
  1562.   /**
  1563.    * Sets up a function to get the x-position of an html-element.
  1564.    *
  1565.    * @version 1.0
  1566.    * @since   0.1.9
  1567.    * @author  Daniel Plücken <daniel@debakel.net>
  1568.    * @access  public
  1569.    * @return  void 
  1570.    */
  1571.   function setFindPosX()
  1572.   {
  1573.     static $alreadyIncluded false;
  1574.  
  1575.     if!$alreadyIncluded )
  1576.     {
  1577.       $out  "  function findPosX( obj )\r\n";
  1578.       $out .= "  {\r\n";
  1579.       $out .= "    var curleft = 0;\r\n";
  1580.       $out .= "    if ( obj.offsetParent )\r\n";
  1581.       $out .= "    {\r\n";
  1582.       $out .= "       while ( obj.offsetParent )\r\n";
  1583.       $out .= "       {\r\n";
  1584.       $out .= "          curleft += obj.offsetLeft;\r\n";
  1585.       $out .= "          obj = obj.offsetParent;\r\n";
  1586.       $out .= "       }\r\n";
  1587.       $out .= "    }\r\n";
  1588.       $out .= "    else\r\n";
  1589.       $out .= "    if( obj.x )\r\n";
  1590.       $out .= "      curleft += obj.x;\r\n\r\n";
  1591.       $out .= "    return curleft;\r\n";
  1592.       $out .= "  }\r\n\r\n";
  1593.  
  1594.       $this->body .= $out;
  1595.       $alreadyIncluded true;
  1596.     }
  1597.   }
  1598.  
  1599.  
  1600.  
  1601.   /**
  1602.    * Sets up a function to get the y-position of an html-element.
  1603.    *
  1604.    * @version 1.0
  1605.    * @since   0.1.9
  1606.    * @author  Daniel Plücken <daniel@debakel.net>
  1607.    * @access  public
  1608.    * @return  void 
  1609.    */
  1610.   function setFindPosY()
  1611.   {
  1612.     static $alreadyIncluded false;
  1613.  
  1614.     if!$alreadyIncluded )
  1615.     {
  1616.       $out  "  function findPosY( obj )\r\n";
  1617.       $out .= "  {\r\n";
  1618.       $out .= "    var curtop = 0;\r\n";
  1619.       $out .= "    if ( obj.offsetParent )\r\n";
  1620.       $out .= "    {\r\n";
  1621.       $out .= "       while ( obj.offsetParent )\r\n";
  1622.       $out .= "       {\r\n";
  1623.       $out .= "          curtop += obj.offsetTop\r\n";
  1624.       $out .= "          obj = obj.offsetParent;\r\n";
  1625.       $out .= "       }\r\n";
  1626.       $out .= "    }\r\n";
  1627.       $out .= "    else\r\n";
  1628.       $out .= "    if( obj.y )\r\n";
  1629.       $out .= "      curtop += obj.y;\r\n\r\n";
  1630.       $out .= "    return curtop;\r\n";
  1631.       $out .= "  }\r\n\r\n";
  1632.  
  1633.       $this->body .= $out;
  1634.       $alreadyIncluded true;
  1635.     }
  1636.   }
  1637.  
  1638.  
  1639.  
  1640.   /**
  1641.    * Returns a function that has the same behaviour like the same named
  1642.    * php-function.
  1643.    *
  1644.    * @version   1.0
  1645.    * @since     0.2.4
  1646.    * @author    Frank Olschewski <info.2004-03-27@fobit.de> (Javasript)
  1647.    * @author    Daniel Plücken <daniel@debakel.net> (only include here)
  1648.    * @see       http://www.fobit.com
  1649.    * @copyright Copyright (c) Frank Olschewski
  1650.    * @access    public
  1651.    * @return    void 
  1652.    */
  1653.   function setNumberFormat()
  1654.   {
  1655.     static $alreadyIncluded false;
  1656.  
  1657.     if!$alreadyIncluded )
  1658.     {
  1659.       $out  = <<<JSCODE
  1660.   function number_format (number, decimals, dec_point, thousands_sep)
  1661.   {
  1662.     var exponent = "";
  1663.     var numberstr = number.toString ();
  1664.     var eindex = numberstr.indexOf ("e");
  1665.     if (eindex > -1)
  1666.     {
  1667.       exponent = numberstr.substring (eindex);
  1668.       number = parseFloat (numberstr.substring (0, eindex));
  1669.     }
  1670.  
  1671.     if (decimals != null)
  1672.     {
  1673.       var temp = Math.pow (10, decimals);
  1674.       number = Math.round (number * temp) / temp;
  1675.     }
  1676.     var sign = number < 0 ? "-" : "";
  1677.     var integer = (number > 0 ?
  1678.         Math.floor (number) : Math.abs (Math.ceil (number))).toString ();
  1679.  
  1680.     var fractional = number.toString ().substring (integer.length + sign.length);
  1681.     dec_point = dec_point != null ? dec_point : ".";
  1682.     fractional = decimals != null && decimals > 0 || fractional.length > 1 ?
  1683.                  (dec_point + fractional.substring (1)) : "";
  1684.     if (decimals != null && decimals > 0)
  1685.     {
  1686.       for (i = fractional.length - 1, z = decimals; i < z; ++i)
  1687.         fractional += "0";
  1688.     }
  1689.  
  1690.     thousands_sep = (thousands_sep != dec_point || fractional.length == 0) ?
  1691.                     thousands_sep : null;
  1692.     if (thousands_sep != null && thousands_sep != "")
  1693.     {
  1694.     for (i = integer.length - 3; i > 0; i -= 3)
  1695.         integer = integer.substring (0 , i) + thousands_sep + integer.substring (i);
  1696.     }
  1697.  
  1698.     return sign + integer + fractional + exponent;
  1699.   }
  1700.  
  1701. JSCODE;
  1702.  
  1703.       $this->body .= $out;
  1704.       $alreadyIncluded true;
  1705.     }
  1706.   }
  1707.  
  1708.  
  1709.  
  1710.   /**
  1711.    * incomplete.
  1712.    *
  1713.    * @version 1.0
  1714.    * @since   0.1.9
  1715.    * @author  Daniel Plücken <daniel@debakel.net>
  1716.    * @access  public
  1717.    * @return  void 
  1718.    */
  1719.   function setSwapStyle()
  1720.   {
  1721.     static $alreadyIncluded false;
  1722.  
  1723.     if!$alreadyIncluded )
  1724.     {
  1725.       $this->setArrayUniqueInsert();
  1726.  
  1727.       $out  "  stateSTYLE = undefined;\r\n";
  1728.       $out .= "  styleObj = new Array();\r\n";
  1729.       $out .= "  function swapStyle( which, styleArr, styleValArr )\r\n";
  1730.       $out .= "  {\r\n";
  1731.       $out .= "    if( which != stateSTYLE )\r\n";
  1732.       $out .= "      for( i = 0; i < styleArr.length; i++ )\r\n";
  1733.  
  1734.       $out .= "          which.style[styleArr[i]] = styleValArr[i];\r\n";
  1735.       /*
  1736.       $out .= "      {\n";
  1737.       $out .= "        if( styleArr[i] == \"backgroundColor\" )\r\n";
  1738.       $out .= "          which.style.backgroundColor = styleValArr[i];\r\n";
  1739.       $out .= "        else\r\n";
  1740.       $out .= "        if( styleArr[i] == \"color\" )\r\n";
  1741.       $out .= "          which.style.color = styleValArr[i];\r\n";
  1742.       $out .= "      }\r\n";
  1743.       */
  1744.  
  1745.       $out .= "  }\r\n\r\n";
  1746.  
  1747.       $this->body .= $out;
  1748.       $alreadyIncluded true;
  1749.     }
  1750.   }
  1751.  
  1752.  
  1753.  
  1754.   /**
  1755.    * incomplete.
  1756.    *
  1757.    * @version 1.0
  1758.    * @since   0.1.9
  1759.    * @author  Daniel Plücken <daniel@debakel.net>
  1760.    * @access  public
  1761.    * @return  void 
  1762.    */
  1763.   function setStateStyle()
  1764.   {
  1765.     static $alreadyIncluded false;
  1766.  
  1767.     if!$alreadyIncluded )
  1768.     {
  1769.       $this->setSwapStyle();
  1770.  
  1771.       $out  "  function stateStyle( which )\r\n";
  1772.       $out .= "  {\r\n";
  1773.       $out .= "    stateSTYLE = which;\r\n";
  1774.       $out .= "  }\r\n\r\n";
  1775.  
  1776.       $this->body .= $out;
  1777.       $alreadyIncluded true;
  1778.     }
  1779.   }
  1780.  
  1781.  
  1782.  
  1783.   /**
  1784.    * Adds a string to the content of this javascript.
  1785.    *
  1786.    * @version 1.0
  1787.    * @since   0.1.2
  1788.    * @author  Daniel Plücken <daniel@debakel.net>
  1789.    * @access  public
  1790.    * @param   string $string 
  1791.    * @return  void 
  1792.    */
  1793.   function add$string )
  1794.   $this->body .= $string}
  1795.  
  1796.  
  1797.  
  1798.   /**
  1799.    * Returns a generated string based on the attributes of this object.
  1800.    *
  1801.    * @access  public
  1802.    * @version 1.01
  1803.    * @since   0.1.0
  1804.    *
  1805.    * @param   boolean $bool_no_html_comments 
  1806.    *                   If this is set to true, there will be no html-comments
  1807.    *                   added at first and last script line.
  1808.    *
  1809.    * @return  string 
  1810.    */
  1811.   function get$bool_no_html_comments false )
  1812.   {
  1813.     if!empty$this->body ) )
  1814.     {
  1815.       $out  "\r\n<script language=\"javascript\" type=\"text/javascript\">"
  1816.                ."\r\n";
  1817.  
  1818.       if !$bool_no_html_comments )
  1819.       {  $out .= "<!--\r\n"}
  1820.  
  1821.       $out .= "\r\n".$this->body."\r\n";
  1822.  
  1823.       if !$bool_no_html_comments )
  1824.       {  $out .= "// -->\r\n"}
  1825.  
  1826.       $out .= "</script>\r\n";
  1827.     }
  1828.  
  1829.     return PlainTextFormatter::indentText$out);
  1830.   }
  1831. // END of class JavaScripts
  1832. ?>

Documentation generated on Thu, 05 Jun 2008 19:13:38 +0200 by phpDocumentor 1.4.1