blob: ff45e524d8759a18e3da8145ac8a60e8e804d737 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
from django import template
from django.conf import settings
register = template.Library()
@register.tag
def jquery(parser, token):
return JQueryNode()
class JQueryNode(template.Node):
def render(self, context):
# if we have the request in context, we can check if it is secure and
# serve content from HTTPS instead.
secure = 'secure' in context and context['secure']
prefixes = { False: 'http', True: 'https' }
version = '1.4.2'
oncdn = getattr(settings, 'CDN_ENABLED', True)
if oncdn:
jquery = '%s://ajax.googleapis.com/ajax/libs/jquery/' \
'%s/jquery.min.js' % (prefixes[secure], version)
else:
jquery = '/media/jquery-%s.min.js' % version
return '<script type="text/javascript" src="%s"></script>' % jquery
# vim: set ts=4 sw=4 et:
|