I have revisited the inner workings of tw.tabber.__init__.py in order
to figure out how to pull in a javascript 'onClick' function. It turns
out that some of the earlier discussion about modifications to this
routine was on the wrong track.
Starting from the standard version 0.8, the following mods seem to be
required to make it work properly and allow for an 'onClick' function:
1. Add js_symbol to the imports from tw.api
2. Replace the __init__ method in the Tabber class with:
def __init__(self, *args, **kw):
super(Tabber, self).__init__(*args, **kw)
if 'onClick' in self.options:
clickFunc = 'function(argsObj){ return ' +
str(self.options['onClick']) + '(argsObj)}'
self.options['onClick'] = js_symbol(clickFunc)
3. Add an update_params function to the class thus:
def update_params(self, d):
super(Tabber, self).update_params(d)
self.add_call(tabberAutomatic(self.options))
The last thing ensures that the call to tabberAutomatic comes at the
end of the html, not in the head.
In the controller, subclass Tabber something like this, replacing
'static/events.js' with the location of your 'onClick' function,
relative to the controller:
class MyTabber(Tabber):
javascript = Tabber.javascript
javascript.append(JSLink(modname=__name__, filename='static/
events.js'))
Then create an instance like so, replacing 'tabberOnClick' with the
name of your 'onClick' function:
myTabber = MyTabber(options = {'onClick':'tabberOnClick'})
Pass myTabber into the template as discussed earlier.
I would post a ticket about this, if someone would let me know the
appropriate place to do that, since tw.tabber is not in Trac.
Regards,
Phil