[web] fix #736332: iespec functionality for add_css
Patch provided by vgodard.
--- a/utils.py Wed Mar 10 12:19:55 2010 +0100
+++ b/utils.py Wed Mar 10 12:37:34 2010 +0100
@@ -195,10 +195,10 @@
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=u'[if lt IE 8]'):
"""registers some IE specific CSS"""
- if (cssfile, media) not in self.ie_cssfiles:
- self.ie_cssfiles.append( (cssfile, media) )
+ 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 +228,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')
--- a/web/request.py Wed Mar 10 12:19:55 2010 +0100
+++ b/web/request.py Wed Mar 10 12:37:34 2010 +0100
@@ -492,26 +492,33 @@
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=u'[if lt IE 8]'):
"""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
:param localfile: if True, the default data dir prefix is added to the
CSS filename
+ :param ieonly: True if this css is specific to IE
+ :param iespec: conditional expression that will be used around
+ the css inclusion. cf:
+ http://msdn.microsoft.com/en-us/library/ms537512(VS.85).aspx
"""
if isinstance(cssfiles, basestring):
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):