Skip to content

Commit

Permalink
[#1788] fix for IE 6/7/8 conditional comments which prevented executi…
Browse files Browse the repository at this point in the history
…on of Python code in Genshi, and caused html5 support script not being loaded/executed.

This required the addition of a pure Python function, and call of that function inside layout_base.html to resolve h.url_for_static() calls.
  • Loading branch information
zydio committed Mar 1, 2012
1 parent 05d8800 commit 52855c8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
19 changes: 19 additions & 0 deletions ckan/templates/_util.html
Expand Up @@ -480,4 +480,23 @@
</span>
</div>

<!--! jsConditionalForIe(ieVersion, tagContent, matchOperator): takes a
IE version number, a tag or other HTML code that will be wrapped inside
a IE conditional comment, and the comparison operator (lt, lte, etc..
see http://msdn.microsoft.com/en-us/library/ms537512%28v=vs.85%29.aspx)
returning Genshi stream ready to be shown in a template.
NOTE:
Internet Explorer Conditional Import are confused as Genshi comments
and python variables and method calls are not executed if inside them.
This function helps to output tags with Python code inside conditional
comments, eg ${h.url_for_static()} -->
<?python
from genshi import HTML
def jsConditionalForIe(ieVersion, tagContent, matchOperator = 'lt'):
html = HTML('<!--[if ' + matchOperator + ' IE ' + str(ieVersion) + ''']>
''' + tagContent + '''
<![endif]-->''')
return html
?>
</html>
8 changes: 2 additions & 6 deletions ckan/templates/layout_base.html
Expand Up @@ -34,13 +34,9 @@
<link rel="stylesheet" href="${h.url_for_static('/css/chosen.css')}" type="text/css" />
<link rel="stylesheet" href="${h.url_for_static('/css/blueprint/screen.css')}" type="text/css" media="screen, projection" />
<link rel="stylesheet" href="${h.url_for_static('/css/blueprint/print.css')}" type="text/css" media="print" />
<!--[if lt IE 8]>
<link rel="stylesheet" href="${h.url_for_static('/css/blueprint/ie.css')}" type="text/css" media="screen, projection">
<![endif]-->
<!--[if lt IE 9]>
<script type="text/javascript" src="${h.url_for_static('/scripts/vendor/html5shiv/html5.js')}"></script>
<![endif]-->
${jsConditionalForIe(8, '&lt;link rel="stylesheet" href="' + h.url_for_static('/css/blueprint/ie.css') + '" type="text/css" media="screen, projection"&gt;')}
<link rel="stylesheet" href="${h.url_for_static('/css/style.css?v=2')}" />
${jsConditionalForIe(9, '&lt;script type="text/javascript" src=" + h.url_for_static('/scripts/vendor/html5shiv/html5.js') + "&gt;&lt;/script&gt;')}

<py:if test="defined('optional_head')">
${optional_head()}
Expand Down

0 comments on commit 52855c8

Please sign in to comment.