Commits

Jun Omae committed 1afdd21 Draft

Avoids requests to unnecessary javascript and stylesheet files when mac theme is disabled

Comments (0)

Files changed (2)

TracMacOSTheme/tracmacos/templates/mac_theme.html

     </li>
   </ul>
 
+  <py:match path="head" once="true" buffer="false"><head>
+    ${select('*|text()|comment()')}
+    <link py:if="'NetSurf' in (req.get_header('User-Agent') or '')"
+          rel="stylesheet" type="text/css" href="${req.href.chrome('theme/netsurf.css')}" />
+    <script type="text/javascript" src="${req.href.chrome('theme/jquery.jqDock.min.js')}"></script>
+    <script type="text/javascript" src="${req.href.chrome('theme/animatedcollapse.js')}"></script>
+    <script type="text/javascript" src="${req.href.chrome('theme/jquery.cookie.js')}"></script>
+  </head></py:match>
+
   <py:match path="body" once="true" buffer="false"><body py:with="macos=getattr(req, 'macos')">
     <div id="fixed-wrapper">
       <div id="mainpanel" class="nav">

TracMacOSTheme/tracmacos/theme.py

     
     def post_process_request(self, req, template, data, content_type):
 #        self._prepare_request(req)
-        self._add_macos_scripts(req)
         # Force IE to render in standard mode
         req.send_header('X-UA-Compatible', 'IE=edge')
         return template, data, content_type
         stream = tmpl.generate(req=req, supported=self.BROWSER_SUPPORTED)
         req.send(stream.render('xhtml'))
     
-    # Internal methods
-    def _add_macos_scripts(self, req):
-        add_script(req, '/chrome/theme/jquery.jqDock.min.js')
-        add_script(req, '/chrome/theme/animatedcollapse.js')
-        add_script(req, '/chrome/theme/jquery.cookie.js')
-        # Send browser specific files
-        ua = dict(req._inheaders).get('user-agent')
-        if 'NetSurf' in ua :
-            add_stylesheet(req, '/chrome/theme/netsurf.css');
-        
     def _prepare_request(self, req):
         def to_text(fragment):
           if isinstance(fragment, (Element, Fragment, Markup)):
         
         def macos_prepare_request(_):
             req.chrome = value = old_prepare_chrome(req)
-            self._add_macos_scripts(req)
             return value
             
         req.callbacks['chrome'] = macos_prepare_request