new (require("bajaux/commands/ToggleCommand"))( [params])
A ToggleCommand adds an additional state variable allowing it to be
turned on or off. If no function is specified in the Constructor, the default
behavior is to simply call 'toggle'.
Extends:
Parameters:
| Name | Type | Argument | Description | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
params |
object |
<optional> |
all parameters compatible with module:bajaux/commands/Command Properties
|
Methods
-
getAccelerator()
-
Return the accelerator for the Command or null if
nothing is defined.- Inherited From:
- See:
Returns:
The accelerator or null if nothing is defined.
- Type
- Object
-
getDescriptionFormat()
-
Get the unformatted description of the command.
- Inherited From:
Returns:
- Type
- String
-
getDisplayNameFormat()
-
Return the format display name of the command.
- Inherited From:
Returns:
- Type
- String
-
getFlags()
-
Get this command's flags.
- Inherited From:
Returns:
- Type
- Number
-
getFunction()
-
Return the raw function associated with this command.
- Inherited From:
Returns:
- Type
- function
-
getIcon()
-
Return the Command's icon URI
- Inherited From:
Returns:
- Type
- String
-
getId()
-
Return a unique numerical id for the Command.
This is id unique to every Command object created.
- Inherited From:
-
hasFlags(flags)
-
Check to see if this command's flags match any of the bits of the
input flags.Parameters:
Name Type Description flagsNumber The flags to check against
- Inherited From:
Returns:
- Type
- Boolean
-
invoke()
-
Invoke the Command. Triggers a
bajaux:invokecommandor
bajaux:failcommandevent, as appropriate.Arguments can be passed into
invoke()that will be passed into the
function's Command Handler.- Inherited From:
Returns:
A promise object that will be resolved (or rejected)
once the Command's function handler has finished invoking.- Type
- Promise
-
isCommand()
-
Always returns true.
- Inherited From:
-
isEnabled()
-
Gets this command's enabled status.
- Inherited From:
Returns:
- Type
- Boolean
-
isLoading()
-
Return true if the Command is still loading.
- Inherited From:
Returns:
true if still loading.
- Type
- Boolean
-
isSelected()
-
Gets this command's selected status.
Returns:
- Type
- Boolean
-
isToggleCommand()
-
Always returns true.
-
jq( [jqDom])
-
If a jQuery DOM argument is specified, this will set the DOM.
If not specified then no DOM will be set.
This method will always return the jQuery DOM associated with this Command.Parameters:
Name Type Argument Description jqDomJQuery <optional>
If specified, this will set the jQuery DOM.
- Inherited From:
Returns:
A jQuery DOM object for firing events on.
- Type
- JQuery
-
loading()
-
Return the loading promise for the Command.
The returned promise will be resolved once the Command
has finished loading.- Inherited From:
Returns:
The promise used for loading a Command.
- Type
- Promise
-
merge(cmd)
-
Attempt to merge this command with another command, and return a new
Command that does both tasks. If the two commands are mutually
incompatible, return a falsy value.Parameters:
Name Type Description cmdmodule:bajaux/commands/Command - Inherited From:
Returns:
Example
Here is an example to show the basic concept. Commands that simply add two numbers together can easily be merged together thanks to the associative property.
var AddCommand = function AddCommand(inc) { this.$inc = inc; Command.call(this, { displayName: 'Add ' + inc + ' to the given number', func: function (num) { return num + inc; } }); }; AddCommand.prototype = Object.create(Command.prototype); AddCommand.prototype.merge = function (cmd) { if (cmd instanceof AddCommand) { return new AddCommand(this.$inc + cmd.$inc); } }; var addOneCommand = new AddCommand(1), addFiveCommand = new AddCommand(5), addSixCommand = addOneCommand.merge(addFiveCommand); addSixCommand.invoke(10) .then(function (result) { console.log('is 16? ', result === 16); }); -
off( [event] [, handler])
-
Unregister a function callback handler for the specified event.
Parameters:
Name Type Argument Description eventString <optional>
The name of the event to unregister.
If name isn't specified, all events for the Command will be unregistered.handlerfunction <optional>
The function to unregister. If
not specified, all handlers for the event will be unregistered.- Inherited From:
-
on(event, handler)
-
Register a function callback handler for the specified event.
Parameters:
Name Type Description eventString The event id to register the function for.
handlerfunction The event handler to be called when the event is fired.
- Inherited From:
-
setAccelerator(acc)
-
Set the accelerator information for the Command.
Parameters:
Name Type Description accObject | String | Number | null | undefined The accelerator keyboard information. This can
be a keyCode number, a character (i.e. 'a') or an Object that contains the accelerator information.
If no accelerator should be used the null/undefined should be specified.Properties
Name Type Argument Description keyCodeString | Number The key code of the accelerator. This can be a character
code number or a character (i.e. 'a').ctrlBoolean <optional>
trueif the control key needs to be pressed.shiftBoolean <optional>
trueif the shift key needs to be pressed.altBoolean <optional>
trueif the alt key needs to be pressed.metaBoolean <optional>
trueif a meta key needs to be pressed. -
setDescriptionFormat(description)
-
Set the description format of the command. Triggers a
bajaux:changecommandevent.Parameters:
Name Type Description descriptionString the command description - supports baja Format
syntax- Inherited From:
-
setDisplayNameFormat(displayName)
-
Set the display name format of the command. Triggers a
bajaux:changecommandevent.Parameters:
Name Type Description displayNameString display name - supports baja Format syntax
- Inherited From:
-
setEnabled(enabled)
-
Sets this command's enabled status. Triggers a
bajaux:changecommandevent.Parameters:
Name Type Description enabledBoolean - Inherited From:
-
setFlags(flags)
-
Set this command's flags.
Parameters:
Name Type Description flagsNumber - Inherited From:
-
setFunction(func)
-
Set the Command's function handler.
Parameters:
Name Type Description funcfunction The new function handler for the command.
- Inherited From:
-
setIcon(icon)
-
Sets the icon for this Command. Triggers a
bajaux:changecommandevent.Parameters:
Name Type Description iconString The Command's icon (either a URI or a module:// ORD string)
- Inherited From:
-
setSelected(selected [, params])
-
Sets this command's selected status. Triggers a
bajaux:changecommand.Parameters:
Name Type Argument Description selectedBoolean paramsObject <optional>
Some optional parameters to pass through
to the events that are fired. -
toDescription()
-
Access the Command's description.
In order to access the description, a promise will be returned
that will be resolved once the command has been loaded and
the description has been found.- Inherited From:
Returns:
Promise to be resolved with the description
- Type
- Promise
-
toDisplayName()
-
Access the Command's display name.
In order to access the display name, a promise will be returned
that will be resolved once the command has been loaded and
the display name has been found.- Inherited From:
Returns:
Promise to be resolved with the display name
- Type
- Promise
-
toggle( [params])
-
Selects if deselected, or deselects if selected. Triggers a
bajaux:changecommand.Parameters:
Name Type Argument Description paramsObject <optional>
Some optional parameters to pass through to
setting the selection. -
trigger(name)
-
Triggers an event from this Command.
Parameters:
Name Type Description nameString - Inherited From:
-
visit(func)
-
Visit this Command with the specified function.
Parameters:
Name Type Description funcfunction Will be invoked with this
Command passed in as an argument.- Inherited From: