class ButtonElement(Element): """ A button with an automatic Athena event handler. """ preprocessors = LiveElement.preprocessors docFactory = loaders.stan(tags.button[athena.handler(event='onclick', handler='handler')])
def _radios(): for choice in data.rtype.choices: yield T.label(for_=choice)[choice] yield T.input(type='radio', name='model-radio-%s' % hash(self), value=choice, class_='model-radio')[ athena.handler(event='onclick', handler='changed') ] yield T.br
def add_item(self, item): k = unicode(str(hash(item)), 'ascii') self._models.append(item) self._labels[k] = Label(k) self._labels[k].page = self.page i = T.span(id=u'_%s' % k, style='{cursor: pointer}')[ athena.handler(event='onclick', handler='changed'), self._labels[k]] self._items.append(i)
def test_handlerMacro(self): """ Test that the handler macro rewrites athena:handler nodes to the appropriate JavaScript. """ expectedOutput = ('return Nevow.Athena.Widget.handleEvent(' 'this, "onclick", "bar");') tag = tags.span[athena.handler(event='onclick', handler='bar')] mutated = athena._rewriteEventHandlerToAttribute(tag) output = flat.flatten(mutated) self.assertEquals(output, '<span onclick="' + expectedOutput + '"></span>')
class TestRunner(TestSuiteFragment): jsClass = u'Nevow.Athena.Test.TestRunner' docFactory = loaders.stan( tags.div(_class='test-runner', render=tags.directive('liveFragment')) [tags.form(action='#')[ athena.handler(event='onsubmit', handler='runWithDefaults'), tags.input(type='submit', value='Run Tests')], tags.div[tags.div[tags.div['Tests passed: ', tags.span(_class='test-success-count')[0]], tags.div['Tests failed: ', tags.span(_class='test-failure-count')[0]], tags.div['Tests completed in: ', tags.span(_class='test-time')['-']], tags.div(render=tags.directive('debug'))], tags.hr, tags.div[tags.span(_class='test-results')], tags.hr, tags.div(render=tags.directive('tests'))]]) def render_debug(self, ctx, data): f = athena.IntrospectionFragment() f.setFragmentParent(self) return f
def render_widget(self, ctx, data): return ctx.tag[ T.input(type='checkbox', class_='model-checkbox')[ athena.handler(event='onclick', handler='changed') ] ]
def render_widget(self, ctx, data): return ctx.tag[ T.input(type='text', class_='model-entry')[ athena.handler(event='onkeydown', handler='changed') ] ]