Created
December 25, 2012 18:25
-
-
Save FHenry/4374648 to your computer and use it in GitHub Desktop.
Color selector simple
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?PHP | |
/** | |
* Output a HTML code to select a color | |
* | |
* @param string $set_color Pre-selected color | |
* @param string $prefix Name of HTML field | |
* @param string $form_name Name of form | |
* @param int $showcolorbox 1=Show color code and color box, 0=Show only color code | |
* @param array $arrayofcolors Array of colors. Example: array('29527A','5229A3','A32929','7A367A','B1365F','0D7813') | |
* @return void | |
*/ | |
function select_color($set_color='', $htmlname='f_color') | |
{ | |
print '<input id="AGF_TEXT_COLOR" type="text" size="8" name="AGF_TEXT_COLOR" value="'.$conf->global->AGF_TEXT_COLOR.'" /></td><td></td></tr>'; | |
print '<script type="text/javascript" language="javascript"> | |
$(document).ready(function() { | |
$("#AGF_TEXT_COLOR").css("backgroundColor", \'#'.$conf->global->AGF_TEXT_COLOR.'\'); | |
$("#AGF_TEXT_COLOR").ColorPicker({ | |
color: \'#'.$conf->global->AGF_TEXT_COLOR.'\', | |
onShow: function (colpkr) { | |
$(colpkr).fadeIn(500); | |
return false; | |
}, | |
onHide: function (colpkr) { | |
$(colpkr).fadeOut(500); | |
return false; | |
}, | |
onChange: function (hsb, hex, rgb) { | |
$("#AGF_PDF_COLOR").css("backgroundColor", \'#\' + hex); | |
}, | |
onSubmit: function (hsb, hex, rgb) { | |
$("#AGF_PDF_COLOR").val(hex); | |
} | |
}); | |
}) | |
.bind(\'keyup\', function(){ | |
$(this).ColorPickerSetColor(this.value); | |
}); | |
</script>';//$this->selectColor($set_color, $prefix, $form_name, $showcolorbox, $arrayofcolors); | |
} | |
/** | |
* Output a HTML code to select a color | |
* | |
* @param string $set_color Pre-selected color | |
* @param string $prefix Name of HTML field | |
* @param string $form_name Name of form | |
* @param int $showcolorbox 1=Show color code and color box, 0=Show only color code | |
* @param array $arrayofcolors Array of colors. Example: array('29527A','5229A3','A32929','7A367A','B1365F','0D7813') | |
* @return void | |
*/ | |
function selectColor($set_color='', $prefix='f_color', $form_name='objForm', $showcolorbox=1, $arrayofcolors='') | |
{ | |
global $langs; | |
$out=''; | |
if (! is_array($arrayofcolors) || count($arrayofcolors) < 1) | |
{ | |
$langs->load("other"); | |
$out.= '<link rel="stylesheet" media="screen" type="text/css" href="'.DOL_URL_ROOT.'/includes/jquery/plugins/jpicker/css/jPicker-1.1.6.css" />'; | |
$out.= '<script type="text/javascript" src="'.DOL_URL_ROOT.'/includes/jquery/plugins/jpicker/jpicker-1.1.6.js"></script>'; | |
$out.= '<script type="text/javascript"> | |
jQuery(document).ready(function(){ | |
$(\'#colorpicker'.$prefix.'\').jPicker( { | |
window: { | |
title: \''.dol_escape_js($langs->trans("SelectAColor")).'\', /* any title for the jPicker window itself - displays "Drag Markers To Pick A Color" if left null */ | |
effects: | |
{ | |
type: \'show\', /* effect used to show/hide an expandable picker. Acceptable values "slide", "show", "fade" */ | |
speed: | |
{ | |
show: \'fast\', /* duration of "show" effect. Acceptable values are "fast", "slow", or time in ms */ | |
hide: \'fast\' /* duration of "hide" effect. Acceptable values are "fast", "slow", or time in ms */ | |
} | |
}, | |
position: | |
{ | |
x: \'screenCenter\', /* acceptable values "left", "center", "right", "screenCenter", or relative px value */ | |
y: \'center\' /* acceptable values "top", "bottom", "center", or relative px value */ | |
}, | |
}, | |
images: { | |
clientPath: \''.DOL_URL_ROOT.'/includes/jquery/plugins/jpicker/images/\', | |
picker: { file: \'../../../../../theme/common/colorpicker.png\', width: 14, height: 14 } | |
}, | |
localization: // alter these to change the text presented by the picker (e.g. different language) | |
{ | |
text: | |
{ | |
title: \''.dol_escape_js($langs->trans("SelectAColor")).'\', | |
newColor: \''.dol_escape_js($langs->trans("New")).'\', | |
currentColor: \''.dol_escape_js($langs->trans("Current")).'\', | |
ok: \''.dol_escape_js($langs->trans("Save")).'\', | |
cancel: \''.dol_escape_js($langs->trans("Cancel")).'\' | |
} | |
} | |
} ); }); | |
</script>'; | |
$out.= '<input id="colorpicker'.$prefix.'" name="'.$prefix.'" size="6" maxlength="7" class="flat" type="text" value="'.$set_color.'" />'; | |
} | |
else // In most cases, this is not used. We used instead function with no specific list of colors | |
{ | |
$out.= '<link rel="stylesheet" href="'.DOL_URL_ROOT.'/includes/jquery/plugins/colorpicker/jquery.colorpicker.css" type="text/css" media="screen" />'; | |
$out.= '<script src="'.DOL_URL_ROOT.'/includes/jquery/plugins/colorpicker/jquery.colorpicker.js" type="text/javascript"></script>'; | |
$out.= '<script type="text/javascript"> | |
jQuery(document).ready(function(){ | |
jQuery(\'#colorpicker'.$prefix.'\').colorpicker({ | |
size: 14, | |
label: \'\', | |
hide: true | |
}); | |
}); | |
</script>'; | |
$out.= '<select id="colorpicker'.$prefix.'" class="flat" name="'.$prefix.'">'; | |
//print '<option value="-1"> </option>'; | |
foreach ($arrayofcolors as $val) | |
{ | |
$out.= '<option value="'.$val.'"'; | |
if ($set_color == $val) $out.= ' selected="selected"'; | |
$out.= '>'.$val.'</option>'; | |
} | |
$out.= '</select>'; | |
} | |
return $out; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment