This example shows how to use Ajile's Namespace directive to create a namespace. Click this section's title to test it.
Namespace ("com.iskitz.ajile.examples"); var msg = typeof com.iskitz.ajile.examples == "undefined" ? "Failed to create" : "Successfully created"; alert(msg + " the [ com.iskitz.ajile.examples ] namespace!");
This example shows how to use Ajile's Load directive to load an external JavaScript file. Click this section's title to test it.
Load ("scripts/com.iskitz.ajile.examples.LoadExample.js"); function testLoad() { if( "undefined" != typeof com.iskitz.ajile.examples && "undefined" != typeof com.iskitz.ajile.examples.LoadExample) com.iskitz.ajile.examples.LoadExample(); else alert( "Load test was unsuccessful :-(\n\n" + "Failed to Load [ com.iskitz.ajile.examples.LoadExample.js ]"); } /** LoadExample.js: *******************************************************/ Namespace("com.iskitz.ajile.examples"); com.iskitz.ajile.examples.LoadExample = function() { var msg = navigator.userAgent + "\n\n\t\t" + "Successfully Loaded [ com.iskitz.ajile.examples.LoadExample ]!"; alert(msg); };
This example uses Ajile's Include directive to include an externally defined function. When successful, the included function is executed and a success message is displayed. If unsuccessful a failure message will be shown. Click this section's title to test it.
Include ("com.iskitz.ajile.examples.IncludeExample"); function testInclude() { if("undefined" != typeof com.iskitz.ajile.examples) if("undefined" != typeof com.iskitz.ajile.examples.IncludeExample) com.iskitz.ajile.examples.IncludeExample(); else alert( "Include test was unsuccessful :-(\n\n" + "Failed to Include [ com.iskitz.ajile.examples.IncludeExample.js ]"); } /** InludeExample.js: **********************************************************/ Namespace ("com.iskitz.ajile.examples"); com.iskitz.ajile.examples.IncludeExample = function() { var wasImported = typeof window["IncludeExample"] != "undefined"; alert( "[ com.iskitz.ajile.examples.IncludeExample ] was " + (wasImported ? "Included *and* Imported." : "successfully Included!")); };
This example uses the Import directive to import a function module so that it can be executed using its short name. Click this section's title to test it.
Import ("com.iskitz.ajile.examples.ImportFunction"); function testImport() { if("undefined" != typeof ImportFunction) ImportFunction(); else alert( "Import test was unsuccessful :-(\n\n" + "Failed to Import [ com.iskitz.ajile.examples.ImportFunction ]"); } /** ImportFunction.js: *******************************/ Namespace ("com.iskitz.ajile.examples"); com.iskitz.ajile.examples.ImportFunction = function () { alert("ImportFunction was successfully imported!"); };
This example uses Ajile's Import Listener feature to determine if all of this page's modules have been successfully imported. Click this section's title to test it.
// ImportListener that triggers the Examples page's initialization once all // required modules are ready for use. function isPageReady(moduleName) { if( "undefined" == typeof AComplex || "undefined" == typeof Complex || "undefined" == typeof ImportFunction || "undefined" == typeof showContents || "undefined" == typeof com.iskitz.ajile.examples.LoadExample) return; Ajile.RemoveImportListener(isPageReady); isPageReady = true; initialize(); } // Add listener to observe any import/include events. Ajile.AddImportListener(isPageReady); // Tests whether all imports were successful. function testImportListener() { var status = isPageReady == true ? ' ' : " NOT "; alert( "Import Listener test was" + status +"successful!\n\n" + "All required modules have"+ status +"been imported."); }
This example imports a module's public members so that each can be easily accessed using their short names instead of their fully qualified namespaces. Click this section's title to test it.
Import ("com.iskitz.ajile.examples.ImportModule.*"); function testImportModule() { // Test if showContents method has been imported. var imported = "undefined" != typeof showContents; if(imported)// Test if imported showContents is ImportModule.showContents. if("undefined" != typeof com.iskitz.ajile.examples.ImportModule) if(showContents == com.iskitz.ajile.examples.ImportModule.showContents) imported = true; if(imported) showContents(); else alert( "ImportModule test was unsuccessful :-(\n\n Failed to " + "Import [ com.iskitz.ajile.examples.ImportModule.* ]"); } /** ImportModule.js: *******************************************************/ Namespace ("com.iskitz.ajile.examples.ImportModule"); com.iskitz.ajile.examples.ImportModule = function() { var THIS = this; // Constructor :: Creates public members. function $ImportModule() { this.aNumber = 1; this.aString = "member 5"; this.aFunction = function(){ alert("member 1"); }; this.anArray = ["member3"]; this.anObject = { member:"member 2" }; this.aRegularExpression = (/member 6/); this.showContents = showContents; } function showContents() { var contents = ".:{ com.iskitz.ajile.examples.ImportModule }:.\n\n"; alert(contents + (THIS.constructor.toString ? THIS.constructor : '')); } $ImportModule(); };
This example shows how to use Ajile to define dependencies. Here we import one externally defined module from within another then instantiate and use the imported module. Click this section's title to test it.
Import ("com.iskitz.ajile.examples.Complex"); function testDependence() { if("undefined" != typeof Complex) { var complex = new Complex(); complex.sayHello(); } else alert( "Dependency test was unsuccessful :-(\n\n" + "Failed to Import [ com.iskitz.ajile.examples.Complex ]"); } /** Simple.js: **************************************************/ Namespace ("com.iskitz.ajile.examples"); com.iskitz.ajile.examples.Simple = function() { this.toString = function toString() { return "[Simple]"; }; }; /** Complex.js: *************************************************/ Namespace ("com.iskitz.ajile.examples"); Import ("com.iskitz.ajile.examples.Simple"); com.iskitz.ajile.examples.Complex = function() { var simple = new Simple(); this.sayHello = function sayHello() { var message = "Hello World!\n\nThis is a " + this.toString() + " object that imported and is\nusing a " + simple.toString() + " object!"; alert(message); }; this.toString = function toString() { return "[Complex]"; }; };
This example uses Ajile's ImportAs directive to import two externally defined modules that use the same short name, "Complex". Each module also defines a dependency for the Simple module. Click this section's title to test it.
Import ("com.iskitz.ajile.examples.Complex"); ImportAs ("AComplex", "com.iskitz.ajile.examples.ambiguity.Complex"); function testImportAlias() { if("undefined" != typeof Complex && "undefined" != typeof AComplex) { (new Complex() ).sayHello(); // Create & use Complex object. (new AComplex()).sayHello(); // Create & use ambiguous Complex object. } else alert( "Ambiguity test was unsuccessful :-(\n\n" + "Failed to import both [ com.iskitz.ajile.examples.Complex ]\n" + "and [ com.iskitz.ajile.examples.ambiguous.Complex ]"); } /* Ambiguous Complex.js: See Simple.js and the original Complex.js above. */ Namespace ("com.iskitz.ajile.examples.ambiguous"); Import ("com.iskitz.ajile.examples.Simple"); com.iskitz.ajile.examples.ambiguous.Complex = function() { var simple = new Simple(); this.sayHello = function sayHello() { var message = "Hello World!\n\nThis is an " + this.toString() + " object that\nimported and is using a " + simple.toString() + " object!"; alert(message); }; this.toString = function toString() { return "[ambiguous.Complex]"; }; };