JavaScript#
- class alfred3.element.misc.JavaScript(code: Optional[str] = None, url: Optional[str] = None, path: Optional[str] = None, priority: int = 10)[source]#
Bases:
alfred3.element.core.Element
Adds JavaScript to a page.
Javascript can be used to implement dynamic behavior on the client side.
- Parameters
code – Javascript code.
url – Url to Javascript code.
path – Path to a .js file.
priority – Controls the order in which Javascript code is placed on a page. Lower numbers are included first. Can be useful, if you have trouble with overriding code. In everyday use, it’s fine to stick with the default.
Notes
You can use the jquery API (version 3.5.1 as of 2021-01-20).
See also
See
Element.css_class_element
andElement.css_class_container
for information on element CSS classes and IDs.The method
Element.add_js()
can be used to add JS to a specific element.
Examples
In this example, we use JavaScript to create a text element that will lead to automatic submission of the current page, when a change to its input is detected:
import alfred3 as al exp = al.Experiment() @exp.member class HelloWorld(al.Page): name = "hello_world" def on_exp_access(self): js_code = ''' $( '#test_el' ).on('change', function() { move('forward') // the move() JavaScript function is provided by alfred3. }) ''' self += al.JavaScript(code=js_code) self += al.TextEntry("Element 1", name="test_el")
Methods
Adds CSS to the element.
Adds Javascript to the element.
Tells the element that it was added to an experiment.
Tells the element that it was added to a page.
Hook for computations for preparing an element's web widget.
Renders the element template
element_template
.Attributes
Base template for the element, which will be used to hold the rendered element template.
List of bootstrap column widths at different screen sizes.
Returns the name the element container's CSS class.
Returns the name of the element's CSS class.
A list of tuples, which contain a priority and CSS code.
A list of tuples, which contain a priority and an url pointing to CSS code.
If True (default), the element will be displayed as usual on its own.
The element's specific, inner template.
Returns a string of column width definitions.
The experiment session to which this element belongs.
Alias for
exp
Font size
A list of tuples, which contain a priority and Javascript.
A list of tuples, which contain a priority and an url pointing to JavaScript.
Unique identifier for the element.
The page to which this element belongs.
Position of the whole element on the page.
The direct parent section of this element's page.
String, giving the exact position in the experiment.
Conditions that have to be met for the element to be shown.
Dictionary of data to be passed on to jinja templates.
String, giving the exact position in the experiment.
Element width