3 'alt': false, // whether is the Alt key pressed
4 'focus': -1 // currently selected indeks of document.links
8 box = document.getElementById('msgbox')
9 box.innerHTML= box.innerHTML+'<br>'+msg
13 box = document.getElementById('msgbox');
14 box.innerHTML= "<center><table width='98%' border='1' cellpadding=3 "
15 +"bordercolor='#007700' style='border-collapse: collapse'>"
16 +"<tr><td align='center' bgcolor='#ccffcc' >"
17 +"<img src='"+user.theme+"images/progressbar.gif' alt='"
18 +user.loadtxt+"' /></td></tr></table></center><br>";
19 box.style.display = 'block';
22 function save_focus(e) {
23 _focus = e.name||e.id;
24 var h = document.getElementById('hints');
26 h.style.display = e.title && e.title.length ? 'inline' : 'none';
27 h.innerHTML = e.title ? e.title : '';
31 function _expand(tabobj) {
33 var ul = tabobj.parentNode.parentNode;
34 var alltabs=ul.getElementsByTagName("input");
35 var frm = tabobj.form;
37 if (ul.getAttribute("rel")){
38 for (var i=0; i<alltabs.length; i++){
39 alltabs[i].className = "ajaxbutton" //deselect all tabs
41 tabobj.className = "current";
42 JsHttpRequest.request(tabobj)
46 //interface for selecting a tab (plus expand corresponding content)
47 function expandtab(tabcontentid, tabnumber) {
48 var tabs = document.getElementById(tabcontentid);
49 _expand(tabs.getElementsByTagName("input")[tabnumber]);
52 function _set_combo_input(e) {
53 e.setAttribute('_last', e.value);
55 var but_name = this.name.substring(0, this.name.length-4)+'button';
56 var button = document.getElementsByName(but_name)[0];
57 var select = document.getElementsByName(this.getAttribute('rel'))[0];
59 // submit request if there is submit_on_change option set and
60 // search field has changed.
61 if (button && (this.value != this.getAttribute('_last'))) {
62 JsHttpRequest.request(button);
63 } else if(this.className=='combo2') {
64 this.style.display = 'none';
65 select.style.display = 'inline';
66 setFocus(select.name);
70 e.onkeyup = function(ev) {
71 var select = document.getElementsByName(this.getAttribute('rel'))[0];
72 if(select && select.selectedIndex>=0) {
73 var len = select.length;
74 var byid = this.className=='combo';
75 var ac = this.value.toUpperCase();
76 select.options[select.selectedIndex].selected = false;
77 for (i = 0; i < len; i++) {
78 var txt = byid ? select.options[i].value : select.options[i].text;
79 if (txt.toUpperCase().indexOf(ac) >= 0) {
80 select.options[i].selected = true;
86 e.onkeydown = function(ev) {
87 ev = ev||window.event;
88 key = ev.keyCode||ev.which;
96 function _update_box(s) {
97 var byid = s.className=='combo';
98 var rel = s.getAttribute('rel');
99 var box = document.getElementsByName(rel)[0];
100 if(box && s.selectedIndex>=0) {
101 var opt = s.options[s.selectedIndex];
103 box.value = byid ? opt.value : opt.text;
104 box.setAttribute('_last', box.value);
109 function _set_combo_select(e) {
110 // When combo position is changed via js (eg from searchbox)
111 // no onchange event is generated. To ensure proper change
112 // signaling we must track selectedIndex in onblur handler.
113 e.setAttribute('_last', e.selectedIndex);
114 e.onblur = function() {
115 if(this.className=='combo')
117 if (this.selectedIndex != this.getAttribute('_last'))
120 e.onchange = function() {
122 this.setAttribute('_last', this.selectedIndex);
123 if(s.className=='combo')
125 if(s.selectedIndex>=0) {
126 var sname = '_'+s.name+'_update';
127 var update = document.getElementsByName(sname)[0];
129 JsHttpRequest.request(update);
134 e.onkeydown = function(event) {
135 event = event||window.event;
136 key = event.keyCode||event.which;
137 var box = document.getElementsByName(this.getAttribute('rel'))[0];
138 if (box && key == 32 && this.className == 'combo2') {
139 this.style.display = 'none';
140 box.style.display = 'inline';
145 if (this.getAttribute('aspect') == 'editable' && key==115) {
146 // F4: call related database editor - not available in non-js fallback mode
147 JsHttpRequest.request('_'+this.name+'_editor', this.form);
148 return false; // prevent default binding
149 // TODO: stopPropagation when needed
155 Behaviour definitions
158 'form': function(e) {
159 e.onkeydown = function(ev) {
160 ev = ev||window.event;
161 key = ev.keyCode||ev.which;
162 if((ev.ctrlKey && key == 13) || key == 27) {
163 ev.cancelBubble = true;
164 if(ev.stopPropagation) ev.stopPropagation();
165 // here ctrl-enter/escape support
166 ev.returnValue = false;
172 'input': function(e) {
173 if(e.onfocus==undefined) {
174 e.onfocus = function() {
176 if (this.className == 'combo')
180 if (e.className == 'combo' || e.className == 'combo2') {
184 if(e.type == 'text' ) {
185 e.onkeydown = function(ev) {
186 ev = ev||window.event;
187 key = ev.keyCode||ev.which;
189 if(e.className == 'searchbox') e.onblur();
196 'input.combo2,input[aspect="fallback"]':
198 // this hides search button for js enabled browsers
199 e.style.display = 'none';
203 // this shows divs for js enabled browsers only
204 e.style.display = 'block';
206 'input.ajaxsubmit','button.ajaxsubmit,button.editbutton,button.navibutton':
208 e.onclick = function() {
209 if (this.getAttribute('aspect') == 'process')
211 JsHttpRequest.request(this);
215 '.amount': function(e) {
216 if(e.onblur==undefined) {
217 e.onblur = function() {
218 var dec = this.getAttribute("dec");
219 price_format(this.name, get_amount(this.name), dec);
223 '.searchbox': // emulated onchange event handling for text inputs
225 e.setAttribute('_last_val', e.value);
226 e.setAttribute('autocomplete', 'off'); //must be off when calling onblur
227 e.onblur = function() {
228 var val = this.getAttribute('_last_val');
229 if (val != this.value) {
230 this.setAttribute('_last_val', this.value);
231 JsHttpRequest.request('_'+this.name+'_changed', this.form);
234 /* e.onkeydown = function(ev) {
235 ev = ev||window.event;
236 key = ev.keyCode||ev.which;
237 if (key == 13 && (this.value != this.getAttribute('_last_val'))) {
243 'select': function(e) {
244 if(e.onfocus==undefined) {
245 e.onfocus = function() {
249 if (c == 'combo' || c == 'combo2')
250 _set_combo_select(e);
253 'textarea,a': function(e) {
254 if(e.onfocus==undefined) {
255 e.onfocus = function() {
260 'ul.ajaxtabs': function(ul) {
261 var ulist=ul.getElementsByTagName("li");
262 for (var x=0; x<ulist.length; x++){ //loop through each LI e
263 var ulistlink=ulist[x].getElementsByTagName("input")[0];
264 if(ulistlink.onclick==undefined) {
265 // ? var modifiedurl=ulistlink.getAttribute("href").replace(/^http:\/\/[^\/]+\//i, "http://"+window.location.hostname+"/")
266 var url = ulistlink.form.action
267 ulistlink.onclick=function(){
274 '#msgbox': function(e) {
275 // this is to avoid changing div height after ajax update in IE7
276 e.style.display = e.innerHTML.length ? 'block' : 'none';
279 'a.date_picker': function(e) {
280 // this un-hides data picker for js enabled browsers
281 e.href = date_picker(this.getAttribute('rel'));
282 e.style.display = '';
283 e.tabindex = -1; // skip in tabbing order
287 function stopEv(ev) {
288 ev.returnValue = false;
289 ev.cancelBubble = true;
290 if(ev.preventDefault) ev.preventDefault();
294 Modified accesskey system. While Alt key is pressed letter keys moves
295 focus to next marked link. Alt key release activates focused link.
297 function setHotKeys() {
298 document.onkeydown = function(ev) {
299 ev = ev||window.event;
300 key = ev.keyCode||ev.which;
301 if (key == 18) { // start selection
306 if (key == 27) { // cancel selection
307 _hotkeys.alt = false;
311 else if (_hotkeys.alt && ((key>47 && key<58) || (key>64 && key<91))) {
312 var n = _hotkeys.focus;
313 var l = document.links;
315 key = String.fromCharCode(key);
316 for (var i=0; i<cnt; i++) {
318 // check also if the link is visible
319 if (l[n].accessKey==key && l[n].scrollWidth) {
321 // The timeout is needed to prevent unpredictable behaviour on IE.
322 var tmp = function() {document.links[_hotkeys.focus].focus();};
331 document.onkeyup = function(ev) {
332 if (_hotkeys.alt==true) {
333 ev = ev||window.event;
334 key = ev.keyCode||ev.which;
337 _hotkeys.alt = false;
338 if (_hotkeys.focus>=0) {
339 window.location = document.links[_hotkeys.focus].href;
348 Behaviour.register(inserts);
350 Behaviour.addLoadEvent(setFocus);
351 Behaviour.addLoadEvent(setHotKeys);