Ajile Directives


Ajile provides five directives for working with JavaScript modules: Import, ImportAs, Load, Namespace, and Include. Each is explained and detailed in the following sections.

Back to Documentation



Import: The Import directive is used to dynamically load an external JavaScript module and make it accessible via its shortened name. A module's shortened name is the portion following the last "." in its fully-qualified name. If a module, system variable, object or function with the exact shortened name already exists. The newly imported module will only be accessible via its fully-qualified name. In this situation the ImportAs directive should be used to import the module using an alias. NOTE: The browser will not process the imported module until the currently executing module or HTML script block is completely processed or executed. Until that time, none of the variables or functions in the imported module will be accessible. Use Ajile.AddImportListener() to be notified when the imported script is ready for use. Syntax: Import ( moduleName [, location] [, namingStyle] [, container] ) Parameters: moduleName - The fully-qualified name of the module or namespace to be imported. location - Optional. The url or file path at which the specified module can be located. When not specified the location parameter defaults to the namespace's location or the Ajile module's location if the namespace has not been created. namingStyle - Optional. The naming style used by the specified module. The namingStyle parameter can be any quoted notation character i.e. ".", "/", "-", etc. container - Optional. The object within which the imported module will be accessible. When not specified, the container parameter defaults to the browser's window object. Examples: The following statement: Import ("com.iskitz.ajile.examples.ImportExample"); Imports the ImportExample module from the com.iskitz.ajile.examples namespace using default settings for its location, namingStyle and container. If the com.iskitz.ajile.examples namespace was not already defined, the ImportExample module would be loaded using the com.iskitz.ajile namespace location and naming style. See: - Import - Include - Ajile.AddImportListener() - Load - Namespace Back to Top or Documentation


ImportAs: The ImportAs directive is used to dynamically load an external JavaScript module and make it accessible via the specified alias name. This directive enhances the Import directive by removing the limitation of shortened name accessiblity. As with the Import directive, if the specified alias exactly matches the name of an existing module, system variable, object or function the newly imported module will only be accessible via its fully-qualified name. In this situation a different alias name should be used. NOTE: The browser will not process the imported module until the currently executing module or HTML script block is completely processed or executed. Until that time, none of the variables or functions in the imported module will be accessible. Use Ajile.AddImportListener() to be notified when the imported script is ready for use. Syntax: ImportAs ( aliasName, moduleName [, location] [, namingStyle] [, container] ) Parameters: aliasName - The alias by which the imported module will be accessible. moduleName - The fully-qualified name of the module or namespace to be imported. location - Optional. The url or file path at which the specified module can be located. When not specified the location parameter defaults to the namespace's location or the Ajile module's location if the namespace has not been created. namingStyle - Optional. The naming style used by the specified module. The namingStyle parameter can be any quoted notation character i.e. ".", "/", "-", etc. container - Optional. The object within which the imported module will be accessible. When not specified, the container parameter defaults to the browser's window object. Examples: The following statement: ImportAs ("MyExample", "com.iskitz.ajile.examples.ImportExample"); Imports the ImportExample module from the com.iskitz.ajile.examples namespace using the MyExample alias name. The module is imported using default settings for its location, namingStyle and container. If the com.iskitz.ajile.examples namespace was not already defined, the ImportExample module would be loaded using the com.iskitz.ajile namespace location and naming style. See: - Import - Include - Ajile.AddImportListener() - Load - Namespace Back to Top or Documentation


Include: The Include directive is used to dynamically load an external JavaScript module and make it accessible via its fully-qualified name. A module's fully-qualified name is comprised of its full namespace and its short name. If a module, object or function with the exact fully-qualified name already exists, the module being included won't be accessible via its fully-qualified name. In this situation the ImportAs directive should be used to include the module using an alias. NOTE: The browser will not process the included module until the currently executing module or HTML script block is completely processed or executed. Until that time, none of the variables or functions in the included module will be accessible. Use Ajile.AddImportListener() to be notified when the included script is ready for use. Syntax: Include ( moduleName [, location] [, namingStyle] [, container] ) Parameters: moduleName - The fully-qualified name of the module or namespace to be included. location - Optional. The url or file path at which the specified module can be located. When not specified the location parameter defaults to the namespace's location or the Ajile module's location if the namespace has not been created. namingStyle - Optional. The naming style used by the specified module. The namingStyle parameter can be any quoted notation character i.e. ".", "/", "-", etc. container - Optional. The object within which the included module will be accessible. When not specified, the container parameter defaults to the browser's window object. Examples: The following statement: Include ("com.iskitz.ajile.examples.IncludeExample"); Includes the IncludeExample module from the com.iskitz.ajile.examples namespace using default settings for its location, namingStyle and container. If the com.iskitz.ajile.examples namespace was not already defined, the IncludeExample module would be loaded using the com.iskitz.ajile namespace location and naming style. See: - Import - ImportAs - Ajile.AddImportListener() - Load - Namespace Back to Top or Documentation


Load: The Load directive is used to dynamically load an external JavaScript module from the specified location. NOTE: The browser will not process the loaded module until the currently executing module or HTML script block is completely processed or executed. Until that time, none of the variables or functions in the loaded module will be accessible. Syntax: Load ( location [, container] [,code] [, defer] [, title] [, type] [, language] ) Parameters: location - The url or file path where the external JavaScript module can be located. container - Optional. The object within which the loaded script will be accessible. When not specified, the container parameter defaults to the browser's window object. code - Optional. JavaScript code to be executed. defer - Optional. A boolean to indicate whether the browser should delay processing of the loaded script until it' host page has completed loading. true indicates title - Optional. A string to be associated with the loaded script. The default value is blank. type - Optional. A string representing the content-type of script to be loaded (i.e. "text/javascript"). This parameter defaults to "text/javascript" when unspecified. language - Optional. A string representing the loaded script's language (i.e. "JavaScript"). This parameter defaults to "JavaScript" when unspecified. Examples: The following statement: Load ("http://ajile.iskitz.com/examples/Examples.js"); Loads the Examples module from the /examples/ directory on the ajile.iskitz.com server using default values for its container, type, defer, language, and title settings. See: - Import - ImportAs - Include Back to Top or Documentation


Namespace: The Namespace directive is used to create a unique JavaScript namespace if none matching the specified name exists. JavaScript modules that wish to be uniquely identifiable should use the Namespace directive to declare their namespace membership. A module cannot be defined as a member of a namespace that has not been created via the Namespace directive. This is the reason why the Namespace directive must be used prior to defining namespace member modules. NOTE: Namespaces are immediately available after using the Namespace directive. Syntax: Namespace (name [, location] [, namingStyle] [, container] ) Parameters: name - A string representing the fully-qualified namespace to be created. location - Optional. The url or file path to be associated with the new namespace. When not specified the location parameter defaults to the parent namespace's location or the Ajile module's location if the parent namespace has not been created. namingStyle - Optional. The naming style used by the specified module. The namingStyle parameter can be any quoted notation character i.e. ".", "/", "-", etc. container - Optional. The object within which the namespace will be accessible. When not specified, the container parameter defaults to the browser's window object. Examples: The following statements: Namespace ("com.iskitz.ajile.examples"); com.iskitz.ajile.examples.MyExample = function() { this.message = "This is my example!"; }; Create the com.iskitz.ajile.examples namespace and define the MyExample module. The namespace is created using default values for its location, namingStyle, and container settings. See: - Import - ImportAs Back to Top or Documentation