API-Version: 1.9

script

In every script the variable script refers to the encapsulating function.

Source:

Members

<static, constant> path

The path of the script

Source:

Methods

<static> debug(params|Function)

Print debug messages. Basically the same as io.debug but prints some additional information.

Parameters:
Name Type Description
params|Function Object | Function

Parameters passed to io.debug or a function to debug, see also Function

Source:
Example
 
script.debug({ message : "foobar" });

var myFunction = function() {
     ...
};

bind("xx", script.debug(myFunction));

// Equivalent to 
bind("xx", myFunction.debug(script));

<static> deletePrivate(object, key) → {Object}

Deletes a private property from an object previously set with setPrivate and returns the previously set property if any

Parameters:
Name Type Description
object Object

The object on which the value was set

key String

The property name

Source:
Returns:

The private value

Type
Object

<static> generateId() → {String}

Generates a unique id. Successive calls will generate new ids.

Source:
Returns:

A unique id

Type
String

<static> getPrivate(object, key) → {Object}

Gets a private property of an object previously set with setPrivate

Parameters:
Name Type Description
object Object

The object on which the value was set

key String

The property name

Source:
Returns:

The private value

Type
Object

<static> include(relPath, global) → {Object}

Includes a script, same as include but the path must be relative to the including script's path.

Parameters:
Name Type Description
relPath String

The relative path of the script

global Boolean

Whether to inject the script into the global scope

Source:
Returns:

The object returned from the included script

Type
Object

<static> own(objects) → {Array}

Own handles returned from timer.start, Signal.connect and bind or other objects that implement a remove function.

Parameters:
Name Type Description
objects Objects...

Some objects that implement a remove function

Source:
Returns:

The arguments accumulated to an array

Type
Array
Example
 
script.own(
     timer.start(1000, timerCallback), 
     bind.start("shortcut", bindCallback), 
     Signal.connect("navigation", navigationCallback)
);

<static> removeHandles()

Removes all handles owned by this script

Source:
Example
 
script.own(
     bind.start("shortcut", bindCallback), 
     Signal.connect("navigation", navigationCallback)
);
bind(null, function() {
     script.removeHandles();
}, "stopscript");

<static> setPrivate(object, key, value)

Convenience function to set a private property on an object that doesn’t conflict with properties set in other scripts. It uses a random unique id to set the property, so the property can most likely only be retrieved with getPrivate. This is mostly useful for objects derived from GObject since GObjects are shared between all scripts.

Parameters:
Name Type Description
object Object

The object whichs property will be set

key String

The property name

value Object

The value to set

Source:
Example
 
signals.connect("loadFinished", function(wv) {
     // would conflict if another script also sets foo on the same webview
     wv.foo = "bar" 
     // secure, won't conflict with other scripts
     script.setPrivate(wv, "foo", "bar");
});