Dr John Stockton <spam@merlyn.demon.co.uk> writes:
[color=blue][color=green]
>> var text = func.toString();[/color][/color]
[color=blue]
> Code display within my javascript pages is largely based on
> function.toString(); I only see the results in MSIE.
>
> I write my code (E&OE) to fit within 69-character-wide boxes (as seen in
> IE 4), and I choose the height of each box to suit the code.[/color]
Yes, checking in IE, I can see that the code doesn't have to overflow the
box :)
[color=blue]
> Are the results generally acceptable in other browsers, and could
> anything be done to make the average better (given the wide use of IE)?[/color]
The boxes overflow in both Mozilla and Opera.
One of the problems is the number of empty lines between functions in
boxes with more than one function. In IE, there is one line, in both
Mozilla and Opera, there are three (an extra line before and after
each function). It shouldn't hurt to remove these empty lines, if they
exist.
Another difference is that IE doesn't reformat the body of the
function at all, whereas the other browsers do. In particular, they
move "}"'s to a line of their own. Opera also moves "{"'s to their
own line (the thing that makes me prefer Mozilla's format).
I don't see a simple solution to this.
The non-IE browsers also doesn't include comments in the output. All
in all, lines are probably shorter than in IE.
A non-simple solution would be to make the ShowFF function calculate
the necessary number of lines for the textarea, instead of providing
it as an argument. E.g.:
---
function trim(str) {
var match = /\S([\s\S]*\S)*/.exec(str);
return match ? match[0] : "";
}
function countLines(str, lineLength) {//counts lines when wrapped at lineLength
var lines = str.split(/[\n\r]/g);
var lineCount = lines.length;
for (var i = 0; i < lines.length; i++) {
lineCount += Math.floor(lines[i].length / lineLength);
}
return lineCount;
}
function ShowFF() { // Args are functions, last Arg is unused
var Len = arguments.length-1, S = ""
for (var j=0 ; j<Len ; j++) {
if (j>0) { S += "\n\n"; }
S += trim(arguments[j].toString());
}
var numLines = countLines(S, BoxX);
Depict(BoxX, numLines, S, "lightgreen") ; return "" }
function ShowDo(Fn, Ht) { // N.B. this calls Fn()
var string = trim(Fn.toString());
Depict(BoxX, countLines(string, BoxX), string, "red" ) ; Fn() ; return "" }
---
Good luck
/L
--
Lasse Reichstein Nielsen -
lrn@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'