Semantic modules all provide the ability to log performance traces to the console, allowing you to see which aspects of the module are more or less performant and to track total init time onDomReady
Design Pattern
All official javascript modules in Semantic are designed using a singular design pattern. This pattern allows several useful features common to all javascript components
View Commented ExampleUnlike other component libraries which hides explanations of behavior in inline comments which can only be read by combing the source, semantic modules provide run-time debug output to the javascript console telling you what each component is doing as it is doing it.
Semantic provides methods to set default settings, set settings at initialization, and set settings after initialization, allowing complete flexibility over component behaviors.
All events and metadata are namespaced and can be removed after initialization, modules automatically handle destroy/init events to allow users to lazy-initialize a plugin multiple times with no issues.
Modules store their instance in metadata meaning that, in a pinch, you can directly modify the instance of a UI element by modifying its properties.
Behaviors
Behaviors are an elements API. These can be invoke functionality or return aspects of the current state for an element
Triggering a Behavior
Behaviors are triggered in Semantic using a familiar syntax. API behaviors can be called using spaced words, camelcase or dot notation. The preferred method however is spaced words. Method lookup is done internally.
Common Behaviors
All modules have a set of core behaviors which allow you to configure the component
Name | Usage |
---|---|
initialize | Initializes an element, adding page event handlers and init data |
destroy | Removes all changes to the page made by initialization |
refresh | Refreshes cached values for a component |
setting(setting, value) | Allows you to modify or read a component setting |
invoke(query, passedArguments, instance) | Internal method used for translating sentence case method into an internal method |
log(comment, values) | Displays a log if a user has logging enabled |
verbose(comment, values) | Displays a log if a user has verbose logging enabled |
error(name) | Displays a name error message from the component's settings |
performance log(comment, value) | Adds a performance trace for an element |
performance display | Displays current element performance trace |
Settings
Unlike many javascript components, anything arbitrary in Semantic is a setting. This means no need to dig inside the internals of the component to alter an expected css selector or class name, simply alter the settings object
Common Settings
That means class names, selectors, error output, dom metadata etc can all be controlled by altering the settings object.
The following is a list of common settings usually found in each javascript module.
Name | Usage | |
---|---|---|
name | Name used in debug logs to differentiate this widget from other debug statements. | |
debug | Provides standard debug output to console. | |
performance | Provides performance logging to console of internal method calls. | |
verbose | Provides extra debug output to console | |
namespace | Namespace used for DOM event and metadata namespacing. Allows module's destroy method to not affect other modules. | |
metadata | An object containing any metadata attributes used. | |
selectors | An object containing all selectors used in the module, these are usually children of the module. | |
classNames | An object containing all classnames used in the module. | |
errors | A javascript array of error statements used in the plugin. These may sometimes appear to the user, but most often appear in debug statements. |
Changing Settings
The following examples use popup as an example for how to modify settings
Reading Settings
Settings can also be read programmatically: