Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

XUL:attribute:left

8 views
Skip to first unread message

ramaboule

unread,
Oct 30, 2006, 5:11:35 AM10/30/06
to
Hi,

In the documentation for this attribute
(http://developer.mozilla.org/en/docs/XUL:Attribute:left), it is said
that the type is integer.

However, when I use it in javascript, the left property is a string
(please see the example below).

Is there an inconsistency here or am I missing something? My guess is
that this is the generic way XUL attribute values are exported to
javascript.

Thanks,

Julien.

///////////////////////////////////////////////////////////////////////////////
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>

<window id="main-window" title="test-left" width="400" height="300"

xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">


<script>
function buttonClicked(event) {
var button = event.target;
alert("left attribute of " + button.id +
" is of type " + typeof(button.left) +
" and has value " + button.left);
}
</script>

<stack flex="1">
<button id="my-button" left="100" top="200" label="Click me!"
oncommand="buttonClicked(event)" />
</stack>

</window>
///////////////////////////////////////////////////////////////////////////////

Neil

unread,
Nov 1, 2006, 7:43:48 AM11/1/06
to
ramaboule wrote:

>In the documentation for this attribute (http://developer.mozilla.org/en/docs/XUL:Attribute:left), it is said that the type is integer.
>
>However, when I use it in javascript, the left property is a string (please see the example below).
>
>Is there an inconsistency here or am I missing something? My guess is that this is the generic way XUL attribute values are exported to javascript.
>

I didn't write the documentation, but, apart from allowevents, collapsed
and hidden, XUL element properties have always been strings.

--
Warning: May contain traces of nuts.

ramaboule

unread,
Nov 2, 2006, 2:16:05 PM11/2/06
to
Hi Neil,

Thanks for the response. I would be helpful to update the doc then and
warn people about this: if you do foo.left += 10, you will have a
surprise... (actually I had one...).

Julien.

Nickolay Ponomarev

unread,
Nov 2, 2006, 5:12:09 PM11/2/06
to ramaboule, dev-te...@lists.mozilla.org
On 2 Nov 2006 11:16:05 -0800, ramaboule <julien...@gmail.com> wrote:
> Hi Neil,
>
> Thanks for the response. I would be helpful to update the doc then and
> warn people about this: if you do foo.left += 10, you will have a
> surprise... (actually I had one...).
>
Please feel free to update the doc yourself. The documentation is in
the wiki, letting anyone edit it.

Nickolay

ramaboule

unread,
Nov 2, 2006, 9:30:58 PM11/2/06
to
Hi Nickolay,

Now that I'm given this responsability, I'm chickening out a little
bit...

The thing is that you could (maybe should) read the documentation as
just an XML reference and in this case, the current documentation makes
perfect sense: if you had to write a schema for this attribute, you
would say:
<xs:attribute name="left" type="xs:integer"/>

There are a lot of attributes in this case: top, flex etc... I haven't
checked the "boolean" ones but I will ASAP.

What I find confusing is that the mapping of these attributes in the
javascript DOM objects is string as opposed to a type similar to the
XML one.

So a better approach I think would be just to add a comment for all
these integer attributes saying something like:
WARNING: XUL attributes are exposed to javascript as string objects. If
you're doing any computation on these, please make sure to use the
parseInt function.

What do you think?

Thanks,

Julien.

Neil Deakin

unread,
Nov 2, 2006, 10:09:25 PM11/2/06
to
ramaboule wrote:

> So a better approach I think would be just to add a comment for all
> these integer attributes saying something like:
> WARNING: XUL attributes are exposed to javascript as string objects. If
> you're doing any computation on these, please make sure to use the
> parseInt function.
>

This behaviour will probably change in the future though, such that
values are properly exposed as integers when needed.

Neil

Neil

unread,
Nov 3, 2006, 5:50:05 AM11/3/06
to
ramaboule wrote:

>Thanks for the response. I would be helpful to update the doc then and warn people about this: if you do foo.left += 10, you will have a surprise... (actually I had one...).
>

foo.left -= -10 works ;-)

Nickolay Ponomarev

unread,
Nov 3, 2006, 6:23:18 AM11/3/06
to ramaboule, dev-mdc, dev-te...@lists.mozilla.org
[Cross-posting to dev-mdc, perhaps someone there will be able to come
up with a way to clearly specify the "type" of attributes in the XUL
reference. Original thread is at
http://groups-beta.google.com/group/mozilla.dev.tech.xul/browse_thread/thread/95da86a0014e6ae4/89995304ae2089a3
]

On 2 Nov 2006 18:30:58 -0800, ramaboule <julien...@gmail.com> wrote:
> The thing is that you could (maybe should) read the documentation as
> just an XML reference and in this case, the current documentation makes
> perfect sense: if you had to write a schema for this attribute, you
> would say:
> <xs:attribute name="left" type="xs:integer"/>
>

You're right about the attributes, which are always strings. From JS
you usually work with properties (e.g. |elem.left|) , which are
different from attributes.

So http://developer.mozilla.org/en/docs/XUL:Property:left is
definitely incorrect.

In any case, claiming that 'type' of something is an integer, when
it's in fact a string representation of an integer, is confusing. I'm
not sure how this should be fixed myself. Maybe put "string containing
an integer" in the type field or something?

> What I find confusing is that the mapping of these attributes in the
> javascript DOM objects is string as opposed to a type similar to the
> XML one.
>

Yep, as Neil said, it's unfortunate and probably will be fixed later.

> So a better approach I think would be just to add a comment for all
> these integer attributes saying something like:
> WARNING: XUL attributes are exposed to javascript as string objects. If
> you're doing any computation on these, please make sure to use the
> parseInt function.
>

If you add this to individual pages, it won't be seen by people
reading the XUL:(element) pages.

Nickolay

> What do you think?
>
> Thanks,
>
> Julien.
>
>
>
> Nickolay Ponomarev wrote:
> > On 2 Nov 2006 11:16:05 -0800, ramaboule <julien...@gmail.com> wrote:
> > > Hi Neil,
> > >
> > > Thanks for the response. I would be helpful to update the doc then and
> > > warn people about this: if you do foo.left += 10, you will have a
> > > surprise... (actually I had one...).
> > >
> > Please feel free to update the doc yourself. The documentation is in
> > the wiki, letting anyone edit it.
> >
> > Nickolay
>

> _______________________________________________
> dev-tech-xul mailing list
> dev-te...@lists.mozilla.org
> https://lists.mozilla.org/listinfo/dev-tech-xul
>

Eric Shepherd

unread,
Nov 3, 2006, 11:35:08 AM11/3/06
to Nickolay Ponomarev, dev-mdc, dev-te...@lists.mozilla.org, ramaboule
Hm. Yeah, we need to do something about this. Probably exactly that
way, by changing the type to "string containing an integer" or
possibly adding a note to each page indicating that the integers are
represented in strings.


Eric Shepherd
Developer Documentation Lead
she...@mozilla.com

Eric Shepherd

unread,
Nov 3, 2006, 2:25:14 PM11/3/06
to Julien Boeuf, dev-mdc, Nickolay Ponomarev, dev-te...@lists.mozilla.org
The more help we get, the better. :)


Eric Shepherd
Developer Documentation Lead
she...@mozilla.com

On Nov 3, 2006, at 1:23 PM, Julien Boeuf wrote:

> That sounds good to me too. Eric, do you want me to help or do you
> prefer to do it yourself?

Nickolay Ponomarev

unread,
Nov 7, 2006, 9:29:02 AM11/7/06
to Julien Boeuf, dev-mdc, Eric Shepherd, dev-te...@lists.mozilla.org
On 11/7/06, Julien Boeuf <julien...@gmail.com> wrote:
> Hi all,
>
> I've updated the doc for these attributes:
> http://developer.mozilla.org/en/docs/XUL_element_attributes
>
> I've also checked that the boolean attributes are exported correctly
> to javascript (into boolean properties and not "string representing a
> boolean").
>
Thanks for that. Note, however, that *all* attributes are strings
(while _properties_ can be of varying types). Right now the
XUL_element_attributes page looks like some _attributes_ are strings,
while some are booleans, which is confusing.

Nickolay

> Thanks,
>
> Julien.
>
>
> On 11/3/06, Julien Boeuf <julien...@gmail.com> wrote:
> > Very cool. I'll do it this week-end and send you links to the modified
> > pages to make sure you're ok with the changes.
> >
> > Julien.

Eric Shepherd

unread,
Nov 7, 2006, 1:18:48 PM11/7/06
to Julien Boeuf, dev-mdc, Nickolay Ponomarev, dev-te...@lists.mozilla.org
Great job; I was just looking at those a little while ago. Thanks!


Eric Shepherd
Developer Documentation Lead
she...@mozilla.com

On Nov 7, 2006, at 2:29 AM, Julien Boeuf wrote:

> Hi all,
>
> I've updated the doc for these attributes:
> http://developer.mozilla.org/en/docs/XUL_element_attributes
>
> I've also checked that the boolean attributes are exported correctly
> to javascript (into boolean properties and not "string representing a
> boolean").
>

0 new messages