Edgewall Software
Modify

Opened 15 years ago

Closed 14 years ago

Last modified 13 years ago

#7774 closed enhancement (fixed)

Allow to set script charset in add_script

Reported by: martin@… Owned by: martin@…
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: add_script takes optional charset argument (defaults to 'utf-8'). [10196]

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  
    2020      <link type="application/opensearchdescription+xml" rel="search"
    2121            href="${href.search('opensearch')}" title="Search $project.name"/>
    2222    </py:if>
    23     <script py:for="script in chrome.scripts"
     23    <script py:for="script in chrome.scripts" charset="${script.charset}"
    2424            type="${script.type}" src="${script.href}"></script>
    2525    ${Markup('&lt;!--[if lt IE 7]&gt;')}
    2626    <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  
    8282            href = href.chrome
    8383    add_link(req, 'stylesheet', href(filename), mimetype=mimetype)
    8484
    85 def add_script(req, filename, mimetype='text/javascript'):
     85def add_script(req, filename, mimetype='text/javascript', charset='UTF-8'):
    8686    """Add a reference to an external javascript file to the template.
    8787   
    8888    If the filename is absolute (i.e. starts with a slash), the generated link
     
    101101        if not filename.startswith('/'):
    102102            href = href.chrome
    103103        path = filename
    104     script = {'href': href(path), 'type': mimetype}
     104    script = {'href': href(path), 'type': mimetype, 'charset': charset }
    105105
    106106    req.chrome.setdefault('scripts', []).append(script)
    107107    scriptset.add(filename)

Attachments (0)

Change History (5)

comment:1 by Christian Boos, 15 years ago

Keywords: patch added
Milestone: 0.13

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

comment:2 by Christian Boos, 14 years ago

Milestone: next-major-0.1X0.13

Patch looks good, I'll test and apply it.

comment:3 by Christian Boos, 14 years ago

API Changes: modified (diff)
Resolution: fixed
Severity: normalminor
Status: newclosed

Done in r10196, along with a small clean-up of layout.html. Thanks for the patch!

comment:4 by Christian Boos, 14 years ago

Owner: set to martin@…

comment:5 by Remy Blank, 13 years ago

API Changes: modified (diff)

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain martin@….
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from martin@… to the specified user.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.