/includes/skip/elements/forms/color.php

  1. <?php 
  2. /** 
  3. * Skip Color Field Class 
  4. * @package Skip\Forms 
  5. * @since 1.0 
  6. * @ignore 
  7. */ 
  8.  
  9. namespace skip\v1_0_0; 
  10.  
  11. class Color extends Textfield{ 
  12.  
  13. /** 
  14. * Constructor 
  15. * @package Skip 
  16. * @since 1.0 
  17. * @param string $name Name of Color field. 
  18. * @param array/string $args List of Arguments. 
  19. */ 
  20. function __construct( $name, $label = FALSE, $args = array() ) { 
  21. /** 
  22. * Additional parent args: 
  23. * 'id' 
  24. * 'classes' 
  25. * 'before_element' 
  26. * 'after_element' 
  27. * 'params' 
  28. * 'default_value' 
  29. */ 
  30. parent::__construct( $name, $label, $args ); 
  31.  
  32. /** 
  33. * Rendering Color field 
  34. * @package Skip 
  35. * @since 1.0 
  36. * @return string $html Returns The HTML Code. 
  37. */  
  38. public function render() { 
  39. global $skip_javascripts; 
  40.  
  41. $skip_javascripts[] = ' 
  42. $("#' . $this->params[ 'id' ] . '").colorpicker({ 
  43. altField: "#' . $this->params[ 'id' ] . '",  
  44. altProperties: "background-color",  
  45. }); 
  46. '; 
  47.  
  48. return parent::render(); 
  49. /** 
  50. * Color field getter Function 
  51. * @see skip_color() 
  52. * @ignore 
  53. */ 
  54. function get_color( $name, $label = FALSE, $args = array() ) { 
  55. $color = new Color( $name, $label, $args ); 
  56. return $color->render(); 
  57. /** 
  58. * <pre>skip_color( $name, $args = array() );</pre> 
  59. * Adding a jQuery UI color field. 
  60. *  
  61. * <b>Default Usage</b> 
  62. * <code> 
  63. * skip_color( 'backgroundcolor' ); 
  64. * </code> 
  65. * This will create an automated saved field with a jQueryui Colorpicker. 
  66. *  
  67. * <b>Parameters</b> 
  68. *  
  69. * <code> 
  70. * $name // (string) (required) The name of the field. 
  71. * $args // (array/string) (optional) Values for further settings. 
  72. * </code> 
  73. *  
  74. * <b>$args Settings</b> 
  75. *  
  76. * <ul> 
  77. * <li>id (string) ID if the HTML Element.</li>  
  78. * <li>label (string) Label for Element.</li>  
  79. * <li>default (string) Default Value if no Value is set before.</li> 
  80. * <li>classes (string) Name of CSS Classes which will be inserted into HTML seperated by empty space.</li> 
  81. * <li>before_element (string) Content before the element.</li> 
  82. * <li>after_element (string) Content after the element.</li> 
  83. * </ul> 
  84. *  
  85. * <b>Example</b> 
  86. *  
  87. * Creating a labeled Colorfield in an automatic saved form. 
  88. * <code> 
  89. * skip_form_start( 'myformname' ); 
  90. *  
  91. * $args = array( 
  92. * 'id' = 'myelementid',  
  93. * 'label' => 'Background Color' 
  94. * ); 
  95. * skip_color( 'backgroundcolor', $args ); 
  96. *  
  97. * skip_form_end(); 
  98. * </code> 
  99. *  
  100. * Getting back the saved data. 
  101. * <code> 
  102. * $city = skip_value( 'myformname', 'backgroundcolor' ); 
.