Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 2ed420df

Von Sven Schöling vor mehr als 16 Jahren hinzugefügt

  • ID 2ed420dfe72c02a01457b104f561c3571354405c
  • Vorgänger f5e340df
  • Nachfolger 8be9afee

Umgestellt auf DOM 1, sollte jetzt sogar im IE funktionieren.

Unterschiede anzeigen:

js/common.js
1

  
2 1
if (!window.a_onload_functions)   var a_onload_functions   = new Object();
3 2
if (!window.a_onsubmit_functions) var a_onsubmit_functions = new Object();
4

  
3
if (!window.a_onfocus_functions)  var a_onfocus_functions  = new Object();
4
window.focused_element = null;
5 5

  
6 6
function setupPoints(numberformat, wrongFormat) {
7 7
  decpoint = numberformat.substring((numberformat.substring(1, 2).match(/\.|\,/) ? 5 : 4), (numberformat.substring(1, 2).match(/\.|\,/) ? 6 : 5));
......
139 139
  return '';
140 140
}
141 141

  
142
window.focused_element = null;
143
document.addEventListener("focus", function(event){ 
144
  var e = event.target;
145
  if (is_element_focussable(e)) window.focused_element = e;
146
}, true);
142
a_onfocus_functions["focus_listener"] = function (event) { 
143
  if (focussable(event.target)) window.focused_element = event.target;
144
}
147 145

  
148
function get_cursor_position() {
146
a_onsubmit_functions["get_cursor_position"] = function () {
149 147
  if (window.focused_element)
150
  document.forms[0].cursor_fokus.value = window.focused_element.name;
148
    document.forms[0].cursor_fokus.value = window.focused_element.name;
151 149
}
152 150

  
153 151
function set_cursor_position(n) {
154 152
  document.getElementsByName(n)[0].focus();
155 153
}
156 154

  
157
function restore_cursor_position() {
155
a_onload_functions["restore_cursor_position"] = function () {
158 156
  var e = document.getElementsByName('cursor_fokus')[0];
159 157
  var f = document.getElementsByName(e.value)[0];
160
  if (is_element_focussable(f)) set_cursor_position(f.name)
161
   else set_cursor_to_first_element();
158
  if (focussable(f)) set_cursor_position(f.name)
159
    else set_cursor_to_first_element();
162 160
}
163 161

  
164
function is_element_focussable(e) {
162
function focussable(e) {
165 163
  return e && e.type != 'hidden' && e.type != 'submit' && e.disabled != true;
166 164
}
167 165

  
......
169 167
  var df = document.forms;
170 168
  for (var f = 0; f < df.length; f++)
171 169
    for (var i = 0; i < df[f].length; i++)
172
      if (is_element_focussable(df[f][i]))
170
      if (focussable(df[f][i]))
173 171
        try { df[f][i].focus(); return } catch (er) { }
174 172
}
175
a_onload_functions["restore_cursor_position"] = restore_cursor_position;
176
a_onsubmit_functions["get_cursor_position"]   = get_cursor_position;
173

  
174
function add_event(e, type, fn, c) {
175
  var ret = 0;
176
  if (e.addEventListener) ret = e.addEventListener(type, fn, c)
177
  else if (e.attachEvent) ret = e.attachEvent('on' + type, fn)
178
  else e['on' + type] = fn;
179
  return ret;
180
} 
177 181

  
178 182
function do_load_events() {
179
  var oldl = window.onload;
180
  window.onload = function() {
181
    if (oldl) oldl();
182
    if (window.a_onload_functions) 
183
      for (var name in window.a_onload_functions) 
184
        a_onload_functions[name]();
185
  }
186
  window.onsubmit = function() {
187
    if (window.a_onsubmit_functions) 
188
      for (var name in window.a_onsubmit_functions) 
189
        a_onsubmit_functions[name]();
190
  }
183
  for (var name in window.a_onload_functions)   add_event(window, "load",   window.a_onload_functions[name],   false);
184
  for (var name in window.a_onsubmit_functions) add_event(window, "submit", window.a_onsubmit_functions[name], false);
185
  for (var name in window.a_onfocus_functions)  add_event(window, "focus",  window.a_onfocus_functions[name],  true);
191 186
}
192 187
do_load_events();

Auch abrufbar als: Unified diff