From: stekkel Date: Fri, 12 Jul 2002 15:50:57 +0000 (+0000) Subject: added a few functions X-Git-Url: https://vcs.fsf.org/?p=squirrelmail.git;a=commitdiff_plain;h=6789a91427b5f2c25c0398fc27076466f40ea89b added a few functions git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@3083 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- diff --git a/class/html.class b/class/html.class index f44e66ee..80ab1aa3 100644 --- a/class/html.class +++ b/class/html.class @@ -27,10 +27,58 @@ class html { $this->javascript = $javascript; } - function htmlAdd($el) { - $this->html_el[] = $el; + function htmlAdd($el, $last=true) { + if ($last) { + $this->html_el[] = $el; + } else { + echo 'JOPPPEEE'; + $new_html_el = array(); + $new_html_el[] = $el; + foreach ($this->html_el as $html_el) { + $new_html_el[] = $html_el; + } + $this->html_el = $new_html_el; + } } + function AddChild($tag='', $text='', $style ='', $class='', $id='', + $xtr_prop = '', $javascript = '') { + $el = new html ($tag, $text, $style, $class, $id, $xtr_prop, $javascript); + $this->htmlAdd($el); + } + + function FindId($id) { + $cnt = count($this->html_el); + $el = false; + if ($cnt) { + for ($i = 0 ; $i < $cnt; $i++) { + if ($this->html_el[$i]->id == $id) { + $ret = $this->html_el[$i]; + return $ret; + } else if (count($this->html_el[$i]->html_el)) { + $el = $this->html_el[$i]->FindId($id); + } + if ($el) return $el; + } + } + return $el; + } + + function InsToId( $el, $id, $last=true) { + $html_el = &$this->FindId($id); + if ($html_el) { + $html_el->htmlAdd($el, $last); + } + } + + function scriptAdd($script) { + $s = "\n".''."\n"; + $el = new html ('script',$s,''.''.''.array('language' => 'JavaScript', + 'type' => 'text/javascript')); + $this->htmlAdd($el); + } function echoHtml( $usecss=false, $indent='') { $tag = $this->tag; @@ -56,8 +104,11 @@ class html { $js.=' '.$k.'="'.$v.'";'; } } - - echo $indent . '<' . $tag; + if ($tag) { + echo $indent . '<' . $tag; + } else { + echo $indent; + } if ($class) { echo ' class="'.$class.'"'; } @@ -73,7 +124,7 @@ class html { if ($javascript) { echo ' '.$js; } - echo '>'; + if ($tag) echo '>'; if ($text) { if ($style && !$usecss) { /* if use css then fallback to stylesheet for layout */ foreach ($style as $k => $v) { @@ -91,14 +142,30 @@ class html { } $cnt = count($this->html_el); if ($cnt) { + if ($style && !$usecss) { + foreach ($style as $k => $v) { + echo '<'.$k.'>'; + } + } echo "\n"; $indent.=' '; for($i = 0;$i<$cnt;$i++) { $el = $this->html_el[$i]; $el->echoHtml($usecss,$indent); } + if ($style && !$usecss) { + foreach ($style as $k => $v) { /* if value of key value = true close the tag */ + if ($v) { + echo ''; + } + } + } + } + if ($tag) { + echo ''."\n"; + } else { + echo "\n"; } - echo ''."\n"; } }