[announcement] ISKEET library 0.0.2

  • Thread starter Ekkehard Morgenstern
  • Start date
M

Michael Winter

That JavaScript can safely use the HTTP User Agent string.

This is the last time (honest :) that I will mention the User-Agent
header...

As I tried to point out - you can't. Without the guarantee of an accurate
browser description, there is nothing 'safe' about its usage.

You said that your usage of User-Agent is based upon the need to detect
browsers that don't implement DOM methods correctly. Wouldn't a much more
forward-thinking approach be to call the method in such a way that it
will, if not implemented as you expect, fail and use that to resort to a
compatibility replacement. At least that way, a browser with an abnormal
implementation can be fixed in the future and will not be subjected to
unwarranted fallback procedures.

JavaScript on Opera, for function objects, assumes toSource() semantics
where toString() would be appropriate.

toSource() is a browser-specific function introduced in Netscape
Navigator. It is present on all Netscape/Mozilla-type implementations.

Fine. However, you cannot tell someone to go an read an unrelated
specification in such a way that implies an incorrect implementation.

In the event reference for Opera 7, it says that images support only
"complete". However, mouse down, up, over and out events are also
supported. :)

Read it again... The information you refer to is from the section
entitled, "Support for non-standard JScript and JavaScript objects". The
onmousedown, onmouseup, onmouseover and onmouseout intrinsic events are
specified in the HTML 4.01 Specification as applicable to the IMG element,
so they are not 'non-standard', and do not belong to that section.

Mike
 
R

Richard Cornford

message
How so?

How can I detect a language bug?

If you can demonstrate a bug (in isolation) then it becomes obvious how
to test for it. But a test for one ECMA Script language feature that is
not always present in older web browsers is confirming that the
String.prototype.replace function accepts function references as its
second parameter instead of just strings.

if('a'.replace(/a/, function(){return '';}).length == 0){
// String.prototye.replace accepts
// function reference arguments.
}
In fact, it's very possible to do that, since not only
PHP sites depend on the proper setting of it.

Whether PHP sites depend on it or not does not effect the fact that
deductions about the type or version of a web browser (or even details
like the operating system) cannot be validly derived from the User Agent
headers sent from common web browsers.
I do not compare the entire string for equality, I just
for keywords in the string, like "Opera <version>" or
"MSIE <version>", which are guaranteed to be set anyway.

So which of the web browsers installed on the computer I am using now
sends the UA header:-

Mozilla/4.0 (compatible; MSIE 5.0; Windows 98)

- by default? (Hint: it isn't IE 5.0, that isn't even installed on this
computer). And how about:-

Mozilla/4.0 (compatible; MSIE 6.0; Windows 98)

- (Hint: it isn't IE 6).

Where are your discriminating sub-strings? The bottom line is that the
User Agent string is not an indicator of anything but the User Agent
string.

In version 0.0.4 I use object and feature detection in conjunction
with the UA string, and it also works when the UA string isn't set
at all, so I guess the problem is solved now.

You are using the existence of objects within the DOM to infer the type
of browser. That is almost as invalid as browser detecting using the
User Agent string.

Feature detecting tests the features required by a script (at some
point) prior to using them and does not ever infer anything about one
object/feature from another. It is the *only* reliable strategy for
matching the execution of JavaScript code with the browser's ability to
support that code. And feature detection based code has no interest in
the type or version of the browser.
If you know what you're doing when parsing the UA string,
it's not a problem that it contains flags to indicate compatibility
with other browsers.

It is completely normal for User Agent strings to be completely
indistinguishable from the UA strings of other more common browsers, and
for one browser to use UA strings that are indistinguishable from the UA
strings of many other browsers (user selected under preferences).
Nope. If they support DOM, they'll get as much DOM-handling as
possible, ...
<snip>

That isn't the question that I asked. I know exactly how they will
respond to your code. What I was asking is how your much-vaunted PHP UA
base browser detectors would respond if either sent a UA header that
admitted which browser they were.

It is the answer to that question that explains why browsers habitually
send UA headers that cannot be distinguished from IE's (or Mozilla, or
even occasionally Opera).

Richard.
 
R

Richard Cornford

message
In the ISKEET library, the ISKEET_DocEncap class encapsulates DOM.

"encapsulates DOM" seems a bit of an overstatement as the only DOM
methods used in the code are implementation, implementation.hasFeature,
getElementById, addEventListener and removeEventListener, which is a
tiny fraction of the DOM.
Only things not supported in DOM are passed to the
compatibility layer, in the ISKEET_CompatEncap class.

In practice it is the things that the code believes not to be supported
that are being passed to the ISKEET_CompatEncap code, without regard for
whether the browser in use supports them or not, at least beyond asking
implementation.hasFeature if a particular set of DOM standards are fully
implemented. And as you have noticed 98% implementation of the HTML DOM
Level 2 interfaces does not justify having - hasFeature - return true
for "HTML", "2.0".
Unfortunately, DOM isn't even implemented the same across browsers.

