Changeset 2210
- Timestamp:
- 04/28/07 15:04:15 (2 years ago)
- Files:
-
- ctxtnavaddplugin/0.11/ctxtnavadd/htdocs/js/ctxtnavadd.js (modified) (1 diff)
- ctxtnavaddplugin/0.11/ctxtnavadd/templates/ctxtnavadd.js (added)
- ctxtnavaddplugin/0.11/ctxtnavadd/web_ui.py (modified) (4 diffs)
- ctxtnavaddplugin/0.11/setup.py (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
ctxtnavaddplugin/0.11/ctxtnavadd/htdocs/js/ctxtnavadd.js
r806 r2210 1 function find_old_last() { 2 var ctxtnav = document.getElementById('ctxtnav'); 3 for (var i in ctxtnav.childNodes) { 4 if(ctxtnav.childNodes[i].tagName == 'UL') { 5 var ul_node = ctxtnav.childNodes[i]; 6 for (var j in ul_node.childNodes) { 7 if(ul_node.childNodes[j].tagName == 'LI') { 8 var li_node = ul_node.childNodes[j]; 9 if(li_node.getAttribute('class') == 'last') { 10 return(li_node); 11 } 12 } 13 } 14 } 15 } 1 function add_ctxtnav(html) { 2 var ctxtnav_bar = $('#ctxtnav'); 3 ctxtnav_bar.find('li:last-child').removeClass('last').after('<li class="last">'+html+'</li>'); 16 4 } 17 18 function add_ctxtnav(txt) {19 // Make a new <li> and find the old <li class="last">20 var new_li = document.createElement('LI');21 var old_li = find_old_last();22 23 // Insert content24 new_li.innerHTML = txt;25 26 // Set the class on the new <li> and clear the old one27 new_li.setAttribute('class','last');28 old_li.removeAttribute('class');29 30 // Insert the new node31 old_li.parentNode.appendChild(new_li);32 }33 34 35 function add_ctxtnav_link(href, txt) {36 var html = '<a href="' + href + '">' + txt + '</a>';37 add_ctxtnav(html);38 }ctxtnavaddplugin/0.11/ctxtnavadd/web_ui.py
r902 r2210 1 1 from trac.core import * 2 from trac.web.chrome import INavigationContributor, ITemplateProvider 3 from trac.util import Markup 4 5 try: 6 from trac.web.chrome import add_javascript 7 have_aj = True 8 except ImportError: 9 have_aj = False 2 from trac.web.chrome import ITemplateProvider, add_script 3 from trac.web.api import IRequestHandler, IRequestFilter 4 from genshi.core import Markup 5 from genshi.builder import tag 10 6 11 7 from ctxtnavadd.api import ICtxtnavAdder … … 13 9 inc_script = """<script type="text/javascript" src="%s"></script>""" 14 10 11 class ReqProxy(object): 12 """A proxy to intercept req.path_info.""" 13 14 def __init__(self, req, path_info): 15 object.__setattr__(self, '_req', req) 16 object.__setattr__(self, 'path_info', path_info) 17 18 def __getattr__(self, key): 19 return getattr(self._req, key) 20 21 def __setattr__(self, key, value): 22 setattr(self._req, key, value) 23 15 24 class CtxtnavAddModule(Component): 16 25 """An evil module that adds buttons to the ctxtnav bar of other plugins.""" 17 26 18 implements(I NavigationContributor, ITemplateProvider)27 implements(ITemplateProvider, IRequestFilter, IRequestHandler) 19 28 20 29 ctxtnav_adders = ExtensionPoint(ICtxtnavAdder) … … 26 35 def get_navigation_items(self, req): 27 36 evil_js = '/'.join(['ctxtnavadd','js','ctxtnavadd.js']) 28 if have_aj: 29 add_javascript(req, evil_js) 30 else: 31 self._add_js_inc(req, req.href.chrome(evil_js)) 32 self._add_js(req,self._make_js(req)) 37 #add_script(req, evil_js) 38 #self._add_js(req,self._make_js(req)) 33 39 34 40 return [] # This returns no buttons … … 36 42 # ITemplateProvider methods 37 43 def get_templates_dirs(self): 38 """39 Return the absolute path of the directory containing the provided40 ClearSilver templates.41 """42 44 from pkg_resources import resource_filename 43 #return [resource_filename(__name__, 'templates')] 44 return [] 45 return [resource_filename(__name__, 'templates')] 45 46 46 47 def get_htdocs_dirs(self): 47 """48 Return a list of directories with static resources (such as style49 sheets, images, etc.)50 51 Each item in the list must be a `(prefix, abspath)` tuple. The52 `prefix` part defines the path in the URL that requests to these53 resources are prefixed with.54 55 The `abspath` is the absolute path to the directory containing the56 resources on the local file system.57 """58 48 from pkg_resources import resource_filename 59 49 return [('ctxtnavadd', resource_filename(__name__, 'htdocs'))] 60 50 51 # IRequestHandler methods 52 def match_request(self, req): 53 return req.path_info.startswith('/ctxtnavadd') 54 55 def process_request(self, req): 56 data = {} 57 real_path = req.path_info[11:] 58 fake_req = ReqProxy(req, real_path) 59 data['adds'] = self._get_adds(fake_req) 60 return 'ctxtnavadd.js', data, 'text/plain' 61 62 # IRequestFilter methods 63 def pre_process_request(self, req, handler): 64 return handler 65 66 def post_process_request(self, req, template, data, content_type): 67 add_script(req, 'ctxtnavadd/js/ctxtnavadd.js') 68 add_script(req, '/ctxtnavadd'+req.path_info) 69 #self._add_js(req, data, self._make_js(req)) 70 return template, data, content_type 71 61 72 # Internal methods 62 def _add_js(self, req, data): 63 """Add javascript to a page via hdf['project.footer']""" 64 footer = req.hdf['project.footer'] 65 footer += data 66 req.hdf['project.footer'] = Markup(footer) 67 68 def _add_js_inc(self, req, file): 69 """Add a javascript include via hdf['project.footer']""" 70 self._add_js(req, inc_script%file) 71 72 def _make_js(self, req): 73 """Generate the needed Javascript.""" 74 adds = [] 73 def _get_adds(self, req): 74 """Find all links to add.""" 75 75 for adder in self.ctxtnav_adders: 76 76 if adder.match_ctxtnav_add(req): 77 77 for add in adder.get_ctxtnav_adds(req): 78 78 if isinstance(add, Markup): 79 adds.append(Markup(add.replace("'","\\'")))79 yield Markup(add.replace("'","\\'")) 80 80 else: 81 href, text = add 82 adds.append(Markup('<a href="%s">%s</a>'%(href,Markup.escape(text,False)))) 83 js = "" 84 for add in adds: 85 js += "add_ctxtnav('%s');\n"%add 86 return """<script type="text/javascript">%s</script>"""%js 81 yield tag.a(add[1], href=Markup(add[0])) 82 87 83 84 ctxtnavaddplugin/0.11/setup.py
r901 r2210 6 6 setup( 7 7 name = 'TracCtxtnavAdd', 8 version = ' 1.1-r1',8 version = '2.0', 9 9 packages = ['ctxtnavadd'], 10 10 package_data={ 'ctxtnavadd' : [ 'templates/*.cs' , 'htdocs/js/*.js' ] }, … … 16 16 keywords = "trac plugin ctxtnav", 17 17 url = "http://trac-hacks.org/wiki/CtxtnavAddPlugin", 18 18 classifiers = [ 19 'Framework :: Trac', 20 ], 21 19 22 entry_points = { 20 23 'trac.plugins': [ … … 22 25 ], 23 26 }, 24 25 install_requires = [ ],26 27 )
