01: /*
02: * MyGWT Widget Library
03: * Copyright(c) 2007, MyGWT.
04: * licensing@mygwt.net
05: *
06: * http://mygwt.net/license
07: */
08: package net.mygwt.ui.client.util;
09:
10: import net.mygwt.ui.client.MyDOM;
11:
12: import com.google.gwt.user.client.DOM;
13: import com.google.gwt.user.client.Element;
14:
15: /**
16: * Provides functions for removing and adding stylesheets.
17: */
18: public class CSS {
19:
20: /**
21: * Removes a style or link tag by id.
22: *
23: * @param id the id of the tag
24: */
25: public static void removeStyleSheet(String id) {
26: Element elem = DOM.getElementById(id);
27: if (elem != null) {
28: Element p = DOM.getParent(elem);
29: DOM.setElementProperty(p, "disabled", "disabled");
30: DOM.removeChild(p, elem);
31: }
32: }
33:
34: /**
35: * Adds a stylesheet to the document.
36: *
37: * @param id the id
38: * @param url the stylesheet url
39: */
40: public static void addStyleSheet(String id, String url) {
41: Element link = DOM.createElement("link");
42: DOM.setElementProperty(link, "rel", "stylesheet");
43: DOM.setElementProperty(link, "type", "text/css");
44: DOM.setElementProperty(link, "id", id);
45: DOM.setElementProperty(link, "href", url);
46: DOM.setElementProperty(link, "disabled", "");
47: Element elem = MyDOM.getHead();
48: DOM.appendChild(elem, link);
49: }
50:
51: /**
52: * Adds a rules string in a <code><dstyle><d/style></code> element.
53: *
54: * @param style the <code><dstyle><d/style></code> element
55: * @param cssStr the rules string
56: */
57: native public static void setRules(Element style, String cssStr) /*-{
58: style.setAttribute("type", "text/css");
59: if(style.styleSheet){// IE
60: style.styleSheet.cssText = cssStr;
61: } else {// w3c
62: while (style.firstChild) {
63: style.removeChild(style.firstChild);
64: }
65: var cssText = $doc.createTextNode(cssStr);
66: style.appendChild(cssText);
67: }
68: }-*/;
69:
70: }
|