module.js

Summary
module.js
NinjsModuleA NinjsModule is an object which encapsulates a certain behavior or functionality.
Variables
dataThe module’s data object
nameThe module’s name (string)
run_tests (beta)Boolean to turn tests on/off
tests (beta)Array of test files to run
Functions
actionsThe actions method contains code to be executed when run is called.
runWaits for the DOM to load then calls execute.
call_on_readyWaits for the DOM to be ready and then executes a callback.
executeWrapper method that set’s up the environment and then calls actions.
elementsMethod to define module elements.
set_dataAdds properties to the module’s data object.
add_testAdds a test file to the tests array (beta).
_run_testsRuns the test files in the test array.

NinjsModule

A NinjsModule is an object which encapsulates a certain behavior or functionality.

Parameters

namethe name of the module

See Also

NinjsApplication

Summary
Variables
dataThe module’s data object
nameThe module’s name (string)
run_tests (beta)Boolean to turn tests on/off
tests (beta)Array of test files to run
Functions
actionsThe actions method contains code to be executed when run is called.
runWaits for the DOM to load then calls execute.
call_on_readyWaits for the DOM to be ready and then executes a callback.
executeWrapper method that set’s up the environment and then calls actions.
elementsMethod to define module elements.
set_dataAdds properties to the module’s data object.
add_testAdds a test file to the tests array (beta).
_run_testsRuns the test files in the test array.

Variables

data

this.data

The module’s data object

name

this.name

The module’s name (string)

run_tests (beta)

this.run_tests

Boolean to turn tests on/off

tests (beta)

this.tests

Array of test files to run

Functions

actions

The actions method contains code to be executed when run is called.  This method is a placeholder to be overwritten.

 MyModule.actions = function() {
  // define actions here
};

run

Waits for the DOM to load then calls execute.

MyModule.run();

call_on_ready

Waits for the DOM to be ready and then executes a callback.

Parameters

callbackfunction to be called when the DOM is ready
MyModule.call_on_ready(function() {
   // some code to execute when the DOM is ready
});

execute

Wrapper method that set’s up the environment and then calls actions.

MyModule.execute();

elements

Method to define module elements.

Parameters

callbackfunction to define a module’s elements
MyModule.elements(function() {
   // element definitions go here
});

set_data

Adds properties to the module’s data object.

Parameters

keystring or object (if string = key, if object sets multiple properties)
valuevalue of key if key is string
MyModule.set_data('some_key', 'some_value');
MyModule.data.some_key === 'some_value'
MyModule.set_data({
   'property_one': 'value_one',
   'property_two': 'value_two'
});
MyModule.data.property_one === 'value_one'
MyModule.data.property_two === 'value_two'

add_test

Adds a test file to the tests array (beta).

Parameters

test_fileFile to add to the tests array
MyModule.add_test('mytest.test.js');

_run_tests

Runs the test files in the test array.  This method is automatically called by the execute method if run_tests === true

this.data
The module’s data object
this.name
The module’s name (string)
this.run_tests
Boolean to turn tests on/off
this.tests
Array of test files to run
An NinjsApplication object serves as your application’s namespace and includes a utility to add modules to the application object.
Close