/[bfilter]/trunk/combo2/Combo.php
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /trunk/combo2/Combo.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 38 - (show annotations)
Wed Nov 17 09:25:10 2004 UTC (19 years, 5 months ago) by dpavlin
File size: 6824 byte(s)
added new combobox implementation by Matko Andjelinic together with example
implementation in php

1 <?php
2 /*
3
4 Combo.php
5 Copyright (c) 2004 Matko Andjelinic (matko.andjelinic@gmail.com)
6 This library is distributed under the GPL v2 or later
7
8
9 */
10
11
12 class Combo {
13 var $name;
14
15 var $body_onload;
16 var $head;
17 var $html;
18
19 var $bfilterurl;
20 var $jscombourl;
21 var $translateurl;
22
23 var $headlines;
24
25 var $js_onchange;
26
27
28 function loadjsurl($url) {
29 if (empty($_GLOBALS["combo_loaded_jsurls"])) $_GLOBALS["combo_loaded_jsurls"] = array();
30 if (!in_array($url, $_GLOBALS["combo_loaded_jsurls"])) {
31 $_GLOBALS["combo_loaded_jsurls"][] = $url;
32 $this->head .= "<script type=\"text/javascript\" src=\"".$url."\"></script>";
33 }
34 }
35
36 function js_check_code() {
37 $ret = "
38 <script type=\"text/javascript\">
39 function ".$this->name."_combo_empty() {
40 var entry = document.getElementById('".$this->name."textfilter') || null;
41 if (entry) {
42 if (entry.value.match(/^\s*$/)) return true;
43 }
44 return false;
45 }
46 </script>
47 ";
48 return $ret;
49 }
50
51 function get() {
52 if (!$this->bfilterurl) $this->bfilterurl = $this->JSCombo_location . "/bfilter.js";
53 if (!$this->jscombourl) $this->jscombourl = $this->JSCombo_location . "/JSCombo.js";
54 if (!$this->translateurl) $this->translateurl = $this->JSCombo_location . "/translate.js";
55
56 $this->loadjsurl($this->bfilterurl);
57 $this->loadjsurl($this->jscombourl);
58
59 if ($this->translateurl) {
60 $this->loadjsurl($this->translateurl);
61 }
62
63 if ($this->translateurl) {
64 $thisvalue = "JSCombo_translate(this.value)";
65 } else {
66 $thisvalue = "this.value";
67 }
68
69 $this->head .= $this->js_check_code();
70
71 $this->html = "
72 <div id='status' style='display:none'>
73 </div>
74 <table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" class=\"combo_box\">
75 <tr>
76 <td style=\"padding-left:1px\">
77 <input autocomplete=\"off\" class=\"combo_textfilter\" id=\"".$this->name."textfilter\" type=\"text\"
78 onKeyDown=\"self.document.".$this->name."_combo.textbox_keydown(event);\"
79 onKeyUp=\"self.document.".$this->name."_combo.filter(".$thisvalue.");return false;\"
80 onClick=\"self.document.".$this->name."_combo.myfilter.clear_results();\"
81 name=\"".$this->name."\"
82 value=\"".$this->currval."\">
83 </td>
84 <td align=\"right\" style=\"padding-top:1px;padding-right:1px;\">
85 <input tabindex=\"999\" class=\"combo_expand\" type=\"submit\" value=\"&middot;\" onclick=\"return false;\" onMouseUp=\"self.document.".$this->name."_combo.myfilter.show_filter(self.document.getElementById('".$this->name."textfilter').value);return false;\">
86 </td>
87 </tr>
88 <tr>
89 <td colspan=\"2\">
90 <select tabindex=\"998\" class=\"combo_sel\" id=\"".$this->name."sel\" size=\"5\"
91 onKeyDown=\"self.document.".$this->name."_combo.dropdown_keydown(event);\"
92 onChange=\"self.document.getElementById('".$this->name."textfilter').value = this.options[this.selectedIndex].text;".(empty($this->js_onchange) ? "":$this->js_onchange.";")."\"
93 onClick=\"self.document.".$this->name."_combo.myfilter.clear_results();\"
94 style=\"display:none\"
95 ></select>
96 </td>
97 </tr>
98 </table>
99 ";
100
101 return array(
102 "body_onload" => $this->body_onload
103 , "head" => $this->head
104 , "html" => $this->html
105 );
106
107 }
108
109
110
111 function sort($headlines) {
112 if (empty($headlines)) return $headlines; //return the empty array
113 foreach ($headlines as $key=>$val) {
114 $headlines1[$key]["show"] = $val;
115 $translatefunction = $this->translateFunction;
116 $headlines1[$key]["sort"] = $translatefunction($val);
117 }
118 uasort($headlines1, $this->sortFunction);
119 return $headlines1;
120 }
121
122 function _jsheadlines($headlines) {
123 $varname = $this->name."_headlines";
124 $tmp = "var ".$varname." = new Object();\n";
125 $headlines_count = 0;
126 foreach ($headlines as $key=>$val) {
127 if (empty($val["sort"])) continue;
128 $headlines_count ++;
129 if (empty($letter) || (strtolower($val["sort"][0]) != $letter )) {
130 if (!empty($letter)) $tmp .= "];\n";
131 $letter = strtolower($val["sort"][0]);
132 $tmp .= $varname."['".$letter."'] = [\n";
133 } else {
134 $tmp .= ",";
135 }
136 $tmp .= "['".addslashes($val["sort"])."','".addslashes($val["show"])."','".addslashes($key)."']\n";
137 }
138 if (!empty($letter)) $tmp.="];\n";
139 $tmp.= $varname.".min_len = 1;\n";
140 $tmp.= $varname.".length = ".$headlines_count.";\n";
141 return $tmp;
142 }
143
144 function Combo($name, $headlines, $currval) {
145 $this->name = $name;
146 $this->currval = $currval;
147
148 $this->JSCombo_location = ".";
149
150 $this->sortFunction = "Combo_Ascii_Sort";
151 $this->translateFunction = "Combo_translate";
152
153 $this->headlines = $this->sort($headlines);
154
155 $this->head .= "<script type=\"text/javascript\">".$this->_jsheadlines($this->headlines)."</script>";
156
157 $this->body_onload = "self.document.".$this->name."_combo = new JSCombo('".$this->name."', ".$this->name."_headlines);";
158
159 }
160
161 }
162
163 function Combo_Ascii_Sort($val_1, $val_2) {
164 $retVal = 0;
165 $firstVal = strtolower($val_1["sort"]);
166 $secondVal = strtolower($val_2["sort"]);
167 if($firstVal > $secondVal) {
168 $retVal = 1;
169 } else if($firstVal < $secondVal) {
170 $retVal = -1;
171 }
172 return $retVal;
173 }
174
175
176 function Combo_translate($text) {
177 $text = preg_replace("/[¡ÁÂÃÄ]/",'A',$text);
178 $text = preg_replace("/[ÆÇÈ]/",'C',$text);
179 $text = preg_replace("/[ÏÐ]/",'D',$text);
180 $text = preg_replace("/[ÉÊËÌ]/",'E',$text);
181 $text = preg_replace("/[ÍÎ]/",'I',$text);
182 $text = preg_replace("/[£¥Å]/",'L',$text);
183 $text = preg_replace("/[ÑÒ]/",'N',$text);
184 $text = preg_replace("/[ÓÔÕÖ]/",'O',$text);
185 $text = preg_replace("/[ÀØ]/",'R',$text);
186 $text = preg_replace("/[¦©ª]/",'S',$text);
187 $text = preg_replace("/[«Þ]/",'T',$text);
188 $text = preg_replace("/[ÙÚÛÜ]/",'U',$text);
189 $text = preg_replace("/[Ý]/",'Y',$text);
190 $text = preg_replace("/[¬®¯]/",'Z',$text);
191 $text = preg_replace("/[±áâãä]/",'a',$text);
192 $text = preg_replace("/[æçè]/",'c',$text);
193 $text = preg_replace("/[ïð]/",'d',$text);
194 $text = preg_replace("/[éêëì]/",'e',$text);
195 $text = preg_replace("/[íî]/",'i',$text);
196 $text = preg_replace("/[³µå]/",'l',$text);
197 $text = preg_replace("/[ñò]/",'n',$text);
198 $text = preg_replace("/[óôõö]/",'o',$text);
199 $text = preg_replace("/[àø]/",'r',$text);
200 $text = preg_replace("/[¶¹º]/",'s',$text);
201 $text = preg_replace("/[»þ]/",'t',$text);
202 $text = preg_replace("/[ùúûü]/",'u',$text);
203 $text = preg_replace("/[ý]/",'y',$text);
204 $text = preg_replace("/[¼¾¿]/",'z',$text);
205 return $text;
206 }
207
208
209 ?>

  ViewVC Help
Powered by ViewVC 1.1.26