Пример #1
0
 /**
  * @brief Crea un campo que permite capturar una imagen y mostrarla de
  * inmediato en modo de edición.
  *
  * De acuerdo al navegador, se podra arrastrar un archivo sobre el area, para
  * subir la imagen, o se debe usar un boton para esto. La imagen se cargar
  * y se presentara en edición, donde el objetivo es usar la parte de la imagen
  * que mas se acomode a la necesidad.
  *
  * El arreglo de configuracion puede tomar los siguientes parametros:
  *  + width   => Ancho del div donde se mostrara la imagen.
  *  + height  => Alto del div donde se mostrara la imagen.
  *  + action  => Accion encargada de manipular la imagen cuando se carga.
  *  + preview => ID del elemento donde se va a mostrar la previsualizacion.
  *  + thumb   => Arreglo con las dimensiones del Thumb.
  */
 function imageCropField($name, $config = array())
 {
     $_value = AmadeusUtilHtml::_getValue($name, $config);
     $_id = AmadeusUtilHtml::_getID($name, $config);
     $_rnd = mt_rand();
     $size = '';
     if (isset($config['width'])) {
         $size .= 'width: "' . $config['width'] . '"';
     }
     $height = 0;
     if (isset($config['height'])) {
         $size .= $size != '' ? ',' : '';
         $size .= 'height: "' . $config['height'] . '"';
     }
     $html = '';
     $html .= '<div id="' . $_id . '-image" class="upload-field" style="' . $style . '"></div>';
     $html .= '<script>';
     $html .= 'jQuery(document).ready(function(){';
     $html .= '    new _jCrop({';
     $html .= '        id: "' . $_id . '",';
     $html .= '        extensions: ["' . join('", "', array('jpg', 'JPG', 'jpeg', 'JPEG', 'png', 'PNG')) . '"],';
     $html .= '        action: "' . $config['action'] . '",';
     $html .= '        labels: {';
     $html .= '            "labelButton": "' . JText::_('ICF_LABELBUTTON') . '",';
     $html .= '            "labelDrop": "' . JText::_('ICF_LABELDROP') . '",';
     $html .= '            "labelCancel": "' . JText::_('ICF_LABELCANCEL') . '",';
     $html .= '            "labelFailed": "' . JText::_('ICF_LABELFAILED') . '"';
     $html .= '        },';
     $html .= '        upload: true,';
     $html .= '        aspectratio: "' . $config['aspectratio'] . '",';
     $html .= '        preview: "' . $config['preview'] . '",';
     $html .= '        thumb: {width: ' . $config['thumb']['width'] . ', height: ' . $config['thumb']['height'] . '},';
     $html .= '        size: {' . $size . '}';
     if (isset($config['height'])) {
         $html .= '    ,height: "' . $config['height'] . '"';
     }
     $html .= '    })';
     $html .= '});';
     $html .= '</script>';
     return $html;
 }