Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def add_script(req, filename, mimetype='text/javascript'):
- """Add a reference to an external javascript file to the template.
- If the filename is absolute (i.e. starts with a slash), the generated link
- will be based off the application root path. If it is relative, the link
- will be based off the `/chrome/` path.
- """
- scriptset = req.chrome.setdefault('scriptset', set())
- if filename in scriptset:
- return False # Already added that script
- if filename.startswith('common/') and 'htdocs_location' in req.chrome:
- href = Href(req.chrome['htdocs_location'])
- path = filename[7:]
- else:
- href = req.href
- if not filename.startswith('/'):
- href = href.chrome
- path = filename
- script = {'href': href(path), 'type': mimetype}
- req.chrome.setdefault('scripts', []).append(script)
- scriptset.add(filename)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement