// TODO: move from lace/ into lace/scripts/ console.log("Test"); var chatPane = null; var textField = null; var nameField = null; addEventListener("load", function() { chatPane = document.getElementById('main'); /* fix the text fields to be more cozy with the keyboard */ setupTextField(textField = document.getElementById('text')); setupTextField(nameField = document.getElementById('name')); setTimeout(updateLayout, 0); setInterval(updateLayout, 400); }, false); function setupTextField(field) { field.addEventListener("focus", textFieldFocus, false); field.addEventListener("blur", textFieldBlur, false); } var onceFocused = false; function textFieldFocus (event) { if (event.target.clearPhase) return; // it happens once for no reason... so ignore the first time if (!onceFocused) { onceFocused = true; return; } setTimeout(function() { window.scrollTo(0, 205); }, 300); } function textFieldBlur (event) { if (event.target.clearPhase) return; window.scrollTo(0, 1); // if the text input field has text in it, submit if (textField.value != '') textField.form.onsubmit(); } window.alert = function (s) { if (!confirm(s)) { window.alert = null; } } function updatePane() { window.scrollTo(0, 1); chatPane.scrollTop = chatPane.scrollHeight; } var currentWidth = 0; function updateLayout() { var newWidth = (window.fake_iphone ? window.setWidth : window.innerWidth); if (newWidth != currentWidth) { if (currentWidth == 0) { // this happens once, on load. hack until we find why it rearranges the whole page after onload. for (var i = 1; i < 4; i++) { setTimeout(updatePane, (i*1000)); } } else { setTimeout(updatePane, 300); } // alert("cW: " + currentWidth + " => " + newWidth); currentWidth = newWidth; // XXX: since the resizing of various elements causes the page to temporarily expand to ~333 from 320px, // XXX: it was necessary to make the check a little less exact here. 320 = profile, 480 = landscape var orient = currentWidth < 430 ? "profile" : "landscape"; // kalle: not necessary; was only necessary when updateLayout // was called before document had fully loaded. // if (document.body) { document.body.setAttribute("orient", orient); // } } }