At least they are all moving in the same direction and it never will be
the same.
Refer to the Gecko DOM reference (for Netscape/Mozilla), the
Opera DOM reference, and Internet Explorer's DOM reference.

That sounds like an order. But why just those 3?
For example, Internet Explorer and Opera support some aspects of
DOM 2.0, but instead of supporting all features to justify DOM
2.0 Core, Event and CSS compliance, which would've been simple
to implement, they expose simply some 2.0 features that they
happen to support.

That isn't really a problem, unless you want to make decisions about haw
a script is going to act based on inferences instead of direct testing.
DOM 2.0 is already old, and 3.0 in the works. This shows how
browser implementors adhere to standards.

Yes it does, they are implemented over time, at different rates and more
or less successfully. And the whole process will be repeated when Level
3 is finished.
The ISKEET library relieves the programmer from thinking about
such stuff. If a feature doesn't work, I can put it into the
DocEncap or CompatEncap layers without the programmer knowing about it.

And if there is no fall-back method to implement in CompatEncap? In that
case the programmer needs to know.
Abstract libraries have been proven successful on Java, C++,
C, and other languages, and ECMAScript / JavaScript makes no
exception.

The suitability of an abstract library has nothing to do with ECMAScript
or any other language. The only important factor is the environment that
is being scripted and it is the web browsers environment that renders
abstract libraries inappropriate.
I certainly don't want to hardcode my JavaScript support
for every web page I'm writing.

Like it or not you are still going to have to write the code even if you
use your library. But in reality nobody else is re-creating code for
each new project from scratch. Code does not have to be wrapped up in a
couple of objects to be easily re-usable.
JavaScript is not a toy language for little bits of script,
it's a full-blown object-oriented scripting language that can
be used for other things than providing little expressions in
HTML tag script attributes.

Your point is? We are not talking about the implementation of business
logic on an IIS server we are talking about the optimum approach to
cross-browser scripting.

If the DOM implementation was good, they would've supported
all relevant modules of DOM 2.0, which is already an old standard.

Opera 7's DOM implementation is good, it's your approach that is
standing in the way of your ability to take advantage of it.
But you're right, Opera is suprisingly compatible to Internet
Explorer, which is a good thing. :)

From my point of view it is mostly irrelevant as I code to prefer the
DOM method where supported (so on when the browser is Opera 7)
It would've also failed if I had used object-recognition for
browser detection,

It never was a question of browser detection by any method. Browser
detection is not reliably achievable by any method. Fortunately it is
never necessary to know which browser/version is being used so it isn't
important that it is impossible to know.
since in Opera 7, the JavaScript implementation is broken,

You keep saying that but you are yet to demonstrate that it is actually
the case.
which I provided a workaround for. So all my pages using ISKEET
0.0.4 are working now unchanged on Opera 7.

So you changed your code and now it works "unchanged"?
I'm using mouseovers and click handlers on the ISKEET web site,
which can't be implemented in pure HTML.

Mouseovers are optional visual enhancements so it doesn't (shouldn't)
matter much when they don't work. But are you really saying that HTLM
has no mechanism that will load a new page in one frame of a frameset
when clicked on? If anything, that is the one thing that can be taken
for granted on a web browser.
When JavaScript isn't enabled, the ISKEET library is never called.

Exactly as would happen with any other script.
Hence, the web site developer has to include "<noscript>"
tags on their web site. (currently I haven't done so on the
ISKEET home page, but that hasn't anything to do with the ISKEET
library itself)

NOSCRIPT tags are almost never an appropriate response to the absence of
client-side script support. They are problematic to use because of the
type of element they are, and the desired relationship to guarantee
clean degradation is with the ability of the browser to successfully
execute the script. While it is the case that a script must fail in the
absence of client-side support there will still be plenty of JavaScript
capable and enabled browsers on which it will also fail and NOSCRIPT
cannot help in those cases.
ISKEET 0.0.4 provides clean degradation.

ISKEET cannot provide clean degradation, it cannot tell what clean
degradation represents as that depends entirely on the circumstances in
which it would be being employed. It might facilitate clean degradation
by appreciating and reporting its failures, though there is currently on
evidence of any code for that task. You may be confusing clean
degradation with failing silently, they are not the same thing.
Refer to the ISKEET manual.

That is not true -- if the application programmer can
rely on a library to handle browser-specifics,

The library cannot make a browser do something that it is just not
capable of doing.
they don't have to code browser-specifics
for any script application.

So the best you are offering is a means of avoiding the mechanics of
coding a task when it can be done, it is still the task of the page
author to code for when they cant (and to test for those cases), and
your job to make it easy for them to know when that is the case.
If their script application fails, it's a problem that can
be corrected in the library then, in the ideal case.

That would imply that all JavaScript capable browsers are capable of
everything that could be asked of them. They are not.
With ISKEET, the program can rely entirely on the library.

Not with the code as you have it now.
The behaviour of the ISKEET library is supposed to be a black box,
but the programmer can have a look at the manual to find out what
it exactly does.

Which is exactly what I said, to use the API you have to learn the API.
Yes. ISKEET is designed just for that purpose.

If there's an incompatibility, it can be corrected within ISKEET.

