I wanted to make TVImageResizer script more flexible, by customizing image TV’s with own ’width’ and ’height’ properties.
Therefore i decide to use some TV fields that images don’t proceed at all. This 2 fields was:
1. Input Option Values (field ’elements’ in ’modx_site_tmplvars’ table)
2. Default Value (field ’default_text’ in ’modx_site_tmplvars’ table)
You can see these in the image attached.
After this i have to make some changes in "TVimageResizer.inc.php" file (the blue text):
if ($e->name == ’OnDocFormRender’) {
$result = $modx->db->select(’id,name,elements,default_text’, $tb_tmplvars, "type=’image’");
$tvs = ’’;
$tvs_width = ’’;
$tvs_height = ’’;
while ($row = $modx->db->getRow($result))
{
$tvs .= ",’" . $row[’id’] . "’";
$w = (intval($row[’elements’])>0) ? intval($row[’elements’]) : $th_width;
$tvs_width .= ",’" . $w . "’";
$h = (intval($row[’default_text’])>0) ? intval($row[’default_text’]) : $th_height;
$tvs_height .= ",’" . $h . "’";
}
$tvs = substr($tvs, 1);
$tvs_width = substr($tvs_width, 1);
$tvs_height = substr($tvs_height, 1);
$output = <<< OUT
<!-- TVimageResizer -->
<script type="text/javascript">
var trImgNames = [$tvs];
var trImgWidth = [$tvs_width];
var trImgHeight = [$tvs_height];
window.onDomReady(function(){
for (var i=0;i<trImgNames.length;i++){
var elem = $(’tv’ + trImgNames[ i]);
if(elem!=null){
var br = new Element(’br’);
var field1 = new Element(’input’,{type:’checkbox’, name:’rsz[]’, id:’rsz’+(i+1), value:trImgNames[ i]});
var label = new Element(’label’,{’for’:’rsz’+(i+1)});
var field2 = new Element(’input’,{type:’text’, size:’5’, name:’rszwidth[]’, value:trImgWidth[ i], ’styles’: {’width’:’20px’}});
var field3 = new Element(’input’,{type:’text’, size:’5’, name:’rszheight[]’, value:trImgHeight[ i], ’styles’: {’width’:’20px’}});
elem.getParent()
.adopt(br,field1,label.appendText(’resize’))
.adopt(field2).appendText(’x’,’after’)
.adopt(field3);
}
}
});
</script>
<!-- /TVimageResizer -->
OUT;
$e->output($output);
This way i have done customizable TV images with very own WIDTH and HEIGHT properties, witch you can see on second attachment.
I hope this will be useful for other people, who have same as my problems with TV images