def test_js_dependencies_are_collected(self): d1 = JSSource(src="d1") d2 = JSSource(src="d2") w = JSSource(src="foo", javascript=[d1,d2]) js = w.retrieve_resources()['head'] self.failUnlessEqual(js[0].src, 'd1') self.failUnlessEqual(js[1].src, 'd2') self.failUnlessEqual(js[2].src, 'foo')
def central_station(endpoint, start=True): """ This function creates a JSSource widget which should be declared as dependency for all widgets that have java-script that relies on the existence of a "central_station". """ opts = dict( endpoint=endpoint, ) start = "true" if start else "false" return JSSource(""" $(function() { // one global window.central_station = new CentralStation(%(opts)s); if(%(start)s) { window.central_station.start(); } }); """ % dict(opts=dumps(opts), start=start), javascript = [centralstation_js] )
def render(self, *args, **kwargs): src = JSSource.render(self, *args, **kwargs) return src % {'add_url': _('Add another URL')}
def render(self, *args, **kwargs): if not hasattr(self, 'condition') or self.condition(): return JSSource.render(self, *args, **kwargs) return ""
def render(self, *args, **kwargs): src = JSSource.render(self, *args, **kwargs) return src % {"add_url": _("Add another URL")}
def test_js_is_collected_from_JSSource(self): w = JSSource(src="foo") self.failUnless(w in w.retrieve_resources()['head'])
# Lil' chunk o' CSS for tasty eye-candy ;) # External css files can be wrapped with CSSLink css = CSSSource(""" label.required, .fielderror { font-weight: bold; color: red; }; """) # We define the source for some JS functions we're going to interface # External js files can be wrapped with JSLink functions = JSSource( """ var focus_element = function (elem) { var elem = document.getElementById(elem); elem.focus(); elem.select(); }; """, ) alert = js_function('alert') focus_element = js_function('focus_element') # This is needed because of the way TurboGears validates as it adds # spurious variables to the value being validated. class FilteringSchema(Schema): filter_extra_fields = True allow_extra_fields = True