001: /*
002: * GWT-Ext Widget Library
003: * Copyright(c) 2007-2008, GWT-Ext.
004: * licensing@gwt-ext.com
005: *
006: * http://www.gwt-ext.com/license
007: */
008: package com.gwtext.client.core;
009:
010: import com.google.gwt.user.client.Element;
011:
012: /**
013: * Utility class for working with DOM and/or Templates. It transparently supports using HTML fragments or DOM.<br><br>
014: * <p/>
015: * This is an example, where an unordered list with 5 children items is appended to an existing element with id 'my-div':<br>
016: * <p/>
017: * <pre>
018: * <code>
019: * <p/>
020: * DomConfig config = new DomConfig("ul", null, "my-list");
021: * config.addChild(new DomConfig("li", "item0", null, "List Item 0"));
022: * config.addChild(new DomConfig("li", "item1", null, "List Item 1"));
023: * config.addChild(new DomConfig("li", "item2", null, "List Item 2"));
024: * config.addChild(new DomConfig("li", "item3", null, "List Item 3"));
025: * config.addChild(new DomConfig("li", "item4", null, "List Item 4"));
026: * <p/>
027: * Element list = DomHelper.append("my-div", config);
028: * </code>
029: * </pre>
030: */
031: public class DomHelper {
032:
033: /**
034: * Creates new Dom element(s) and appends them to the parent element.
035: *
036: * @param parentId the parent element id
037: * @param rawHtml raw html blob
038: * @return the new node
039: */
040: public static native Element append(String parentId, String rawHtml)/*-{
041: return $wnd.Ext.DomHelper.append(parentId, rawHtml);
042: }-*/;
043:
044: /**
045: * Creates new Dom element(s) and appends them to the parent element.
046: *
047: * @param parentId the parent element id
048: * @param config child dom config
049: * @return the new node
050: */
051: public static native Element append(String parentId,
052: DomConfig config)/*-{
053: var configJS = config.@com.gwtext.client.core.DomConfig::getJsObject()();
054: return $wnd.Ext.DomHelper.append(parentId, configJS);
055: }-*/;
056:
057: /**
058: * Creates new Dom element(s) and appends them to the parent element.
059: *
060: * @param parent the parent element
061: * @param rawHtml raw html blob
062: * @return the new node
063: */
064: public static native Element append(Element parent, String rawHtml)/*-{
065: return $wnd.Ext.DomHelper.append(parent, rawHtml);
066: }-*/;
067:
068: /**
069: * Creates new Dom element(s) and appends them to the parent element.
070: *
071: * @param parent the parent element
072: * @param config child dom config
073: * @return the new node
074: */
075: public static native Element append(Element parent, DomConfig config)/*-{
076: var configJS = config.@com.gwtext.client.core.DomConfig::getJsObject()();
077: return $wnd.Ext.DomHelper.append(parent, configJS);
078: }-*/;
079:
080: /**
081: * Creates new Dom element(s) and appends them to the parent element.
082: *
083: * @param parent the parent element
084: * @param child child element
085: * @return the new node
086: */
087: public static native Element append(Element parent, Element child)/*-{
088: return $wnd.Ext.DomHelper.append(parent, child);
089: }-*/;
090:
091: /**
092: * Applies a style specification to an element.
093: *
094: * @param element the element to apply styles to
095: * @param styles a style specification string eg "width:100px"
096: */
097: public static native void applyStyles(Element element, String styles)/*-{
098: return $wnd.Ext.DomHelper.applyStyles(element, styles);
099: }-*/;
100:
101: /**
102: * Creates a new Template from the Dom config spec.
103: *
104: * @param config the dom config
105: * @return the new Template
106: */
107: public static native Template createTemplate(DomConfig config) /*-{
108: var configJS = config.@com.gwtext.client.core.DomConfig::getJsObject()();
109: var tpl = $wnd.Ext.DomHelper.createTemplate(configJS);
110: return @com.gwtext.client.core.Template::instance(Lcom/google/gwt/core/client/JavaScriptObject;)(tpl);
111: }-*/;
112:
113: /**
114: * Creates new Dom element(s) and inserts them after the specified element.
115: *
116: * @param id the element id
117: * @param rawHtml raw html blob
118: * @return the new node
119: */
120: public static native Element insertAfter(String id, String rawHtml)/*-{
121: return $wnd.Ext.DomHelper.insertAfter(id, rawHtml);
122: }-*/;
123:
124: /**
125: * Creates new Dom element(s) and inserts them after the specified element.
126: *
127: * @param id the element id
128: * @param config the element dom config spec
129: * @return the new node
130: */
131: public static native Element insertAfter(String id, DomConfig config)/*-{
132: var configJS = config.@com.gwtext.client.core.DomConfig::getJsObject()();
133: return $wnd.Ext.DomHelper.insertAfter(id, configJS);
134: }-*/;
135:
136: /**
137: * Creates new Dom element(s) and inserts them after the specified element.
138: *
139: * @param elem the element
140: * @param rawHtml the raw html blob
141: * @return the new node
142: */
143: public static native Element insertAfter(Element elem,
144: String rawHtml)/*-{
145: return $wnd.Ext.DomHelper.insertAfter(parent, rawHtml);
146: }-*/;
147:
148: /**
149: * Creates new Dom element(s) and inserts them after the specified element.
150: *
151: * @param elem the element
152: * @param config the element dom config spec
153: * @return the new node
154: */
155: public static native Element insertAfter(Element elem,
156: DomConfig config)/*-{
157: var configJS = config.@com.gwtext.client.core.DomConfig::getJsObject()();
158: return $wnd.Ext.DomHelper.insertAfter(parent, configJS);
159: }-*/;
160:
161: /**
162: * Creates new Dom element and inserts them after the specified element.
163: *
164: * @param elem the element
165: * @param sibling the sibling element
166: * @return the new node
167: */
168: public static native Element insertAfter(Element elem,
169: Element sibling)/*-{
170: return $wnd.Ext.DomHelper.insertAfter(elem, sibling);
171: }-*/;
172:
173: /**
174: * Creates new Dom element and inserts them before the specified element.
175: *
176: * @param id the element id
177: * @param rawHtml the raw html blob
178: * @return the new node
179: */
180: public static native Element insertBefore(String id, String rawHtml)/*-{
181: return $wnd.Ext.DomHelper.insertBefore(id, rawHtml);
182: }-*/;
183:
184: /**
185: * Creates new Dom element and inserts them before the specified element.
186: *
187: * @param id the element id
188: * @param config the dom config object
189: * @return the new node
190: */
191: public static native Element insertBefore(String id,
192: DomConfig config)/*-{
193: var configJS = config.@com.gwtext.client.core.DomConfig::getJsObject()();
194: return $wnd.Ext.DomHelper.insertBefore(id, configJS);
195: }-*/;
196:
197: /**
198: * Creates new Dom element and inserts them before the specified element.
199: *
200: * @param elem the element
201: * @param rawHtml the raw html blob
202: * @return the new node
203: */
204: public static native Element insertBefore(Element elem,
205: String rawHtml)/*-{
206: return $wnd.Ext.DomHelper.insertBefore(parent, rawHtml);
207: }-*/;
208:
209: /**
210: * Creates new Dom element and inserts them before the specified element.
211: *
212: * @param elem the element
213: * @param config the dom config object
214: * @return the new node
215: */
216: public static native Element insertBefore(Element elem,
217: DomConfig config)/*-{
218: var configJS = config.@com.gwtext.client.core.DomConfig::getJsObject()();
219: return $wnd.Ext.DomHelper.insertBefore(parent, configJS);
220: }-*/;
221:
222: /**
223: * Creates new Dom element and inserts them before the specified element.
224: *
225: * @param elem the element
226: * @param sibling the sibling element
227: * @return the new node
228: */
229: public static native Element insertBefore(Element elem,
230: Element sibling)/*-{
231: return $wnd.Ext.DomHelper.insertBefore(elem, sibling);
232: }-*/;
233:
234: /**
235: * Creates new Dom element(s) and inserts them as the first child of the parent element.
236: *
237: * @param parentId the parent element id
238: * @param rawHtml raw html blob
239: * @return the new node
240: */
241: public static native Element insertFirst(String parentId,
242: String rawHtml)/*-{
243: return $wnd.Ext.DomHelper.insertFirst(parentId, rawHtml);
244: }-*/;
245:
246: /**
247: * Creates new Dom element(s) and inserts them as the first child of the parent element.
248: *
249: * @param parentId the parent element id
250: * @param config the child dom config object
251: * @return the new node
252: */
253: public static native Element insertFirst(String parentId,
254: DomConfig config)/*-{
255: var configJS = config.@com.gwtext.client.core.DomConfig::getJsObject()();
256: return $wnd.Ext.DomHelper.insertFirst(parentId, configJS);
257: }-*/;
258:
259: /**
260: * Creates new Dom element(s) and inserts them as the first child of the parent element.
261: *
262: * @param parent the parent element
263: * @param rawHtml raw html blob
264: * @return the new node
265: */
266: public static native Element insertFirst(Element parent,
267: String rawHtml)/*-{
268: return $wnd.Ext.DomHelper.insertFirst(parent, rawHtml);
269: }-*/;
270:
271: /**
272: * Creates new Dom element(s) and inserts them as the first child of the parent element.
273: *
274: * @param parent the parent element
275: * @param config the child dom config object
276: * @return the new node
277: */
278: public static native Element insertFirst(Element parent,
279: DomConfig config)/*-{
280: var configJS = config.@com.gwtext.client.core.DomConfig::getJsObject()();
281: return $wnd.Ext.DomHelper.insertFirst(parent, configJS);
282: }-*/;
283:
284: /**
285: * Creates new Dom element(s) and inserts them as the first child of the parent element.
286: *
287: * @param parent the parent element
288: * @param child the child element
289: * @return the new node
290: */
291: public static native Element insertFirst(Element parent,
292: Element child)/*-{
293: return $wnd.Ext.DomHelper.insertFirst(parent, child);
294: }-*/;
295:
296: /**
297: * Returns the markup for the passed Element config.
298: *
299: * @param config the element config
300: * @return markup
301: */
302: public static native String markup(DomConfig config)/*-{
303: var configJS = config.@com.gwtext.client.core.DomConfig::getJsObject()();
304: return $wnd.Ext.DomHelper.markup(elem);
305: }-*/;
306:
307: /**
308: * Creates new Dom element(s) and overwrites the contents of the old element with them.
309: *
310: * @param oldId the old element id
311: * @param newRawHtml raw html blob
312: * @return the new node
313: */
314: public static native Element overwrite(String oldId,
315: String newRawHtml)/*-{
316: return $wnd.Ext.DomHelper.overwrite(oldId, newRawHtml);
317: }-*/;
318:
319: /**
320: * Creates new Dom element(s) and overwrites the contents of the old element with them.
321: *
322: * @param oldId the old element id
323: * @param config the dom config object
324: * @return the new node
325: */
326: public static native Element overwrite(String oldId,
327: DomConfig config)/*-{
328: var configJS = config.@com.gwtext.client.core.DomConfig::getJsObject()();
329: return $wnd.Ext.DomHelper.overwrite(oldId, configJS);
330: }-*/;
331:
332: /**
333: * Creates new Dom element(s) and overwrites the contents of the old element with them.
334: *
335: * @param oldElem the old element
336: * @param newRawHtml raw html blob
337: * @return the new node
338: */
339: public static native Element overwrite(Element oldElem,
340: String newRawHtml)/*-{
341: return $wnd.Ext.DomHelper.overwrite(oldElem, newRawHtml);
342: }-*/;
343:
344: /**
345: * Creates new Dom element(s) and overwrites the contents of the old element with them.
346: *
347: * @param oldElem the old element
348: * @param config the dom config object
349: * @return the new node
350: */
351: public static native Element overwrite(Element oldElem,
352: DomConfig config)/*-{
353: var configJS = config.@com.gwtext.client.core.DomConfig::getJsObject()();
354: return $wnd.Ext.DomHelper.overwrite(oldElem, configJS);
355: }-*/;
356:
357: /**
358: * Creates new Dom element(s) and overwrites the contents of the old element with them.
359: *
360: * @param oldElem the old element
361: * @param newElem the new element
362: * @return the new node
363: */
364: public static native Element overwrite(Element oldElem,
365: Element newElem)/*-{
366: return $wnd.Ext.DomHelper.overwrite(oldElem, newElem);
367: }-*/;
368: }
|