1 function centerParms(width,height,extra) {
2 xPos = (screen.width - width) / 2;
3 yPos = (screen.height - height) / 2;
5 string = "left=" + xPos + ",top=" + yPos;
8 string += "width=" + width + ",height=" + height;
13 function get_input_value(input_name) {
14 var the_input = document.getElementsByName(input_name);
15 if (the_input && the_input[0])
16 return the_input[0].value;
20 function set_cursor_position(n) {
21 $('[name=' + n + ']').focus();
24 function focussable(e) {
25 return e && e.name && e.type != 'hidden' && e.type != 'submit' && e.disabled != true;
28 function set_cursor_to_first_element(){
29 var df = document.forms;
30 for (var f = 0; f < df.length; f++)
31 for (var i = 0; i < df[f].length; i++)
32 if (focussable(df[f][i]))
33 try { df[f][i].focus(); return } catch (er) { }
36 function getElementByIndirectName(name){
37 var e = document.getElementsByName(name)[0];
38 if (e) return document.getElementsByName(e.value)[0];
41 function focus_by_name(name){
42 var f = getElementByIndirectName(name);
44 set_cursor_position(f.name);
51 $('input').focus(function(){
52 if (focussable(this)) window.focused_element = this;
55 // setting focus inside a tabbed area fails if this is encountered before the tabbing is complete
56 // in that case the elements count as hidden and jquery aborts .focus()
57 setTimeout(function(){
58 // Lowest priority: first focussable element in form.
59 set_cursor_to_first_element();
61 // Medium priority: class set in template
62 var initial_focus = $(".initial_focus").filter(':visible')[0];
64 $(initial_focus).focus();
66 // special: honour focus_position
67 // if no higher priority applies set focus to the appropriate element
68 if ($("#display_row")[0] && kivi.myconfig.focus_position) {
69 switch(kivi.myconfig.focus_position) {
70 case 'last_partnumber' : $('#display_row tr.row:gt(-3):lt(-1) input[name*="partnumber"]').focus(); break;
71 case 'last_description' : $('#display_row tr.row:gt(-3):lt(-1) input[name*="description"]').focus(); break;
72 case 'last_qty' : $('#display_row tr.row:gt(-3):lt(-1) input[name*="qty"]').focus(); break;
73 case 'new_partnumber' : $('#display_row tr:gt(1) input[name*="partnumber"]').focus(); break;
74 case 'new_description' : $('#display_row tr:gt(1) input[name*="description"]').focus(); break;
75 case 'new_qty' : $('#display_row tr:gt(1) input[name*="qty"]').focus(); break;
79 // all of this screws with the native location.hash focus, so reimplement this as well
81 var hash_name = location.hash.substr(1);
82 var $hash_by_id = $(location.hash + ':visible');
83 if ($hash_by_id.length > 0) {
84 $hash_by_id.get(0).focus();
86 var $by_name = $('[name=' + hash_name + ']:visible');
87 if ($by_name.length > 0) {
88 $by_name.get(0).focus();
93 // legacy. some forms install these
94 if (typeof fokus == 'function') { fokus(); return; }
95 if (focus_by_name('cursor_fokus')) return;
99 $('form').submit(function(){
100 if (window.focused_element)
101 document.forms[0].cursor_fokus.value = window.focused_element.name;