[ Index ]
 

Code source de Horde 3.1.3

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/services/images/ -> colorpicker.php (source)

   1  <?php
   2  /**
   3   * $Horde: horde/services/images/colorpicker.php,v 1.19.10.4 2006/01/01 21:29:14 jan Exp $
   4   *
   5   * Copyright 2002-2006 Michael Cochrane <mike@graftonhall.co.nz>
   6   *
   7   * See the enclosed file COPYING for license information (LGPL).  If you
   8   * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
   9   */
  10  
  11  @define('HORDE_BASE', dirname(__FILE__) . '/../..');
  12  require_once  HORDE_BASE . '/lib/base.php';
  13  
  14  $title = _("Color Picker");
  15  require  HORDE_TEMPLATES . '/common-header.inc';
  16  
  17  $form = Util::getFormData('form');
  18  $target = Util::getFormData('target');
  19  
  20  echo Horde::img('colorscale.png', '', 'id="colorpicker" onclick="changeColor(getColor(event)); return false;" onmousemove="demoColor(getColor(event)); return false;" style="cursor:crosshair;background-color:white;padding:1px"');
  21  ?>
  22  
  23  <div id="colorDemo" style="background-color:white;width:100px;height:20px;padding:1px"></div>
  24  <script type="text/javascript">
  25  <!--
  26  function changeColor(color)
  27  {
  28      if (parent.opener.closed) {
  29          alert("<?php echo addslashes(_("The Options window has closed. Exiting.")) ?>");
  30          this.close();
  31          return;
  32      }
  33  
  34      if (!parent.opener.document.<?php echo $form ?>) {
  35          alert("<?php echo addslashes(_("This window must be called from an Options window")) ?>");
  36          this.close();
  37          return;
  38      }
  39  
  40      parent.opener.document.<?php echo $form ?>["<?php echo $target ?>"].value = color;
  41      parent.opener.document.<?php echo $form ?>["<?php echo $target ?>"].style.backgroundColor = color;
  42      parent.opener.document.<?php echo $form ?>["<?php echo $target ?>"].style.color = brightness(color) < 128 ? 'white' : 'black';
  43  
  44      this.close();
  45  }
  46  
  47  function demoColor(color)
  48  {
  49      var target = document.getElementById('colorDemo');
  50      target.style.backgroundColor = color;
  51      target.style.color = brightness(color) < 128 ? 'white' : 'black';
  52      target.innerHTML = color;
  53  }
  54  
  55  function getColor(event)
  56  {
  57      var img = document.getElementById('colorpicker');
  58  
  59      var x = event.clientX - 10;
  60      var y = event.clientY - 10;
  61  
  62      var rmax = 0;
  63      var gmax = 0;
  64      var bmax = 0;
  65  
  66      if (y <= 32) {
  67          rmax = 255;
  68          gmax = (y / 32.0) * 255;
  69          bmax = 0;
  70      } else if (y <= 64) {
  71          y = y - 32;
  72          rmax = 255 - (y / 32.0) * 255;
  73          gmax = 255;
  74          bmax = 0;
  75      } else if (y <= 96) {
  76          y = y - 64;
  77          rmax = 0;
  78          gmax = 255;
  79          bmax = (y / 32.0) * 255;
  80      } else if (y <= 128) {
  81          y = y - 96;
  82          rmax = 0;
  83          gmax = 255 - (y / 32.0) * 255;
  84          bmax = 255;
  85      } else if (y <= 160) {
  86          y = y - 128;
  87          rmax = (y / 32.0) * 255;
  88          gmax = 0;
  89          bmax = 255;
  90      } else {
  91          y = y - 160;
  92          rmax = 255;
  93          gmax = 0;
  94          bmax = 255 - (y / 32.0) * 255;
  95      }
  96  
  97      if (x <= 50) {
  98          var r = Math.abs(Math.floor(rmax * x / 50.0));
  99          var g = Math.abs(Math.floor(gmax * x / 50.0));
 100          var b = Math.abs(Math.floor(bmax * x / 50.0));
 101      } else {
 102          x -= 50;
 103          var r = Math.abs(Math.floor(rmax + (x / 50.0) * (255 - rmax)));
 104          var g = Math.abs(Math.floor(gmax + (x / 50.0) * (255 - gmax)));
 105          var b = Math.abs(Math.floor(bmax + (x / 50.0) * (255 - bmax)));
 106      }
 107  
 108      return makeColor(r, g, b);
 109  }
 110  
 111  function makeColor(r, g, b)
 112  {
 113      color = '#';
 114      color += hex(Math.floor(r / 16));
 115      color += hex(r % 16);
 116      color += hex(Math.floor(g / 16));
 117      color += hex(g % 16);
 118      color += hex(Math.floor(b / 16));
 119      color += hex(b % 16);
 120      return color;
 121  }
 122  
 123  function brightness(color)
 124  {
 125      var r = new Number("0x" + color.substr(1, 2));
 126      var g = new Number("0x" + color.substr(3, 2));
 127      var b = new Number("0x" + color.substr(5, 2));
 128      return ((r * 299) + (g * 587) + (b * 114)) / 1000;
 129  }
 130  
 131  function hex(dec)
 132  {
 133      return (dec).toString(16);
 134  }
 135  //-->
 136  </script>
 137  </body>
 138  </html>


Généré le : Sun Feb 25 18:01:28 2007 par Balluche grâce à PHPXref 0.7