Iris exposes all of its methods and properties on the iris
object:
- Core
- Util
- Event
- Language & Regional
- Components
- iris.include(paths, callback)
- iris.welcome(path)
- iris.navigate(path)
- iris.screen(function(self){...}, path)
- iris.destroyScreen(path)
- iris.ui(function(self){...}, path)
- iris.tmpl(path, html)
- iris.resource(function(self){...}, path)
- iris.Settable Class
- iris.Component Class
- iris.UI Class
- iris.Screen Class
- iris.Resource Class
Since: v0.5.0
Set the base URL applied to load Iris components like screens, UIs & resources.
// You can define paths as
iris.path = {
screen : {
js: "./path/to/iris/components/screen.js",
html: "./path/to/iris/components/screen.html"
}
};
// Or you can use iris.baseUri to short paths
iris.path = {
screen : {
js: "screen.js",
html: "screen.html"
}
};
iris.baseUri("./path/to/iris/components/");
Since: v0.5.0
Set or get a boolean value that indicates whether Iris' calls are cached or not. In local environments (localhost, 127.0.0.1) the cache are disabled by default.
// Getter
iris.cache();
// Setter
iris.cache(true);
Since: v0.5.0
Set or get a value that will be added as a parameter in all Iris' ajax calls. You can use it to force Iris components to be cached with a version string.
iris.cacheVersion("v1.0");
Since: v0.5.0
Set cache to false when the environment match with the current URL.
// By default iris executes:
iris.noCache("localhost", "127.0.0.1");
Since: v0.5.0
Enable or disable the iris.log outputs.
iris.enableLog(false);
iris.log("test"); // "test" is not printed
Since: v0.5.0
Prints the parameters values to the console for debugging purposes.
iris.log("obj = ", obj);
Since: v0.5.0
Perform an HTTP (Ajax) request. Accepts the same parameters as jQuery.ajax() See JQuery Ajax for more details. Returns a jQuery jqXHR object.
iris.ajax({
"url" : "http://www.example.com/",
"type" : "GET"
}).done(successCallback).fail(errorCallback);
Since: v0.5.0
Get value from Javascript object using a label string. You can use dot to get object's children.
var book = {
author : {
name : "value"
}
};
var authorName = iris.val(book, "author.name");
Since: v0.5.0
Formats a Date object or timestamp to the specified format and according to the current locale. See Language & Regional for more information. You can use the following special characters:
- a 'a.m.' or 'p.m.'
- A 'AM' or 'PM'
- b Month, textual, 3 letters, lowercase. 'jan'
- d Day of the month, 2 digits with leading zeros. '01' to '31'
- D Day of the week, textual, 3 letters. 'Fri'
- F Month, textual, long. 'January'
- h Hour, 12-hour format. '01' to '12'
- H Hour, 24-hour format. '00' to '23'
- i Minutes. '00' to '59'
- l Day of the week, textual, long. 'Friday'
- m Month, 2 digits with leading zeros. '01' to '12'
- M Month, textual, 3 letters. 'Jan'
- n Month without leading zeros. '1' to '12'
- s Seconds, 2 digits with leading zeros. '00' to '59'
- U Seconds since the Unix Epoch (January 1 1970 00:00:00 UTC)
- y Year, 2 digits. '99'
- Y Year, 4 digits. '1999'
iris.date(new Date(),"ymd");
iris.date(1331954654564,"d/m/y h:i:s"); // "17/03/12 04:24:14"
iris.date("Thu Feb 14 2013 12:42:49 GMT+0100 (CET)", "d-m-Y"); // "14-02-2013"
Since: v0.5.0
Formats a number according to the current locale or config
values.
See Language & Regional for more information.
Default config
value are:
{
formatPos: "n",
formatNeg: "- n",
decimal: ".",
thousand: ",",
precision: 2
}
e.g. :
iris.locale(
"es_ES", {
number : {
decimal: ",",
thousand: ".",
precision: 2
}
}
);
iris.number(5600.899); // "5.600,90"
iris.number(5600.899, { precision: 0 }); // "5,601"
iris.number(5600.899, {
decimal: ".",
thousand: ",",
precision: 1
}); // "5,600.9"
Since: v0.5.0
Formats a amount according to the current locale or config
values.
See Language & Regional for more information.
Default config
value are:
{
formatPos: "sn",
formatNeg: "(sn)",
symbol : "$"
}
e.g. :
iris.locale(
"es_ES", {
currency : {
formatPos: "n s",
formatNeg: "- n s",
decimal: ",",
thousand: ".",
precision: 2
}
}
);
iris.currency(5600.899); // "5.600,90 €"
iris.currency(-5600.899); // "- 5.600,90 €"
iris.currency(5600.899, { symbol : "" }); // "5.600,90"
Since: v0.5.1
Returns an object with the browser information using user-agent.
iris.log( iris.browser() );
Since: v0.5.0
Triggers an event.
See iris.on
and iris.off
for more details.
iris.notify("my-event", {param : value});
iris.notify("my-event");
Since: v0.5.0
Adds an event listener.
See iris.notify
and iris.off
for more details.
iris.on("my-event", callback);
Since: v0.5.0
Removes an event listener.
See iris.notify
and iris.on
for more details.
If callback is not specified, all callback are removed.
iris.off("my-event", callback);
iris.off("my-event"); // remove all callbacks
Since: v0.5.0
Removes a collection of event listeners.
iris.destroyEvents("my-event", [callback1, callback2]);
Since: v0.5.0
Adds an event listener associated with a component. When the component is destroyed, the listener will be deleted.
For more details, see iris.on
.
self.on("my-event", callback);
Since: v0.5.0
Removes an event listener.
See iris.off
for more details.
Since: v0.5.0
Removes an event listener.
See iris.notify
for more details.
Since: v0.5.0
EventId fired before do a navigation.
iris.on(iris.BEFORE_NAVIGATION, function () {
iris.log("before navigation : " + document.location.hash)
});
Since: v0.5.0
EventId fired after do a navigation.
iris.on(iris.AFTER_NAVIGATION, function () {
iris.log("after navigation : " + document.location.hash)
});
Since: v0.5.0
EventId fired when a resource ajax call fails.
iris.on(iris.RESOURCE_ERROR, function (request, textStatus, errorThrown) {
iris.log("resource error", request, textStatus, errorThrown);
});
Since: v0.5.0
Translates a text using the locale.
// Add the translations
iris.translations("es_ES", {GREETING : "Saludos"})
iris.translate("GREETING", "es_ES");
iris.translate("GREETING"); // Using default locale ( iris.locale() )
If no locale is passed, Iris will use the default locale.
Since: v0.5.0
Adds translations in a particular language. This method can be called multiple times with the same language.
terms: Object containing the definitions in format text: definition. It admits a multi level hierarchy. See example.
file: Path to a file with the terms definitions in JSON format.
Object with two attributes (success and error) containing the functions called after retrieve the terms.
iris.translations("en_US", {
GREETING: "Hi!",
GREETINGS: {
MORNING: "Good Morning",
AFTERNOON: "Good Afternoon",
NIGHT: "Good Night"
}
});
The translations can be in a JSON file. The call is asynchronous.
iris.translations("fr_FR", "./lang_FR.json", {"success" : onFRSuccess, "error" : onFRError });
Since: v0.5.0
Defines or gets the locale format. You can use the available locales.
//Example of regional definition. Sets de locale to "en_US" if locale is not set:
iris.locale(
"en_US", {
dayNames: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
monthNames: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
dateFormat: "m/d/Y h:i:s",
currency: {
formatPos: "s n",
formatNeg: "(s n)",
decimal: ".",
thousand: ",",
precision: 2,
symbol: "$"
},
number : {
decimal: ".",
thousand: ",",
precision: 2
}
}
);
//To set the locale
iris.locale("en_US");
//To get the current locale
var locale = iris.locale();
Since: v0.5.0
Gets a regional value acording to the setting locale.
If label is not passed, returns all the regional definition.
iris.locale("dayNames");
Since: v0.5.1
Load the components using the paths
array parameter. When all files are loaded, executes the callback
function.
You can load and use iris resources before call to the iris.welcome
function, eg:
iris.path = {
user_resource : "resource/user.js",
welcome : "screen/welcome.js"
};
iris.include([iris.path.user_resource], function () {
iris.resource(iris.path.user_resource).checkUserInSession().done(loginDone).fail(loginFail);
});
function loginDone () {
iris.welcome(iris.path.welcome);
}
function loginFail () {
alert("forbidden");
}
Since: v0.5.0
Establishes and navigates to the Welcome screen component.
iris.welcome("screen/welcome.js");
Or
iris.welcome(iris.path.welcome.js);
Since: v0.5.0
Navigates to a Screen Component.
iris.navigate("screen/help");
iris.navigate(iris.path.help.js);
Since: v0.5.0
Defines a Screen component.
iris.screen(
function (self) {
//Called once when the Component is created
self.create = function () {
self.tmpl(iris.path.help.html);
};
//Called when the Component is showed.
self.awake = function () {
...
};
//Called when the component is hidden because you navigate to another Screen
self.sleep = function () {
...
};
//Called before hiding component.
//If the method returns false, the navigation is interrupted and not hidden nor self.seelp method is called
//This method only is applied to the Screens components
self.canSleep = function () {
...
};
//Called when the component is destroyed
self.destroy = function () {
...
};
}, iris.path.help.js
);
Since: v0.5.0
Destroys a Screen component.
iris.destroyScreen(iris.path.help.js);
Since: v0.5.0
Defines an UI Component.
iris.ui(function(self){...});
See iris.screen
for more details.
Since: v0.5.0
Loads the template in memory and associates it to a path.
iris.tmpl("screen/welcome.html","<div>...</div>");
See self.tmpl
for more details.
Since: v0.5.0
Defines or creates a Resource Component.
//To define
iris.resource(function(self){
//Some RESTful methods
self.load = function (id) {
return self.get("service/book/" + id);
};
self.create = function (params) {
return self.post("service/book", params);
};
self.update = function (id, params) {
return self.put("service/book/" + id, params);
};
self.remove = function (id) {
return self.del("service/book/" + id);
};
}, iris.path.resource.js);
//To create
iris.resource(iris.path.resource.js);
Since: v0.5.0
Gets o sets a value attribute.
//To set
self.setting("attribute_name", {...});
//To get
var attribute_value = self.setting("attribute_name");
Since: v0.5.0
Sets multiples and complex attributes values.
self.settings({ person: { name:"test name"}, money: -67890.678, region: { country: "country test" }});
var attribute_value = self.setting("person.name");
Since: v0.5.0
Loads the template of the component into the DOM.
This method must be called in the self.create method of the Component.
Example:
self.tmpl(iris.path.ui.login.html, {"name":"John"}, self.APPEND);
The parameters will be replaced in the template where ##parameter_name## is found.
<p>The name is ##name##</p>
mode: When self.APPEND or self.PREPEND are passed as the third parameter, the template container will not be replaced with the template, otherwise the container will be replaced by the template. The default mode is self.REPLACE.
Since: v0.5.0
Gets the JQuery object whose data-id matches with the param. If no data-id is passed, the JQuery root DOM node will be returned.
<p data-id="paragraph">The name is John</p>
self.get("paragraph").text("Anna");
Since: v0.5.0
Replaces in the template the object passed as parameter. The text of the DOM elements that have an data-model attribute that match some attribute of the object passed, will be replaced.
self.inflate({date: new Date()});
<span data-model="date">Not set yet</span>
Since: v0.5.0
Create a new UI Component and replaces or adds it to the container.
Example:
In the template of the parent:
...
<div data-id="ui_container"></div>
...
In the presenter of the parent:
...
self.ui("ui_container", iris.path.ui.my_ui.js, {name: "John"}, self.APPEND);
//The name parameter may be recovered in my_ui's presenter with the *self.setting* method.
...
For help about the templateMode parameter see self.tmpl method.
Since: v0.5.0
Destroy the UI component. If ui_component
is not specified, destroy the current UI (auto-destroy).
var my_ui = self.ui("ui_container", iris.path.ui.my_ui.js);
self.destroyUI(my_ui);
// Auto-destroy
self.destroyUI();
Since: v0.5.0
Destroy all the UI in a container.
var my_ui = self.ui("ui_container", iris.path.ui.my_ui.js);
self.destroyUIs("ui_container");
### iris.UI Class Inherit methods from Component, Settable & Event classes
Since: v0.5.0
Sets the template mode. This method must be called before the tmpl.method.
The possible values are:
self.APPEND
: Adds the UI to as the last element in the container.self.PREPEND
: Adds the UI to as the first element in the container.self.REPLACE
: Replace the container with the UI template. This is the default behavior.
### iris.Screen Class Inherit methods from Component, Settable & Event classes
Since: v0.5.0
Registers Screens and allows to navigate to them. This method can be called once for each component.
self.screens("screens", [
["home", iris.path.home.js],
["help", iris.path.help.js]
]);
//The first parameter is the data-id attribute of the container
### iris.Resource Class Inherit methods from Settable class
Since: v0.5.0
Perform an asynchronous HTTP (Ajax) request of type GET
.
Returns a jQuery jqXHR object.
self.get(path).done(function() {
alert("done");
}).fail(function() {
alert("fail");
});
Since: v0.5.0
Perform an asynchronous HTTP (Ajax) request of type POST
.
Returns a jQuery jqXHR object.
self.post(path).done(function() {
alert("done");
}).fail(function() {
alert("fail");
});
Since: v0.5.0
Perform an asynchronous HTTP (Ajax) request of type PUT
.
Returns a jQuery jqXHR object.
self.put(path).done(function() {
alert("done");
}).fail(function() {
alert("fail");
});
Since: v0.5.0
Perform an asynchronous HTTP (Ajax) request of type DEL
.
Returns a jQuery jqXHR object.
self.del(path).done(function() {
alert("done");
}).fail(function() {
alert("fail");
});