bindings
This section is tested and adjusted for the current Firefox implementation. Please edit only if an actual behavior differs from the described one. Please do not edit only on the basis of another XBL specification.
<!ELEMENT bindings ( binding* ) > Hierarchy: root element May contain: <binding>
The bindings
element is the root element of any XBL document. It should usually declare XBL as the default namespace (unless an XBL namespace prefix is used) and it may additionally declare other namespace prefixes used in your binding.
bindings
contains zero or more binding
elements as children. Each binding
child element defines a unique binding that can be attached to elements in other documents.
An element can have only one binding attached (explicitly or inherited) at one moment. From several bindings only the last in the sequence will be used (like with any CSS rule).
HelloWorld example: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"> <html> <head> <title>Hello world!</title> <style type="text/css"> p { -moz-binding: url(hello.xml#default); } #p03 { -moz-binding: url(hello.xml#hello2); } </style> </head> <body <p>Default content</p> <p>Default content</p> <p id="p03">Default content</p> </body> </html> // hello.xml <?xml version="1.0"?> <bindings xmlns="https://www.mozilla.org/xbl" xmlns:html="https://www.w3.org/1999/xhtml"> <binding id="default"> <content><html:b>Hello world! </html:b><children/></content> </binding> <binding id="hello2"> <content><html:b>Hello from my binding! </html:b><children/></content> </binding> </bindings>
Next: <big>bindings > binding</big>
element.
Notes
- In the current stable releases of Mozilla products (e.g. Firefox 2) it is impossible to attach bindings to table sub-elements (rows, cells etc.) You can attach binding only to the table element itself. This has been fixed for future versions of Mozilla products. See bug 83830 for more information and for workarounds.
- Default encoding in XML documents (including XBL files) is UTF-8. An explicit encoding declarations may be present to override the default, for example
<?xml version="1.0" encoding="ISO-8859-1"?>
- URI in namespace declarations is an opaque string used to uniquely identify the namespace. It doesn't have to (and often it doesn't) point to some actual schema or a namespace-related resource. Namespaces in XML
- Besides the default namespace, you can declare any amount of additional namespaces to handle your content. The most useful namespaces could be HTML/XHTML, XUL (XML User Interface Language), SVG (Scalable Vector Graphics) and XLink. This way a more-or-less universal namespace declaration in your
bindings
could be like:
<bindings xmlns="https://www.mozilla.org/xbl" xmlns:html = "https://www.w3.org/1999/xhtml" xmlns:xul = "https://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:svg = "https://www.w3.org/2000/svg" xmlns:xlink= "https://www.w3.org/1999/xlink">
바인딩
<!ENTITY % binding-content "(resources?,content?,implementation?,handlers?)"> <!ELEMENT binding %binding-content;> <!ATTLIST binding id ID #REQUIRED extends CDATA #IMPLIED display CDATA #IMPLIED inheritstyle true #IMPLIED >
binding
요소는 단일 XBL 바인딩을 기술합니다. XBL 바인딩은 HTML/XML 요소에
anonymous content
,
fields
,
properties
,
methods
,
event handlers
를 추가할 수 있습니다.
단일 XBL 바인딩은 스타일 시트나 스크립팅을 사용하여 요소에 붙일 수 있습니다 (<table>에 특정한 사항은 bug 83830를 참고하십시오).
CSS:
div { -moz-binding: url(myBinding.xml#default); }
DOM:
elementReference.style.MozBinding = "url(myBinding.xml#default}";
위의 두 가지 경우 모두는 myBinding.xml
에 포함된 id="default"
를 가진 바인딩을 사용하고 있습니다.
Firefox 3부터는 바인딩을 인라인으로 삽입하기 위해 data:
URL을 사용할 수 있습니다.
div { -moz-binding: url(data:text/xml;charset=utf-8,%3C%3Fxml%20version%3D%221.0%22%3F%3E%0A%3Cbindings%20id%3D%22xbltestBindings%22%20xmlns%3D%22http%3A//www.mozilla.org/xbl%22%3E%0A%20%20%3Cbinding%20id%3D%22xbltest%22%3E%3Ccontent%3EPASS%3C/content%3E%3C/binding%3E%0A%3C/bindings%3E%0A); }
data:
URL은 부분 식별자(fragment identifier)를 지원하지 않기 때문에 대신 삽입된 XML에서 발견한 첫 번째 바인딩을 사용합니다. 바인딩은 참조하지 않더라도 아이디가 있어야 한다는 점을 염두해 두십시오.
앞선 예제의 삽입된 XML은 다음과 같습니다.
<?xml version="1.0"?> <bindings id="xbltestBindings" xmlns="https://www.mozilla.org/xbl"> <binding id="xbltest"><content>PASS</content></binding> </bindings>
CSS 선언만이 바인딩을 임의의 요소 집합에 붙이는 쉬운 방법을 제공합니다. 이는 또한 스크립팅이 비할성화되어 있을 때 바인딩이 부분적으로 동작하게 만듭니다. 이 경우 모든 메소드와 핸들러는 차단되지만 익명의 내용과 스타일은 계속 사용됩니다. 그러므로 실행 중에 개별 요소에 바인딩을 추가할 필요가 없다면 항상 CSS 선언을 사용해야 합니다.
binding
요소는 resources 태그, content 태그, implementation 태그, handlers 태그를 포함할 수 있습니다.
id
-id
속성은 문서에서 유일한(document-unique) 식별자입니다.binding
요소에서 이 속성은 바인딩을 붙이는데 사용되므로 꼭 필요합니다.extends
-extends
속성은 이 바인딩이 물려 받은 바인딩의 URL을 지정하는데 사용합니다 (Inheritance of Implementations 참고). URL은 특정한 바인딩 문서를 지정합니다. 바인딩 문서 내에서 특정 바인딩id
를 가리키려면 # 표시를 꼭 사용해야 합니다. 내용은 상속할 수 없으며 동작만 상속된다는 점에 주의하십시오.display
- 이 속성은 태그가 표시되는 방법을 지정합니다. 이 속성을 지정함으로써 기존 요소의 레이아웃과 표시 특성을 가진 요소를 가질 수 있습니다. 예를 들어, 'xul:button' 값을 사용하면 버튼처럼 표시되는 요소를 생성할 수 있습니다. 콜론 이전의 부분은 이름 공간 접두어이므로 XUL 이름 공간도 정의해야 합니다. 다음 XML 표시 형식을 사용할 수 있습니다: browser, button, checkbox, description, editor, grippy, iframe, image, label, menu, menuitem, menubar, progressmeter, radio, resizer, scrollbar, scrollbox, spacer, splitter, titlebar, treechildren, treecol. 또한 다수의 HTML, MathML, SVG 태그를 사용할 수 있습니다. 'display' 속성은extends
속성이 지정되지 않으면 동작하지 않는데, 이는 버그 bug 119389를 참고하십시오. 이러한 경우에는display
속성의 값을extends
에 넣으십시오.inheritstyle
-inheritstyle
속성은 문서의 스타일 규칙이 XBL 바인딩이 생성한 익명의 내용에 영향을 미칠 것인지 가리킵니다. 속성이 true이면 문서의 스타일은 XBL이 생성한 익명의 내용에도 영향을 미칩니다.
content
<!ELEMENT content ANY> <!ATTLIST content id ID #IMPLIED >
A binding can specify new content that is placed inside the bound element. Although you can see this content on screen as if it was directly in the file, this content is anonymous and is hidden from the normal DOM. To access anonymous nodes on an XBL bound element, you can use the getAnonymousElementByAttribute and getAnonymousNodes functions. The only XBL element that can appear inside the content tag is the children tag. Attributes on the <content> element in the binding are set on the bound element.
id
- The id attribute is a document-unique identifier.
children
<!ELEMENT children EMPTY> <!ATTLIST children id ID #IMPLIED includes CDATA #IMPLIED >
Specifies the location where any child elements of the bound element are placed in the generated content.
Normally, if the element bound to has its own content, the anonymous content is not generated. However, with a children
element, you can merge the content from the HTML/XML element and the XBL content.
If the children tag contains content itself, that content will become the default content. If the element the binding is attached to contains content, the default content will be ignored. If the element does not contain content, the default content will be added.
id
- Theid
attribute is a document-unique identifier.includes
- Theincludes
attribute can be used to indicate that only certain content should be placed at the insertion point specified by thechildren
element. Its value can be a tag name or multiple tag names separated by commas. A child can only be placed within the insertion point if it is matched by the value in theincludes
attribute. Only immediate children are matched against the selector. For example, an XML fragment<customElement><foobar><hoge/></foobar></customElement>
with an binding definition<binding id="customElement"><content><xul:box><children includes="hoge"/></xul:box></content></binding>
for thecustomElement
element,<xul:box/>
becomes empty because the selectorincludes="hoge"
doesn't match for the immediate childfoobar
element.
implementation
<!ENTITY % implementation-content "(method|property)*"> <!ELEMENT implementation %implementation-content;> <!ATTLIST implementation id ID #IMPLIED name CDATA #IMPLIED implements CDATA #IMPLIED >
The implementation
element describes the set of methods and properties that are attached to the bound element. Once the binding is attached, these methods and properties can be invoked directly from the bound element.
id
- Theid
attribute is a document-unique identifier.name
- Thename
attribute can be used to provide a specific name for an implementation. This name can then be used to reference the implementation. For example, in JavaScript the value of this attribute represents the name of the corresponding class that is constructed for the implementation. If no name attribute is specified then the binding's document URI and id are used to uniquely reference the binding's implementation.implements
- Theimplements
attribute can be used to describe the set of interfaces that are implemented by the binding. Its value is a comma-separated list of named interfaces. If supported, in strongly typed languages the bound element can be referenced not only as any of the interfaces that the element might already support (e.g., HTMLElement) but also as any of the interfaces described by this attribute. Support of this capability is optional.
constructor
The code inside the constructor
is called when a binding
has just been attached to an element. So full access to anonymous nodes generated by the binding is already possible. The constructor
tag must be placed inside the implementation
tag.
id
- Theid
attribute is a document-unique identifier.
destructor
The code inside the destructor
is called when a binding
is being removed from an element. You can use this to unload resources to free memory. However the destructor
is often not called when it should, see bug 230086. The destructor
tag must be placed inside the implementation
tag.
id
- Theid
attribute is a document-unique identifier.
method
<!ENTITY % method-content "(parameter*,body?)"> <!ELEMENT method %method-content;> <!ATTLIST method id ID #IMPLIED name CDATA #REQUIRED type CDATA #IMPLIED >
The method
element is used to describe a single method of a binding implementation.
id
- Theid
attribute is a document-unique identifier.name
- Thename
attribute's value is the name given to the method when it is attached to the bound element. The method can be invoked directly from the bound element using this value.
Example
<method name="scrollTo"> <parameter name="index"/> <body> this.setAttribute("scrollpos", index); </body> </method>
parameter
<!ELEMENT parameter EMPTY> <!ATTLIST parameter id ID #IMPLIED name CDATA #REQUIRED >
The parameter
element is used inside a method
element. It represents a single parameter of a method.
id
- Theid
attribute is a document-unique identifier.name
- The value of thename
attribute is used by script within a method'sbody
element to reference this parameter.
body
<!ELEMENT body CDATA> <!ATTLIST body id ID #IMPLIED >
The body
element represents the implementation of its corresponding method
. Its contents are the script that is executed when the method is invoked.
id
- Theid
attribute is a document-unique identifier.
field
<!ELEMENT field EMPTY> <!ATTLIST field id ID #IMPLIED name CDATA #REQUIRED readonly (true|false) #IMPLIED >
A field is similar to a property
, except that it should not have a getter or setter. It is useful as a simple holder for a value. The field element must have content which is code that determines the initial value of the field. The field
tag must be inside the implementation
tag.
id
- Theid
attribute is a document-unique identifier.name
- The name of the field. This is the name used to refer to the field on the bound element.readonly
- If true, this field is read-only. If this attribute is omitted, the field will be readable and writable.
Here are some examples of cases in which the behavior of your code may change due to this change in Firefox 3:
- If you have two fields, one named
A
and one namedB
, and fieldA
sets.B
, the value of.B
will depend on whether or not.A
has already been accessed. - If a proto is inserted into the proto chain after binding instantiation, doing so may affect field values (this wasn't the case in prior versions of Firefox).
- At binding attachment time,
<field name="parentNode">this.parentNode</field>
is undefined instead of the value ofparentNode
. - A field no longer changes the value of a property set on the object itself (rather than a proto) before binding attachment.
property
<!ENTITY % property-content "(getter?,setter?)"> <!ELEMENT property %property-content;> <!ATTLIST property id ID #IMPLIED name CDATA #REQUIRED readonly (true|false) #IMPLIED onget CDATA #IMPLIED onset CDATA #IMPLIED >
The property
element represents a single property of an implementation. A property consists of a pair of getter/setter functions that can be defined using onget
/onset
attributes or getter/setter elements underneath the property
element. Like methods, once the binding is attached, the property can be obtained directly from the bound element. The property
tag must be inside the implementation
tag.
id
- Theid
attribute is a document-unique identifier.name
- The name of the property. This is the name used to refer to the property on the bound element.readonly
- Thereadonly
attribute is used to designate a property as read-only. If set totrue
, the value of the property cannot be altered. If this attribute is omitted, the property will be readable and writable.onget
- Theonget
attribute's value is a script that executes when the value of the property is requested. If this attribute is set, any initial value contained underneath the element will be ignored. The return value of the script represents the value of the property that will be returned to the requestor. A property getter can also be specified as a child of theproperty
element using thegetter
tag.onset
- Theonset
attribute's value is a script that executes when the value of the property is being altered. If this attribute is set, any initial value contained underneath the element will be ignored. Within the script, the parameterval
represents the new value being assigned. The script should always return the actual value assigned in order to allow for chained assignment operations. A property setter can also be specified as a child of theproperty
element using asetter
tag.
getter
<!ELEMENT getter PCDATA> <!ATTLIST getter id ID #IMPLIED >
The getter
element contains script that gets executed when a specific property gets called. The getter
tag must be inside the property
tag.
id
- Theid
attribute is a document-unique identifier.
setter
<!ELEMENT setter PCDATA> <!ATTLIST setter id ID #IMPLIED >
The setter
element contains script that gets executed when a specific property is being set. The setter
tag must be inside the property
tag.
id
- Theid
attribute is a document-unique identifier.
handlers
<!ENTITY % handlers-content "handler*"> <!ELEMENT handlers %handlers-content;> <!ATTLIST handlers id ID #IMPLIED >
The handlers
element contains event handlers that can be attached to elements within the bound document. These handlers are installed when the binding is attached and removed when the binding is detached. The handlers
tag must be inside the binding
tag.
id
- Theid
attribute is a document-unique identifier.
handler
<!ENTITY % handler-content "PCDATA"> <!ELEMENT handler %handler-content;> <!ATTLIST handler id ID #IMPLIED event NMREF #REQUIRED action CDATA #IMPLIED phase (capturing|bubbling|target) #IMPLIED button (1|2|3) #IMPLIED modifiers CDATA #IMPLIED keycode CDATA #IMPLIED key CDATA #IMPLIED charcode CDATA #IMPLIED clickcount (1|2|3) #IMPLIED command ID #IMPLIED preventdefault false|true #IMPLIED >
The handler
element describes a single event handler. This handler is attached to its target at the time the binding is attached and unhooked when the binding is detached from the bound element. The script inside the handler
is executed when the event handler is matched. The handler
tag must be inside the handlers
tag.
id
- Theid
attribute is a document-unique identifier.event
- Theevent
attribute describes the specific event that this handler is listening for. Its value can be any legal DOM event name (including custom events created using the DocumentEvent interface of the DOM).action
- Theaction
attribute contains script that is invoked when the handler fires. Thetype
attribute on the enclosinghandlers
element determines the language of the script. The handler script can also be specified as a child of thehandler
element.phase
- This attribute specifies the phase of the event flow that this handler should monitor. The possible values arecapturing
,bubbling
, andtarget
. If a phase is specified, the handler will only be invoked during that phase of the event handling process. If no phase is specified, a default ofbubbling
is assumed.button
- Thebutton
attribute imposes a filter on the handler. It is used with mouse handlers to specify a particular button. The event handler will only be matched if the value of thebutton
field in the DOM mouse event object matches the value of the attribute.modifiers
- Themodifiers
attribute imposes a filter on key and mouse handlers. Its value is a whitespace- or comma-separated list of modifier keys. If present in the list, then the modifier key must be set in the DOM event object in order for the handler to be matched. If themodifiers
is not empty and the modifier is not present in the list, then the modifier key must not be set in the DOM event object in order for the handler to be matched.
Supported modifiers are:shift
alt
control
meta
accel
- the platform's primary accelerator key. It is left up to the user agent to decide which modifier key represents the primary key. (It's the Control key on Windows and Meta on Mac.)accesskey
- the platform's primary shortcut mnemonic key should be used (the Alt key on Windows and Linux, has no effect on Mac).
keycode
- Thekeycode
attribute imposes a filter on key handlers. Its value is a key identifier for a specific keycode, e.g.,vk_enter
.
[Editor's Note: A forthcoming DOM events specification will presumably outline the list of valid keycode strings.]
If this attribute is present, then its value must match the keyCode field of the DOM key event object in order for the handler to fire.charcode
- Thecharcode
attribute imposes a filter on key handlers. Its value is a single character, e.g., "z
". If this attribute is present, then its value must match the charCode field of the DOM key event object in order for the handler to fire.
[Editor's note: As DOM Events mature more attributes may be added. For example, mutation events define several new fields such as relatedTarget that could be supported in the filtering syntax.]key
- Thekey
attribute has the same meaning ascharcode
.clickcount
- Theclickcount
attribute imposes a filter on the handler. It is used with mouse handlers to specify how many times a button has been clicked. The event handler will only be matched if the value of theclickcount
field in the DOM mouse event object matches the value of the attribute.command
- The id of a command to invoke when the event occurs. If used in a non-chrome document, the entire handler will be ignored.preventdefault
- If set to true, the default action of the event is not performed. See also preventDefault method of the Event object.
resources
<!ENTITY % resources-content "(image?,stylesheet?)"> <!ELEMENT resources %resources-content;> <!ATTLIST property id ID #IMPLIED >
Used for inclusion of image elements, to cache them for later use, and for inclusion of stylesheet elements. The resources
tag must be used directly inside the binding
tag.
id
- Theid
attribute is a document-unique identifier.
stylesheet
<!ELEMENT stylesheet EMPTY> <!ATTLIST stylesheet id ID #IMPLIED src URI #REQUIRED >
The stylesheet
element declares a style sheet used by the binding. The style rules in the style sheet will only be applied to the binding, not to other elements in the document. The stylesheet
tag must be inside the resources
tag.
id
- Theid
attribute is a document-unique identifier.src
- The URL of the style sheet to apply to the binding content.
image
<!ELEMENT image EMPTY> <!ATTLIST image id ID #IMPLIED src URI #REQUIRED >
Declares an image resource used by the binding. The image is loaded as soon as the binding is used. You can use this to preload a number of images for later use. The image
tag must be inside the resources
tag.
id
- Theid
attribute is a document-unique identifier.src
- The URL of the image to load.