Alternate Stylesheets DOM ========================= This version: http://www.hixie.ch/specs/css/dom/altss/altss-1.0-pre6 Latest version: http://www.hixie.ch/specs/css/dom/altss/altss Previous version: http://www.hixie.ch/specs/css/dom/altss/altss-1.0-pre5 Editor: Ian Hickson, Opera Software Status of this document ----------------------- This is a draft proposal. It may one day become part of a W3C draft, or, it may not. Implementors must realise that this is not a formal specification and that they must be ready to change their implementations to match more formal specifications if required. Some of the ideas in this draft were dropped due to performance concerns. Interface --------- // Introduced in DOM Level 2: interface DocumentStyle { readonly attribute StyleSheetList styleSheets; // Introduced in DOM Level 3: attribute DOMString selectedStylesheetSet; readonly attribute DOMString preferredStylesheetSet; readonly attribute DOMStringList stylesheetSets; }; Attributes ---------- selectedStylesheetSet of type DOMString This attribute indicates which stylesheet set (see [[HTML4]]) is in use. This attribute is live; changing the disabled attribute on stylesheets directly will change the value of this attribute. If all the sheets that are enabled have the same title (by case insensitive comparisons) then the value of this attribute is exactly equal to the title of the first enabled stylesheet in the styleSheets list. If stylesheets from different sets are enabled, or if all stylesheets are disabled, or if there are no alternate stylesheets, then selectedStylesheetSet returns the empty string (there is no way to determine what the selected stylesheet set is in those conditions). Setting this attribute changes the 'disabled' attribute on each StyleSheet object in the styleSheets attribute, so that all those whose title matches the selectedStylesheetSet or who have no title will be enabled, and all others will be disabled. Title matches are case insensitive. Setting selectedStylesheetSet to the empty string disables all alternate and preferred styles (i.e. it only enables stylesheets that have no title). The initial value of selectedStylesheetSet may be different from preferredStylesheetSet if the UA supports persisting the selectedStylesheetSet across sessions. Note that from the DOM's perspective, all views have the same selectedStylesheetSet. If a UA supports multiple views with different selected alternate stylesheets, then this attribute (and the StyleSheet 'disabled' attribute) return and set the value for the default view. preferredStylesheetSet of type DOMString, readonly This attribute indicates the preferredStylesheetSet as set by the author. It is determined from the order of stylesheet declarations and the Default-Style HTTP headers. See [[HTML4]]. If there is no preferred stylesheet set, this attribute returns the empty string. The case of this attribute must exactly match the case given by the author where the preferred stylesheet is specified or implied. stylesheetSets of type DOMStringList, readonly This is a live list of the currently available stylesheet sets. This list is constructed by enumerating all the stylesheets for this document available to the implementation, in the order they are listed in the styleSheets attribute, adding the title of each stylesheet with a title to the list, avoiding duplicates by dropping titles that match (case insensitively) titles that have already been added to the list. Dynamically adding new stylesheets ---------------------------------- If new stylesheets with titles are added to the document, the UA must decide whether or not the stylesheets should be initially enabled or not. How this happens depends on the exact state of the document at the time the stylesheet is added. If the stylesheet is a preferred stylesheet (it has a title, but is not marked as alternate), and there is no current preferred stylesheet (the preferredStylesheetSet attribute is equal to the empty string) then the preferredStylesheetSet attribute is set to the exact value of this stylesheet's title, and the selectedStylesheetSet attribute is set to the value of the preferredStylesheetSet attribute, thus enabling the newly added stylesheet. Otherwise, if the stylesheet's title is equal (by case insensitive match) to the current value of the live selectedStylesheetSet attribute, the stylesheet is enabled. Otherwise, the stylesheet is disabled. If the UA has the preferred stylesheet set changed, for example if it receives a "Default-Style:" HTTP header after it receives HTTP "Link:" headers implying another preferred stylesheet, then the preferredStylesheetSet attribute's value should change appropriately, and the selectedStylesheetSet should be set to the new value. Thus, in the following HTML snippet: ...the only stylesheets that end up enabled are stylesheets "a" and "b", and the "selectedStylesheetSet" attribute would return "". Similarly, in the following HTML snippet: ...the 'before' variable will be equal to the empty string, the 'after' variable will be equal to "foo", and stylesheets "a" and "c" will be enabled. This is the case even though the first script block sets stylesheet "b" to be enabled, because upon parsing the following element, the preferredStylesheetSet is set, and this changes which stylesheets are enabled and which are not. Future compatibility -------------------- Note: Future versions of CSS may introduce ways of having alternate stylesheets declared at levels lower than the top level, i.e. embedded within other stylesheets. Implementations of this specification that also support this proposed declaration of alternate stylesheets are expected to perform depth-first traversals of the styleSheets list, not simply enumerations of the styleSheets list, which only contains the top level. Acknowledgements ---------------- David Hyatt and Boris Zbarsky have contributed valuable suggestions to this proposal.