1: | <?php
|
2: | |
3: | |
4: | |
5: | |
6: |
|
7: | namespace Sphp\comp\html{
|
8: |
|
9: | class Img extends \Sphp\tools\Control{
|
10: |
|
11: | public function __construct($name='',$fieldName='',$tableName='') {
|
12: | $this->tagName = "img";
|
13: | $this->init($name,$fieldName,$tableName);
|
14: | $this->unsetEndTag();
|
15: |
|
16: | }
|
17: |
|
18: |
|
19: | public function onjsrender(){
|
20: |
|
21: | }
|
22: |
|
23: | public function onrender(){
|
24: | $sphp_settings = getSphpSettings();
|
25: | $basepath = $sphp_settings->base_path;
|
26: | if($this->value!=''){
|
27: | $this->setAttribute('src', $this->value);
|
28: | }
|
29: | if($this->getAttribute('src')!='' && $this->getAttribute('width')!=''){
|
30: | $size = getimagesize(str_replace($basepath, '',$this->getAttribute('src')));
|
31: | $size0 = $size[0];
|
32: | $size1 = $size[1];
|
33: | $aspectratio = $size0/$size1;
|
34: | $width = $this->getAttribute('width');
|
35: | $height = $width / $aspectratio;
|
36: | $this->setAttribute('height', strval($height));
|
37: | }
|
38: |
|
39: | }
|
40: |
|
41: |
|
42: | public function getJSValue(){
|
43: | return "document.getElementById('$this->name').value" ;
|
44: | }
|
45: |
|
46: | public function setJSValue($exp){
|
47: | return "document.getElementById('$this->name').value = $exp;" ;
|
48: | }
|
49: |
|
50: | public function getJSSrc(){
|
51: | return "document.getElementById('$this->name').src" ;
|
52: | }
|
53: |
|
54: | public function setJSSrc($exp){
|
55: | return "document.getElementById('$this->name').src = $exp;" ;
|
56: | }
|
57: |
|
58: | }
|
59: | }
|
60: | |