Modify ↓
#7774 closed enhancement (fixed)
Allow to set script charset in add_script
| Reported by: | Owned by: | ||
|---|---|---|---|
| Priority: | normal | Milestone: | 1.0 |
| Component: | web frontend | Version: | none |
| Severity: | minor | Keywords: | add_script javascript chrome patch |
| Cc: | Branch: | ||
| Release Notes: | |||
| API Changes: |
chrome: |
||
| Internal Changes: | |||
Description
The function add_script in trac.web.chrome should allow the programmer to set a charset attribute for the script he/she is adding.
I wrote a small path for this:
-
trac/templates/layout.html
diff -Naur Trac-0.11.1-py2.5.egg/trac/templates/layout.html Trac-0.11.1-py2.5.egg.new/trac/templates/layout.html
old new 20 20 <link type="application/opensearchdescription+xml" rel="search" 21 21 href="${href.search('opensearch')}" title="Search $project.name"/> 22 22 </py:if> 23 <script py:for="script in chrome.scripts" 23 <script py:for="script in chrome.scripts" charset="${script.charset}" 24 24 type="${script.type}" src="${script.href}"></script> 25 25 ${Markup('<!--[if lt IE 7]>')} 26 26 <script type="text/javascript" src="${chrome.htdocs_location}js/ie_pre7_hacks.js"></script> -
Trac-0.11.1-py2.5.egg
diff -Naur Trac-0.11.1-py2.5.egg/trac/web/chrome.py Trac-0.11.1-py2.5.egg.new/trac/web/chrome.py
old new 82 82 href = href.chrome 83 83 add_link(req, 'stylesheet', href(filename), mimetype=mimetype) 84 84 85 def add_script(req, filename, mimetype='text/javascript' ):85 def add_script(req, filename, mimetype='text/javascript', charset='UTF-8'): 86 86 """Add a reference to an external javascript file to the template. 87 87 88 88 If the filename is absolute (i.e. starts with a slash), the generated link … … 101 101 if not filename.startswith('/'): 102 102 href = href.chrome 103 103 path = filename 104 script = {'href': href(path), 'type': mimetype }104 script = {'href': href(path), 'type': mimetype, 'charset': charset } 105 105 106 106 req.chrome.setdefault('scripts', []).append(script) 107 107 scriptset.add(filename)
Attachments (0)
Change History (5)
comment:1 by , 17 years ago
| Keywords: | patch added |
|---|---|
| Milestone: | → 0.13 |
comment:2 by , 15 years ago
| Milestone: | next-major-0.1X → 0.13 |
|---|
Patch looks good, I'll test and apply it.
comment:3 by , 15 years ago
| API Changes: | modified (diff) |
|---|---|
| Resolution: | → fixed |
| Severity: | normal → minor |
| Status: | new → closed |
Done in r10196, along with a small clean-up of layout.html. Thanks for the patch!
comment:4 by , 15 years ago
| Owner: | set to |
|---|
comment:5 by , 15 years ago
| API Changes: | modified (diff) |
|---|
Note:
See TracTickets
for help on using tickets.



I think it defaults anyway to UTF-8, so the argument should probably be:
, charset=None):.