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>
///////////////////////////////////////////////////////////////////////////////
>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.
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
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.
> 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
>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 ;-)
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
Developer Documentation Lead
she...@mozilla.com
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
> 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
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").
>