cubicweb #736332 iespec functionality for add_css [resolved]

Current add_css implementation does not offer the ability to deliver specific css for different versions of IE. Please find here a backward compatible implementation of it below

diff -r a9caa76ba2c8 utils.py
--- a/utils.py Tue Mar 09 19:59:44 2010 +0100
+++ b/utils.py Wed Mar 10 11:41:36 2010 +0100
@@ -195,10 +195,12 @@
         if (cssfile, media) not in self.cssfiles:
             self.cssfiles.append( (cssfile, media) )

-    def add_ie_css(self, cssfile, media='all'):
+    def add_ie_css(self, cssfile, media='all', iespec=None):
         """registers some IE specific CSS"""
-        if (cssfile, media) not in self.ie_cssfiles:
-            self.ie_cssfiles.append( (cssfile, media) )
+        if iespec is None:
+            iespec = u'[if lt IE 8]'
+        if (cssfile, media, iespec) not in self.ie_cssfiles:
+            self.ie_cssfiles.append( (cssfile, media, iespec) )

     def add_unload_pagedata(self):
         """registers onunload callback to clean page data on server"""
@@ -228,8 +230,8 @@
               (media, xml_escape(cssfile)))
         # 3/ ie css if necessary
         if self.ie_cssfiles:
-            w(u'<!--[if lt IE 8]>\n')
-            for cssfile, media in self.ie_cssfiles:
+            for cssfile, media, iespec in self.ie_cssfiles:
+                w(u'<!--%s>\n' % iespec)
                 w(u'<link rel="stylesheet" type="text/css" media="%s" href="%s"/>\n' %
                   (media, xml_escape(cssfile)))
             w(u'<![endif]--> \n')
diff -r a9caa76ba2c8 web/request.py
--- a/web/request.py   Tue Mar 09 19:59:44 2010 +0100
+++ b/web/request.py   Wed Mar 10 11:41:36 2010 +0100
@@ -492,7 +492,8 @@
                 jsfile = self.datadir_url + jsfile
             self.html_headers.add_js(jsfile)

-    def add_css(self, cssfiles, media=u'all', localfile=True, ieonly=False):
+    def add_css(self, cssfiles, media=u'all', localfile=True, ieonly=False,
+                iespec=None):
         """specify a CSS file to include in the HTML headers
         :param cssfiles: a CSS filename or a list of CSS filenames
         :param media: the CSS's media if necessary
@@ -503,15 +504,17 @@
             cssfiles = (cssfiles,)
         if ieonly:
             if self.ie_browser():
+                extraargs = [iespec]
                 add_css = self.html_headers.add_ie_css
             else:
                 return # no need to do anything on non IE browsers
         else:
+            extraargs = []
             add_css = self.html_headers.add_css
         for cssfile in cssfiles:
             if localfile:
                 cssfile = self.datadir_url + cssfile
-            add_css(cssfile, media)
+            add_css(cssfile, media, *extraargs)

     def build_ajax_replace_url(self, nodeid, rql, vid, replacemode='replace',
                                **extraparams):
prioritynormal
typebug
done in3.6.2
load left0.000
closed by<not specified>