diff options
author | Matti Tahvonen <matti.tahvonen@itmill.com> | 2008-12-09 08:11:37 +0000 |
---|---|---|
committer | Matti Tahvonen <matti.tahvonen@itmill.com> | 2008-12-09 08:11:37 +0000 |
commit | bd77e796573fecaf6551248fe3e64a4470edca8b (patch) | |
tree | 30d7f43512ba5a07b30e2ba51cb9468bc9cd2b44 | |
parent | 8794bd79b21c9afdc67ae8d93fa538ca4e482b8c (diff) | |
download | vaadin-framework-bd77e796573fecaf6551248fe3e64a4470edca8b.tar.gz vaadin-framework-bd77e796573fecaf6551248fe3e64a4470edca8b.zip |
Refactored custom layout relative image prefixing to use regexp befor setting template to dom. Now works with IE.
svn changeset:6126/svn branch:trunk
-rw-r--r-- | src/com/itmill/toolkit/terminal/gwt/client/ui/ICustomLayout.java | 38 |
1 files changed, 23 insertions, 15 deletions
diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/ICustomLayout.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/ICustomLayout.java index 357b9ae5b4..762b7eabd7 100644 --- a/src/com/itmill/toolkit/terminal/gwt/client/ui/ICustomLayout.java +++ b/src/com/itmill/toolkit/terminal/gwt/client/ui/ICustomLayout.java @@ -210,14 +210,30 @@ public class ICustomLayout extends ComplexPanel implements Paintable, // Connect body of the template to DOM template = extractBodyAndScriptsFromTemplate(template); + + // TODO prefix img src:s here with a regeps, cannot work further with IE + + String themeUri = client.getThemeUri(); + String relImgPrefix = themeUri + "/layouts/"; + + // prefix all relative image elements to point to theme dir with a + // regexp search + template = template.replaceAll( + "<((?:img)|(?:IMG)) ([^>]*)src=\"((?![a-z]+:)[^/][^\"]+)\"", + "<$1 $2src=\"" + relImgPrefix + "$3\""); + // also support src attributes without quotas + template = template + .replaceAll( + "<((?:img)|(?:IMG)) ([^>]*)src=[^\"]((?![a-z]+:)[^/][^ />]+)[ />]", + "<$1 $2src=\"" + relImgPrefix + "$3\""); + getElement().setInnerHTML(template); // Remap locations to elements locationToElement.clear(); scanForLocations(getElement()); - String themeUri = client.getThemeUri(); - initImgElements(getElement(), themeUri + "/layouts/"); + initImgElements(); elementWithNativeResizeFunction = DOM.getFirstChild(getElement()); if (elementWithNativeResizeFunction == null) { @@ -269,24 +285,16 @@ public class ICustomLayout extends ComplexPanel implements Paintable, }-*/; /** - * Img elements needs some special handling in custom layout - * - * Prefixes img tag srcs with given prefix, if it has a relative uri. - * - * Img elements will also get their onload events sunk to notify paren of - * possible size change. - * + * Img elements needs some special handling in custom layout. Img elements + * will get their onload events sunk. This way custom layout can notify + * parent about possible size change. */ - private static void initImgElements(Element e, String srcPrefix) { - NodeList<com.google.gwt.dom.client.Element> nodeList = e + private void initImgElements() { + NodeList<com.google.gwt.dom.client.Element> nodeList = getElement() .getElementsByTagName("IMG"); for (int i = 0; i < nodeList.getLength(); i++) { com.google.gwt.dom.client.ImageElement img = (ImageElement) nodeList .getItem(i); - String src = img.getAttribute("src"); - if (!(src.startsWith("/") || src.contains("://"))) { - img.setSrc(srcPrefix + src); - } DOM.sinkEvents((Element) img.cast(), Event.ONLOAD); } } |