[Library] mobl

Source: mobl.mobl

Types

Functions

sleep(ms : Num) : void

Sleeps for ms milliseconds, then continues execution:

Example:

doThis();
sleep(1000); // Sleep 1s
doSomethingElse();

repeat(ms : Num, fn : Callback) : void

Repeat something every ms milliseconds, ad infinitum.

Example:

// Call syncAll() every second
repeat(1000, {
  syncAll();
});

now() : DateTime

Returns the current date and time.

Example:

var t = now();

parseNum(s : String) : Num

Parses a string and turns it into a number:

Example:

var n = parseNum("10");
n // -> 10

log(o : Object) : void

Logs to the browser's Javascript console, useful for debugging.

Example:

log("Here!");

alert(o : Object) : void

Pops up an alert dialog box.

Example:

alert("Surprise!");

add(e : Object) : void

Adds an object to the database. add only needs to be called on newly instantiated entity objects once. Once they are added, they are tracked for life.funny quotes

Example:

var t = Task();
add(t);

remove(e : Object) : void

Removes an object from the database.

Example:

remove(t);

resetDatabase() : void

Resets the database (drops all tables and data). Best used in combination with reload() to reload the page and recreate tables.

Example:

resetDatabase();
reload();

reload() : void

Reloads the application (browser refresh).

Example:

reload();

formatDate(d : DateTime) : String

Produces a nice string representation of a date using terms like "just now", "2 hours ago" and so on.

Example:

formatDate(now()) // -> "just now"

openUrl(url : String) : void

Redirects the user's browser to url.

Example:

openUrl("http://bit.ly/1AHm7r");

range(from : Num, to : Num) : Array<Num>

Generates an array of numbers from from to to. Useful for foreach loops.

Example:

// logs 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 to the console
foreach(n in range(0, 10)) {
   log(n);
}

random(max : Num) : Num

Generates a random number between 0 and max.

Example:

random(100) // -> e.g. 42

isIphone() : Bool

Returns whether this application is running on an iPhone.

Example:

isIphone() // -> true

isIpad() : Bool

Returns whether this application is running on an iPad.

Example:

isIpad() // -> true

isAndroid() : Bool

Returns whether this application is running on an Android phone.

Example:

isAndroid() // -> true

isLandscape() : Bool

Returns whether the device is currently in landscape mode (determined by comparing the browser's window.innerWidth to window.innerHeight).

Example:

isLandscape() // -> true

isPortrait() : Bool

Returns whether the device is currently in portrait mode (determined by comparing the browser's window.innerWidth to window.innerHeight).

Example:

isPortrait() // -> false

isTouchDevice() : Bool

Returns whether the application is run on a touch capable device.

Example:

isTouchDevice() // -> true

$(sel : String) : JQuery

Performs a JQuery query and returns results as a JQuery object.

Example:

// turns background black
$("body").css("background-color", "black"); 

_(key : String, placeholders : [Object] = []) : String

Internationalize a string. Uses language bundle, fetched using fetchLanguageBundle and returns the internationalize version, or the key string if no internationalized version of the string has been found.

Example:

_("Back") // -> "Terug"
_("Hello, %%", [user.name]) // -> "Hallo, Zef"

fetchLanguageBundle(path : String) : void

Loads the language bundle located at path. A language bundle has a JSON format.

Example english.json:

{"Back": "Terug",
 "Hello, %%": "Hallo, %%"}

Example use:

resource english.json // make sure it's copied to output
screen root() {
   script {
     fetchLanguageBundle("english.json");
   }
   var name = "Zef"
   ...
   label(_("Hello, %%", [name]))
}

httpRequest(url : String, method : String = "GET", encoding : String = "json", data : String = null, mapper : Function1<?,?> = dummyMapper) : Dynamic

Request a particular url using method method with data in its body, where the result is encoded as encoding (either "json", "text", "xml" or "jsonp"). A mapper can be defined to map the resulting data to the required type.

Example:

var text = httpRequest("/about.txt", encoding="text");

Example 2:

var result = httpRequest("/task/" + t.id, method="POST",
                         data=JSON.stringify(t));
if(result.status == "ok") {
  ...
}

Controls

Global Variables

window

An instance of Window representing the browser window.

Example:

window.innerHeight // -> 300
mobl.txt · Last modified: 2013/10/01 02:28 (external edit)