And when it cannot be corrected?
That is a common misconception about JavaScript.

It is a misconception that it is only necessary to write sufficient code
to address the situation?
ECMAScript / JavaScript is a full object-oriented scripting
language. It is designed for more than just small bits of
script code.

If you are going to repeat this I have to point out that "object-based"
is the official categorisation.
With DOM 2.0, and DOM 3.0, provided there'll be standard-conformant
implementation across all browsers, JavaScript becomes the standard
tool for scripting web sites.

What are you talking about? JavaScript has been the standard tool for
scripting web sites since long before there were DOM specifications and
regardless of how standard-conformant any implementations may be.

ISKEET is a small, modular library. The programmer decides
which modules they use.

I see 3 files and each is dependent on the others. They may be small now
but it doesn't do a great deal. There is an great deal more that could
be included, boosting the total size in the process.
In the ISKEET manual, it is mentioned how the programmer can
omit parts of the library.

And to edit out parts of the library it will be necessary to understand
how it works.

Richard.
 
L

Lasse Reichstein Nielsen

Ekkehard Morgenstern said:
As soon as the Opera developers correct their JavaScript implementation
to conform to the standard (i.e. do proper parameter passing of objects
by reference), then I can lift the workaround for the new version.

Interesting! Could you describe the problem in more detail?
See my website, http://www.iskeet.de for a detailed problem description.
Download version 0.0.4 to see my workaround.

Didn't enlighten me to the details of the problem :)

However, we are talking about host objects (the window object), so I
doubt the ECMA262 standard applies. Not that they won't want to be
compatible with it anyway.

/L
 
J

Jim Ley

That JavaScript can safely use the HTTP User Agent string.

Of course, you have to know what you're doing.

Yet you've clearly demonstrated that you don't. So why are you doing
it?
ISKEET 0.0.4 can recognize Opera, Opera 6 and Opera 7.

Well, it can recognise some of them sometimes...
So, yeah, the ISKEET library 0.0.4 currently relies on the de-facto usage
of the HTTP User Agent string.

which is undefined, no behaviour is defined, and caches blow all your
reliance out the water, proxy caches (both transparent and official)
can and do modify the user agent string (for awhile the largest ISP in
the UK claimed everything was IE5.0 as that is what they have to
customers on the registration disk, even if they were dialling up on
their phone.)
It is only the matter of minutes to change it into using object detection
only.

So do it, it's definately necessary.
However, my library wouldn't have worked on Opera 7 that way, because
it has a bug in its JavaScript implementation.

So you keep asserting yet don't provide any details, I'm sure it does
- the other implementations all do - I doubt it's a serious one
(unless it's the ignoring unicode of earlier Opera's JS
implementations but I'm pretty sure that's fixed.)
Like the JavaScript bug in Opera 7, that permits setting a load handler
for a window only hardcoded.

Never seen that one.
JavaScript on Opera, for function objects, assumes toSource() semantics
where toString() would be appropriate.

eh? there is no toSource defined... and toString is impl. specific.
toSource() is a browser-specific function introduced in Netscape Navigator.
It is present on all Netscape/Mozilla-type implementations.

