]> source.dussan.org Git - vaadin-framework.git/commitdiff
ApplicationConnection now loads theme css
authorMatti Tahvonen <matti.tahvonen@itmill.com>
Wed, 23 Apr 2008 09:09:53 +0000 (09:09 +0000)
committerMatti Tahvonen <matti.tahvonen@itmill.com>
Wed, 23 Apr 2008 09:09:53 +0000 (09:09 +0000)
svn changeset:4206/svn branch:trunk

WebContent/reservr.html
src/com/itmill/toolkit/terminal/gwt/client/ApplicationConnection.java
src/com/itmill/toolkit/terminal/gwt/server/ApplicationServlet.java

index 764d81869f606aeed9c82ef26593fcec2703b4a9..a08b689b3fa6460e3d6285b4ae8b55c7395074c1 100644 (file)
@@ -2,11 +2,6 @@
 <html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml">\r
 <head>\r
        <title>IT Mill Toolkit 5 Demo: Reservr</title>\r
-       <script type="text/javascript">\r
-               var itmill = {\r
-                       appUri:'Reservr', pathInfo: '/'\r
-               };\r
-       </script>\r
        <!-- \r
                Google Maps needs an API key if you're not running this demo on "localhost". \r
                \r
@@ -20,8 +15,6 @@
                <script src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAA4q5gw_y_N1Anvvn1KqbLwRTHuC2ERVOT66iQW8-FqpCQQUlHqBTZ0rGKdlKh9fxQOKN87TCwVNlIXQ" type="text/javascript"></script>      \r
        -->\r
        <script src="http://maps.google.com/maps?file=api&v=2" type="text/javascript"></script>\r
-       <script language='javascript' src='ITMILL/widgetsets/com.itmill.toolkit.demo.reservation.gwt.ReservationWidgetSet/com.itmill.toolkit.demo.reservation.gwt.ReservationWidgetSet.nocache.js'></script>\r
-       <link REL="stylesheet" TYPE="text/css" HREF="ITMILL/themes/reservr/styles.css">\r
 </head>\r
 <body>\r
        <iframe id="__gwt_historyFrame" style="width:0;height:0;border:0"></iframe>\r
                <span id="logo"> Reservr Inc</span>\r
                <span id="arrow"> </span>\r
                <span id="slogan">Representational cars on-the-road</span>\r
-       </div>\r
+       </div>
+       <script type="text/javascript">
+       //<![CDATA[
+       if(!itmill || !itmill.toolkitConfigurations) {
+        if(!itmill) { var itmill = {}} 
+       itmill.toolkitConfigurations = {};
+       itmill.themesLoaded = {};
+       document.write('<iframe id="__gwt_historyFrame" style="width:0;height:0;border:0;overflow:hidden" src="javascript:false"></iframe>');
+       document.write("<script language='javascript' src='/ITMILL/widgetsets/com.itmill.toolkit.demo.reservation.gwt.ReservationWidgetSet/com.itmill.toolkit.demo.reservation.gwt.ReservationWidgetSet.nocache.js'><\/script>");
+       }
+       itmill.toolkitConfigurations["itmill-ajax-window"] = {appUri:'/Reservr', pathInfo: '/', themeUri:'/ITMILL/themes/reservr'};
+       //]]>
+       </script>\r
        <div id="itmill-ajax-window"></div>     \r
 </body>\r
 </html>\r
index 1b8f0f0b31716f4bf3c12dd9abbf9d141e5833e1..8a9380ff5ae46c196042730f37a190f11947047e 100755 (executable)
@@ -97,6 +97,10 @@ public class ApplicationConnection {
         this.widgetSet = widgetSet;
         configuration = cnf;
 
+        if (cnf.getThemeUri() != null) {
+            injectCss(cnf.getThemeUri() + "/styles.css");
+        }
+
         if (isDebugMode()) {
             console = new DebugConsole(this);
         } else {
@@ -126,6 +130,27 @@ public class ApplicationConnection {
         applicationRunning = true;
     }
 
+    /**
+     * Injects CSS to head element
+     * 
+     * TODO since gwt 1.5 this can be made non-native
+     * 
+     * @param css
+     */
+    private native static void injectCss(String cssUri)
+    /*-{
+        
+        if(!$wnd.itmill.themesLoaded[cssUri]) {
+            var stylesheet = $doc.createElement('link');
+            stylesheet.setAttribute('rel', 'stylesheet');
+            stylesheet.setAttribute('type', 'text/css');
+            stylesheet.setAttribute('href', cssUri);
+            var h = $doc.getElementsByTagName("head")[0];   
+            h.appendChild(stylesheet);
+            $wnd.itmill.themesLoaded[cssUri] = true;
+        }
+    }-*/;
+
     /**
      * Method to check if application is in testing mode. Can be used after
      * application init.
index f1cfcd90ef2c2d398090f171d488cfa51b4fbac0..af972ca82c72b1c2d180707d9d87e42bbe3fc7b1 100644 (file)
@@ -798,23 +798,6 @@ public class ApplicationServlet extends HttpServlet {
         }
         page.write("};\n//]]>\n</script>\n");
 
-        if (themeName != null) {
-            // Custom theme's stylesheet, load only once, in different script
-            // tag to be dominate styles injected by widget
-            // set
-            page.write("<script type=\"text/javascript\">\n");
-            page.write("//<![CDATA[\n");
-            page.write("if(!itmill.themesLoaded['" + themeName + "']) {\n");
-            page.write("var stylesheet = document.createElement('link');\n");
-            page.write("stylesheet.setAttribute('rel', 'stylesheet');\n");
-            page.write("stylesheet.setAttribute('type', 'text/css');\n");
-            page.write("stylesheet.setAttribute('href', '" + themeUri
-                    + "/styles.css');\n");
-            page.write("document.body.appendChild(stylesheet);\n");
-            page.write("itmill.themesLoaded['" + themeName + "'] = true;\n}\n");
-            page.write("//]]>\n</script>\n");
-        }
-
         page.write("<div id=\"" + appId + "\" class=\"i-app\"></div>\n");
 
         if (!fragment) {