Prev: IE Scrollbars
Next: Ugh
From: Thomas 'PointedEars' Lahn on
Matthias Watermann wrote:
> On Tue, 06 May 2008 02:25:41 -0700, VK wrote:
>> [...]
>
> Just some hints after reading (w/o testing) it:
>
>> if ('userLanguage' in navigator) {
>> var lang = navigator.userLanguage.substring(0,2);
>> }
>> else if ('language' in navigator) {
>> var lang = navigator.language.substring(0,2);
>> }
>> else {
>> var lang = 'en';
>> }
>
> Should be:

Says who?

> var lang = 'en';
> if ('userLanguage' in navigator) {

`navigator' is a reference to a host object. The `in' operation is not
backwards compatible, and untested property access should be avoided with
host objects. Better:

if (typeof navigator.userLanguage != "undefined")

> lang = navigator.userLanguage.substring(0,2);
> }
> else if ('language' in navigator) {
> lang = navigator.language.substring(0,2);
> }

Same here.

>> TransModal.lang = (lang in TransModal.buttonLabelSet) ?
>> lang : 'en';

Same here, although `TransModal' is probably a native object which limits
the error-proneness of this approach to that of the `in' operation.

See also http://PointedEars.de/es-matrix

> I'd assume that "lang" is unknown here since there are only three
> vars with that name each of which inside a different "if"-scope.

Utter nonsense.

ECMAScript implementations do not support automatic block scoping. `lang'
is a redeclared variable (because of two VariableDeclaration statements in
the source code, processed *before execution*). In any case, it would have
been initialized, because there is an `else' branch that executes its
BlockStatement without further conditionals.

Apparently you also don't know how the `in' operation works. It
type-converts the left-hand operand to string. If we would assume for
educational purposes that the variable would not have been initialized, it
would keep the initial value of `undefined'. The string representation of
`undefined' is "undefined". Since it would be unlikely that the object
referred to by `TransModal.buttonLabelSet' would have a property named
`undefined', the `TransModal.lang' property would then be assigned "en".

I strongly suggest you refrain from giving further advice or making further
assumptions from your position in the learning curve. You won't be making
even educated guesses at this time.

>> [...]
>> var wndDialog = document.createElement('DIV');
>>
>> wndDialog.id = 'TransModalDialog';
>>
>> /* Some complex styling of a completely empty element
>> * may make IE to act strange. To avoid that we are
>> * setting the default content to NO-BREAK SPACE
>> */
>> wndDialog.innerHTML = '<span>\u00A0</span>';
>
> Why use "innerHTML" (instead of "createElement()") here?

Good question. A reasonable answer to it is that the Document interface of
W3C DOM Level 2 Core may not implemented in one of the target environments.
Nevertheless, the proprietary `innerHTML' property should be avoided where
possible, and standards-compliant DOM mutator methods should be preferred
(but feature-tested at runtime before being used).

Furthermore, the character U+00A0 as-is constitutes a whitespace character
in HTML that is therefore rendered as if it was a space character (U+0020).
To have a non-breaking space rendered so, the HTML source code and so the
value assigned to the `innerHTML' property has to include one of `&nbsp;',
`&#160;', or `&#xA0;'.

>> with (wndDialog.style) {
>> position = 'absolute';
>> zIndex = '1002';
>> left = '0px';
>> top = '0px';
>> cursor = 'default';
>> visibility = 'hidden';
>> }
>
> Just a matter of style & opinion:
>
> var s;
> if ((s = wndDialog.style)) {
> s.position = 'absolute';
> s.zIndex = '1002';
> s.left = '0px';
> s.top = '0px';
> s.cursor = 'default';
> s.visibility = 'hidden';
> }

IIRC, earlier Opera versions retrieved the `style' property as a string.
You would be augmenting a string object with properties, and not modify
the DOM representation of the element's `style' attribute, then.

>> [...]
>> var wndCover = document.createElement('DIV');
>>
>> wndCover.id = 'TransModalVeil';
>>
>> wndCover.innerHTML = '<span>\u00A0</span>';
>
> see above.
>
>> with (wndCover.style) {
>> position = 'absolute';
>> zIndex = '1001';
>> left = '0px';
>> top = '0px';
>> margin = '0px 0px';
>> padding = '0px 0px';

left = "0";
top = "0";
margin = "0";
padding = "0";

>> borderStyle = 'none';
>> cursor = 'not-allowed';
>> visibility = 'hidden';
>> }
>
> Same as above.

With the added error-proneness of the `with' statement.


PointedEars
--
realism: HTML 4.01 Strict
evangelism: XHTML 1.0 Strict
madness: XHTML 1.1 as application/xhtml+xml
-- Bjoern Hoehrmann
First  |  Prev  | 
Pages: 1 2
Prev: IE Scrollbars
Next: Ugh