Good for them, ECMAScript extensions are to be encouraged (in fact you
can even in ECMAScript make even syntax errors not be errors and still
be conformant, that's perhaps not so encouraged...)
But why not support the script tag in XML mode?

Because it's harder to do...
Yeah, but some people think it _is_ DOM 2.0 compliant.

So what exactly are they supposed to do, take out big adverts in the
press stating clearly that Opera 7.0 is not DOM 2.0 compliant - which
seen as precious little else is, isn't much to write home about.

Jim.
 
E

Ekkehard Morgenstern

Richard Cornford said:
If you can demonstrate a bug (in isolation) then it becomes obvious how
to test for it.

Ok, such stuff is ideal to encapsulate in a library.

I think I already know how to test for the Opera bug.
So which of the web browsers installed on the computer I am using now
sends the UA header:-

Mozilla/4.0 (compatible; MSIE 5.0; Windows 98)

- by default? (Hint: it isn't IE 5.0, that isn't even installed on this
computer). And how about:-

Mozilla/4.0 (compatible; MSIE 6.0; Windows 98)

- (Hint: it isn't IE 6).

Well, I don't care as long as it's compatible to those.

Plus, I verify if they support the features of the browsers I assume
them to be.

If they don't, feature testing will reveal to which browser it is
really compatible.

(as of ISKEET 0.0.3 / 0.0.4, the latter of which has the Opera bug
workaround)

I might strip the UA string testing in the future, but for now
I can use it. It's only version 0.0.4, after all. ;-)
You are using the existence of objects within the DOM to infer the type
of browser. That is almost as invalid as browser detecting using the
User Agent string.

My code behaves properly if they don't exist.

As I already mentioned, ISKEET is implemented in two layers --

1. the document encapsulation layer (which encapsulates DOM)
2. the compatibility encapsulation layer (which encapsulates other
browser-specifics.

In the face of normative efforts by the W3 consortium, I guess I can
use hasFeature() tests to reveal the amount of DOM support present
in an implementation.

I do take into account that, for example, Opera 7 and Internet Explorer 6
have partial implementations of DOM 2.0.

However, in the not-so-distant future, all browsers will implement DOM
in a standard-conformant way.

I don't actually use most of the browser and DOM version flags yet,
they're just for a quick way of handling browser-version-specifics,
should they be necessary.
Feature detecting tests the features required by a script (at some
point) prior to using them and does not ever infer anything about one
object/feature from another. It is the *only* reliable strategy for
matching the execution of JavaScript code with the browser's ability to
support that code. And feature detection based code has no interest in
the type or version of the browser.

That's true. And I certainly do use feature detection.

Would you mind reading some of ISKEET's documentation (or its source)
before making assumptions about its implementation?

You're way off on a tangent.
 
E

Ekkehard Morgenstern

Lasse Reichstein Nielsen said:
Interesting! Could you describe the problem in more detail?

Of course:

in my sample script test1.js, used in test1.html (from v0.0.4), I make an
object method call:

ISKEET_DEO.addEventHandler( "load", window, load_handler );

Which calls:

function ISKEET_DocEncap_AddEventHandler( EventType, Elem, Code ) {
var listener = new Array();
listener.handleEvent = Code;
listener.iskeet = new Array();
listener.iskeet.elem = Elem;
listener.iskeet.type = EventType;
if ( this.HasDOM && this.HasCoreDOM2 && this.HasDOM2Events ) {
listener.iskeet.elem.addEventListener( listener.iskeet.type, listener, false );
}
else {
ISKEET_CEO_AddEventHandler( listener.iskeet.type, listener.iskeet.elem, listener.handleEvent );
}
return listener;
}

Which, on Opera 7, effectively resolves to:

var listener = new Array();
listener.handleEvent = Code;
listener.iskeet = new Array();
listener.iskeet.elem = Elem;
listener.iskeet.type = EventType;
ISKEET_CEO_AddEventHandler( listener.iskeet.type, listener.iskeet.elem, listener.handleEvent );

Which calls:

function ISKEET_CEO_AddEventHandler( EventType, Elem, Code ) {
if ( ISKEET_CEO.Handlers[EventType] != undefined ) {
ISKEET_CEO.addElementEventHandler( EventType, Elem, Code );
var browsermethod = ISKEET_CEO.Handlers[EventType].browserHandlerMethod;
if ( ISKEET_CEO.IsIE ) {
/* 0.0.4: due to compatibility problems with Opera, the parameters are passed directly now.
* for the special case that doesn't work (load handler for window).
*/
if ( ISKEET_CEO.IsOpera && EventType == "load" && Elem == window ) {
window.onload = Code;
}
else {
Elem[browsermethod.toLowerCase()] = ISKEET_CEO_InvokeEventHandler_IE;
}
}
else if ( ISKEET_CEO.IsMoz ) {
Elem[browsermethod] = ISKEET_CEO_InvokeEventHandler_Moz;
}
}
}

Note the workaround I mentioned in the comment.

At the time
Elem[browsermethod.toLowerCase()] = ISKEET_CEO_InvokeEventHandler_IE;

would be executed, both Elem and browsermethod.toLowerCase() seem to be correct.
However, the handler is never called.

If I use the workaround

window.onload = Code;

it does work.

Don't ask me why! :)

Must be a bug somewhere in the JavaScript interpreter of Opera 7.

On all other browsers it works without the workaround.
 
E

Ekkehard Morgenstern

Michael Winter said:
You said that your usage of User-Agent is based upon the need to detect
browsers that don't implement DOM methods correctly.

No! There's two layers in ISKEET, one that handles DOM, and one that
handles the other stuff. The DOM-Code uses only the DOM features present
in the browser, and passes all other stuff to the compatibility layer,
which is below the document layer. The compatibility layer uses various
methods to recognize the browser-type, including feature detection.

Have a look at the ISKEET documentation for more info on how it actually
works.
Wouldn't a much more
forward-thinking approach be to call the method in such a way that it
will, if not implemented as you expect, fail and use that to resort to a
compatibility replacement. At least that way, a browser with an abnormal
implementation can be fixed in the future and will not be subjected to
unwarranted fallback procedures.

It's already implemented that way! Please look at the ISKEET manual.
 
E

Ekkehard Morgenstern

Richard Cornford said:
"encapsulates DOM" seems a bit of an overstatement as the only DOM
methods used in the code are implementation, implementation.hasFeature,
getElementById, addEventListener and removeEventListener, which is a
tiny fraction of the DOM.

Look at the version number. Currently 0.0.4.

And DOM isn't really that big. I will add more DOM support as soon as
the groundwork is laid out properly.

I don't think I have to rush it.
In practice it is the things that the code believes not to be supported
that are being passed to the ISKEET_CompatEncap code, without regard for
whether the browser in use supports them or not, at least beyond asking
implementation.hasFeature if a particular set of DOM standards are fully
implemented. And as you have noticed 98% implementation of the HTML DOM
Level 2 interfaces does not justify having - hasFeature - return true
for "HTML", "2.0".

Yeah, I know Opera 7 and IE 6 have partial DOM support.

If I do feature test for every individual feature, ISKEET will get too big.

ELEMENT.style handling will be next. The code for getting/setting styles
will access the style object if present even if DOM 2 hasFeature() doesn't
indicate its support.
At least they are all moving in the same direction and it never will be
the same.

Someday, it will. Because it'll slow down feature usage until standard
implementation is complete.

There's already XHTML 2.0 and DOM 3.0 in the make, I wonder when we'll
ever get to see this implemented.

Sooner or later browser implementors will have to adhere to the standards.
It's just like having 20 types of screws, if you have only 1, things
get much simpler, and that's what standards ares there for.

That standards begin to work after a while has been proven by C and C++.

Look in the C and C++ newsgroups. Everybody is talking only about standards
and standards conformance. Non-conformance to standards has not been
accepted there for a long time now.

And the same will happen to web programming.
That sounds like an order.

Really? English is not my first language, sorry.
But why just those 3?

Because I don't have proper environments to test other browsers.

I don't claim my library or website is compatible with something
when I have not seen it myself.
That isn't really a problem, unless you want to make decisions about haw
a script is going to act based on inferences instead of direct testing.

.... which is suggested by the W3 consortium ...

In the DOM standard specifications, hasFeature() is declared to be
the means to find out about feature support.

Just another thing that cannot be relied upon for existing implementations.
That's really sad, but I'm convinced that'll change in the future.

From all the comments in this thread, I guess I'll have to strip
UA string and DOM hasFeature() testing entirely for version 0.0.5.

No problem for me, just a few lines of code changes.
And if there is no fall-back method to implement in CompatEncap? In that
case the programmer needs to know.

Up to now, there's always a fallback.

I don't use any feature without testing for its actual presence,
whether or not I have other indicators pointing me in some direction.
is being scripted and it is the web browsers environment that renders
abstract libraries inappropriate.

That's not true. ISKEET proves it and will do so even more in the future.
each new project from scratch. Code does not have to be wrapped up in a
couple of objects to be easily re-usable.

Copy-and-paste programming problems start when you want to change something.

Imagine a script of yours that you've used by copy-and-paste in a couple
hundred web pages, and then you find out that you've overlooked some
browser-specifics that you didn't know about before.
You keep saying that but you are yet to demonstrate that it is actually
the case.

read the ISKEET manual or some of the other posts here, I just posted
a detailed reply to someone, don't wanna repeat it umpteen times.
So you changed your code and now it works "unchanged"?

I modified the library and didn't have to change one iota on the actual
web page. That's what encapsulation and abstraction is all about.
Update the library -- done!
 
R

Richard Cornford

message
Well, I don't care as long as it's compatible to those.

No, the first is mostly compatible with IE but has a fairly complete DOM
implementation. The second is no so compatible with IE and its DOM
implementation is non-dynamic.
Plus, I verify if they support the features of the
browsers I assume them to be.

Then you no longer need to spend time reading the UA strings (which I
notice you have stopped as of 0.0.5).

My code behaves properly if they don't exist.

Only if you define "behaves properly" as does nothing. Doing nothing is
harmless but often insufficient to result in a suitable script, as the
code using the API cannot know of, or respond to, that inactivity.
As I already mentioned, ISKEET is implemented in two layers --

1. the document encapsulation layer (which encapsulates DOM)
2. the compatibility encapsulation layer (which encapsulates other
browser-specifics.

In the face of normative efforts by the W3 consortium, I guess
I can use hasFeature() tests to reveal the amount of DOM support
present in an implementation.

Only within the significant restriction imposed on the hasFeature method
by the W3C.
I do take into account that, for example, Opera 7 and Internet
Explorer 6 have partial implementations of DOM 2.0.

But how many others also have partial implementations?
However, in the not-so-distant future, all browsers will
implement DOM in a standard-conformant way.

When I was young it was commonly suggested that there would be colonies
on Mars by now.

That's true. And I certainly do use feature detection.

Only really starting with version 0.0.5, prior to that it was all object
inference and UA string.
Would you mind reading some of ISKEET's documentation (or
its source) before making assumptions about its implementation?

I did read the code and the parts of the manual that weren't just
stating what the methods were supposed to do when they worked. I also
read the 0.002 and 0.004 code (didn't bother with .3) else I wouldn't
have commented on them.

Your feature detecting is better but there are still a lot of wrong
things in your code (including that non-ECMA EventListener interface
object). For example, this function from iskeet_document.js:-

function ISKEET_DocEncap() {
/* v0.0.5: modified to suit new feature detection,
removed all code, added new */
this.HasGetElementById = false;
this.HasAddEventListener = false;
if ( ISKEET_CEO.HasDoc ) {
if ( ISKEET_CE_IsDef( document.getElementById ) ) {
this.HasGetElementById = true;
}
}
if ( ISKEET_CEO.HasWin ) {
if ( ISKEET_CE_IsDef( window.addEventListener ) ) {
this.HasAddEventListener = true;
}
}
}

- which is using the presence of window.addEventListener to make
decisions about the use of event listeners. That is against the DOM
specs as none of the W3C (HTML related) DOM specs defines any aspects of
the global object and so a fully conforming browser has no reason for
having an addEventListener property on the window object. And in
practice Opera 7 supports addEventListener on every element that the DOM
specs require but not the window object and so you deny Opera 7 the
opportunity to exploit this very useful built-in functionality.
You're way off on a tangent.

OK, I'll admit it. I know absolutely nothing about using ECMA Script to
script web browsers. I don't know what could possibly have induced me to
even suggest that your API library wasn't the best approach to the
problem ever conceived and I will say no more on the subject ever.

Richard.
 
R

Richard Cornford

message
Yeah, I know Opera 7 and IE 6 have partial DOM support.

And if you insist on using implementation.hasFeature to verify their
support you will be declining the opportunity to exploit the features
that those browsers do support.
If I do feature test for every individual feature, ISKEET will
get too big.

Which is exactly the problem with the API library concept that I
described. If you insist on encapsulating the interface in one or two
big objects then the code needed to properly exploit the available
features of the browsers and provide suitable notification of their
unavailability will always render an API library that attempts anything
beyond the trivial too bulky for practical use. Forcing pages that only
need a tiny fraction of the features provided to download and initialise
a substantial piece of code, most of which they could happily do
without.

Someday, it will. Because it'll slow down feature usage until
standard implementation is complete.

The W3C DOM, even if fully implemented by everyone, is only a small part
of the scriptable aspects of web browsers and there will always be
features supported by some browsers but not all, and clients will want
to exploit those features where available. And it will always continue
to be the case that desktop browsers will have more of those features
than embedded and PDA browsers.
There's already XHTML 2.0 and DOM 3.0 in the make, I wonder
when we'll ever get to see this implemented.

And in the mean-while there may be DOM 4 and 5 and so on.

That standards begin to work after a while has been proven
by C and C++.
And the same will happen to web programming.

Even when (and if) everyone adheres to the existing published standards
there will still be non-standard features being introduced and used and
later there will be new standards attempting to formalise the best of
those non-standard features.

The only standard that is important for browser scripting is ECMA 262
(and maybe 327) because given consistent language support the
inconsistencies of the object model being scripted can be coped with.

Because I don't have proper environments to test other browsers.

I don't claim my library or website is compatible with something
when I have not seen it myself.
testing.

... which is suggested by the W3 consortium ...

In the DOM standard specifications, hasFeature() is declared
to be the means to find out about feature support.

But making decisions based on hasFeature means not using various parts
of the DOM specs at all until they are fully implemented. That might be
necessary with other languages like Java but JavaScript is more flexible
and can take advantage of what actually exists rather than waiting for
some formal declaration of completeness in a DOM implementation. A good
thing too as there aren't many complete implementations around.
Just another thing that cannot be relied upon for existing
implementations. That's really sad, but I'm convinced that'll
change in the future.

You can be as optimistic as you like but nobody is currently working in
the future. How many clients are going to pay for: "It doesn't do much
now but when the web browsers conform to the standard it will be
spectacular".

Up to now, there's always a fallback.

Up to now you have only tested on, at best, a couple of versions of 3
web browsers and you haven't attempted to implement more than half a
dozen features. With the possible exception of standard form validation
code in (exclusively) HTML documents there are no browser features that
are universally supported.
I don't use any feature without testing for its actual presence,

Yes you do (even in the 0.0.5 code).

That's not true. ISKEET proves it and will do so even more in
the future.

When did implementing an inappropriate technique prove it appropriate?
Copy-and-paste programming problems start when you want to
change something.

Imagine a script of yours that you've used by copy-and-paste in
a couple hundred web pages,

So that's one external JS file then.
and then you find out that you've overlooked some
browser-specifics that you didn't know about before.

Generally well designed, implemented and tested feature detection based
scripts are extremely resilient to unexpected browser-specific problems.
But in the event, I edit the one external JS file.
read the ISKEET manual or some of the other posts here, I just
posted a detailed reply to someone, don't wanna repeat it
umpteen times.

I read the manual and the note in the code. Neither state what the
problem is, they just assert that there is a problem, as do all of your
other replies in this thread. But asserting that there is a problem is
not the same as demonstrating that there is a problem. Your belief that
you have seen a problem in your code does not help as your code is
derived from a series of convoluted assumptions and is as likely to be
introducing the error that you are attributing to Opera as it is to be
suffering from it. Demonstrate the problem in isolation and you have a
point, repeatedly assert that there is a problem that you cannot isolate
and you will not be taken seriously.
I modified the library and didn't have to change one iota on
the actual web page. That's what encapsulation and abstraction
is all about. Update the library -- done!

The encapsulation and the abstraction are not the problem with the
concept. The problem comes with the attempt to wrap the whole thing up
in a couple of large objects to provide an API for the entire browser
DOM.

Small components providing an abstract interface to particular aspects
of a browser's DOM are entirely sensible. For example, a frequent
requirement that would need to be handled differently of various
browsers might be the need to acquire the amount by which a page was
scrolled. The following function encapsulates the required testing and
returns an object that provides a common interface to the desired
information:-

var getPageScroll = (function(){
var global = this;
var notSetUp = true;
var readScroll = {scrollLeft:NaN,scrollTop:NaN};
var readScrollX = 'scrollLeft';
var readScrollY = 'scrollTop';
var interface = {
getScrollX:function(){
return readScroll[readScrollX];
},
getScrollY:function(){
return readScroll[readScrollY];
}
};
function compatModeTest(obj){
if((document.compatMode)&&
(document.compatMode == 'CSS1Compat')&&
(document.documentElement)&&
(typeof document.documentElement[readScrollX] == 'number')){
return document.documentElement;
}else if((document.body)&&
(typeof document.body[readScrollX] == 'number')){
return document.body;
}else{
return obj;
}
}
function setUp(){
if(typeof global.pageXOffset == 'number'){
readScroll = global;
readScrollY = 'pageYOffset';
readScrollX = 'pageXOffset';
}else{
readScroll = compatModeTest(readScroll);
}
notSetUp = false;
}
return (function(){
if(notSetUp){
setUp();
}
return interface;
});
})(); //Only call getPageScroll after opening BODY tag has been parsed.

// USE:

var commonInterface = getPageScroll();
//Keep the interface reference for repeated use.
var xScroll = commonInterface.getScrollX();
var yScroll = commonInterface.getScrollY();
if(!isNaN(xScroll)){
// scroll values good!
}

Notice the absence of any interest in the type or version of the browser
and the well-defined behaviour (returning NaN, which is testable) in the
face of a failure of the browser to provide any of the scroll value
retrieval mechanisms.

Other versions might include the viewPort or document dimensions in the
interface. The choice of which to use would depend entirely on the
information that was required and the code is totally re-usable. But
when the functionality provided is not required the function is just not
included in the JS file (obviously anyone wanting to use such code still
needs to observe interdependencies, such as a element positioning
interface needing access to this interface in order to do its task, but
appropriate comments serve as sufficient reminder, or speed the
resolution of errors of omission).

Any sufficiently large collection of similar functionality encapsulating
code might be considered a library. Though it would be used by cutting
and pasting only the parts required and so completely avoid burdening
the pages that used the JS file with the download of code that they were
not going to use.

Richard.
 
E

Ekkehard Morgenstern

Richard Cornford said:
Only within the significant restriction imposed on the hasFeature method
by the W3C.

which would be??

please point me to the location in the DOM 2.0 standard specification
which explains the restriction you're talking about, because I can't
find any.
things in your code (including that non-ECMA EventListener interface
object).

It is perfectly valid in ECMAScript to use an object or array as
associative storage. Point me to the text in the ECMA 262 standard
specification where it is stated that it is not allowed. I couldn't
find anything pertaining to interfaces in it.

Hence, the interface code works with Netscape/Mozilla.

Netscape invented ECMAScript.

But I see the need for a correction of the code, after seeing your
example in another branch of this thread.
- which is using the presence of window.addEventListener to make
decisions about the use of event listeners. That is against the DOM
specs as none of the W3C (HTML related) DOM specs defines any aspects of
the global object and so a fully conforming browser has no reason for
having an addEventListener property on the window object. And in
practice Opera 7 supports addEventListener on every element that the DOM
specs require but not the window object and so you deny Opera 7 the
opportunity to exploit this very useful built-in functionality.

I will improve the DOM support in the library in due time, as for now,
on Opera, classic event handling will be used.

(it doesn't accept my interface implementation and hence I have to work
on that to make it more compatible with such browsers)
 
R

Richard Cornford

Ekkehard Morgenstern said:
which would be??

please point me to the location in the DOM 2.0 standard
specification which explains the restriction you're talking
about, because I can't find any.

The restriction is that hasFeature is only allowed to report true if the
relevant part of the DOM is fully implemented. When there are so few
complete implementations about that doesn't make it an effective way of
matching browser support for any feature with code that wishes to use it
because for the majority of features in isolation it will report false
negatives.
It is perfectly valid in ECMAScript to use an object or
array as associative storage. Point me to the text in the
ECMA 262 standard specification where it is stated that it
is not allowed. I couldn't find anything pertaining to
interfaces in it.

It has nothing to do with the capabilities of ECMA objects, your
EventListenre is non-ECMA because it does not conform with the ECMA
Language Binding specification for the EventListener interface. Instead
it conformed with the Java language binding.
Hence, the interface code works with Netscape/Mozilla.

No hence about it. I would in fact be unexpected for a DOM
implementation intended for use with ECMA script to accept an object
constructed to conform to the Java binding and the fact that Mozilla
does is probably only a coincidence resulting from an implementation
detail. It certainly would be misguided to expect any other DOM events
implementation to function with anything but the ECMA version of
EventListener.

A nice thing about ECMA functions is that they are entirely capable of
simultaneously implementing both the ECMA EventListener definition and
the Java one:-

funcRef.handleEvent = funcRef;

But I doubt that it would be worth the effort (and it would make the -
this - reference unusable within the function as it would mean different
things depending on whether the function was called as a method of
itself or as a method of the element to which it is attached).
Netscape invented ECMAScript.

?

I will improve the DOM support in the library in due time, as
for now, on Opera, classic event handling will be used.

(it doesn't accept my interface implementation and hence I have
to work on that to make it more compatible with such browsers)

Once again, as you clearly didn't read it the first time; the ECMA
Language Binding defines EventListener as:-

<quote cite="http://www.w3.org/TR/2000/
REC-DOM-Level-2-Events-20001113/ecma-script-binding.html">
Object EventListener
This is an ECMAScript function reference. This method has
no return value. The parameter is a Event object.
</quote>

If you implement EventListener as a (non-function) object with a -
handleEvent - property you are not following the ECMA Script binding and
should have no expectation of the result working in DOM events
implementing web browses scripted with ECMA Script.

The correct ECMA implementation is to pass the addEventListener (and
related) method a reference to the function object that is to be
executed when the event happens. That is, the function _is_ the
EventListener interface in ECMA Script.

Richard.
 
M

Michael Winter

Netscape invented ECMAScript.

Incorrect. Netscape invented JavaScript.

ECMAScript "is based on several originating technologies, the most well
known being JavaScript (Netscape) and JScript (Microsoft)." (ECMA-262,
Brief History)

Mike
 
E

Ekkehard Morgenstern

Richard Cornford said:
This is an ECMAScript function reference. This method has
no return value. The parameter is a Event object.

If you implement EventListener as a (non-function) object with a -
handleEvent - property you are not following the ECMA Script binding and
should have no expectation of the result working in DOM events
implementing web browses scripted with ECMA Script.

The whole stuff has nothing to do with the ECMA standard,
it has something to do with the DOM specification. You should be
more clear about such things to avoid misunderstandings.

But yeah, I looked it up in the DOM implementation reference for
2.0 Event objects, and yeah, you're right, and I have to correct
my implementation to match that.

However, it worked with neither method with Opera (I tried both).
 
M

Michael Winter

Yes, and then passed it to ECMA for standardization.

You didn't quote the important part of my quote. That was:

ECMAScript "is based on several originating technologies, the most well
known being JavaScript (Netscape) and JScript (Microsoft)." (ECMA-262,
Brief History)

As ECMAScript uses more than one language as its basis, it cannot be
accredited to Netscape alone, even if JavaScript is the major component.
That was my point. :)

Mike
 
E

Ekkehard Morgenstern

Michael Winter said:
You didn't quote the important part of my quote. That was:

ECMAScript "is based on several originating technologies, the most well
known being JavaScript (Netscape) and JScript (Microsoft)." (ECMA-262,
Brief History)

