More Robust

Browsers have a bewildering array of
default behaviours for <textarea>s.

This will work a little more uniformly
across brosswers.
This commit is contained in:
Jacques Distler 2009-12-12 01:12:52 -06:00
parent 561a007682
commit 60a233a917
2 changed files with 19 additions and 9 deletions

View file

@ -53,14 +53,17 @@ function mactionWorkarounds() {
}); });
} }
function updateSize(elt) { function updateSize(elt, w, h) {
// adjust to the size of the user's browser area. // adjust to the size of the user's browser area.
// w and h are the original, unadjusted, width and height per row/column
var parentheight = document.viewport.getHeight() - $('pageName').getHeight() var parentheight = document.viewport.getHeight() - $('pageName').getHeight()
- $('editFormButtons').getHeight() - $('hidebutton').getHeight(); - $('editFormButtons').getHeight() - $('hidebutton').getHeight();
var parentwidth = Math.min( document.viewport.getWidth(), elt.parentNode.getWidth() ) - 10 ; var parentwidth = $('Content').getWidth();
var f = $('MarkupHelp'); var f = $('MarkupHelp');
if (f.visible()) {parentwidth = parentwidth - f.getWidth()} if (f.visible()) {parentwidth = parentwidth - f.getWidth() - 20}
elt.writeAttribute({'cols': Math.floor(parentwidth/10), 'rows': Math.floor(parentheight/20)} ); var newcols = Math.floor(parentwidth/w) - 1;
var newrows = Math.floor(parentheight/h - 3);
elt.writeAttribute({'cols': newcols, 'rows': newrows });
elt.setStyle({Width: parentwidth, Height: parentheight}); elt.setStyle({Width: parentwidth, Height: parentheight});
} }
@ -72,19 +75,21 @@ function resizeableTextarea() {
f.insert({before: hidebutton}); f.insert({before: hidebutton});
} }
$$('textarea#content').each( function(textarea) { $$('textarea#content').each( function(textarea) {
var w = textarea.getWidth()/textarea.getAttribute('cols');
var h = textarea.getStyle('lineHeight').replace(/(\d*)px/, "$1");
Event.observe(hidebutton, 'click', function(){ Event.observe(hidebutton, 'click', function(){
if (f.visible()) { if (f.visible()) {
f.hide(); f.hide();
hidebutton.writeAttribute({value: 'Show markup help'}); hidebutton.writeAttribute({value: 'Show markup help'});
updateSize(textarea) updateSize(textarea, w, h)
} else { } else {
f.show(); f.show();
hidebutton.writeAttribute({value: 'Hide markup help'}); hidebutton.writeAttribute({value: 'Hide markup help'});
updateSize(textarea) updateSize(textarea, w, h)
} }
}); });
Event.observe(window, 'resize', function(){ updateSize(textarea) }); Event.observe(window, 'resize', function(){ updateSize(textarea, w, h) });
updateSize(textarea); updateSize(textarea, w, h);
}); });
} }

View file

@ -408,6 +408,11 @@ span.wikilink-error b {
color: #009; color: #009;
} }
textarea#content {
font-size: 1em;
line-height: 1.125;
}
merror {display:inline;font-size:1em;} merror {display:inline;font-size:1em;}
math[display=block] {overflow:auto;} math[display=block] {overflow:auto;}
math { white-space: nowrap } math { white-space: nowrap }