From bd77e796573fecaf6551248fe3e64a4470edca8b Mon Sep 17 00:00:00 2001 From: Matti Tahvonen Date: Tue, 9 Dec 2008 08:11:37 +0000 Subject: [PATCH] Refactored custom layout relative image prefixing to use regexp befor setting template to dom. Now works with IE. svn changeset:6126/svn branch:trunk --- .../terminal/gwt/client/ui/ICustomLayout.java | 38 +++++++++++-------- 1 file 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 nodeList = e + private void initImgElements() { + NodeList 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); } } -- 2.39.5