As ECMAScript uses more than one language as its basis, it cannot be
accredited to Netscape alone, even if JavaScript is the major component.
That was my point. :)

Ok, you win! ;-)

Now, tell me how to get DOM 2 event listeners to work for Netscape/Mozilla
and Opera! ;-)

With my method,

var listener = new Array();
listener.handleEvent = Code;
element.addEventListener( eventtype, listener, false );

it works on Netscape/Mozilla, whereas

element.addEventListener( eventtype, Code, false );

doesn't. Code is guaranteed to refer to a function of the form:

function Code( Event ) {
...
}

Neither method works with Opera.

What I need is an algorithm that supports any of the HTML event types,
like "load", "mouseover" etc.

I need them on window or at least document objects as well.

Or should I replace calls supplying window or document as element
with using the body-tag element?

I'm gonna try this.
 
D

Douglas Crockford

ECMAScript "is based on several originating technologies, the most well
Ok, you win! ;-)

Not so fast. JavaScript was develeped by Brendan Eich as Netscape, back when
Netscape was a web browser company. Microsoft copied it, but changed the name to
JScript to avoid trademark issues with Sun, which controls Java, a different
language.

When Netscape took JavaScript to ECMA for standardization, the trademark issue
came up again, and again the name was changed, this time to ECMAScript. Three
names. One language. This led to JavaScript becoming the world's most
misunderstood programming language. If Netscape had called it LiveScript, as
originally planned, the trademark issue would not have been so difficult, and
things would have been less confusing.

http://www.ecmascript.org/
 
M

Michael Winter

Not so fast. JavaScript was develeped by Brendan Eich as Netscape, back
when Netscape was a web browser company. Microsoft copied it, but
changed the name to JScript to avoid trademark issues with Sun, which
controls Java, a different language.

When Netscape took JavaScript to ECMA for standardization, the trademark
issue came up again, and again the name was changed, this time to
ECMAScript. Three names. One language. This led to JavaScript becoming
the world's most misunderstood programming language. If Netscape had
called it LiveScript, as originally planned, the trademark issue would
not have been so difficult, and things would have been less confusing.

I'm not sure now whether I should eat humble pie, be forgiven for ECMA's
misleading description of the origins of ECMAScript, or be happy that I'm
correct to some extent.

If it's the former, my apologies to Mr Morgenstern.

Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top