[Cubicweb] Proposition patch CSS IE

Vincent Godard vincent at secondweb.fr
Wed Feb 10 16:44:59 CET 2010


Bonjour,

Nous avons fait un patch cubicweb, au niveau de l'insertion des css, dans le
cas du navigateur Internet Explorer.
Le but est de pouvoir spécifier directement lors du self._cw.add_css la
version d'Internet Explorer correspondant au fichier css fourni.
Ex : self._cw.add_css('css/styles/ie7.css', ieonly=True, iespec=u'[if IE
7]')

VoilĂ  le diff

diff -r 65f4665233e6 utils.py
--- a/utils.py    Thu Feb 04 10:17:15 2010 +0100
+++ b/utils.py    Wed Feb 10 16:13:27 2010 +0100
@@ -282,10 +282,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"""
@@ -315,8 +317,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 65f4665233e6 web/request.py
--- a/web/request.py    Thu Feb 04 10:17:15 2010 +0100
+++ b/web/request.py    Wed Feb 10 16:13:27 2010 +0100
@@ -490,7 +490,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
@@ -501,15 +502,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):


Vincent & Florent
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cubicweb.org/pipermail/cubicweb/attachments/20100210/e71f5529/attachment-0126.html>


More information about the Cubicweb mailing list