01: /*
02: * GWT-Ext Widget Library
03: * Copyright(c) 2007-2008, GWT-Ext.
04: * licensing@gwt-ext.com
05: *
06: * http://www.gwt-ext.com/license
07: */
08:
09: package com.gwtext.client.util;
10:
11: /**
12: * Utility class for manipulating CSS rules.
13: */
14: public class CSS {
15:
16: /**
17: * Very simple dynamic creation of stylesheets from a text blob of rules. The text will wrapped in a style tag and appended to the HEAD of the document.
18: *
19: * @param cssText the text containing the css rules
20: * @param id an id to add to the stylesheet for later removal
21: */
22: public static native void createStyleSheet(String cssText, String id)/*-{
23: $wnd.Ext.util.CSS.createStyleSheet(cssText, id);
24: }-*/;
25:
26: /**
27: * Gets an an individual CSS rule by selector(s).
28: *
29: * @param selector the CSS selector or an array of selectors to try. The first selector that is found is returned
30: * @param refreshCache true to refresh the internal cache if you have recently updated any rules or added styles dynamically
31: * @return the CSS rule or null if one is not found
32: */
33: public static native CSSRule getRule(String selector,
34: boolean refreshCache)/*-{
35: var rule = $wnd.Ext.util.CSS.getRule(selector, refreshCache);
36: if(rule == null || rule === undefined) {
37: return null;
38: } else {
39: return @com.gwtext.client.util.CSSRule::instance(Lcom/google/gwt/core/client/JavaScriptObject;)(rule);
40: }
41: }-*/;
42:
43: //todo getRules
44:
45: /**
46: * Refresh the rule cache if you have dynamically added stylesheets.
47: */
48: public static native void refreshCache()/*-{
49: $wnd.Ext.util.CSS.refreshCache();
50: }-*/;
51:
52: /**
53: * Removes a style or link tag by id
54: *
55: * @param id stylesheet id
56: */
57: public static native void removeStyleSheet(String id)/*-{
58: $wnd.Ext.util.CSS.removeStyleSheet(id);
59: }-*/;
60:
61: /**
62: * Dynamically swaps an existing stylesheet reference for a new one.
63: *
64: * @param id the id of an existing link tag to remove
65: * @param url the href of the new stylesheet to include
66: */
67: public static native void swapStyleSheet(String id, String url)/*-{
68: $wnd.Ext.util.CSS.swapStyleSheet(id, url);
69: }-*/;
70:
71: /**
72: * Updates a rule property.
73: *
74: * @param selector the seelctor. Stops immediately once one is found.
75: * @param property the css property
76: * @param value the new value for the property
77: */
78: public static native void updateRule(String selector,
79: String property, String value)/*-{
80: $wnd.Ext.util.CSS.updateRule(selector, property, value);
81: }-*/;
82: }
|