Inheriting from an HTML element in IE

A

aundro

Hello,

I've recently been developping a google-maps-like api.
Firstly, I started development under Firefox, but I now need to run it
under Internet Explorer, and I'm running into a little bit of
trouble..

With firefox, a "MapView" object actually subclasses a HTMLDivElement, as
follows:

----8<----
MapView.superclass = HTMLDivElement;
MapView.prototype = document.createElement ("div");
MapView.prototype.constructor = MapView;
----8<----

but that does not work with Internet Explorer, as it does not propose
the same (W3C) DOM api as Mozilla-based browsers.

I've been looking after the type of element to subclass under IE, or a
different subclassing mechanism, but without success. Can anyone point
me some reference documentation, or propose any kind of solution?

Many thanks in advance!

Cheers,
Arnaud
 
M

Martin Honnen

aundro said:
MapView.superclass = HTMLDivElement;
MapView.prototype = document.createElement ("div");
MapView.prototype.constructor = MapView;
but that does not work with Internet Explorer, as it does not propose
the same (W3C) DOM api as Mozilla-based browsers.

It is debatable whether the W3C DOM for its ECMAScript binding requires
an implementation to expose stuff like a HTMLDivElement constructor
function or its prototype.
In general there is not anything in the specification and the ECMAScript
binding which suggests that with a few exceptions where static stuff
like Node.ELEMENT_NODE is explicitly mentions which then obviously
requires the implementation to expose Node first to be able to expose
Node.ELEMENT_NODE.
I've been looking after the type of element to subclass under IE, or a
different subclassing mechanism, but without success. Can anyone point
me some reference documentation, or propose any kind of solution?

IE on Windows allows you to implement behaviors for elements and bind
them to elements with a CSS rule so you would encapsulate your stuff in
a behavior and bind e.g.
div { behavior: url(yourBehavior.htc); }
This is not subclassing but what you do with Mozilla is usually not
called subclassing either as ECMAScript as implemented by JavaScript 1.x
in Mozilla/Netscape or by JScript in IE does not know any classes or
class based inheritance.

As for documentation of behaviors and HTCs (HTML components) for IE:
<http://msdn.microsoft.com/library/d...hop/author/behaviors/behaviors_node_entry.asp>
<http://msdn.microsoft.com/library/default.asp?url=/workshop/components/htc/reference/htcref.asp>
 
A

aundro

Hi,

Martin Honnen said:
It is debatable whether the W3C DOM for its ECMAScript binding
requires an implementation to expose stuff like a HTMLDivElement
constructor function or its prototype.
In general there is not anything in the specification and the
ECMAScript binding which suggests that with a few exceptions where
static stuff like Node.ELEMENT_NODE is explicitly mentions which then
obviously requires the implementation to expose Node first to be able
to expose Node.ELEMENT_NODE.

Indeed, I shouldn't have relied on the fact that Mozilla exposes those
constructors in the first time..
IE on Windows allows you to implement behaviors for elements and bind
them to elements with a CSS rule so you would encapsulate your stuff
in a behavior and bind e.g.
div { behavior: url(yourBehavior.htc); }

Well, the purpose of behaviors seems to be to divert the default
behavior of an element of a given type (EG: div).
What I need is to create a new type of element/object that would
'inherit' (*) all the DIV's behaviour (receive events, take the
expected screen estate, ...), but to which (to the prototype of which,
actually) I want to add some functions specific to a map API.

It seems I could do that with the HTCs, but doesn't it seem a little
overkill in this case? Maybe I could consider an alternative: make a
function for creating my MapView objects, like

---
createMapView(width, height)
---

which would just return the result of a
document.createElement("div");, to which I'd have added all the
functions specific to a map view. Something like this:

-------

// IE version
createMapView4IE(width, height) {

var d = document.createElement ("div");
d.addLayer = ___my_predefined_add_layer;
d.panNorth = ___my_predefined_pan_north;
d.panSouth = ___my_predefined_pan_south;
d.resize = ___my_predefined_resize;
...
return d;
}
-------

What do you think? Wouldn't it be simpler?


(*) I know this is not real subclassing :)
This is not subclassing but what you do with Mozilla is usually not
called subclassing either as ECMAScript as implemented by JavaScript
1.x in Mozilla/Netscape or by JScript in IE does not know any classes
or class based inheritance.
As for documentation of behaviors and HTCs (HTML components) for IE:
<http://msdn.microsoft.com/library/d...hop/author/behaviors/behaviors_node_entry.asp>
<http://msdn.microsoft.com/library/default.asp?url=/workshop/components/htc/reference/htcref.asp>

Many, many thanks for the pointers, and for your concern!
Martin Honnen


Best regards,

Arnaud
 

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

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top